org.apache.directory.server.core.entry
Class DefaultServerAttribute

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

public final class DefaultServerAttribute
extends org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
implements ServerAttribute

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
id, isHR, upId, values
 
Constructor Summary
DefaultServerAttribute(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Create a new instance of a EntryAttribute, without ID nor value.
DefaultServerAttribute(org.apache.directory.shared.ldap.schema.AttributeType attributeType, byte[]... vals)
          Create a new instance of a EntryAttribute, with some byte[] values.
DefaultServerAttribute(org.apache.directory.shared.ldap.schema.AttributeType attributeType, org.apache.directory.shared.ldap.entry.EntryAttribute attribute)
          Creates a new instance of DefaultServerAttribute, by copying another attribute, which can be a ClientAttribute.
DefaultServerAttribute(org.apache.directory.shared.ldap.schema.AttributeType attributeType, java.lang.String... vals)
          Create a new instance of a EntryAttribute, without ID but with some values.
DefaultServerAttribute(org.apache.directory.shared.ldap.schema.AttributeType attributeType, org.apache.directory.shared.ldap.entry.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, org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Create a new instance of a EntryAttribute, without value.
DefaultServerAttribute(java.lang.String upId, org.apache.directory.shared.ldap.schema.AttributeType attributeType, byte[]... vals)
          Create a new instance of a EntryAttribute, with some byte[] values.
DefaultServerAttribute(java.lang.String upId, org.apache.directory.shared.ldap.schema.AttributeType attributeType, java.lang.String... vals)
          Create a new instance of a EntryAttribute.
DefaultServerAttribute(java.lang.String upId, org.apache.directory.shared.ldap.schema.AttributeType attributeType, org.apache.directory.shared.ldap.entry.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(org.apache.directory.shared.ldap.entry.Value<?>... vals)
           
 void clear()
          Remove all the values from this attribute type, including a null value.
 ServerAttribute 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(org.apache.directory.shared.ldap.entry.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)
           
 org.apache.directory.shared.ldap.schema.AttributeType getAttributeType()
          Get the attribute type associated with this ServerAttribute.
 int hashCode()
          The hashCode is based on the id, the isHR flag and on the internal values.
 boolean instanceOf(java.lang.String attributeId)
           Check if the current attribute type is of the expected attributeType
 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)
           
 boolean remove(java.lang.String... vals)
           
 boolean remove(org.apache.directory.shared.ldap.entry.Value<?>... vals)
           
 void serialize(java.io.ObjectOutput out)
           
 void setAttributeType(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
           Set the attribute type associated with this ServerAttribute.
 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.
 void setUpId(java.lang.String upId)
           Overload the DefaultClientAttribute.setUpId(String) method.
 void setUpId(java.lang.String upId, org.apache.directory.shared.ldap.schema.AttributeType attributeType)
           Set the user provided ID.
 org.apache.directory.shared.ldap.entry.EntryAttribute toClientAttribute()
          Convert the ServerAttribute to a ClientAttribute
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
contains, get, get, getAll, getBytes, getId, getString, getUpId, isHR, isValid, iterator, put, put, put, put, size
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.directory.shared.ldap.entry.client.ClientAttribute
isValid
 
Methods inherited from interface org.apache.directory.shared.ldap.entry.EntryAttribute
get, get, getAll, getBytes, getId, getString, getUpId, isHR, put, put, put, put, size
 
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(org.apache.directory.shared.ldap.schema.AttributeType attributeType,
                              org.apache.directory.shared.ldap.entry.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(org.apache.directory.shared.ldap.schema.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,
                              org.apache.directory.shared.ldap.schema.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(org.apache.directory.shared.ldap.schema.AttributeType attributeType,
                              org.apache.directory.shared.ldap.entry.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,
                              org.apache.directory.shared.ldap.schema.AttributeType attributeType,
                              org.apache.directory.shared.ldap.entry.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(org.apache.directory.shared.ldap.schema.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,
                              org.apache.directory.shared.ldap.schema.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(org.apache.directory.shared.ldap.schema.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,
                              org.apache.directory.shared.ldap.schema.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 org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
add in class org.apache.directory.shared.ldap.entry.client.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 org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
add in class org.apache.directory.shared.ldap.entry.client.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(org.apache.directory.shared.ldap.entry.Value<?>... vals)
Specified by:
add in interface org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
add in class org.apache.directory.shared.ldap.entry.client.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 org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
clear in class org.apache.directory.shared.ldap.entry.client.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 org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
contains in class org.apache.directory.shared.ldap.entry.client.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 org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
contains in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
Parameters:
vals - the values
Returns:
true if this attribute contains all the values, otherwise false

contains

public boolean contains(org.apache.directory.shared.ldap.entry.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 org.apache.directory.shared.ldap.entry.EntryAttribute
Overrides:
contains in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
Parameters:
vals - the values
Returns:
true if this attribute contains all the values, otherwise false

getAttributeType

public org.apache.directory.shared.ldap.schema.AttributeType getAttributeType()
Get the attribute type associated with this ServerAttribute.

Specified by:
getAttributeType in interface ServerAttribute
Returns:
the attributeType associated with this entry attribute

instanceOf

public boolean instanceOf(java.lang.String attributeId)
                   throws javax.naming.directory.InvalidAttributeValueException

Check if the current attribute type is of the expected attributeType

This method won't tell if the current attribute is a descendant of the attributeType. For instance, the "CN" serverAttribute will return false if we ask if it's an instance of "Name".

Specified by:
instanceOf in interface ServerAttribute
Parameters:
attributeId - The AttributeType ID to check
Returns:
True if the current attribute is of the expected attributeType
Throws:
javax.naming.directory.InvalidAttributeValueException - If there is no AttributeType

isValid

public boolean isValid()
                throws javax.naming.NamingException

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 ServerAttribute
    Overrides:
    isValid in class org.apache.directory.shared.ldap.entry.client.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

    remove

    public boolean remove(byte[]... vals)
    Specified by:
    remove in interface org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    remove in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    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)
    Specified by:
    remove in interface org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    remove in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Returns:
    true if all the values shave been removed from this attribute
    See Also:
    EntryAttribute.remove(String...)

    remove

    public boolean remove(org.apache.directory.shared.ldap.entry.Value<?>... vals)
    Specified by:
    remove in interface org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    remove in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Returns:
    true if all the values shave been removed from this attribute
    See Also:
    EntryAttribute.remove(org.apache.directory.shared.ldap.entry.Value...)

    setAttributeType

    public void setAttributeType(org.apache.directory.shared.ldap.schema.AttributeType attributeType)

    Set the attribute type associated with this ServerAttribute.

    The current attributeType will be replaced. It is the responsibility of the caller to insure that the existing values are compatible with the new AttributeType

    Specified by:
    setAttributeType in interface ServerAttribute
    Parameters:
    attributeType - the attributeType associated with this entry attribute

    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 org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    setHR in class org.apache.directory.shared.ldap.entry.client.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 org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    setId in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Parameters:
    id - The attribute ID

    setUpId

    public void setUpId(java.lang.String upId)

    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:
    setUpId in interface org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    setUpId in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Parameters:
    upId - The attribute ID

    setUpId

    public void setUpId(java.lang.String upId,
                        org.apache.directory.shared.ldap.schema.AttributeType attributeType)

    Set the user provided ID. If we have none, the upId is assigned the attributetype's name. If it does not have any name, we will use the OID.

    If we have an upId and an AttributeType, they must be compatible. : - if the upId is an OID, it must be the AttributeType's OID - otherwise, its normalized form must be equals to ones of the attributeType's names.

    In any case, the ATtributeType will be changed. The caller is responsible for the present values to be compatoble with the new AttributeType.

    Specified by:
    setUpId in interface ServerAttribute
    Parameters:
    upId - The attribute ID
    attributeType - The associated attributeType

    toClientAttribute

    public org.apache.directory.shared.ldap.entry.EntryAttribute toClientAttribute()
    Convert the ServerAttribute to a ClientAttribute

    Specified by:
    toClientAttribute in interface ServerAttribute
    Returns:
    An instance of ClientAttribute

    writeExternal

    public void writeExternal(java.io.ObjectOutput out)
                       throws java.io.IOException
    Specified by:
    writeExternal in interface java.io.Externalizable
    Overrides:
    writeExternal in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    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 org.apache.directory.shared.ldap.entry.client.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 ServerAttribute 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 org.apache.directory.shared.ldap.entry.EntryAttribute
    Overrides:
    clone in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Returns:
    a clone of the current attribute

    equals

    public boolean equals(java.lang.Object obj)
    Overrides:
    equals in class org.apache.directory.shared.ldap.entry.client.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 org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Returns:
    the instance's hash code
    See Also:
    Object.hashCode()

    toString

    public java.lang.String toString()
    Overrides:
    toString in class org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
    Returns:
    A String representation of this instance
    See Also:
    Object.toString()


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