API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.naming. CompositeName View Javadoc
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

/*
 * @(#)CompositeName.java	1.15 05/11/17
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package javax.naming;

import java.util.Enumeration;
import java.util.Properties;

/**
 * This class represents a composite name -- a sequence of 
 * component names spanning multiple namespaces.
 * Each component is a string name from the namespace of a
 * naming system. If the component comes from a hierarchical
 * namespace, that component can be further parsed into
 * its atomic parts by using the CompoundName class.
 *<p>
 * The components of a composite name are numbered.  The indexes of a
 * composite name with N components range from 0 up to, but not including, N.
 * This range may be written as [0,N).
 * The most significant component is at index 0.
 * An empty composite name has no components.
 *<p> 
 * <h4>JNDI Composite Name Syntax</h4>
 * JNDI defines a standard string representation for composite names. This
 * representation is the concatenation of the components of a composite name
 * from left to right using the component separator (a forward 
 * slash character (/)) to separate each component. 
 * The JNDI syntax defines the following meta characters:
 * <ul>
 * <li>escape (backward slash \),
 * <li>quote characters  (single (') and double quotes (")), and
 * <li>component separator (forward slash character (/)).
 * </ul>
 * Any occurrence of a leading quote, an escape preceding any meta character,
 * an escape at the end of a component, or a component separator character 
 * in an unquoted component must be preceded by an escape character when 
 * that component is being composed into a composite name string.
 * Alternatively, to avoid adding escape characters as described,
 * the entire component can be quoted using matching single quotes
 * or matching double quotes. A single quote occurring within a double-quoted
 * component is not considered a meta character (and need not be escaped),
 * and vice versa.
 *<p>
 * When two composite names are compared, the case of the characters
 * is significant.
 *<p> 
 * A leading component separator (the composite name string begins with
 * a separator) denotes a leading empty component (a component consisting
 * of an empty string).
 * A trailing component separator (the composite name string ends with
 * a separator) denotes a trailing empty component.
 * Adjacent component separators denote an empty component.
 *<p>
 *<h4>Composite Name Examples</h4>
 *This table shows examples of some composite names. Each row shows
 *the string form of a composite name and its corresponding structural form
 *(<tt>CompositeName</tt>).
 *<p>
<table border="1" cellpadding=3 width="70%" summary="examples showing string form of composite name and its corresponding structural form (CompositeName)">

<tr>
<th>String Name</th>
<th>CompositeName</th>
</tr>

<tr>
<td>
""
</td>
<td>{} (the empty name == new CompositeName("") == new CompositeName())
</td>
</tr>

<tr>
<td>
"x"
</td>
<td>{"x"}
</td>
</tr>

<tr>
<td>
"x/y"
</td>
<td>{"x", "y"}</td>
</tr>

<tr>
<td>"x/"</td>
<td>{"x", ""}</td>
</tr>

<tr>
<td>"/x"</td>
<td>{"", "x"}</td>
</tr>

<tr>
<td>"/"</td>
<td>{""}</td>
</tr>

<tr>
<td>"//"</td>
<td>{"", ""}</td>
</tr>

<tr><td>"/x/"</td>
<td>{"", "x", ""}</td>
</tr>

<tr><td>"x//y"</td>
<td>{"x", "", "y"}</td>
</tr>
</table>  
 * <p>
 *<h4>Composition Examples</h4>
 * Here are some composition examples.  The right column shows composing
 * string composite names while the left column shows composing the
 * corresponding <tt>CompositeName</tt>s.  Notice that composing the
 * string forms of two composite names simply involves concatenating
 * their string forms together.  

<p> <table border="1" cellpadding=3 width="70%" summary="composition examples showing string names and composite names">

<tr>
<th>String Names</th>
<th>CompositeNames</th>
</tr>

<tr>
<td>
"x/y"		+ "/"	= x/y/
</td>
<td>
{"x", "y"}	+ {""}	= {"x", "y", ""}
</td>
</tr>

<tr>
<td>
""		+ "x"	= "x"
</td>
<td>
{}		+ {"x"}	= {"x"}
</td>
</tr>

<tr>
<td>
"/"		+ "x"	= "/x"
</td>
<td>
{""}		+ {"x"} = {"", "x"}
</td>
</tr>

<tr>
<td>
"x"   + ""	+ ""	= "x"
</td>
<td>
{"x"} + {}	+ {}	= {"x"}
</td>
</tr>

</table>
 *<p>
 *<h4>Multithreaded Access</h4>
 * A <tt>CompositeName</tt> instance is not synchronized against concurrent
 * multithreaded access. Multiple threads trying to access and modify a
 * <tt>CompositeName</tt> should lock the object.
 *
 * @author Rosanna Lee
 * @author Scott Seligman
 * @version 1.15 05/11/17
 * @since 1.3
 */


