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

java.lang.Object
  extended by org.apache.directory.shared.ldap.entry.AbstractValue<java.lang.String>
      extended by org.apache.directory.shared.ldap.entry.client.ClientStringValue
          extended by org.apache.directory.server.core.entry.ServerStringValue
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<org.apache.directory.shared.ldap.entry.Value<java.lang.String>>, org.apache.directory.shared.ldap.entry.Value<java.lang.String>

public class ServerStringValue
extends org.apache.directory.shared.ldap.entry.client.ClientStringValue

A server side schema aware wrapper around a String attribute value. This value wrapper uses schema information to syntax check values, and to compare them for equality and ordering. It caches results and invalidates them when the wrapped value changes.

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

Field Summary
 
Fields inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
normalized, normalizedValue, valid, wrapped
 
Constructor Summary
ServerStringValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Creates a ServerStringValue without an initial wrapped value.
ServerStringValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType, java.lang.String wrapped)
          Creates a ServerStringValue with an initial wrapped String value.
 
Method Summary
protected  java.lang.String checkAttributeType(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Check the attributeType member.
 ServerStringValue clone()
           
 int compareTo(org.apache.directory.shared.ldap.entry.Value<java.lang.String> value)
           
 void deserialize(java.io.ObjectInput in)
          Deserialize a ServerStringValue.
 boolean equals(java.lang.Object obj)
          Checks to see if this ServerStringValue equals the supplied object.
 org.apache.directory.shared.ldap.schema.AttributeType getAttributeType()
          Get the associated AttributeType
 java.lang.String getNormalizedValue()
          Gets the normalized (canonical) representation for the wrapped string.
 int hashCode()
          Implement the hashCode method.
 boolean instanceOf(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Check if the value is stored into an instance of the given AttributeType, or one of its ascendant.
 boolean isValid()
          Uses the syntaxChecker associated with the attributeType to check if the value is valid.
protected  java.lang.String logAssert(java.lang.String message)
          Utility method to get some logs if an assert fails
 void normalize()
          Compute the normalized (canonical) representation for the wrapped string.
 void readExternal(java.io.ObjectInput in)
           
 void serialize(java.io.ObjectOutput out)
          We will write the value and the normalized value, only if the normalized value is different.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.apache.directory.shared.ldap.entry.client.ClientStringValue
get, getCopy, getNormalizedValueCopy, isBinary, normalize, set, toString
 
Methods inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
clear, getNormalizedValueReference, getReference, isNormalized, isNull, isValid, setNormalized
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerStringValue

public ServerStringValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
Creates a ServerStringValue without an initial wrapped value.

Parameters:
attributeType - the schema type associated with this ServerStringValue

ServerStringValue

public ServerStringValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType,
                         java.lang.String wrapped)
Creates a ServerStringValue with an initial wrapped String value.

Parameters:
attributeType - the schema type associated with this ServerStringValue
wrapped - the value to wrap which can be null
Method Detail

logAssert

protected java.lang.String logAssert(java.lang.String message)
Utility method to get some logs if an assert fails


checkAttributeType

protected java.lang.String checkAttributeType(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
Check the attributeType member. It should not be null, and it should contains a syntax.


clone

public ServerStringValue clone()
Specified by:
clone in interface org.apache.directory.shared.ldap.entry.Value<java.lang.String>
Overrides:
clone in class org.apache.directory.shared.ldap.entry.client.ClientStringValue
Returns:
a copy of the current value

normalize

public void normalize()
               throws javax.naming.NamingException
Compute the normalized (canonical) representation for the wrapped string. If the wrapped String is null, the normalized form will be null too.

Specified by:
normalize in interface org.apache.directory.shared.ldap.entry.Value<java.lang.String>
Overrides:
normalize in class org.apache.directory.shared.ldap.entry.AbstractValue<java.lang.String>
Throws:
javax.naming.NamingException - if the value cannot be properly normalized

getNormalizedValue

public java.lang.String getNormalizedValue()
Gets the normalized (canonical) representation for the wrapped string. If the wrapped String is null, null is returned, otherwise the normalized form is returned. If no the normalizedValue is null, then this method will attempt to generate it from the wrapped value: repeated calls to this method do not unnecessarily normalize the wrapped value. Only changes to the wrapped value result in attempts to normalize the wrapped value.

Specified by:
getNormalizedValue in interface org.apache.directory.shared.ldap.entry.Value<java.lang.String>
Overrides:
getNormalizedValue in class org.apache.directory.shared.ldap.entry.client.ClientStringValue
Returns:
gets the normalized value
Throws:
javax.naming.NamingException - if the value cannot be properly normalized

isValid

public final boolean isValid()
Uses the syntaxChecker associated with the attributeType to check if the value is valid. Repeated calls to this method do not attempt to re-check the syntax of the wrapped value every time if the wrapped value does not change. Syntax checks only result on the first check, and when the wrapped value changes.

Specified by:
isValid in interface org.apache.directory.shared.ldap.entry.Value<java.lang.String>
Overrides:
isValid in class org.apache.directory.shared.ldap.entry.AbstractValue<java.lang.String>
See Also:
Value.isValid()

compareTo

public int compareTo(org.apache.directory.shared.ldap.entry.Value<java.lang.String> value)
Specified by:
compareTo in interface java.lang.Comparable<org.apache.directory.shared.ldap.entry.Value<java.lang.String>>
Overrides:
compareTo in class org.apache.directory.shared.ldap.entry.client.ClientStringValue
Throws:
java.lang.IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
See Also:
Comparable.compareTo(Object)

getAttributeType

public org.apache.directory.shared.ldap.schema.AttributeType getAttributeType()
Get the associated AttributeType

Returns:
The AttributeType

instanceOf

public boolean instanceOf(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
                   throws javax.naming.NamingException
Check if the value is stored into an instance of the given AttributeType, or one of its ascendant. For instance, if the Value is associated with a CommonName, checking for Name will match.

Parameters:
attributeType - The AttributeType we are looking at
Returns:
true if the value is associated with the given attributeType or one of its ascendant
Throws:
javax.naming.NamingException

equals

public boolean equals(java.lang.Object obj)
Checks to see if this ServerStringValue equals the supplied object. This equals implementation overrides the StringValue implementation which is not schema aware. Two ServerStringValues are equal if they have the same AttributeType, they are both null, their value are equal or their normalized value are equal. If the AttributeType has a comparator, we use it to compare both values.

Overrides:
equals in class org.apache.directory.shared.ldap.entry.client.ClientStringValue
Throws:
java.lang.IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema

hashCode

public int hashCode()
Implement the hashCode method.

Overrides:
hashCode in class org.apache.directory.shared.ldap.entry.client.ClientStringValue
Returns:
the instance's hash code
Throws:
java.lang.IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
See Also:
Object.hashCode()

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.ClientStringValue
Throws:
java.io.IOException
See Also:
We can't use this method for a ServerStringValue, as we have to feed the value with an AttributeType object

serialize

public void serialize(java.io.ObjectOutput out)
               throws java.io.IOException
We will write the value and the normalized value, only if the normalized value is different. If the value is empty, a flag is written at the beginning with the value true, otherwise, a false is written. The data will be stored following this structure : [empty value flag] [UP value] [normalized] (will be false if the value can't be normalized) [same] (a flag set to true if the normalized value equals the UP value) [Norm value] (the normalized value if different from the UP value)

Parameters:
out - the buffer in which we will stored the serialized form of the value
Throws:
java.io.IOException - if we can't write into the buffer

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.ClientStringValue
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
We can't use this method for a ServerStringValue, 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
Deserialize a ServerStringValue.

Parameters:
in - the buffer containing the bytes with the serialized value
Throws:
java.io.IOException
java.lang.ClassNotFoundException


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