59 * that component is being composed into a composite name string.
60 * Alternatively, to avoid adding escape characters as described,
61 * the entire component can be quoted using matching single quotes
62 * or matching double quotes. A single quote occurring within a double-quoted
63 * component is not considered a meta character (and need not be escaped),
64 * and vice versa.
65 *<p>
66 * When two composite names are compared, the case of the characters
67 * is significant.
68 *<p>
69 * A leading component separator (the composite name string begins with
70 * a separator) denotes a leading empty component (a component consisting
71 * of an empty string).
72 * A trailing component separator (the composite name string ends with
73 * a separator) denotes a trailing empty component.
74 * Adjacent component separators denote an empty component.
75 *
76 *<h1>Composite Name Examples</h1>
77 *This table shows examples of some composite names. Each row shows
78 *the string form of a composite name and its corresponding structural form
79 *(<tt>CompositeName</tt>).
80 *
81 <table border="1" cellpadding=3 summary="examples showing string form of composite name and its corresponding structural form (CompositeName)">
82
83 <tr>
84 <th>String Name</th>
85 <th>CompositeName</th>
86 </tr>
87
88 <tr>
89 <td>
90 ""
91 </td>
92 <td>{} (the empty name == new CompositeName("") == new CompositeName())
93 </td>
94 </tr>
95
96 <tr>
97 <td>
98 "x"
99 </td>
123 <td>{""}</td>
124 </tr>
125
126 <tr>
127 <td>"//"</td>
128 <td>{"", ""}</td>
129 </tr>
130
131 <tr><td>"/x/"</td>
132 <td>{"", "x", ""}</td>
133 </tr>
134
135 <tr><td>"x//y"</td>
136 <td>{"x", "", "y"}</td>
137 </tr>
138 </table>
139 *
140 *<h1>Composition Examples</h1>
141 * Here are some composition examples. The right column shows composing
142 * string composite names while the left column shows composing the
143 * corresponding <tt>CompositeName</tt>s. Notice that composing the
144 * string forms of two composite names simply involves concatenating
145 * their string forms together.
146
147 <table border="1" cellpadding=3 summary="composition examples showing string names and composite names">
148
149 <tr>
150 <th>String Names</th>
151 <th>CompositeNames</th>
152 </tr>
153
154 <tr>
155 <td>
156 "x/y" + "/" = x/y/
157 </td>
158 <td>
159 {"x", "y"} + {""} = {"x", "y", ""}
160 </td>
161 </tr>
162
163 <tr>
173 <td>
174 "/" + "x" = "/x"
175 </td>
176 <td>
177 {""} + {"x"} = {"", "x"}
178 </td>
179 </tr>
180
181 <tr>
182 <td>
183 "x" + "" + "" = "x"
184 </td>
185 <td>
186 {"x"} + {} + {} = {"x"}
187 </td>
188 </tr>
189
190 </table>
191 *
192 *<h1>Multithreaded Access</h1>
193 * A <tt>CompositeName</tt> instance is not synchronized against concurrent
194 * multithreaded access. Multiple threads trying to access and modify a
195 * <tt>CompositeName</tt> should lock the object.
196 *
197 * @author Rosanna Lee
198 * @author Scott Seligman
199 * @since 1.3
200 */
201
202
203 public class CompositeName implements Name {
204
205 private transient NameImpl impl;
206 /**
207 * Constructs a new composite name instance using the components
208 * specified by 'comps'. This protected method is intended
209 * to be used by subclasses of CompositeName when they override
210 * methods such as clone(), getPrefix(), getSuffix().
211 *
212 * @param comps A non-null enumeration containing the components for the new
213 * composite name. Each element is of class String.
214 * The enumeration will be consumed to extract its
215 * elements.
540 * Deletes a component from this composite name.
541 * The component of this composite name at position 'posn' is removed,
542 * and components at indices greater than 'posn'
543 * are shifted down (towards index 0) by one.
544 *
545 * @param posn The index of the component to delete.
546 * Must be in the range [0,size()).
547 * @return The component removed (a String).
548 * @exception ArrayIndexOutOfBoundsException
549 * If posn is outside the specified range (includes case where
550 * composite name is empty).
551 * @exception InvalidNameException If deleting the component
552 * would violate the name's syntax.
553 */
554 public Object remove(int posn) throws InvalidNameException{
555 return impl.remove(posn);
556 }
557
558 /**
559 * Overridden to avoid implementation dependency.
560 * @serialData The number of components (an <tt>int</tt>) followed by
561 * the individual components (each a <tt>String</tt>).
562 */
563 private void writeObject(java.io.ObjectOutputStream s)
564 throws java.io.IOException {
565 s.writeInt(size());
566 Enumeration<String> comps = getAll();
567 while (comps.hasMoreElements()) {
568 s.writeObject(comps.nextElement());
569 }
570 }
571
572 /**
573 * Overridden to avoid implementation dependency.
574 */
575 private void readObject(java.io.ObjectInputStream s)
576 throws java.io.IOException, ClassNotFoundException {
577 impl = new NameImpl(null); // null means use default syntax
578 int n = s.readInt(); // number of components
579 try {
580 while (--n >= 0) {
581 add((String)s.readObject());
|
59 * that component is being composed into a composite name string.
60 * Alternatively, to avoid adding escape characters as described,
61 * the entire component can be quoted using matching single quotes
62 * or matching double quotes. A single quote occurring within a double-quoted
63 * component is not considered a meta character (and need not be escaped),
64 * and vice versa.
65 *<p>
66 * When two composite names are compared, the case of the characters
67 * is significant.
68 *<p>
69 * A leading component separator (the composite name string begins with
70 * a separator) denotes a leading empty component (a component consisting
71 * of an empty string).
72 * A trailing component separator (the composite name string ends with
73 * a separator) denotes a trailing empty component.
74 * Adjacent component separators denote an empty component.
75 *
76 *<h1>Composite Name Examples</h1>
77 *This table shows examples of some composite names. Each row shows
78 *the string form of a composite name and its corresponding structural form
79 *({@code CompositeName}).
80 *
81 <table border="1" cellpadding=3 summary="examples showing string form of composite name and its corresponding structural form (CompositeName)">
82
83 <tr>
84 <th>String Name</th>
85 <th>CompositeName</th>
86 </tr>
87
88 <tr>
89 <td>
90 ""
91 </td>
92 <td>{} (the empty name == new CompositeName("") == new CompositeName())
93 </td>
94 </tr>
95
96 <tr>
97 <td>
98 "x"
99 </td>
123 <td>{""}</td>
124 </tr>
125
126 <tr>
127 <td>"//"</td>
128 <td>{"", ""}</td>
129 </tr>
130
131 <tr><td>"/x/"</td>
132 <td>{"", "x", ""}</td>
133 </tr>
134
135 <tr><td>"x//y"</td>
136 <td>{"x", "", "y"}</td>
137 </tr>
138 </table>
139 *
140 *<h1>Composition Examples</h1>
141 * Here are some composition examples. The right column shows composing
142 * string composite names while the left column shows composing the
143 * corresponding {@code CompositeName}s. Notice that composing the
144 * string forms of two composite names simply involves concatenating
145 * their string forms together.
146
147 <table border="1" cellpadding=3 summary="composition examples showing string names and composite names">
148
149 <tr>
150 <th>String Names</th>
151 <th>CompositeNames</th>
152 </tr>
153
154 <tr>
155 <td>
156 "x/y" + "/" = x/y/
157 </td>
158 <td>
159 {"x", "y"} + {""} = {"x", "y", ""}
160 </td>
161 </tr>
162
163 <tr>
173 <td>
174 "/" + "x" = "/x"
175 </td>
176 <td>
177 {""} + {"x"} = {"", "x"}
178 </td>
179 </tr>
180
181 <tr>
182 <td>
183 "x" + "" + "" = "x"
184 </td>
185 <td>
186 {"x"} + {} + {} = {"x"}
187 </td>
188 </tr>
189
190 </table>
191 *
192 *<h1>Multithreaded Access</h1>
193 * A {@code CompositeName} instance is not synchronized against concurrent
194 * multithreaded access. Multiple threads trying to access and modify a
195 * {@code CompositeName} should lock the object.
196 *
197 * @author Rosanna Lee
198 * @author Scott Seligman
199 * @since 1.3
200 */
201
202
203 public class CompositeName implements Name {
204
205 private transient NameImpl impl;
206 /**
207 * Constructs a new composite name instance using the components
208 * specified by 'comps'. This protected method is intended
209 * to be used by subclasses of CompositeName when they override
210 * methods such as clone(), getPrefix(), getSuffix().
211 *
212 * @param comps A non-null enumeration containing the components for the new
213 * composite name. Each element is of class String.
214 * The enumeration will be consumed to extract its
215 * elements.
540 * Deletes a component from this composite name.
541 * The component of this composite name at position 'posn' is removed,
542 * and components at indices greater than 'posn'
543 * are shifted down (towards index 0) by one.
544 *
545 * @param posn The index of the component to delete.
546 * Must be in the range [0,size()).
547 * @return The component removed (a String).
548 * @exception ArrayIndexOutOfBoundsException
549 * If posn is outside the specified range (includes case where
550 * composite name is empty).
551 * @exception InvalidNameException If deleting the component
552 * would violate the name's syntax.
553 */
554 public Object remove(int posn) throws InvalidNameException{
555 return impl.remove(posn);
556 }
557
558 /**
559 * Overridden to avoid implementation dependency.
560 * @serialData The number of components (an {@code int}) followed by
561 * the individual components (each a {@code String}).
562 */
563 private void writeObject(java.io.ObjectOutputStream s)
564 throws java.io.IOException {
565 s.writeInt(size());
566 Enumeration<String> comps = getAll();
567 while (comps.hasMoreElements()) {
568 s.writeObject(comps.nextElement());
569 }
570 }
571
572 /**
573 * Overridden to avoid implementation dependency.
574 */
575 private void readObject(java.io.ObjectInputStream s)
576 throws java.io.IOException, ClassNotFoundException {
577 impl = new NameImpl(null); // null means use default syntax
578 int n = s.readInt(); // number of components
579 try {
580 while (--n >= 0) {
581 add((String)s.readObject());
|