org.apache.directory.shared.ldap.entry
Class DefaultServerAttribute

java.lang.Object
  extended by org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
      extended by org.apache.directory.shared.ldap.entry.DefaultServerAttribute
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Value<?>>, EntryAttribute

public final class DefaultServerAttribute
extends DefaultClientAttribute
implements EntryAttribute

A server side entry attribute aware of schema.

Version:
$Rev$, $Date$
Author:
Apache Directory Project
See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Fields inherited from class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
attributeType, id, isHR, upId, values
 
Constructor Summary
DefaultServerAttribute(AttributeType attributeType)
          Create a new instance of a EntryAttribute, without ID nor value.
DefaultServerAttribute(AttributeType attributeType, byte[]... vals)
          Create a new instance of a EntryAttribute, with some byte[] values.
DefaultServerAttribute(AttributeType attributeType, EntryAttribute attribute)
          Creates a new instance of DefaultServerAttribute, by copying another attribute, which can be a ClientAttribute.
DefaultServerAttribute(AttributeType attributeType, java.lang.String... vals)
          Create a new instance of a EntryAttribute, without ID but with some values.
DefaultServerAttribute(AttributeType attributeType, Value<?>... vals)
          Doc me more! If the value does not correspond to the same attributeType, then it's wrapped value is copied into a new Value which uses the specified attributeType.
DefaultServerAttribute(java.lang.String upId, AttributeType attributeType)
          Create a new instance of a EntryAttribute, without value.
DefaultServerAttribute(java.lang.String upId, AttributeType attributeType, byte[]... vals)
          Create a new instance of a EntryAttribute, with some byte[] values.
DefaultServerAttribute(java.lang.String upId, AttributeType attributeType, java.lang.String... vals)
          Create a new instance of a EntryAttribute.
DefaultServerAttribute(java.lang.String upId, AttributeType attributeType, Value<?>... vals)
          Doc me more! If the value does not correspond to the same attributeType, then it's wrapped value is copied into a new Value which uses the specified attributeType.
 
Method Summary
 int add(byte[]... vals)
           Adds some values to this attribute.
 int add(java.lang.String... vals)
           Adds some values to this attribute.
 int add(Value<?>... vals)
          Adds some values to this attribute.
 void clear()
          Remove all the values from this attribute type, including a null value.
 EntryAttribute clone()
          Clone an attribute.
 boolean contains(byte[]... vals)
           Indicates whether all the specified values are attribute's values.
 boolean contains(java.lang.String... vals)
           Indicates whether all the specified values are attribute's values.
 boolean contains(Value<?>... vals)
           Indicates whether the specified values are some of the attribute's values.
 void deserialize(java.io.ObjectInput in)
           
 boolean equals(java.lang.Object obj)
           
 int hashCode()
          The hashCode is based on the id, the isHR flag and on the internal values.
 boolean isValid()
           Checks to see if this attribute is valid along with the values it contains.
 void readExternal(java.io.ObjectInput in)
           
 boolean remove(byte[]... vals)
           Removes all the values that are equal to the given values.
 boolean remove(java.lang.String... vals)
          Removes all the values that are equal to the given values.
 boolean remove(Value<?>... vals)
           Removes all the values that are equal to the given values.
 void serialize(java.io.ObjectOutput out)
           
 void setHR(boolean isHR)
           Overload the ClientAttribte isHR method : we can't change this flag for a ServerAttribute, as the HR is already set using the AttributeType.
 void setId(java.lang.String id)
           Overload the DefaultClientAttribute.setId(String) method.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           Overload the DefaultClientAttribute.setUpId(String) method.
 
Methods inherited from class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
contains, get, get, getAll, getAttributeType, getBytes, getId, getString, getUpId, instanceOf, isHR, isValid, iterator, put, put, put, put, setAttributeType, setUpId, setUpId, size, toClientAttribute
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.directory.shared.ldap.entry.EntryAttribute
get, get, getAll, getAttributeType, getBytes, getId, getString, getUpId, instanceOf, isHR, isValid, put, put, put, put, setAttributeType, setUpId, setUpId, size, toClientAttribute
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

DefaultServerAttribute

public DefaultServerAttribute(AttributeType attributeType,
                              EntryAttribute attribute)
