Class CompoundName
- All Implemented Interfaces:
-
Serializable
,Cloneable
,Comparable<Object>
,Name
public class CompoundName extends Object implements 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 separates attribute from value (e.g. "=" in "age=65")
- 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
ACompoundName
instance is not synchronized against concurrent multithreaded access. Multiple threads trying to access and modify a CompoundName
should lock the object.- Since:
- 1.3
- See Also:
Field Summary
Modifier and Type | Field | Description |
---|---|---|
protected Properties |
mySyntax |
Syntax properties for this compound name. |
Constructor Summary
Modifier | Constructor | Description |
---|---|---|
Constructs a new compound name instance by parsing the string n using the syntax specified by the syntax properties supplied. |
||
protected |
Constructs a new compound name instance using the components specified in comps and syntax. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
Name |
add |
Adds a single component at a specified position within this compound name. |
Name |
add |
Adds a single component to the end of this compound name. |
Name |
addAll |
Adds the components of a compound name -- in order -- at a specified position within this compound name. |
Name |
addAll |
Adds the components of a compound name -- in order -- to the end of this compound name. |
Object |
clone() |
Creates a copy of this compound name. |
int |
compareTo |
Compares this CompoundName with the specified Object for order. |
boolean |
endsWith |
Determines whether a compound name is a suffix of this compound name. |
boolean |
equals |
Determines whether obj is syntactically equal to this compound name. |
String |
get |
Retrieves a component of this compound name. |
Enumeration<String> |
getAll() |
Retrieves the components of this compound name as an enumeration of strings. |
Name |
getPrefix |
Creates a compound name whose components consist of a prefix of the components in this compound name. |
Name |
getSuffix |
Creates a compound name whose components consist of a suffix of the components in this compound name. |
int |
hashCode() |
Computes the hash code of this compound name. |
boolean |
isEmpty() |
Determines whether this compound name is empty. |
Object |
remove |
Deletes a component from this compound name. |
int |
size() |
Retrieves the number of components in this compound name. |
boolean |
startsWith |
Determines whether a compound name is a prefix of this compound name. |
String |
toString() |
Generates the string representation of this compound name, using the syntax rules of the compound name. |
Field Details
mySyntax
protected transient Properties mySyntax
Constructor Details
CompoundName
protected CompoundName(Enumeration<String> comps, Properties syntax)
- Parameters:
-
comps
- A non-null enumeration of the components to add. Each element of the enumeration is of class String. The enumeration will be consumed to extract its elements. -
syntax
- A non-null properties that specify the syntax of this compound name. See class description for contents of properties.
CompoundName
public CompoundName(String n, Properties syntax) throws InvalidNameException
- Parameters:
-
n
- The non-null string to parse. -
syntax
- A non-null list of properties that specify the syntax of this compound name. See class description for contents of properties. - Throws:
-
InvalidNameException
- If 'n' violates the syntax specified bysyntax
.
Method Details
toString
public String toString()
equals
public boolean equals(Object obj)
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.
hashCode
public int hashCode()
clone
public Object clone()
compareTo
public int compareTo(Object obj)
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.
- Specified by:
-
compareTo
in interfaceComparable<Object>
- Specified by:
-
compareTo
in interfaceName
- Parameters:
-
obj
- The non-null object to compare against. - Returns:
- a negative integer, zero, or a positive integer as this Name is less than, equal to, or greater than the given Object.
- Throws:
-
ClassCastException
- if obj is not a CompoundName. - See Also:
size
public int size()
isEmpty
public boolean isEmpty()
getAll
public Enumeration<String> getAll()
get
public String get(int posn)
- Specified by:
-
get
in interfaceName
- Parameters:
-
posn
- The 0-based index of the component to retrieve. Must be in the range [0,size()). - Returns:
- The component at index posn.
- Throws:
-
ArrayIndexOutOfBoundsException
- if posn is outside the specified range.
getPrefix
public Name getPrefix(int posn)
- Specified by:
-
getPrefix
in interfaceName
- Parameters:
-
posn
- The 0-based index of the component at which to stop. Must be in the range [0,size()]. - Returns:
- A compound name consisting of the components at indexes in the range [0,posn).
- Throws:
-
ArrayIndexOutOfBoundsException
- If posn is outside the specified range.
getSuffix
public Name getSuffix(int posn)
- Specified by:
-
getSuffix
in interfaceName
- Parameters:
-
posn
- The 0-based index of the component at which to start. Must be in the range [0,size()]. - Returns:
- A compound name consisting of the components at indexes in the range [posn,size()). If posn is equal to size(), an empty compound name is returned.
- Throws:
-
ArrayIndexOutOfBoundsException
- If posn is outside the specified range.
startsWith
public boolean startsWith(Name n)
Implementation note: Currently the syntax properties of n are not used when doing the comparison. They might be in the future.
- Specified by:
-
startsWith
in interfaceName
- Parameters:
-
n
- The possibly null compound name to check. - Returns:
- true if n is a CompoundName and is a prefix of this compound name, false otherwise.
endsWith
public boolean endsWith(Name n)
Implementation note: Currently the syntax properties of n are not used when doing the comparison. They might be in the future.
addAll
public Name addAll(Name suffix) throws InvalidNameException
Implementation note: Currently the syntax properties of suffix is not used or checked. They might be in the future.
- Specified by:
-
addAll
in interfaceName
- Parameters:
-
suffix
- The non-null components to add. - Returns:
- The updated CompoundName, not a new one. Cannot be null.
- Throws:
-
InvalidNameException
- If suffix is not a compound name, or if the addition of the components violates the syntax of this compound name (e.g. exceeding number of components).
addAll
public Name addAll(int posn, Name n) throws InvalidNameException
Implementation note: Currently the syntax properties of suffix is not used or checked. They might be in the future.
- Specified by:
-
addAll
in interfaceName
- Parameters:
-
n
- The non-null components to add. -
posn
- The index in this name at which to add the new components. Must be in the range [0,size()]. - Returns:
- The updated CompoundName, not a new one. Cannot be null.
- Throws:
-
ArrayIndexOutOfBoundsException
- If posn is outside the specified range. -
InvalidNameException
- If n is not a compound name, or if the addition of the components violates the syntax of this compound name (e.g. exceeding number of components).
add
public Name add(String comp) throws InvalidNameException
- Specified by:
-
add
in interfaceName
- Parameters:
-
comp
- The non-null component to add. - Returns:
- The updated CompoundName, not a new one. Cannot be null.
- Throws:
-
InvalidNameException
- If adding comp at end of the name would violate the compound name's syntax.
add
public Name add(int posn, String comp) throws InvalidNameException
- Specified by:
-
add
in interfaceName
- Parameters:
-
comp
- The non-null component to add. -
posn
- The index at which to add the new component. Must be in the range [0,size()]. - Returns:
- The updated CompoundName, not a new one. Cannot be null.
- Throws:
-
ArrayIndexOutOfBoundsException
- If posn is outside the specified range. -
InvalidNameException
- If adding comp at the specified position would violate the compound name's syntax.
remove
public Object remove(int posn) throws InvalidNameException
- Specified by:
-
remove
in interfaceName
- Parameters:
-
posn
- The index of the component to delete. Must be in the range [0,size()). - Returns:
- The component removed (a String).
- Throws:
-
ArrayIndexOutOfBoundsException
- If posn is outside the specified range (includes case where compound name is empty). -
InvalidNameException
- If deleting the component would violate the compound name's syntax.
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.naming/javax/naming/CompoundName.html