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

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

public class ServerBinaryValue
extends org.apache.directory.shared.ldap.entry.client.ClientBinaryValue

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
 
Fields inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
normalized, normalizedValue, valid, wrapped
 
Constructor Summary
ServerBinaryValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Creates a ServerBinaryValue without an initial wrapped value.
ServerBinaryValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType, byte[] wrapped)
          Creates a ServerBinaryValue with an initial wrapped binary value.
 
Method Summary
protected  java.lang.String checkAttributeType(org.apache.directory.shared.ldap.schema.AttributeType attributeType)
          Check the attributeType member.
 ServerBinaryValue clone()
           
 int compareTo(org.apache.directory.shared.ldap.entry.Value<byte[]> value)
           
 void deserialize(java.io.ObjectInput in)
          Deserialize a ServerBinaryValue.
 boolean equals(java.lang.Object obj)
          Checks to see if this ServerBinaryValue equals the supplied object.
 org.apache.directory.shared.ldap.schema.AttributeType getAttributeType()
          Get the associated AttributeType
 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 (cannonical) representation for the wrapped string.
 int hashCode()
           
 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 isSame()
           
 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()
           
 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.ClientBinaryValue
clear, getCopy, isBinary, normalize, set, toString
 
Methods inherited from class org.apache.directory.shared.ldap.entry.AbstractValue
get, getReference, isNormalized, isNull, isValid, setNormalized
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerBinaryValue

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

Parameters:
attributeType - the schema type associated with this ServerBinaryValue

ServerBinaryValue

public ServerBinaryValue(org.apache.directory.shared.ldap.schema.AttributeType attributeType,
                         byte[] wrapped)
Creates a ServerBinaryValue with an initial wrapped binary value.

Parameters:
attributeType - the schema type associated with this ServerBinaryValue
wrapped - the binary value to wrap which may be null, or a zero length byte array
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.


normalize

public void normalize()
               throws javax.naming.NamingException
Specified by:
normalize in interface org.apache.directory.shared.ldap.entry.Value<byte[]>
Overrides:
normalize in class org.apache.directory.shared.ldap.entry.AbstractValue<byte[]>
Throws:
javax.naming.NamingException

getNormalizedValueReference

public byte[] getNormalizedValueReference()
Gets the normalized (cannonical) 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 org.apache.directory.shared.ldap.entry.Value<byte[]>
Overrides:
getNormalizedValueReference in class org.apache.directory.shared.ldap.entry.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 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<byte[]>
Overrides:
getNormalizedValue in class org.apache.directory.shared.ldap.entry.AbstractValue<byte[]>
Returns:
gets the normalized value

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.

Specified by:
getNormalizedValueCopy in interface org.apache.directory.shared.ldap.entry.Value<byte[]>
Overrides:
getNormalizedValueCopy in class org.apache.directory.shared.ldap.entry.client.ClientBinaryValue
Returns:
the normalized version of the wrapped value

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<byte[]>
Overrides:
isValid in class org.apache.directory.shared.ldap.entry.AbstractValue<byte[]>
See Also:
Value.isValid()

isSame

public final boolean isSame()
Returns:
Tells if the wrapped value and the normalized value are the same

compareTo

public int compareTo(org.apache.directory.shared.ldap.entry.Value<byte[]> value)
Specified by:
compareTo in interface java.lang.Comparable<org.apache.directory.shared.ldap.entry.Value<byte[]>>
Overrides:
compareTo in class org.apache.directory.shared.ldap.entry.client.ClientBinaryValue
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:
Value#compareTo(Value)

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

hashCode

public int hashCode()
Overrides:
hashCode in class org.apache.directory.shared.ldap.entry.client.ClientBinaryValue
Returns:
the instance's hash code
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)
Checks to see if this ServerBinaryValue equals the supplied object. This equals implementation overrides the BinaryValue implementation which is not schema aware.

Overrides:
equals in class org.apache.directory.shared.ldap.entry.client.ClientBinaryValue
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 ServerBinaryValue clone()
Specified by:
clone in interface org.apache.directory.shared.ldap.entry.Value<byte[]>
Overrides:
clone in class org.apache.directory.shared.ldap.entry.client.ClientBinaryValue
Returns:
a copy of the current value

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.ClientBinaryValue
Throws:
java.io.IOException
See Also:
We can't use this method for a ServerBinaryValue, 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 : [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

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

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.