public class CompositeName implements Name {

    private transient NameImpl impl;
    /**
      * Constructs a new composite name instance using the components
      * specified by 'comps'. This protected method is intended to be
      * to be used by subclasses of CompositeName when they override
      * methods such as clone(), getPrefix(), getSuffix().
      *
      * @param comps A non-null enumeration containing the components for the new
      *              composite name. Each element is of class String.
      *               The enumeration will be consumed to extract its
      *               elements.
      */
    protected CompositeName(Enumeration<String> comps) {
	impl = new NameImpl(null, comps); // null means use default syntax
    }

    /**
      * Constructs a new composite name instance by parsing the string n
      * using the composite name syntax (left-to-right, slash separated).
      * The composite name syntax is described in detail in the class
      * description.
      *
      * @param	n	The non-null string to parse.
      * @exception InvalidNameException If n has invalid composite name syntax.
      */
    public CompositeName(String n) throws InvalidNameException {
	impl = new NameImpl(null, n);  // null means use default syntax
    }

    /**
      * Constructs a new empty composite name. Such a name returns true
      * when <code>isEmpty()</code> is invoked on it.
      */
    public CompositeName() {
	impl = new NameImpl(null);  // null means use default syntax
    }

    /**
      * Generates the string representation of this composite name.
      * The string representation consists of enumerating in order
      * each component of the composite name and separating
      * each component by a forward slash character. Quoting and
      * escape characters are applied where necessary according to
      * the JNDI syntax, which is described in the class description.
      * An empty component is represented by an empty string.
      *
      * The string representation thus generated can be passed to
      * the CompositeName constructor to create a new equivalent
      * composite name.
      *
      * @return	A non-null string representation of this composite name.
      */
    public String toString() {
	return impl.toString();
    }

    /**
      * Determines whether two composite names are equal.
      * If obj is null or not a composite name, false is returned.
      * Two composite names are equal if each component in one is equal
      * to the corresponding component in the other. This implies
      * both have the same number of components, and each component's
      * equals() test against the corresponding component in the other name
      * returns true.
      *
      * @param	obj	The possibly null object to compare against.
      * @return	true if obj is equal to this composite name, false otherwise.
      * @see #hashCode
      */
    public boolean equals(Object obj) {
	return (obj != null &&
		obj instanceof CompositeName &&
		impl.equals(((CompositeName)obj).impl));
    }

    /**
      * Computes the hash code of this composite name.
      * The hash code is the sum of the hash codes of individual components
      * of this composite name.
      * 
      * @return An int representing the hash code of this name.
      * @see #equals
      */
    public int hashCode() {
	return impl.hashCode();
    }


    /**
     * Compares this CompositeName with the specified Object for order.  
     * Returns a
     * negative integer, zero, or a positive integer as this Name is less
     * than, equal to, or greater than the given Object.
     * <p>
     * If obj is null or not an instance of CompositeName, ClassCastException
     * is thrown.
     * <p>
     * See equals() for what it means for two composite names to be equal.
     * If two composite names are equal, 0 is returned.
     * <p>
     * Ordering of composite names follows the lexicographical rules for
     * string comparison, with the extension that this applies to all
     * the components in the composite name. The effect is as if all the
     * components were lined up in their specified ordered and the
     * lexicographical rules applied over the two line-ups.
     * If this composite name is "lexicographically" lesser than obj,
     * a negative number is returned.
     * If this composite name is "lexicographically" greater than obj,
     * a positive number is returned.
     * @param obj The non-null object to compare against.
     *
     * @return  a negative integer, zero, or a positive integer as this Name
     *		is less than, equal to, or greater than the given Object.
     * @exception ClassCastException if obj is not a CompositeName.
     */
    public int compareTo(Object obj) {
	if (!(obj instanceof CompositeName)) {
	    throw new ClassCastException("Not a CompositeName");
	}
	return impl.compareTo(((CompositeName)obj).impl);
    }

    /**
      * Generates a copy of this composite name.
      * Changes to the components of this composite name won't
      * affect the new copy and vice versa.
      *
      * @return A non-null copy of this composite name.
      */
    public Object clone() {
	return (new CompositeName(getAll()));
    }

