You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/12/09 03:37:19 UTC
svn commit: r602613 - in /directory:
apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/
apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/
shared/branches/bigbang/ldap/src/...
Author: akarasulu
Date: Sat Dec 8 18:37:19 2007
New Revision: 602613
URL: http://svn.apache.org/viewvc?rev=602613&view=rev
Log:
changes to entry and server core entry interfaces
o remove get() from Value interface
o moved accessors down into specific implementations
- ServerBinaryValue.getCopy()
- ServerBinaryValue.getReference()
- ServerBinaryValue.getNormalizedCopy()
- ServerBinaryValue.getNormalizedReference()
- ServerStringValue.get()
- ServerStringValue.getNormalized()
o cleaned up some problems that resulted from these changes
o note that now some methods like compareTo need to down cast to specific
subtypes to properly perform a comparison: not a big deal though
o added some more documentation
o fixed some warnings
Modified:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java Sat Dec 8 18:37:19 2007
@@ -63,9 +63,9 @@
* wrapped value is copied into a new ServerValue which uses the specified
* attributeType.
*
- * @param attributeType
- * @param val
- * @throws NamingException
+ * @param attributeType the attribute type according to the schema
+ * @param val an initial value for this attribute
+ * @throws NamingException if there are problems creating the new attribute
*/
public BasicServerAttribute( AttributeType attributeType, ServerValue<?> val ) throws NamingException
{
@@ -81,9 +81,9 @@
* attributeType.
*
* @param upId
- * @param attributeType
- * @param val
- * @throws NamingException
+ * @param attributeType the attribute type according to the schema
+ * @param val an initial value for this attribute
+ * @throws NamingException if there are problems creating the new attribute
*/
public BasicServerAttribute( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
{
@@ -107,11 +107,13 @@
}
else if ( val instanceof ServerStringValue )
{
- values.add( new ServerStringValue( attributeType, ( String ) val.get() ) );
+ ServerStringValue serverString = ( ServerStringValue ) val;
+ values.add( new ServerStringValue( attributeType, serverString.get() ) );
}
else if ( val instanceof ServerBinaryValue )
{
- values.add( new ServerBinaryValue( attributeType, ( byte[] ) val.get() ) );
+ ServerBinaryValue serverBinary = ( ServerBinaryValue ) val;
+ values.add( new ServerBinaryValue( attributeType, serverBinary.getCopy() ) );
}
else
{
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Sat Dec 8 18:37:19 2007
@@ -19,10 +19,11 @@
package org.apache.directory.server.core.entry;
+import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.entry.BinaryValue;
import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +47,7 @@
private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
/** used to dynamically lookup the attributeType when/if deserializing */
+ @SuppressWarnings ( { "FieldCanBeLocal", "UnusedDeclaration" } )
private final String oid;
/** reference to the attributeType which is not serialized */
@@ -117,7 +119,7 @@
{
// Why should we invalidate the normalized value if it's we're setting the
// wrapper to it's current value?
- byte[] value = getUnsafe();
+ byte[] value = getReference();
if ( value != null )
{
@@ -146,9 +148,10 @@
* this method do not unnecessarily normalize the wrapped value. Only changes
* to the wrapped value result in attempts to normalize the wrapped value.
*
- * @see ServerValue#getNormalizedValue()
+ * @return a reference to the normalized version of the wrapped value
+ * @throws NamingException with failures to normalize
*/
- public byte[] getNormalizedValue() throws NamingException
+ public byte[] getNormalizedReference() throws NamingException
{
if ( isNull() )
{
@@ -161,11 +164,11 @@
if ( normalizer == null )
{
- normalizedValue = get();
+ normalizedValue = getCopy();
}
else
{
- normalizedValue = ( byte[] ) normalizer.normalize( get() );
+ normalizedValue = ( byte[] ) normalizer.normalize( getCopy() );
}
}
@@ -174,6 +177,26 @@
/**
+ * 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.
+ *
+ * @return the normalized version of the wrapped value
+ * @throws NamingException if schema entity resolution fails or normalization fails
+ */
+ public byte[] getNormalizedCopy() throws NamingException
+ {
+ if ( normalizedValue == null )
+ {
+ getNormalizedReference();
+ }
+
+ return Arrays.copyOf( normalizedValue, normalizedValue.length );
+ }
+
+
+ /**
* 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
@@ -189,12 +212,13 @@
return valid;
}
- valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getUnsafe() );
+ valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
return valid;
}
/**
+ *
* @see ServerValue#compareTo(ServerValue)
* @throws IllegalStateException on failures to extract the comparator, or the
* normalizers needed to perform the required comparisons based on the schema
@@ -219,18 +243,27 @@
return 1;
}
}
-
- try
- {
- return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
- }
- catch ( NamingException e )
+
+ if ( value instanceof ServerBinaryValue )
{
- String msg = "Failed to compare normalized values for " + Arrays.toString( getUnsafe() )
- + " and " + Arrays.toString( value.get() );
- LOG.error( msg, e );
- throw new IllegalStateException( msg, e );
+ ServerBinaryValue binaryValue = ( ServerBinaryValue ) value;
+
+ try
+ {
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedReference(), binaryValue.getNormalizedReference() );
+ }
+ catch ( NamingException e )
+ {
+ String msg = "Failed to compare normalized values for " + Arrays.toString( getReference() )
+ + " and " + value;
+ LOG.error( msg, e );
+ throw new IllegalStateException( msg, e );
+ }
}
+
+ throw new NotImplementedException( "I don't really know how to compare anything other " +
+ "than ServerBinaryValues at this point in time." );
}
@@ -281,7 +314,7 @@
try
{
- return getNormalizedValue().hashCode();
+ return getNormalizedReference().hashCode();
}
catch ( NamingException e )
{
@@ -332,7 +365,7 @@
// now unlike regular values we have to compare the normalized values
try
{
- return Arrays.equals( getNormalizedValue(), other.getNormalizedValue() );
+ return Arrays.equals( getNormalizedReference(), other.getNormalizedReference() );
}
catch ( NamingException e )
{
@@ -342,7 +375,7 @@
+ toString() + " and " + other.toString() , e );
// recover by comparing non-normalized values
- return Arrays.equals( getUnsafe(), other.getUnsafe() );
+ return Arrays.equals( getReference(), other.getReference() );
}
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java Sat Dec 8 18:37:19 2007
@@ -154,9 +154,9 @@
*
* @todo if URI is already cannonical this method may be useless
* @todo consider this while figuring out how to deal with streamed values
- * @see ServerValue#getNormalizedValue()
+ * @see ServerValue#getNormalizedReference()
*/
- public URI getNormalizedValue() throws NamingException
+ public URI getNormalizedReference() throws NamingException
{
if ( get() == null )
{
@@ -199,7 +199,7 @@
try
{
- return getNormalizedValue().hashCode();
+ return getNormalizedReference().hashCode();
}
catch ( NamingException e )
{
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Sat Dec 8 18:37:19 2007
@@ -19,6 +19,7 @@
package org.apache.directory.server.core.entry;
+import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.entry.StringValue;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.MatchingRule;
@@ -45,6 +46,7 @@
private static final Logger LOG = LoggerFactory.getLogger( ServerStringValue.class );
/** used to dynamically lookup the attributeType when/if deserializing */
+ @SuppressWarnings ( { "FieldCanBeLocal", "UnusedDeclaration" } )
private final String oid;
/** reference to the attributeType which is not serialized */
@@ -141,9 +143,10 @@
* this method do not unnecessarily normalize the wrapped value. Only changes
* to the wrapped value result in attempts to normalize the wrapped value.
*
- * @see ServerValue#getNormalizedValue()
+ * @return gets the normalized value
+ * @throws NamingException if the value cannot be properly normalized
*/
- public String getNormalizedValue() throws NamingException
+ public String getNormalized() throws NamingException
{
if ( isNull() )
{
@@ -211,17 +214,24 @@
{
return 1;
}
-
- try
- {
- return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
- }
- catch ( NamingException e )
+
+ if ( value instanceof ServerStringValue )
{
- String msg = "Failed to compare normalized values for " + get() + " and " + value.get();
- LOG.error( msg, e );
- throw new IllegalStateException( msg, e );
+ ServerStringValue stringValue = ( ServerStringValue ) value;
+ try
+ {
+ //noinspection unchecked
+ return getComparator().compare( getNormalized(), stringValue.getNormalized() );
+ }
+ catch ( NamingException e )
+ {
+ String msg = "Failed to compare normalized values for " + get() + " and " + value;
+ LOG.error( msg, e );
+ throw new IllegalStateException( msg, e );
+ }
}
+
+ throw new NotImplementedException( "I don't know what to do if value is not a ServerStringValue" );
}
@@ -272,7 +282,7 @@
try
{
- return getNormalizedValue().hashCode();
+ return getNormalized().hashCode();
}
catch ( NamingException e )
{
@@ -323,7 +333,7 @@
// now unlike regular values we have to compare the normalized values
try
{
- return getNormalizedValue().equals( other.getNormalizedValue() );
+ return getNormalized().equals( other.getNormalized() );
}
catch ( NamingException e )
{
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java Sat Dec 8 18:37:19 2007
@@ -55,18 +55,6 @@
public interface ServerValue<T> extends Value<T>, Comparable<ServerValue<T>>
{
/**
- * Gets 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.
- *
- * @return the normalized version of the wrapped value
- * @throws NamingException if schema entity resolution fails or normalization fails
- */
- T getNormalizedValue() throws NamingException;
-
-
- /**
* Checks to see if this ServerValue is valid according to the syntax
* of the ServerAttribute which contains it.
*
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java Sat Dec 8 18:37:19 2007
@@ -267,7 +267,7 @@
// check that normalization and syntax checks work as expected
ServerStringValue value = new ServerStringValue( at, "HIGH" );
- assertEquals( value.get(), value.getNormalizedValue() );
+ assertEquals( value.get(), value.get() );
assertTrue( value.isValid() );
value = new ServerStringValue( at, "high" );
assertFalse( value.isValid() );
@@ -367,7 +367,7 @@
// check that normalization and syntax checks work as expected
ServerStringValue value = new ServerStringValue( at, "hello" );
- assertEquals( value.get(), value.getNormalizedValue() );
+ assertEquals( value.get(), value.get() );
assertTrue( value.isValid() );
// create a bunch to best tested for equals and in containers
@@ -417,7 +417,7 @@
{
if ( o1 != null )
{
- String n1 = o1.getNormalizedValue();
+ String n1 = o1.get();
if ( n1 != null )
{
b1 = n1.getBytes( "UTF-8" );
@@ -426,10 +426,10 @@
if ( o2 != null )
{
- String n2 = o2.getNormalizedValue();
+ String n2 = o2.get();
if ( n2 != null )
{
- b2 = o2.getNormalizedValue().getBytes( "UTF-8" );
+ b2 = o2.get().getBytes( "UTF-8" );
}
}
}
@@ -440,6 +440,7 @@
try
{
+ //noinspection unchecked
return mr.getComparator().compare( b1, b2 );
}
catch ( Exception e )
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java Sat Dec 8 18:37:19 2007
@@ -83,11 +83,11 @@
/**
- * Returns the wrapped binary value. The value
- * is copied, so any modification in the caller
- * won't impact the local value.
+ * Gets a copy of the binary value.
+ *
+ * @return a copy of the binary value
*/
- public byte[] get()
+ public byte[] getCopy()
{
if ( wrapped == null )
{
@@ -101,11 +101,13 @@
/**
- * Returns the wrapped binary value.
+ * Gets a reference to the wrapped binary value.
*
* Warning ! The value is not copied !!!
+ *
+ * @return a direct handle on the binary value that is wrapped
*/
- protected byte[] getUnsafe()
+ public byte[] getReference()
{
return wrapped;
}
@@ -114,7 +116,7 @@
/**
* Returns <code>true</code> if the wrapper contains no value.
*/
- public boolean isNull()
+ public final boolean isNull()
{
return wrapped == null;
}
@@ -123,7 +125,7 @@
/**
* Sets this value's wrapped value to a copy of the src array.
*
- * @param src the source byte array to use as the wrapped value
+ * @param wrapped the byte array to use as the wrapped value
*/
public void set( byte[] wrapped )
{
@@ -183,6 +185,7 @@
return true;
}
+ //noinspection SimplifiableIfStatement
if ( isNull() != binaryValue.isNull() )
{
return false;
@@ -195,10 +198,10 @@
/**
* Compare with the current BinaryValue
*
- * @param value The BinaryValue we want to compare the current value with
- * @return
+ * @see Comparable#compareTo(Object)
*/
- public int compareTo( Value<byte[]> value )
+ @SuppressWarnings ( { "JavaDoc" } )
+ public int compareTo( BinaryValue value )
{
if ( value == null )
{
@@ -217,6 +220,6 @@
return -1;
}
- return BYTE_ARRAY_COMPARATOR.compare( wrapped, value.get() );
+ return BYTE_ARRAY_COMPARATOR.compare( wrapped, value.getReference() );
}
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java Sat Dec 8 18:37:19 2007
@@ -117,11 +117,6 @@
return 1;
}
- if ( value.get() == null )
- {
- return -1;
- }
-
- return wrapped.compareTo( value.get() );
+ throw new NotImplementedException();
}
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java Sat Dec 8 18:37:19 2007
@@ -116,8 +116,8 @@
{
return wrapped;
}
-
-
+
+
public boolean isNull()
{
return wrapped == null;
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java?rev=602613&r1=602612&r2=602613&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java Sat Dec 8 18:37:19 2007
@@ -29,12 +29,12 @@
*/
public interface Value<T>
{
- /**
- * Get the wrapped value.
- *
- * @return the wrapped value, as its original type (String,byte[],URI)
- */
- T get();
+// /**
+// * Get the wrapped value.
+// *
+// * @return the wrapped value, as its original type (String,byte[],URI)
+// */
+// T get();
/**