Creates a new instance of DefaultServerAttribute, by copying another attribute, which can be a ClientAttribute. If the other attribute is a ServerAttribute, it will be copied.

Parameters:
attributeType - The attribute's type
attribute - The attribute to be copied

DefaultServerAttribute

public DefaultServerAttribute(AttributeType attributeType)
Create a new instance of a EntryAttribute, without ID nor value.

Parameters:
attributeType - the attributeType for the empty attribute added into the entry

DefaultServerAttribute

public DefaultServerAttribute(java.lang.String upId,
                              AttributeType attributeType)
Create a new instance of a EntryAttribute, without value.

Parameters:
upId - the ID for the added attributeType
attributeType - the added AttributeType

DefaultServerAttribute

public DefaultServerAttribute(AttributeType attributeType,
                              Value<?>... vals)
Doc me more! If the value does not correspond to the same attributeType, then it's wrapped value is copied into a new Value which uses the specified attributeType.

Parameters:
attributeType - the attribute type according to the schema
vals - an initial set of values for this attribute

DefaultServerAttribute

public DefaultServerAttribute(java.lang.String upId,
                              AttributeType attributeType,
                              Value<?>... vals)
Doc me more! If the value does not correspond to the same attributeType, then it's wrapped value is copied into a new Value which uses the specified attributeType. Otherwise, the value is stored, but as a reference. It's not a copy.

Parameters:
upId - the ID of the added attribute
attributeType - the attribute type according to the schema
vals - an initial set of values for this attribute

DefaultServerAttribute

public DefaultServerAttribute(AttributeType attributeType,
                              java.lang.String... vals)
Create a new instance of a EntryAttribute, without ID but with some values.

Parameters:
attributeType - The attributeType added on creation
vals - The added value for this attribute

DefaultServerAttribute

public DefaultServerAttribute(java.lang.String upId,
                              AttributeType attributeType,
                              java.lang.String... vals)
Create a new instance of a EntryAttribute.

Parameters:
upId - the ID for the added attribute
attributeType - The attributeType added on creation
vals - the added values for this attribute

DefaultServerAttribute

public DefaultServerAttribute(AttributeType attributeType,
                              byte[]... vals)
Create a new instance of a EntryAttribute, with some byte[] values.

Parameters:
attributeType - The attributeType added on creation
vals - The value for the added attribute

DefaultServerAttribute

public DefaultServerAttribute(java.lang.String upId,
                              AttributeType attributeType,
                              byte[]... vals)
Create a new instance of a EntryAttribute, with some byte[] values.

Parameters:
upId - the ID for the added attribute
attributeType - the AttributeType to be added
vals - the values for the added attribute
Method Detail

add

public int add(byte[]... vals)

Adds some values to this attribute. If the new values are already present in the attribute values, the method has no effect.

The new values are added at the end of list of values.

This method returns the number of values that were added.

If the value's type is different from the attribute's type, the value is not added.

It's the responsibility of the caller to check if the stored values are consistent with the attribute's type.

Specified by:
add in interface EntryAttribute
Overrides:
add in class DefaultClientAttribute
Parameters:
vals - some new values to be added which may be null
Returns:
the number of added values, or 0 if none has been added

add

public int add(java.lang.String... vals)

Adds some values to this attribute. If the new values are already present in the attribute values, the method has no effect.

The new values are added at the end of list of values.

This method returns the number of values that were added.

If the value's type is different from the attribute's type, the value is not added.

Specified by:
add in interface EntryAttribute
Overrides:
add in class DefaultClientAttribute
Parameters:
vals - some new values to be added which may be null
Returns:
the number of added values, or 0 if none has been added
See Also:
EntryAttribute.add(String...)

add

public int add(Value<?>... vals)
Description copied from class: DefaultClientAttribute
Adds some values to this attribute. If the new values are already present in the attribute values, the method has no effect.

The new values are added at the end of list of values.

This method returns the number of values that were added.

If the value's type is different from the attribute's type, a conversion is done. For instance, if we try to set some StringValue into a Binary attribute, we just store the UTF-8 byte array encoding for this StringValue.

If we try to store some BinaryValue in a HR attribute, we try to convert those BinaryValue assuming they represent an UTF-8 encoded String. Of course, if it's not the case, the stored value will be incorrect.

It's the responsibility of the caller to check if the stored values are consistent with the attribute's type.

