File: DataSourceReferenceTest.java

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (685 lines) | stat: -rw-r--r-- 28,539 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
/*

   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.DataSourceReferenceTest

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */

package org.apache.derbyTesting.functionTests.tests.jdbcapi;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.spi.ObjectFactory;
import junit.framework.Test;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.BaseTestSuite;
import org.apache.derbyTesting.junit.J2EEDataSource;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.JDBCDataSource;
import org.apache.derbyTesting.junit.TestConfiguration;


/**
 * Test obtaining a <code>javax.naming.Reference</code> from a Derby data
 * source and recreating a Derby data source from it.
 * <p>
 * Tests that the recreated value has the same value for all the properties
 * the data source supports. The list of properties is obtained
 * dynamically from the getter methods that return int, String, boolean,
 * short and long. Should Derby data sources support any other bean
 * property types then this test should be modified to pick them up and
 * handle them. The test will fail when such a property is added.
 * <p>
 * Default values of the properties are also tested. Default and set
 * values of the properties must be specified by creating a data source
 * descriptor.
 * <p>
 * At no point does this test attempt to connect using these data sources.
 */
public class DataSourceReferenceTest
        extends BaseJDBCTestCase {

    /** Lookup constant for the descriptor array. */
    private static final int BASE_DS = 0;
    /** Lookup constant for the descriptor array. */
    private static final int POOL_DS = 1;
    /** Lookup constant for the descriptor array. */
    private static final int XA_DS = 2;

    /** Descriptor for the basic embedded data source. */
    private static final DataSourceDescriptor BASE_EMBEDDED_DS =
            new DataSourceDescriptor("Basic embedded data source");

    static {
        BASE_EMBEDDED_DS.addProperty("attributesAsPassword", "true", "false");
        BASE_EMBEDDED_DS.addProperty("connectionAttributes",
                                     "XX_connectionAttributes_2135");
        BASE_EMBEDDED_DS.addProperty("createDatabase", "create");
        BASE_EMBEDDED_DS.addProperty("dataSourceName",
                                     "XX_dataSourceName_1420");
        BASE_EMBEDDED_DS.addProperty("databaseName", "XX_databaseName_1206");
        BASE_EMBEDDED_DS.addProperty("description", "XX_description_1188");
        BASE_EMBEDDED_DS.addProperty("loginTimeout", "1280", "0");
        BASE_EMBEDDED_DS.addProperty("password", "XX_password_883");
        BASE_EMBEDDED_DS.addProperty("shutdownDatabase", "shutdown");
        BASE_EMBEDDED_DS.addProperty("user", "XX_user_447");
    }

    /** Descriptor for the basic client data source. */
    private static final DataSourceDescriptor BASE_CLIENT_DS =
            new DataSourceDescriptor("Basic client data source");

    static {
        // Properties with default values
        BASE_CLIENT_DS.addProperty("loginTimeout", "1280", "0");
        BASE_CLIENT_DS.addProperty("portNumber", "1070", "1527");
        BASE_CLIENT_DS.addProperty("retrieveMessageText", "false", "true");
        BASE_CLIENT_DS.addProperty("securityMechanism", "1851", "4");
        BASE_CLIENT_DS.addProperty("serverName", "tmpHostName", "localhost");
        BASE_CLIENT_DS.addProperty("ssl", "basic", "off");
        BASE_CLIENT_DS.addProperty("user", "XX_user_447", "APP");
        // Properties without default values.
        BASE_CLIENT_DS.addProperty("connectionAttributes",
                                   "XX_connectionAttributes_2135");
        BASE_CLIENT_DS.addProperty("createDatabase", "create");
        BASE_CLIENT_DS.addProperty("databaseName", "XX_databaseName_1206");
        BASE_CLIENT_DS.addProperty("dataSourceName", "XX_dataSourceName_1420");
        BASE_CLIENT_DS.addProperty("description", "XX_description_1188");
        BASE_CLIENT_DS.addProperty("password", "XX_password_883");
        BASE_CLIENT_DS.addProperty("shutdownDatabase", "shutdown");
        BASE_CLIENT_DS.addProperty("traceFile", "XX_traceFile_911");
        BASE_CLIENT_DS.addProperty("traceFileAppend", "true", "false");
        BASE_CLIENT_DS.addProperty("traceLevel", "1031", "-1");
        BASE_CLIENT_DS.addProperty("traceDirectory", "XX_traceDirectory_1476");
    }

    /** Descriptor for the client connection pool data source. */
    private static final DataSourceDescriptor POOL_CLIENT_DS =
            new DataSourceDescriptor("Connection pool client data source",
                                     BASE_CLIENT_DS);

    static {
        POOL_CLIENT_DS.addProperty("maxStatements", "10", "0");
    }

    /**
     * Creates a new fixture.
     *
     * @param name fixture name
     */
    public DataSourceReferenceTest(String name) {
        super(name);
    }

    /**
     * Creates a suite with tests for both embedded and client data sources.
     *
     * @return A suite with the appropriate tests.
     */
    public static Test suite() {
       Test suite;
       if (JDBC.vmSupportsJSR169() || !JDBC.vmSupportsJNDI()) {
            // Referenceable is not supported with JSR169 or without JNDI
            suite = new BaseTestSuite(
                    "DatasourceReferenceTest cannot run with JSR169");
        } else {
            suite = TestConfiguration.defaultSuite(
                                                DataSourceReferenceTest.class);
        }
       return suite;
    }

    /**
     * Tests a data source, with focus on serialization/deserialization.
     * <p>
     * For each data source, the following actions are performed:
     * <ol> <li>Create an empty data source from the class name.
     *      <li>Discover and validate the bean property list.
     *      <li>Create a reference and recreate the data source.
     *      <li>Compare the original and the empty recreated data source.
     *      <li>Serialize the data source and recreate.
     *      <li>Compare the original and the deserialized data source.
     *      <li>Set a value for every property of the data source.
     *      <li>Create a reference and recreate the data source.
     *      <li>Compare the populated original and the recreated data source.
     *      <li>Serialize the populated data source and recreate.
     *      <li>Compare the populated original and the deserialized data source.
     * </ol>
     *
     * @throws Exception on a wide variety of error conditions...
     */
    public void testDataSourceReference()
            throws Exception {
        DataSourceDescriptor[] descriptors;
        if (usingDerbyNetClient()) {
            // Specify client data source descriptors.
            descriptors = new DataSourceDescriptor[] {
                BASE_CLIENT_DS, // Base
                POOL_CLIENT_DS, // Pool
                BASE_CLIENT_DS  // XA
            };
        } else {
            // Specify embedded data source descriptors.
            descriptors = new DataSourceDescriptor[] {
                BASE_EMBEDDED_DS, // Base
                BASE_EMBEDDED_DS, // Pool
                BASE_EMBEDDED_DS  // XA
            };
        }
        // Test basic data source.
        String className = JDBCDataSource.getDataSource().getClass().getName();
        println("Testing base data source: " + className);
        assertDataSourceReference(descriptors[BASE_DS], className);

        // Test connection pool data source.
        className =
              J2EEDataSource.getConnectionPoolDataSource().getClass().getName();
        println("Testing connection pool data source: " + className);
        assertDataSourceReference(descriptors[POOL_DS], className);

        // Test XA data source.
        className = J2EEDataSource.getXADataSource().getClass().getName();
        println("Testing XA data source: " + className);
        assertDataSourceReference(descriptors[XA_DS], className);
    }


    /**
     * Performs the test sequence in the data source.
     *
     * @param dsDesc data source descriptor
     * @param className class name of the data source
     * @throws Exception on a wide variety of error conditions...
     *
     * @see #testDataSourceReference
     */
    private void assertDataSourceReference(
                                        DataSourceDescriptor dsDesc,
                                        String className)
        throws Exception {
        // Instantiate a new data source object and get all its properties.
        Class<?> clazz = Class.forName(className);
        Object dsObj = clazz.getConstructor().newInstance();
        String[] properties = getPropertyBeanList(dsObj);
        // Validate property set (existence and naming).
        assertDataSourceProperties(dsDesc, properties);
        // Test recreating the data source
        assertDataSourceReferenceEmpty(dsDesc, className);
        assertDataSourceReferencePopulated(dsDesc, className);
    }

    /**
     * Asserts that the properties that are in the data source descriptor are
     * found in the list of data source properties, and that the data source
     * does not contain properties that are not in the descriptor.
     * <p>
     * No property values are verified in this assert method.
     *
     * @param dsDesc data source descriptor
     * @param properties list of actual data source properties
     */
    private void assertDataSourceProperties(
                                        DataSourceDescriptor dsDesc,
                                        String[] properties) {
        println("Testing data source bean properties.");
        // Validate the identified property names.
        for (int i=0; i < properties.length; i++) {
            assertTrue("Property '" + properties[i] + "' not in descriptor '" +
                    dsDesc.getName() + "'",
                    dsDesc.hasProperty(properties[i]));
        }
        // Check that all keys defined by the descriptor is found, and that
        // there is only one of each in the data source property list.
        Iterator descPropIter = dsDesc.getPropertyIterator();
        while (descPropIter.hasNext()) {
            String descProp = (String)descPropIter.next();
            boolean match = false;
            // Iterate through all the data source properties.
            for (int i=0; i < properties.length; i++) {
                if (properties[i].equals(descProp)) {
                    if (match) {
                        fail("Duplicate entry '" + descProp + "' in data " +
                                "source property list");
                    }
                    // Don't break, continue to look for duplicates.
                    match = true;
                }
            }
            assertTrue("Property '" + descProp + "' not found in data source " +
                    "property list", match);
        }
        // Check if the expected number of properties are found.
        // Do this last to hopefully get a more descriptive failure
        // message which includes the property name above.
        assertEquals(dsDesc.getPropertyCount(), properties.length);
    }

    /**
     * Make sure it is possible to create a new data source using
     * <code>Referencable</code>, that the new instance has the correct
     * default values set for the bean properties and finally that the
     * data source can be serialized/deserialized.
     *
     * @param dsDesc data source descriptor
     * @param className data source class name
     * @throws Exception on a wide variety of error conditions...
     */
    private void assertDataSourceReferenceEmpty(DataSourceDescriptor dsDesc,
                                                String className)
            throws Exception {
        println("Testing recreated empty data source.");
        // Create an empty data source.
        Class<?> clazz = Class.forName(className);
        Object ds = clazz.getConstructor().newInstance();
        Referenceable refDs = (Referenceable)ds;
        Reference dsAsReference = refDs.getReference();
        String factoryClassName = dsAsReference.getFactoryClassName();
        clazz = Class.forName(factoryClassName);
        ObjectFactory factory =
            (ObjectFactory) clazz.getConstructor().newInstance();
        Object recreatedDs =
            factory.getObjectInstance(dsAsReference, null, null, null);
        // Empty, recreated data source should not be the same as the one we
        // created earlier on.
        assertNotNull("Recreated datasource is <null>", recreatedDs);
        assertNotSame(recreatedDs, ds);
        compareDataSources(dsDesc, ds, recreatedDs, true);

        // Serialize and recreate data source with default values.
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(ds);
        oos.flush();
        oos.close();
        ByteArrayInputStream bais =
                new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        recreatedDs = ois.readObject();
        compareDataSources(dsDesc, ds, recreatedDs, true);
    }

    /**
     * Make sure it is possible to recreate and serialize/deserialize a
     * populated data source.
     * <p>
     * Populated means the various bean properties have non-default
     * values set.
     *
     * @param dsDesc data source descriptor
     * @param className data source class name
     * @throws Exception on a wide variety of error conditions...
     */
    private void assertDataSourceReferencePopulated(
                                                DataSourceDescriptor dsDesc,
                                                String className)
            throws Exception {
        println("Testing recreated populated data source.");
        Class<?> clazz = Class.forName(className);
        Object ds = clazz.getConstructor().newInstance();
        // Populate the data source.
        Iterator propIter = dsDesc.getPropertyIterator();
        while (propIter.hasNext()) {
            String property = (String)propIter.next();
            String value = dsDesc.getPropertyValue(property);
            Method getMethod = getGet(property, ds);
            Method setMethod = getSet(getMethod, ds);
            Class paramType = getMethod.getReturnType();

            if (paramType.equals(Integer.TYPE)) {
                setMethod.invoke(ds, new Object[] {Integer.valueOf(value)});
            } else if (paramType.equals(String.class)) {
                setMethod.invoke(ds, new Object[] {value});
            } else if (paramType.equals(Boolean.TYPE)) {
                setMethod.invoke(ds, new Object[] {Boolean.valueOf(value)});
            } else if (paramType.equals(Short.TYPE)) {
                setMethod.invoke(ds, new Object[] {Short.valueOf(value)});
            } else if (paramType.equals(Long.TYPE)) {
                setMethod.invoke(ds, new Object[] {Long.valueOf(value)});
            } else {
                fail("'" + property + "' not settable - update test!!");
            }
        }

        Referenceable refDs = (Referenceable)ds;
        Reference dsAsReference = refDs.getReference();
        String factoryClassName = dsAsReference.getFactoryClassName();
        clazz = Class.forName(factoryClassName);
        ObjectFactory factory =
            (ObjectFactory) clazz.getConstructor().newInstance();
        Object recreatedDs =
            factory.getObjectInstance(dsAsReference, null, null, null);
        // Recreated should not be same instance as original.
        assertNotSame(recreatedDs, ds);
        compareDataSources(dsDesc, ds, recreatedDs, false);

        // Serialize and recreate.
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(ds);
        oos.flush();
        oos.close();
        ByteArrayInputStream bais =
                new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        recreatedDs = ois.readObject();
        compareDataSources(dsDesc, ds, recreatedDs, false);
    }

    /**
     * Compares two data sources expected to be equal.
     * <p>
     * The data source descriptor is expected to contain both default values
     * and set values for the relevant bean properties of the data source(s).
     *
     * @param dsDesc data source descriptor
     * @param ds original data source
     * @param rds recreated data source
     * @param useDefaultsForComparison <code>true</code> if the default values
     *      should be verified, <code>false</code> if the set values should be
     *      used for verification
     * @throws Exception on a wide variety of error conditions...
     * @throws AssertionFailedError if the data sources are not equal
     */
    private void compareDataSources(DataSourceDescriptor dsDesc,
                                       Object ds, Object rds,
                                       boolean useDefaultsForComparison)
            throws Exception {
        Iterator propIter = dsDesc.getPropertyIterator();
        while (propIter.hasNext()) {
            String property = (String)propIter.next();
            Method getMethod = getGet(property, ds);

            // Obtain value from original data source, then the recreated one.
            Object dsValue = getMethod.invoke(ds, null);
            Object rdsValue = getMethod.invoke(rds, null);

            if (dsValue == null) {
                assertNull(rdsValue);
            } else {
                assertEquals(dsValue, rdsValue);
            }
            // Make sure the value is correct.
            if (useDefaultsForComparison) {
                if (dsValue != null) {
                    assertEquals("Wrong default value for '" + property + "'",
                            dsDesc.getPropertyDefault(property),
                            dsValue.toString());
                } else {
                    assertNull(dsDesc.getPropertyDefault(property));
                }
            } else if (dsValue != null) {
                    assertEquals("'" + property + "' has incorrect value",
                            dsDesc.getPropertyValue(property),
                            dsValue.toString());
            } else {
                // We got null from the data source, and we should have set all
                // values to something else than null.
                fail("Test does not handle this situation...");
            }
        }
    }

    /**
     * Obtains a list of bean properties through reflection.
     *
     * @param ds the data source to investigate
     * @return A list of bean property names.
     */
    private static String[] getPropertyBeanList(Object ds) {
        Method[] allMethods = ds.getClass().getMethods();
        ArrayList<String> properties = new ArrayList<String>();

        for (int i = 0; i < allMethods.length; i++) {
            Method method = allMethods[i];
            String methodName = method.getName();
            // Need at least getXX
            if (methodName.length() < 5 || !methodName.startsWith("get") ||
                    method.getParameterTypes().length != 0) {
                continue;
            }

            Class rt = method.getReturnType();
            if (rt.equals(Integer.TYPE) || rt.equals(String.class) ||
                    rt.equals(Boolean.TYPE) || rt.equals(Short.TYPE) ||
                    rt.equals(Long.TYPE)) {
                // Valid Java Bean property.
                // Convert name:
                //    getPassword -> password
                //    getRetrieveMessageText -> retrieveMessageText
                String beanName = methodName.substring(3,4).toLowerCase()
                        + methodName.substring(4);

                properties.add(beanName);
            } else {
                assertFalse("Method '" + methodName + "' with primitive " +
                    "return type not supported - update test!!",
                    rt.isPrimitive());
            }
        }

        return properties.toArray(new String[properties.size()]);
    }

    /**
     * Obtains the specified get method.
     *
     * @param property property/method name
     * @param ds data source object
     * @return A method object.
     *
     * @throws NoSuchMethodException if the method does not exist
     */
    private static Method getGet(String property, Object ds)
            throws NoSuchMethodException {
        String methodName =
            "get" + property.substring(0,1).toUpperCase()
            + property.substring(1);
        Method m = ds.getClass().getMethod(methodName, null);
        return m;
    }

    /**
     * Obtains the specified set method.
     *
     * @param getMethod the corresponding get method
     * @param ds data source object
     * @return A method object.
     *
     * @throws NoSuchMethodException if the method does not exist
     */private static Method getSet(Method getMethod, Object ds)
            throws NoSuchMethodException {
        String methodName = "s" + getMethod.getName().substring(1);
        Method m = ds.getClass().getMethod(
            methodName, new Class[] {getMethod.getReturnType()});
        return m;
    }

    /**
     * A class describing the bean properties of a data source.
     * <p>
     * A data source is a class implementing
     * <code>javax.sql.CommonDataSource</code>.
     * <p>
     * The data source description consists of the following:
     * <ul> <li>A list of property names.
     *      <li>A list of default values for the properties that have a default.
     *      <li>A list of set values for properties.
     * </ul>
     * In addition it has a name for convenience.
     */
    private static class DataSourceDescriptor {

        /** Name of the description. */
        private final String dsName;
        /**
         * Set values for the data source being described.
         * <p>
         * Note that the keys of this property object describe which bean
         * properties exist for the data source.
         */
        private final Properties propertyValues;
        /**
         * Default values for bean properties having a default.
         * <p>
         * Note that not all properties have a default, and the data source
         * may therefore have more properties than there entries in this
         * list of properties.
         */
        private final Properties propertyDefaults;

        /**
         * Creates a new data source description.
         *
         * @param dsName convenience name for the description/source
         */
        DataSourceDescriptor(String dsName) {
            this.dsName = dsName;
            this.propertyValues = new Properties();
            this.propertyDefaults = new Properties();
        }

        /**
         * Creates a new data source description, based off an existing
         * description.
         * <p>
         * All properties and values defined in the existing descriptor will
         * also be defined in the new descriptor.
         *
         * @param dsName convenience name for the description/source
         * @param copyFrom existing descriptor to copy properties/values from
         */
        DataSourceDescriptor(String dsName, DataSourceDescriptor copyFrom) {
            this.dsName = dsName;
            this.propertyValues = new Properties();
            this.propertyValues.putAll(copyFrom.propertyValues);
            this.propertyDefaults = new Properties(copyFrom.propertyDefaults);
            this.propertyDefaults.putAll(copyFrom.propertyDefaults);
        }

        /**
         * Returns the convenience name of this descriptor.
         *
         * @return A convenience name.
         */
        String getName() {
            return this.dsName;
        }

        /**
         * Adds a property to the description, with a value and no associated
         * default value.
         *
         * @param name property name
         * @param value property value
         * @throws NullPointerException if <code>name</code> or
         *      <code>value</code> is <code>null</code>
         */
        void addProperty(String name, String value) {
            this.propertyValues.setProperty(name, value);
        }

        /**
         * Adds a property to the description, with a value and an associated
         * default value.
         *
         * @param name property name
         * @param value property value
         * @param defaultValue default property value
         * @throws NullPointerException if <code>name</code>, <code>value</code>
         *      or <code>defaultValue</code> is <code>null</code>
         */
        void addProperty(String name, String value, String defaultValue) {
            this.propertyValues.setProperty(name, value);
            this.propertyDefaults.setProperty(name, defaultValue);
        }

        /**
         * Returns the value of the specified property.
         *
         * @param name property name
         * @return The value set for this property.
         *
         * @throws NullPointerException if <code>name</code> is
         *      <code>null</code>
         * @throws AssertionFailedError if the property name is not defined by
         *      this descriptor
         */
        String getPropertyValue(String name) {
            if (!this.propertyValues.containsKey(name)) {
                fail("Property '" + name + "' not in data source descriptor '" +
                        dsName + "'");
            }
            return this.propertyValues.getProperty(name);
        }

        /**
         * Returns the default value for the specified property.
         *
         * @param name property name
         * @return The default value if specified, <code>null<code> if a default
         *      value is not specified.
         *
         * @throws NullPointerException if <code>name</code> is
         *      <code>null</code>
         * @throws AssertionFailedError if the property name is not defined by
         *      this descriptor
         */
        String getPropertyDefault(String name) {
            if (!this.propertyValues.containsKey(name)) {
                fail("Property '" + name + "' not in data source descriptor '" +
                        dsName + "'");
            }
            return this.propertyDefaults.getProperty(name, null);
        }

        /**
         * Returns an iterator over all bean property names.
         *
         * @return An iterator.
         */
        Iterator getPropertyIterator() {
            return this.propertyValues.keySet().iterator();
        }

        /**
         * Tells if the specified property is defined by this descriptor.
         *
         * @param name property name
         * @return <code>true</code> if defined, <code>false</code> if not.
         */
        boolean hasProperty(String name) {
            return this.propertyValues.containsKey(name);
        }

        /**
         * Returns the number of bean properties defined by this descriptor.
         *
         * @return The number of bean properties.
         */
        int getPropertyCount() {
            return this.propertyValues.size();
        }
    } // End class DataSourceDescriptor
}