    /**
      * Retrieves the number of components in this composite name.
      *
      * @return	The nonnegative number of components in this composite name.
      */
    public int size() {
	return (impl.size());
    }

    /**
      * Determines whether this composite name is empty. A composite name
      * is empty if it has zero components.
      *
      * @return true if this composite name is empty, false otherwise.
      */
    public boolean isEmpty() {
	return (impl.isEmpty());
    }

    /**
      * Retrieves the components of this composite name as an enumeration
      * of strings.
      * The effects of updates to this composite name on this enumeration
      * is undefined.
      *
      * @return	A non-null enumeration of the components of
      * 	this composite name. Each element of the enumeration is of
      *		class String.
      */
    public Enumeration<String> getAll() {
	return (impl.getAll());
    }

    /**
      * Retrieves a component of this composite name.
      *
      * @param	posn	The 0-based index of the component to retrieve.
      *			Must be in the range [0,size()).
      * @return The non-null component at index posn.
      * @exception ArrayIndexOutOfBoundsException if posn is outside the
      * 	specified range.
      */
    public String get(int posn) {
	return (impl.get(posn));
    }

    /**
      * Creates a composite name whose components consist of a prefix of the
      * components in this composite name. Subsequent changes to
      * this composite name does not affect the name that is returned.
      *
      * @param	posn	The 0-based index of the component at which to stop.
      *			Must be in the range [0,size()].
      * @return	A composite name consisting of the components at indexes in
      *		the range [0,posn).
      * @exception ArrayIndexOutOfBoundsException
      *		If posn is outside the specified range.
      */
    public Name getPrefix(int posn) {
	Enumeration comps = impl.getPrefix(posn);
	return (new CompositeName(comps));
    }

    /**
      * Creates a composite name whose components consist of a suffix of the
      * components in this composite name. Subsequent changes to
      * this composite name does not affect the name that is returned.
      *
      * @param	posn	The 0-based index of the component at which to start.
      *			Must be in the range [0,size()].
      * @return	A composite name consisting of the components at indexes in
      *		the range [posn,size()).  If posn is equal to 
      * 	size(), an empty composite name is returned.
      * @exception ArrayIndexOutOfBoundsException
      *		If posn is outside the specified range.
      */
    public Name getSuffix(int posn) {
	Enumeration comps = impl.getSuffix(posn);
	return (new CompositeName(comps));
    }

    /**
      * Determines whether a composite name is a prefix of this composite name.
      * A composite name 'n' is a prefix if it is equal to
      * getPrefix(n.size())--in other words, this composite name
      * starts with 'n'. If 'n' is null or not a composite name, false is returned.
      *
      * @param	n	The possibly null name to check.
      * @return	true if n is a CompositeName and
      * 	is a prefix of this composite name, false otherwise.
      */
    public boolean startsWith(Name n) {
	if (n instanceof CompositeName) {
	    return (impl.startsWith(n.size(), n.getAll()));
	} else {
	    return false;
	}
    }

    /**
      * Determines whether a composite name is a suffix of this composite name.
      * A composite name 'n' is a suffix if it it is equal to
      * getSuffix(size()-n.size())--in other words, this
      * composite name ends with 'n'.
      * If n is null or not a composite name, false is returned.
      *
      * @param	n	The possibly null name to check.
      * @return	true if n is a CompositeName and
      * 	is a suffix of this composite name, false otherwise.
      */
    public boolean endsWith(Name n) {
	if (n instanceof CompositeName) {
	    return (impl.endsWith(n.size(), n.getAll()));
	} else {
	    return false;
	}
    }

    /**
      * Adds the components of a composite name -- in order -- to the end of
      * this composite name.
      *
      * @param suffix	The non-null components to add.
      * @return The updated CompositeName, not a new one. Cannot be null.
      * @exception InvalidNameException If suffix is not a composite name.
      */
    public Name addAll(Name suffix)
	throws InvalidNameException
    {
	if (suffix instanceof CompositeName) {
	    impl.addAll(suffix.getAll());
	    return this;
	} else {
	    throw new InvalidNameException("Not a composite name: " +
		suffix.toString());
	}
    }