The caller can set the HR flag in order to enforce a type for the current attribute, otherwise this type will be set while adding the first value, using the value's type to set the flag.

Note : If the entry contains no value, and the unique added value is a null length value, then this value will be considered as a binary value.

Specified by:
add in interface EntryAttribute
Overrides:
add in class DefaultClientAttribute
Returns:
the number of added values into this attribute
See Also:
EntryAttribute.add(org.apache.directory.shared.ldap.entry.Value...)

clear

public void clear()
Remove all the values from this attribute type, including a null value.

Specified by:
clear in interface EntryAttribute
Overrides:
clear in class DefaultClientAttribute

contains

public boolean contains(byte[]... vals)

Indicates whether all the specified values are attribute's values. If at least one value is not an attribute's value, this method will return false

If the Attribute is HR, this method will returns false

Specified by:
contains in interface EntryAttribute
Overrides:
contains in class DefaultClientAttribute
Parameters:
vals - the values
Returns:
true if this attribute contains all the values, otherwise false

contains

public boolean contains(java.lang.String... vals)

Indicates whether all the specified values are attribute's values. If at least one value is not an attribute's value, this method will return false

If the Attribute is not HR, this method will returns false

Specified by:
contains in interface EntryAttribute
Overrides:
contains in class DefaultClientAttribute
Parameters:
vals - the values
Returns:
true if this attribute contains all the values, otherwise false

contains

public boolean contains(Value<?>... vals)

Indicates whether the specified values are some of the attribute's values.

If the Attribute is HR, te metho will only accept String Values. Otherwise, it will only accept Binary values.

Specified by:
contains in interface EntryAttribute
Overrides:
contains in class DefaultClientAttribute
Parameters:
vals - the values
Returns:
true if this attribute contains all the values, otherwise false

isValid

public boolean isValid()
                throws LdapException

Checks to see if this attribute is valid along with the values it contains.

