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

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

public class BinaryValue
extends AbstractValue<byte[]>

A server side schema aware wrapper around a binary 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
protected static long serialVersionUID
          Used for serialization
 
Fields inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
attributeType, normalized, normalizedValue, same, valid, wrappedValue
 
Constructor Summary
BinaryValue()
          Creates a BinaryValue without an initial wrapped value.
BinaryValue(AttributeType attributeType)
          Creates a BinaryValue without an initial wrapped value.
BinaryValue(AttributeType attributeType, byte[] value)
          Creates a BinaryValue with an initial wrapped binary value.
BinaryValue(byte[] value)
          Creates a BinaryValue with an initial wrapped binary value.
 
Method Summary
 BinaryValue clone()
          
 int compareTo(Value<byte[]> value)
           
 void deserialize(java.io.ObjectInput in)
          Deserialize a BinaryValue.
 boolean equals(java.lang.Object obj)
          Checks to see if this BinaryValue equals the supplied object.
 byte[] get()
          Get the wrapped value.
 byte[] getBytes()
          Get the wrapped value as a byte[].
 byte[] getNormalizedValue()
          Gets the normalized (canonical) representation for the wrapped byte[].
 byte[] getNormalizedValueCopy()
          Gets a direct reference to the normalized representation for the wrapped value of this ServerValue wrapper.
 byte[] getNormalizedValueReference()
          Gets the normalized (canonical) representation for the wrapped string.
 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()
          Normalize the value.
 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()
          Dumps binary in hex with label.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
apply, getAttributeType, getLdapComparator, getMatchingRule, getNormalizer, getReference, instanceOf, isNormalized, isNull, isValid, isValid, setNormalized
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

protected static final long serialVersionUID
Used for serialization

See Also:
Constant Field Values

LOG

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

Constructor Detail

BinaryValue

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

Parameters:
attributeType - the schema type associated with this BinaryValue

BinaryValue

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

Parameters:
attributeType - the schema type associated with this BinaryValue

BinaryValue

public BinaryValue(byte[] value)
Creates a BinaryValue with an initial wrapped binary value.

Parameters:
attributeType - the schema type associated with this BinaryValue
value - the binary value to wrap which may be null, or a zero length byte array

BinaryValue

public BinaryValue(AttributeType attributeType,
                   byte[] value)
Creates a BinaryValue with an initial wrapped binary value.

Parameters:
attributeType - the schema type associated with this BinaryValue
value - the binary value to wrap which may be null, or a zero length byte array
Method Detail

getNormalizedValueCopy

public byte[] getNormalizedValueCopy()
Gets a direct reference to the normalized representation for the wrapped value of this ServerValue wrapper. Implementations will most likely leverage the attributeType this value is associated with to determine how to properly normalize the wrapped value.

Returns:
the normalized version of the wrapped value
Throws:
LdapException - if schema entity resolution fails or normalization fails

getNormalizedValueReference

public byte[] getNormalizedValueReference()
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:
getNormalizedValueReference in interface Value<byte[]>
Overrides:
getNormalizedValueReference in class AbstractValue<byte[]>
Returns:
a reference to the normalized version of the wrapped value

getNormalizedValue

public byte[] getNormalizedValue()
Gets the normalized (canonical) representation for the wrapped byte[]. If the wrapped byte[] 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<byte[]>
Overrides:
getNormalizedValue in class AbstractValue<byte[]>
Returns:
gets the normalized value

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

normalize

public void normalize()
               throws LdapException
Normalize the value. In order to use this method, the Value must be schema aware.

Specified by:
normalize in interface Value<byte[]>
Overrides:
normalize in class AbstractValue<byte[]>
Throws:
LdapException - If the value cannot be normalized

compareTo

public int compareTo(Value<byte[]> 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)

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)
Checks to see if this BinaryValue equals the supplied object. This equals implementation overrides the BinaryValue implementation which is not schema aware.

Overrides:
equals in class java.lang.Object
Throws:
java.lang.IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema

clone

public BinaryValue clone()
Description copied from class: AbstractValue

Specified by:
clone in interface Value<byte[]>
Overrides:
clone in class AbstractValue<byte[]>
Returns:
a copy of the current value

get

public byte[] get()
Get the wrapped value. It will return a copy, not a reference.

Returns:
a copy of the wrapped value

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[]. This method returns a copy of the wrapped 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 : [length] the wrapped length. Can be -1, if wrapped is null [value length] [UP value] if not empty [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, and not empty)

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 BinaryValue.

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

toString

public java.lang.String toString()
Dumps binary in hex with label.

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


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