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

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

public class StringValue
extends AbstractValue<java.lang.String>

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
protected static org.slf4j.Logger LOG
          logger for reporting errors that might not be handled properly upstream
 
Fields inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
attributeType, normalized, normalizedValue, same, valid, wrappedValue
 
Constructor Summary
StringValue()
          Creates a StringValue without an initial wrapped value.
StringValue(AttributeType attributeType)
          Creates a StringValue without an initial wrapped value.
StringValue(AttributeType attributeType, java.lang.String value)
          Creates a StringValue with an initial wrapped String value.
StringValue(java.lang.String value)
          Creates a StringValue with an initial wrapped String value.
 
Method Summary
 StringValue clone()
          Get a clone of the Client Value
 int compareTo(Value<java.lang.String> value)
           
 void deserialize(java.io.ObjectInput in)
          Deserialize a StringValue.
 boolean equals(java.lang.Object obj)
           
 java.lang.String get()
          Get a copy of the stored value.
 byte[] getBytes()
          Get the wrapped value as a byte[].
 java.lang.String getNormalizedValue()
          Gets the normalized (canonical) representation for the wrapped string.
 java.lang.String getNormalizedValueCopy()
          Gets a copy of the the normalized (canonical) representation for the wrapped value.
 java.lang.String getString()
          Get the wrapped value as a String.
 int hashCode()
           
 boolean isBinary()
          Tells if the current value is Binary or String
 int length()
           
 void normalize()
          Compute the normalized (canonical) representation for the wrapped string.
 void normalize(Normalizer normalizer)
          Normalize the value.
 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.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
apply, getAttributeType, getLdapComparator, getMatchingRule, getNormalizedValueReference, getNormalizer, getReference, instanceOf, isNormalized, isNull, isValid, isValid, setNormalized
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

protected static final org.slf4j.Logger LOG
logger for reporting errors that might not be handled properly upstream

Constructor Detail

StringValue

public StringValue()
Creates a StringValue without an initial wrapped value.


StringValue

public StringValue(AttributeType attributeType)
Creates a StringValue without an initial wrapped value.

Parameters:
attributeType - the schema type associated with this StringValue

StringValue

public StringValue(java.lang.String value)
Creates a StringValue with an initial wrapped String value.

Parameters:
value - the value to wrap which can be null

StringValue

public StringValue(AttributeType attributeType,
                   java.lang.String value)
Creates a StringValue with an initial wrapped String value.

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

get

public java.lang.String get()
Get a copy of the stored value.

Returns:
A copy of the stored value.

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 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 Value<java.lang.String>
Overrides:
getNormalizedValue in class AbstractValue<java.lang.String>
Returns:
gets the normalized value

getNormalizedValueCopy

public java.lang.String getNormalizedValueCopy()
Gets a copy of the the normalized (canonical) representation for the wrapped value.

Returns:
gets a copy of the normalized value

normalize

public void normalize()
               throws LdapException
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 Value<java.lang.String>
Overrides:
normalize in class AbstractValue<java.lang.String>
Throws:
LdapException - if the value cannot be properly normalized

normalize

public final void normalize(Normalizer normalizer)
                     throws LdapException
Normalize the value. For a client String value, applies the given normalizer. It supposes that the client has access to the schema in order to select the appropriate normalizer.

Parameters:
Normalizer - The normalizer to apply to the value
Throws:
LdapException - If the value cannot be normalized

compareTo

public int compareTo(Value<java.lang.String> value)
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:
ServerValue#compareTo(ServerValue)

clone

public StringValue clone()
Get a clone of the Client Value

Specified by:
clone in interface Value<java.lang.String>
Overrides:
clone in class AbstractValue<java.lang.String>
Returns:
a copy of the current value

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
the instance's hashcode
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Two StringValue are equals if their normalized values are equal

isBinary

public boolean isBinary()
Tells if the current value is Binary or String

Returns:
true if the value is Binary, false otherwise

length

public int length()
Returns:
The length of the interned value

getBytes

public byte[] getBytes()
Get the wrapped value as a byte[].

Returns:
the wrapped value as a byte[]

getString

public java.lang.String getString()
Get the wrapped value as a String.

Returns:
the wrapped value as a String

readExternal

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

writeExternal

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

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

deserialize

public void deserialize(java.io.ObjectInput in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Deserialize a StringValue.

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


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