An attribute is valid if :

  • All of its values are valid with respect to the attributeType's syntax checker
  • If the attributeType is SINGLE-VALUE, then no more than a value should be present
  • Specified by:
    isValid in interface EntryAttribute
    Overrides:
    isValid in class DefaultClientAttribute
    Returns:
    true if the attribute and it's values are valid, false otherwise
    Throws:
    javax.naming.NamingException - if there is a failure to check syntaxes of values
    LdapException - if there is a failure to check syntaxes of values

    remove

    public boolean remove(byte[]... vals)
    Description copied from class: DefaultClientAttribute

    Removes all the values that are equal to the given values.

    Returns true if all the values are removed.

    If the attribute type is HR, then the values will be first converted to String

    Specified by:
    remove in interface EntryAttribute
    Overrides:
    remove in class DefaultClientAttribute
    Parameters:
    vals - the values to be removed
    Returns:
    true if all the values shave been removed from this attribute
    See Also:
    EntryAttribute#remove(byte[]...)

    remove

    public boolean remove(java.lang.String... vals)
    Description copied from class: DefaultClientAttribute
    Removes all the values that are equal to the given values.

    Returns true if all the values are removed.

    If the attribute type is not HR, then the values will be first converted to byte[]

    Specified by:
    remove in interface EntryAttribute
    Overrides:
    remove in class DefaultClientAttribute
    Parameters:
    vals - the values to be removed
    Returns:
    true if all the values shave been removed from this attribute
    See Also:
    EntryAttribute.remove(String...)

    remove

    public boolean remove(Value<?>... vals)
    Description copied from class: DefaultClientAttribute

    Removes all the values that are equal to the given values.

    Returns true if all the values are removed.

    If the attribute type is HR and some value which are not String, we will convert the values first (same thing for a non-HR attribute).

    Specified by:
    remove in interface EntryAttribute
    Overrides:
    remove in class DefaultClientAttribute
    Parameters:
    vals - the values to be removed
    Returns:
    true if all the values shave been removed from this attribute
    See Also:
    EntryAttribute.remove(org.apache.directory.shared.ldap.entry.Value...)

    setHR

    public void setHR(boolean isHR)

    Overload the ClientAttribte isHR method : we can't change this flag for a ServerAttribute, as the HR is already set using the AttributeType. Set the attribute to Human Readable or to Binary.

    Specified by:
    setHR in interface EntryAttribute
    Overrides:
    setHR in class DefaultClientAttribute
    Parameters:
    isHR - true for a Human Readable attribute, false for a Binary attribute.

    setId

    public void setId(java.lang.String id)

    Overload the DefaultClientAttribute.setId(String) method.

    As the attributeType has already been set, we have to be sure that the argument is compatible with the attributeType's name.

    If the given ID is not compatible with the attributeType's possible names, the previously loaded ID will be kept.

    Specified by:
    setId in interface EntryAttribute
    Overrides:
    setId in class DefaultClientAttribute
    Parameters:
    id - The attribute ID

    writeExternal

    public void writeExternal(java.io.ObjectOutput out)
                       throws java.io.IOException

    Overload the DefaultClientAttribute.setUpId(String) method.

    As the attributeType has already been set, we have to be sure that the argument is compatible with the attributeType's name.

    If the given ID is not compatible with the attributeType's possible names, the previously loaded ID will be kept.

    Specified by:
    writeExternal in interface java.io.Externalizable
    Overrides:
    writeExternal in class DefaultClientAttribute
    Parameters:
    upId - The attribute ID public void setUpId( String upId ) { if ( !StringTools.isEmpty( StringTools.trim( upId ) ) ) { if ( attributeType.getName() == null ) { // If the name is null, then we may have to store an OID if ( OID.isOID( upId ) && attributeType.getOid().equals( upId ) ) { // Everything is fine, store the upId. // This should not happen... super.setUpId( upId ); return; } } else { // We have at least one name. Check that the normalized upId // is one of those names. Otherwise, the upId may be an OID too. // In this case, it must be equals to the attributeType OID. String normUpId = StringTools.lowerCaseAscii( StringTools.trim( upId ) ); for ( String atId:attributeType.getNames() ) { if ( atId.equalsIgnoreCase( normUpId ) ) { // Found ! We can store the upId and get out super.setUpId( upId ); return; } } // Last case, the UpId is an OID if ( OID.isOID( normUpId ) && attributeType.getOid().equals( normUpId ) ) { // We have an OID : stores it super.setUpId( upId ); return; } return; } } return; } //------------------------------------------------------------------------- // Serialization methods //------------------------------------------------------------------------- /**
    Throws:
    java.io.IOException
    See Also:
    We can't use this method for a ServerAttribute, as we have to feed the value with an AttributeType object

    serialize

    public void serialize(java.io.ObjectOutput out)
                   throws java.io.IOException
    Throws:
    java.io.IOException
    See Also:

    This is the place where we serialize attributes, and all theirs elements. The inner structure is the same as the client attribute, but we can't call it as we won't be able to serialize the serverValues


    readExternal

    public void readExternal(java.io.ObjectInput in)
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException
    Specified by:
    readExternal in interface java.io.Externalizable
    Overrides:
    readExternal in class DefaultClientAttribute
    Throws:
    java.io.IOException
    java.lang.ClassNotFoundException
    See Also:
    We can't use this method for a ServerAttribute, as we have to feed the value with an AttributeType object

    deserialize

    public void deserialize(java.io.ObjectInput in)
                     throws java.io.IOException,
                            java.lang.ClassNotFoundException
    Throws:
    java.io.IOException
    java.lang.ClassNotFoundException
    See Also:
    Externalizable.readExternal(ObjectInput)

    clone

    public EntryAttribute clone()
    Clone an attribute. All the element are duplicated, so a modification on the original object won't affect the cloned object, as a modification on the cloned object has no impact on the original object

    Specified by:
    clone in interface EntryAttribute
    Overrides:
    clone in class DefaultClientAttribute
    Returns:
    a clone of the current attribute
    See Also:
    Cloneable#clone()

    equals

    public boolean equals(java.lang.Object obj)
    Overrides:
    equals in class DefaultClientAttribute
    Returns:
    true if the two objects are equal
    See Also:
    Object.equals(Object)

    hashCode

    public int hashCode()
    The hashCode is based on the id, the isHR flag and on the internal values.

    Overrides:
    hashCode in class DefaultClientAttribute
    Returns:
    the instance's hash code
    See Also:
    Object.hashCode()

    toString

    public java.lang.String toString()
    Overrides:
    toString in class DefaultClientAttribute
    Returns:
    A String representation of this instance
    See Also:
    Object.toString()


    Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.