    /**
      * Adds the components of a composite name -- in order -- at a specified
      * position within this composite name.
      * Components of this composite name at or after the index of the first
      * new component are shifted up (away from index 0)
      * to accommodate the new components.
      *
      * @param n 	The non-null components to add.
      * @param posn	The index in this name at which to add the new
      *			components.  Must be in the range [0,size()].
      * @return The updated CompositeName, not a new one. Cannot be null.
      * @exception InvalidNameException If n is not a composite name.
      * @exception ArrayIndexOutOfBoundsException
      *		If posn is outside the specified range.
      */
    public Name addAll(int posn, Name n)
	throws InvalidNameException
    {
	if (n instanceof CompositeName) {
	    impl.addAll(posn, n.getAll());
	    return this;
	} else {
	    throw new InvalidNameException("Not a composite name: " +
		n.toString());
	}
    }

    /**
      * Adds a single component to the end of this composite name.
      *
      * @param comp	The non-null component to add.
      * @return The updated CompositeName, not a new one. Cannot be null.
      * @exception InvalidNameException If adding comp at end of the name
      *				would violate the name's syntax.
      */
    public Name add(String comp) throws InvalidNameException {
	impl.add(comp);
	return this;
    }

    /**
      * Adds a single component at a specified position within this
      * composite name.
      * Components of this composite name at or after the index of the new
      * component are shifted up by one (away from index 0) to accommodate
      * the new component.
      *
      * @param 	comp	The non-null component to add.
      * @param	posn	The index at which to add the new component.
      *			Must be in the range [0,size()].
      * @return The updated CompositeName, not a new one. Cannot be null.
      * @exception ArrayIndexOutOfBoundsException
      *		If posn is outside the specified range.
      * @exception InvalidNameException If adding comp at the specified position
      *				would violate the name's syntax.
      */
    public Name add(int posn, String comp)
	throws InvalidNameException
    {
	impl.add(posn, comp);
	return this;
    }

    /**
      * Deletes a component from this composite name.
      * The component of this composite name at position 'posn' is removed,
      * and components at indices greater than 'posn'
      * are shifted down (towards index 0) by one.
      *
      * @param	posn	The index of the component to delete.
      *			Must be in the range [0,size()).
      * @return The component removed (a String).
      * @exception ArrayIndexOutOfBoundsException
      *		If posn is outside the specified range (includes case where
      *		composite name is empty).
      * @exception InvalidNameException If deleting the component
      *				would violate the name's syntax.
      */
    public Object remove(int posn) throws InvalidNameException{
	return impl.remove(posn);
    }

    /**
     * Overridden to avoid implementation dependency.
     * @serialData The number of components (an <tt>int</tt>) followed by
     * the individual components (each a <tt>String</tt>).
     */
    private void writeObject(java.io.ObjectOutputStream s)
	    throws java.io.IOException {
	s.writeInt(size());
	Enumeration comps = getAll();
	while (comps.hasMoreElements()) {
	    s.writeObject(comps.nextElement());
	}
    }

    /**
     * Overridden to avoid implementation dependency.
     */
    private void readObject(java.io.ObjectInputStream s)
	    throws java.io.IOException, ClassNotFoundException {
	impl = new NameImpl(null);  // null means use default syntax
	int n = s.readInt();	// number of components
	try {
	    while (--n >= 0) {
		add((String)s.readObject());
	    }
	} catch (InvalidNameException e) {
	    throw (new java.io.StreamCorruptedException("Invalid name"));
	}
    }

    /**
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
     */
    private static final long serialVersionUID = 1667768148915813118L;

/*
    // %%% Test code for serialization.
    public static void main(String[] args) throws Exception {
	CompositeName c = new CompositeName("aaa/bbb");
	java.io.FileOutputStream f1 = new java.io.FileOutputStream("/tmp/ser");
	java.io.ObjectOutputStream s1 = new java.io.ObjectOutputStream(f1);
	s1.writeObject(c);
	s1.close();
	java.io.FileInputStream f2 = new java.io.FileInputStream("/tmp/ser");
	java.io.ObjectInputStream s2 = new java.io.ObjectInputStream(f2);
	c = (CompositeName)s2.readObject();

	System.out.println("Size: " + c.size());
	System.out.println("Size: " + c.snit);
    }
*/

/*
   %%% Testing code
    public static void main(String[] args) {
	try {
	    for (int i = 0; i < args.length; i++) {
		Name name;
		Enumeration e;
		System.out.println("Given name: " + args[i]);
		name = new CompositeName(args[i]);
		e = name.getComponents();
		while (e.hasMoreElements()) {
		    System.out.println("Element: " + e.nextElement());
		}
		System.out.println("Constructed name: " + name.toString());
	    }
	} catch (Exception ne) {
	    ne.printStackTrace();
	}
    }
*/
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar