Package com.isode.dsapi
Class Attribute
- java.lang.Object
-
- com.isode.dsapi.Attribute
-
- All Implemented Interfaces:
java.lang.Comparable<Attribute>
,java.lang.Iterable<AttributeValue>
- Direct Known Subclasses:
AddAttribute
,DeleteAttribute
,ReplaceAttribute
public class Attribute extends java.lang.Object implements java.lang.Iterable<AttributeValue>, java.lang.Comparable<Attribute>
Representation of an attribute. An Attribute has an AttributeType and a collection of AttributeValues (which may be empty).
-
-
Field Summary
Fields Modifier and Type Field Description protected AttributeType
attrType
Attribute type (should never benull
after leaving constructor).
-
Constructor Summary
Constructors Modifier Constructor Description protected
Attribute()
Used by the native library when creating a new empty objectAttribute(AttributeType attrType)
Create an empty new Attribute object.Attribute(AttributeType attrType, AttributeValue attrValue)
Constructs an Attribute of specific type and value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addValue(AttributeValue value)
Add a value to the list of values for this Attribute.void
addValue(java.lang.String valueString)
Add a value to the list of values for this attribute.void
clearValuesList()
Clear values list.int
compareTo(Attribute oo)
Compare this Attribute with another one, returning an ordering based on syntax-specific comparisons.boolean
equals(java.lang.Object other)
Test whether two Attributes are equal according to syntax-specific comparisons: tests whether they have the same attribute type and all the same values (although perhaps in a different order).int
exactCompareTo(Attribute oo)
Compare this Attribute with another one, returning an ordering based on comparisons on the exact values (without using syntax-specific comparisons).boolean
exactEquals(java.lang.Object other)
Test whether two Attributes are exactly equal according to matching the strings, binary values or BER values exactly: tests whether they have the same attribute type and exactly the same values (although perhaps in a different order).protected void
finalize()
Releases any native structures associated with this object.java.lang.String
getAttributeName()
Returns a String representing the attribute type name.AttributeType
getAttributeType()
Returns the attribute type.Attribute
getNormalizedAttribute()
Return a new Attribute containing normalised versions of all the values contained in this Attribute.int
getSyntaxID()
Returns the integer representing the syntax ID for this Attribute.java.lang.String
getSyntaxName()
Returns a String representing the syntax for this object.AttributeValue
getValue(int pos)
Get a specific AttributeValue from the set of values associated with this Attribute.int
getValueCount()
Returns value count.boolean
hasAttributeType(AttributeType otherAttrType)
Determines if this object has a particular AttributeType.int
hashCode()
Calculate a hash-code consistent with the equals() method.boolean
hasSyntax(int syntax)
Checks if this Attribute has a particular syntax.java.util.Iterator<AttributeValue>
iterator()
Returns an iterator over the values in this Attribute.Attribute
relocate(DN... source_target_list)
If this Attribute contains DNs, and one or more of those DNs are within one of the subtrees indicated by the arguments, then those DN are relocated to the same relative location within the corresponding 'target' subtree (using DN.getRelocatedDN()), and a new Attribute is created and returned.Attribute
relocate(DN source, DN target)
If this Attribute contains DNs, and one or more of those DNs are within the subtree indicated by 'source', then they are relocated to the same relative location within the 'target' subtree (using DN.getRelocatedDN()), and a new Attribute is created and returned.java.lang.String
toString()
Returns a String representation of this Attribute.
-
-
-
Field Detail
-
attrType
protected AttributeType attrType
Attribute type (should never benull
after leaving constructor).
-
-
Constructor Detail
-
Attribute
protected Attribute()
Used by the native library when creating a new empty object
-
Attribute
public Attribute(AttributeType attrType) throws NativeLibraryException
Create an empty new Attribute object.- Parameters:
attrType
- attribute type (notnull
)- Throws:
NativeLibraryException
- if an unrecoverable error was detected by the native library
-
Attribute
public Attribute(AttributeType attrType, AttributeValue attrValue) throws NativeLibraryException, BadSyntaxException
Constructs an Attribute of specific type and value.- Parameters:
attrType
- attribute type (notnull
)attrValue
- attribute value (notnull
)- Throws:
NativeLibraryException
- if an unrecoverable error was detected by the native libraryBadSyntaxException
- if the syntax of value is not valid for this attribute.- Since:
- 16.0
-
-
Method Detail
-
finalize
protected void finalize() throws java.lang.Throwable
Releases any native structures associated with this object.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
clearValuesList
public final void clearValuesList()
Clear values list.
-
getAttributeType
public AttributeType getAttributeType()
Returns the attribute type.- Returns:
- The attribute type (not
null
).
-
hasAttributeType
public boolean hasAttributeType(AttributeType otherAttrType)
Determines if this object has a particular AttributeType.- Parameters:
otherAttrType
- an AttributeType (notnull
)- Returns:
- true if of given type, false otherwise.
-
hasSyntax
public boolean hasSyntax(int syntax) throws NativeLibraryException
Checks if this Attribute has a particular syntax.- Parameters:
syntax
- An integer representing a syntax id, as may be obtained fromDSapi.nameToSyntaxID(String)
- Returns:
- true if attribute has given syntax, false otherwise (or if syntax is an invalid syntax).
- Throws:
NativeLibraryException
- if an unrecoverable error was detected by the native library.- See Also:
getSyntaxID()
-
addValue
public final void addValue(AttributeValue value) throws BadSyntaxException, NativeLibraryException
Add a value to the list of values for this Attribute.- Parameters:
value
- AttributeValue to add. (notnull
)- Throws:
BadSyntaxException
- if the syntax of value is not valid for this attribute.NativeLibraryException
- if an unrecoverable error was detected by the native library.- See Also:
addValue(String)
-
addValue
public void addValue(java.lang.String valueString) throws BadValueException
Add a value to the list of values for this attribute. This method creates aAttributeValue
object using the appropriateAttributeType
and adds it to the list of values.- Parameters:
valueString
- a String representation of an attribute value (notnull
)- Throws:
BadValueException
- if valueString is not a valid string representation for a value of this object's AttributeType.- Since:
- 14.6
- See Also:
addValue(AttributeValue)
-
getValue
public AttributeValue getValue(int pos)
Get a specific AttributeValue from the set of values associated with this Attribute.- Parameters:
pos
- Position of value in list, which is numbered starting from zero togetValueCount()
-1.- Returns:
- the requested AttributeValue (not
null
) - Throws:
java.lang.ArrayIndexOutOfBoundsException
- if pos is out of range.NativeLibraryException
- if an unrecoverable error was detected by the native library.- See Also:
getValueCount()
-
getValueCount
public int getValueCount()
Returns value count.- Returns:
- count of how many values exist for this Attribute.
- See Also:
getValue(int)
-
getAttributeName
public java.lang.String getAttributeName() throws NativeLibraryException
Returns a String representing the attribute type name.For example, "objectclass" or "cn".
- Returns:
- the type name of the Attribute (not
null
) - Throws:
NativeLibraryException
- if an unrecoverable error was detected by the native library.- See Also:
AttributeType.getAttributeTypeName()
,AttributeType.getAlias(String)
-
getSyntaxName
public java.lang.String getSyntaxName() throws NativeLibraryException
Returns a String representing the syntax for this object. For example, "caseignorestring" or "GeneralizedTime"- Returns:
- the syntax of the Attribute (not
null
) - Throws:
NativeLibraryException
- if an unrecoverable error was detected by the native library.- See Also:
AttributeType.getSyntaxName()
,DSapi.nameToSyntaxID(String)
-
getSyntaxID
public int getSyntaxID() throws NativeLibraryException
Returns the integer representing the syntax ID for this Attribute.- Returns:
- the syntax ID of the Attribute
- Throws:
NativeLibraryException
- if an unrecoverable error was detected by the native library.- See Also:
AttributeType.getSyntaxID()
,DSapi.syntaxIDToName(int)
-
getNormalizedAttribute
public Attribute getNormalizedAttribute() throws NativeLibraryException
Return a new Attribute containing normalised versions of all the values contained in this Attribute.- Returns:
- a new attribute (not
null
). - Throws:
NativeLibraryException
- See Also:
AttributeValue.getNormalizedValue()
-
hashCode
public int hashCode()
Calculate a hash-code consistent with the equals() method.- Overrides:
hashCode
in classjava.lang.Object
- Since:
- 14.5
-
equals
public boolean equals(java.lang.Object other)
Test whether two Attributes are equal according to syntax-specific comparisons: tests whether they have the same attribute type and all the same values (although perhaps in a different order).- Overrides:
equals
in classjava.lang.Object
- Since:
- 14.5
-
compareTo
public int compareTo(Attribute oo)
Compare this Attribute with another one, returning an ordering based on syntax-specific comparisons. The lists of values in the two Attributes are temporarily sorted before comparing them to make the results consistent. This call corresponds to the Attribute.equals() method.- Specified by:
compareTo
in interfacejava.lang.Comparable<Attribute>
- Returns:
- -1: this attribute comes before the argument in the sort-order, 0: the attributes are equal, 1: this attribute comes after the argument in the sort-order
- Since:
- 14.5
-
exactEquals
public boolean exactEquals(java.lang.Object other)
Test whether two Attributes are exactly equal according to matching the strings, binary values or BER values exactly: tests whether they have the same attribute type and exactly the same values (although perhaps in a different order).- Since:
- 14.5
-
exactCompareTo
public int exactCompareTo(Attribute oo)
Compare this Attribute with another one, returning an ordering based on comparisons on the exact values (without using syntax-specific comparisons). The lists of values in the two Attributes are temporarily sorted before comparing them to make the results consistent. This call corresponds to the Attribute.exactEquals() method.- Returns:
- -1: this attribute comes before the argument in the sort-order, 0: the attributes are equal, 1: this attribute comes after the argument in the sort-order
- Since:
- 14.5
-
toString
public java.lang.String toString()
Returns a String representation of this Attribute.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation of this Attribute (not
null
).
-
iterator
public java.util.Iterator<AttributeValue> iterator()
Returns an iterator over the values in this Attribute.- Specified by:
iterator
in interfacejava.lang.Iterable<AttributeValue>
- Returns:
- an iterator that can be used to process all the
AttributeValues in this Attribute (not
null
).
-
relocate
public Attribute relocate(DN source, DN target)
If this Attribute contains DNs, and one or more of those DNs are within the subtree indicated by 'source', then they are relocated to the same relative location within the 'target' subtree (using DN.getRelocatedDN()), and a new Attribute is created and returned. Otherwise the current Attribute is returned.At the moment this only relocates DN-syntax values, but in the future it may be expanded to relocate ORNames and other types.
- Parameters:
source
- DN of base of source subtree (notnull
)target
- DN of base of target subtree (notnull
)- Returns:
- Resulting Attribute, or this if no change was necessary
- Since:
- 14.6
-
relocate
public Attribute relocate(DN... source_target_list)
If this Attribute contains DNs, and one or more of those DNs are within one of the subtrees indicated by the arguments, then those DN are relocated to the same relative location within the corresponding 'target' subtree (using DN.getRelocatedDN()), and a new Attribute is created and returned. Otherwise the current Attribute is returned.At the moment this only relocates DN-syntax values, but in the future it may be expanded to relocate ORNames and other types.
- Parameters:
source_target_list
- Array of an even number of DNs, handled in pairs. Of each pair, the first is treated as a source subtree, and the second as a target subtree. The DN is matched against source DNs in the list from the start to the end, and the first pair that it matches is the relocation that is performed. If there are no matches the DN is left unchanged. (notnull
)- Returns:
- Resulting Attribute, or this if no change was necessary
- Since:
- 15.0
-
-