Constructors Summary |
---|
public BasicAttribute(String id)Constructs a new instance of an unordered attribute with no value.
this(id, false);
|
public BasicAttribute(String id, Object value)Constructs a new instance of an unordered attribute with a single value.
this(id, value, false);
|
public BasicAttribute(String id, boolean ordered)Constructs a new instance of a possibly ordered attribute with no value.
attrID = id;
values = new Vector();
this.ordered = ordered;
|
public BasicAttribute(String id, Object value, boolean ordered)Constructs a new instance of a possibly ordered attribute with a
single value.
this(id, ordered);
values.addElement(value);
|
Methods Summary |
---|
public boolean | add(java.lang.Object attrVal)Adds a new value to this attribute.
By default, Object.equals() is used when comparing attrVal
with this attribute's values except when attrVal is an array.
For an array, each element of the array is checked using
Object.equals().
A subclass may use schema information to determine equality.
if (isOrdered() || (find(attrVal) < 0)) {
values.addElement(attrVal);
return true;
} else {
return false;
}
|
public void | add(int ix, java.lang.Object attrVal)
if (!isOrdered() && contains(attrVal)) {
throw new IllegalStateException(
"Cannot add duplicate to unordered attribute");
}
values.insertElementAt(attrVal, ix);
|
private static boolean | arrayEquals(java.lang.Object a1, java.lang.Object a2)Determines whether two arrays are equal by comparing each of their
elements using Object.equals().
int len;
if ((len = Array.getLength(a1)) != Array.getLength(a2))
return false;
for (int j = 0; j < len; j++) {
Object i1 = Array.get(a1, j);
Object i2 = Array.get(a2, j);
if (i1 == null || i2 == null) {
if (i1 != i2)
return false;
} else if (!i1.equals(i2)) {
return false;
}
}
return true;
|
public void | clear()
values.setSize(0);
|
public java.lang.Object | clone()
BasicAttribute attr;
try {
attr = (BasicAttribute)super.clone();
} catch (CloneNotSupportedException e) {
attr = new BasicAttribute(attrID, ordered);
}
attr.values = (Vector)values.clone();
return attr;
|
public boolean | contains(java.lang.Object attrVal)Determines whether a value is in this attribute.
By default,
Object.equals() is used when comparing attrVal
with this attribute's values except when attrVal is an array.
For an array, each element of the array is checked using
Object.equals().
A subclass may use schema information to determine equality.
return (find(attrVal) >= 0);
|
public boolean | equals(java.lang.Object obj)Determines whether obj is equal to this attribute.
Two attributes are equal if their attribute-ids, syntaxes
and values are equal.
If the attribute values are unordered, the order that the values were added
are irrelevant. If the attribute values are ordered, then the
order the values must match.
If obj is null or not an Attribute, false is returned.
By default Object.equals() is used when comparing the attribute
id and its values except when a value is an array. For an array,
each element of the array is checked using Object.equals().
A subclass may override this to make
use of schema syntax information and matching rules,
which define what it means for two attributes to be equal.
How and whether a subclass makes
use of the schema information is determined by the subclass.
If a subclass overrides equals(), it should also override
hashCode()
such that two attributes that are equal have the same hash code.
if ((obj != null) && (obj instanceof Attribute)) {
Attribute target = (Attribute)obj;
// Check order first
if (isOrdered() != target.isOrdered()) {
return false;
}
int len;
if (attrID.equals(target.getID()) &&
(len=size()) == target.size()) {
try {
if (isOrdered()) {
// Go through both list of values
for (int i = 0; i < len; i++) {
if (!valueEquals(get(i), target.get(i))) {
return false;
}
}
} else {
// order is not relevant; check for existence
Enumeration theirs = target.getAll();
while (theirs.hasMoreElements()) {
if (find(theirs.nextElement()) < 0)
return false;
}
}
} catch (NamingException e) {
return false;
}
return true;
}
}
return false;
|
private int | find(java.lang.Object target)
Class cl;
if (target == null) {
int ct = values.size();
for (int i = 0 ; i < ct ; i++) {
if (values.elementAt(i) == null)
return i;
}
} else if ((cl=target.getClass()).isArray()) {
int ct = values.size();
Object it;
for (int i = 0 ; i < ct ; i++) {
it = values.elementAt(i);
if (it != null && cl == it.getClass()
&& arrayEquals(target, it))
return i;
}
} else {
return values.indexOf(target, 0);
}
return -1; // not found
|
public java.lang.Object | get()Retrieves one of this attribute's values.
By default, the value returned is one of those passed to the
constructor and/or manipulated using the add/replace/remove methods.
A subclass may override this to retrieve the value dynamically
from the directory.
if (values.size() == 0) {
throw new
NoSuchElementException("Attribute " + getID() + " has no value");
} else {
return values.elementAt(0);
}
|
public java.lang.Object | get(int ix)
return values.elementAt(ix);
|
public javax.naming.NamingEnumeration | getAll()Retrieves an enumeration of this attribute's values.
By default, the values returned are those passed to the
constructor and/or manipulated using the add/replace/remove methods.
A subclass may override this to retrieve the values dynamically
from the directory.
return new ValuesEnumImpl();
|
public javax.naming.directory.DirContext | getAttributeDefinition()Retrieves this attribute's schema definition.
This method by default throws OperationNotSupportedException. A subclass
should override this method if it supports schema.
throw new OperationNotSupportedException("attribute definition");
|
public javax.naming.directory.DirContext | getAttributeSyntaxDefinition()Retrieves the syntax definition associated with this attribute.
This method by default throws OperationNotSupportedException. A subclass
should override this method if it supports schema.
throw new OperationNotSupportedException("attribute syntax");
|
public java.lang.String | getID()
return attrID;
|
public int | hashCode()Calculates the hash code of this attribute.
The hash code is computed by adding the hash code of
the attribute's id and that of all of its values except for
values that are arrays.
For an array, the hash code of each element of the array is summed.
If a subclass overrides hashCode(), it should override
equals()
as well so that two attributes that are equal have the same hash code.
int hash = attrID.hashCode();
int num = values.size();
Object val;
for (int i = 0; i < num; i ++) {
val = values.elementAt(i);
if (val != null) {
if (val.getClass().isArray()) {
Object it;
int len = Array.getLength(val);
for (int j = 0 ; j < len ; j++) {
it = Array.get(val, j);
if (it != null) {
hash += it.hashCode();
}
}
} else {
hash += val.hashCode();
}
}
}
return hash;
|
public boolean | isOrdered()
return ordered;
|
private void | readObject(java.io.ObjectInputStream s)Overridden to avoid exposing implementation details.
s.defaultReadObject(); // read in the attrID
int n = s.readInt(); // number of values
values = new Vector(n);
while (--n >= 0) {
values.addElement(s.readObject());
}
|
public boolean | remove(java.lang.Object attrval)Removes a specified value from this attribute.
By default, Object.equals() is used when comparing attrVal
with this attribute's values except when attrVal is an array.
For an array, each element of the array is checked using
Object.equals().
A subclass may use schema information to determine equality.
// For the Java 2 platform, can just use "return removeElement(attrval);"
// Need to do the following to handle null case
int i = find(attrval);
if (i >= 0) {
values.removeElementAt(i);
return true;
}
return false;
|
public java.lang.Object | remove(int ix)
Object answer = values.elementAt(ix);
values.removeElementAt(ix);
return answer;
|
public java.lang.Object | set(int ix, java.lang.Object attrVal)
if (!isOrdered() && contains(attrVal)) {
throw new IllegalStateException(
"Cannot add duplicate to unordered attribute");
}
Object answer = values.elementAt(ix);
values.setElementAt(attrVal, ix);
return answer;
|
public int | size()
return values.size();
|
public java.lang.String | toString()Generates the string representation of this attribute.
The string consists of the attribute's id and its values.
This string is meant for debugging and not meant to be
interpreted programmatically.
StringBuffer answer = new StringBuffer(attrID + ": ");
if (values.size() == 0) {
answer.append("No values");
} else {
boolean start = true;
for (Enumeration e = values.elements(); e.hasMoreElements(); ) {
if (!start)
answer.append(", ");
answer.append(e.nextElement());
start = false;
}
}
return answer.toString();
|
private static boolean | valueEquals(java.lang.Object obj1, java.lang.Object obj2)Determines whether two attribute values are equal.
Use arrayEquals for arrays and Object.equals() otherwise.
if (obj1 == obj2) {
return true; // object references are equal
}
if (obj1 == null) {
return false; // obj2 was not false
}
if (obj1.getClass().isArray() &&
obj2.getClass().isArray()) {
return arrayEquals(obj1, obj2);
}
return (obj1.equals(obj2));
|
private void | writeObject(java.io.ObjectOutputStream s)Overridden to avoid exposing implementation details
s.defaultWriteObject(); // write out the attrID
s.writeInt(values.size());
for (int i = 0; i < values.size(); i++) {
s.writeObject(values.elementAt(i));
}
|