CompoundNamepublic class CompoundName extends Object implements NameThis class represents a compound name -- a name from
a hierarchical name space.
Each component in a compound name is an atomic name.
The components of a compound name are numbered. The indexes of a
compound 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 compound name has no components.
Compound Name Syntax
The syntax of a compound name is specified using a set of properties:
- jndi.syntax.direction
- Direction for parsing ("right_to_left", "left_to_right", "flat").
If unspecified, defaults to "flat", which means the namespace is flat
with no hierarchical structure.
- jndi.syntax.separator
- Separator between atomic name components.
Required unless direction is "flat".
- jndi.syntax.ignorecase
- If present, "true" means ignore the case when comparing name
components. If its value is not "true", or if the property is not
present, case is considered when comparing name components.
- jndi.syntax.escape
- If present, specifies the escape string for overriding separator,
escapes and quotes.
- jndi.syntax.beginquote
- If present, specifies the string delimiting start of a quoted string.
- jndi.syntax.endquote
- String delimiting end of quoted string.
If present, specifies the string delimiting the end of a quoted string.
If not present, use syntax.beginquote as end quote.
- jndi.syntax.beginquote2
- Alternative set of begin/end quotes.
- jndi.syntax.endquote2
- Alternative set of begin/end quotes.
- jndi.syntax.trimblanks
- If present, "true" means trim any leading and trailing whitespaces
in a name component for comparison purposes. If its value is not
"true", or if the property is not present, blanks are significant.
- jndi.syntax.separator.ava
- If present, specifies the string that separates
attribute-value-assertions when specifying multiple attribute/value
pairs. (e.g. "," in age=65,gender=male).
- jndi.syntax.separator.typeval
- If present, specifies the string that separators attribute
from value (e.g. "=" in "age=65")
These properties are interpreted according to the following rules:
-
In a string without quotes or escapes, any instance of the
separator delimits two atomic names. Each atomic name is referred
to as a component.
-
A separator, quote or escape is escaped if preceded immediately
(on the left) by the escape.
-
If there are two sets of quotes, a specific begin-quote must be matched
by its corresponding end-quote.
-
A non-escaped begin-quote which precedes a component must be
matched by a non-escaped end-quote at the end of the component.
A component thus quoted is referred to as a
quoted component. It is parsed by
removing the being- and end- quotes, and by treating the intervening
characters as ordinary characters unless one of the rules involving
quoted components listed below applies.
-
Quotes embedded in non-quoted components are treated as ordinary strings
and need not be matched.
-
A separator that is escaped or appears between non-escaped
quotes is treated as an ordinary string and not a separator.
-
An escape string within a quoted component acts as an escape only when
followed by the corresponding end-quote string.
This can be used to embed an escaped quote within a quoted component.
-
An escaped escape string is not treated as an escape string.
-
An escape string that does not precede a meta string (quotes or separator)
and is not at the end of a component is treated as an ordinary string.
-
A leading separator (the compound name string begins with
a separator) denotes a leading empty atomic component (consisting
of an empty string).
A trailing separator (the compound name string ends with
a separator) denotes a trailing empty atomic component.
Adjacent separators denote an empty atomic component.
The string form of the compound name follows the syntax described above.
When the components of the compound name are turned into their
string representation, the reserved syntax rules described above are
applied (e.g. embedded separators are escaped or quoted)
so that when the same string is parsed, it will yield the same components
of the original compound name.
Multithreaded Access
A CompoundName instance is not synchronized against concurrent
multithreaded access. Multiple threads trying to access and modify a
CompoundName should lock the object. |
Fields Summary |
---|
protected transient NameImpl | implImplementation of this compound name.
This field is initialized by the constructors and cannot be null.
It should be treated as a read-only variable by subclasses. | protected transient Properties | mySyntaxSyntax properties for this compound name.
This field is initialized by the constructors and cannot be null.
It should be treated as a read-only variable by subclasses.
Any necessary changes to mySyntax should be made within constructors
and not after the compound name has been instantiated. | private static final long | serialVersionUIDUse serialVersionUID from JNDI 1.1.1 for interoperability |
Constructors Summary |
---|
protected CompoundName(Enumeration comps, Properties syntax)Constructs a new compound name instance using the components
specified in comps and syntax. This protected method is intended to be
to be used by subclasses of CompoundName when they override
methods such as clone(), getPrefix(), getSuffix().
if (syntax == null) {
throw new NullPointerException();
}
mySyntax = syntax;
impl = new NameImpl(syntax, comps);
| public CompoundName(String n, Properties syntax)Constructs a new compound name instance by parsing the string n
using the syntax specified by the syntax properties supplied.
if (syntax == null) {
throw new NullPointerException();
}
mySyntax = syntax;
impl = new NameImpl(syntax, n);
|
Methods Summary |
---|
public javax.naming.Name | add(java.lang.String comp)Adds a single component to the end of this compound name.
impl.add(comp);
return this;
| public javax.naming.Name | add(int posn, java.lang.String comp)Adds a single component at a specified position within this
compound name.
Components of this compound name at or after the index of the new
component are shifted up by one (away from index 0)
to accommodate the new component.
impl.add(posn, comp);
return this;
| public javax.naming.Name | addAll(javax.naming.Name suffix)Adds the components of a compound name -- in order -- to the end of
this compound name.
Implementation note: Currently the syntax properties of suffix
is not used or checked. They might be in the future.
if (suffix instanceof CompoundName) {
impl.addAll(suffix.getAll());
return this;
} else {
throw new InvalidNameException("Not a compound name: " +
suffix.toString());
}
| public javax.naming.Name | addAll(int posn, javax.naming.Name n)Adds the components of a compound name -- in order -- at a specified
position within this compound name.
Components of this compound name at or after the index of the first
new component are shifted up (away from index 0)
to accommodate the new components.
Implementation note: Currently the syntax properties of suffix
is not used or checked. They might be in the future.
if (n instanceof CompoundName) {
impl.addAll(posn, n.getAll());
return this;
} else {
throw new InvalidNameException("Not a compound name: " +
n.toString());
}
| public java.lang.Object | clone()Creates a copy of this compound name.
Changes to the components of this compound name won't
affect the new copy and vice versa.
The clone and this compound name share the same syntax.
return (new CompoundName(getAll(), mySyntax));
| public int | compareTo(java.lang.Object obj)Compares this CompoundName 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.
If obj is null or not an instance of CompoundName, ClassCastException
is thrown.
See equals() for what it means for two compound names to be equal.
If two compound names are equal, 0 is returned.
Ordering of compound names depend on the syntax of the compound name.
By default, they follow lexicographical rules for string comparison
with the extension that this applies to all the components in the
compound name and that comparison of individual components is
affected by the jndi.syntax.ignorecase and jndi.syntax.trimblanks
properties, identical to how they affect equals().
If this compound name is "lexicographically" lesser than obj,
a negative number is returned.
If this compound name is "lexicographically" greater than obj,
a positive number is returned.
Implementation note: Currently the syntax properties of the two compound
names are not compared when checking order. They might be in the future.
if (!(obj instanceof CompoundName)) {
throw new ClassCastException("Not a CompoundName");
}
return impl.compareTo(((CompoundName)obj).impl);
| public boolean | endsWith(javax.naming.Name n)Determines whether a compound name is a suffix of this compound name.
A compound name 'n' is a suffix if it it is equal to
getSuffix(size()-n.size())--in other words, this
compound name ends with 'n'.
If n is null or not a compound name, false is returned.
Implementation note: Currently the syntax properties of n
are not used when doing the comparison. They might be in the future.
if (n instanceof CompoundName) {
return (impl.endsWith(n.size(), n.getAll()));
} else {
return false;
}
| public boolean | equals(java.lang.Object obj)Determines whether obj is syntactically equal to this compound name.
If obj is null or not a CompoundName, false is returned.
Two compound names are equal if each component in one is "equal"
to the corresponding component in the other.
Equality is also defined in terms of the syntax of this compound name.
The default implementation of CompoundName uses the syntax properties
jndi.syntax.ignorecase and jndi.syntax.trimblanks when comparing
two components for equality. If case is ignored, two strings
with the same sequence of characters but with different cases
are considered equal. If blanks are being trimmed, leading and trailing
blanks are ignored for the purpose of the comparison.
Both compound names must have the same number of components.
Implementation note: Currently the syntax properties of the two compound
names are not compared for equality. They might be in the future.
// %%% check syntax too?
return (obj != null &&
obj instanceof CompoundName &&
impl.equals(((CompoundName)obj).impl));
| public java.lang.String | get(int posn)Retrieves a component of this compound name.
return (impl.get(posn));
| public java.util.Enumeration | getAll()Retrieves the components of this compound name as an enumeration
of strings.
The effects of updates to this compound name on this enumeration
is undefined.
return (impl.getAll());
| public javax.naming.Name | getPrefix(int posn)Creates a compound name whose components consist of a prefix of the
components in this compound name.
The result and this compound name share the same syntax.
Subsequent changes to
this compound name does not affect the name that is returned and
vice versa.
Enumeration comps = impl.getPrefix(posn);
return (new CompoundName(comps, mySyntax));
| public javax.naming.Name | getSuffix(int posn)Creates a compound name whose components consist of a suffix of the
components in this compound name.
The result and this compound name share the same syntax.
Subsequent changes to
this compound name does not affect the name that is returned.
Enumeration comps = impl.getSuffix(posn);
return (new CompoundName(comps, mySyntax));
| public int | hashCode()Computes the hash code of this compound name.
The hash code is the sum of the hash codes of the "canonicalized"
forms of individual components of this compound name.
Each component is "canonicalized" according to the
compound name's syntax before its hash code is computed.
For a case-insensitive name, for example, the uppercased form of
a name has the same hash code as its lowercased equivalent.
return impl.hashCode();
| public boolean | isEmpty()Determines whether this compound name is empty.
A compound name is empty if it has zero components.
return (impl.isEmpty());
| private void | readObject(java.io.ObjectInputStream s)Overridden to avoid implementation dependency.
mySyntax = (Properties)s.readObject();
impl = new NameImpl(mySyntax);
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"));
}
| public java.lang.Object | remove(int posn)Deletes a component from this compound name.
The component of this compound name at position 'posn' is removed,
and components at indices greater than 'posn'
are shifted down (towards index 0) by one.
return impl.remove(posn);
| public int | size()Retrieves the number of components in this compound name.
return (impl.size());
| public boolean | startsWith(javax.naming.Name n)Determines whether a compound name is a prefix of this compound name.
A compound name 'n' is a prefix if it is equal to
getPrefix(n.size())--in other words, this compound name
starts with 'n'.
If n is null or not a compound name, false is returned.
Implementation note: Currently the syntax properties of n
are not used when doing the comparison. They might be in the future.
if (n instanceof CompoundName) {
return (impl.startsWith(n.size(), n.getAll()));
} else {
return false;
}
| public java.lang.String | toString()Generates the string representation of this compound name, using
the syntax rules of the compound name. The syntax rules
are described in the class description.
An empty component is represented by an empty string.
The string representation thus generated can be passed to
the CompoundName constructor with the same syntax properties
to create a new equivalent compound name.
return (impl.toString());
| private void | writeObject(java.io.ObjectOutputStream s)Overridden to avoid implementation dependency.
s.writeObject(mySyntax);
s.writeInt(size());
Enumeration comps = getAll();
while (comps.hasMoreElements()) {
s.writeObject(comps.nextElement());
}
|
|