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 2006/08/27 09:03:59 UTC
svn commit: r437312 - in /directory/branches/shared/0.9.5/ldap/src:
main/antlr/ main/java/org/apache/directory/shared/ldap/filter/
main/java/org/apache/directory/shared/ldap/name/
main/java/org/apache/directory/shared/ldap/schema/ test/java/org/apache/...
Author: akarasulu
Date: Sun Aug 27 00:03:57 2006
New Revision: 437312
URL: http://svn.apache.org/viewvc?rev=437312&view=rev
Log:
Fix for DIRSERVER-169 and partially for DIRSERVER-715
Added:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/schema/ByteArrayComparatorTest.java
Modified:
directory/branches/shared/0.9.5/ldap/src/main/antlr/filter-parser.g
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NoOpNormalizer.java
Modified: directory/branches/shared/0.9.5/ldap/src/main/antlr/filter-parser.g
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/antlr/filter-parser.g?rev=437312&r1=437311&r2=437312&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/antlr/filter-parser.g (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/antlr/filter-parser.g Sun Aug 27 00:03:57 2006
@@ -27,6 +27,7 @@
import antlr.*;
import java.util.ArrayList;
+import org.apache.directory.shared.ldap.util.StringTools;
}
// ----------------------------------------------------------------------------
@@ -288,18 +289,42 @@
{
selector.select( valueLexer );
Object value = valueParser.value( attribute );
+
+ if ( value instanceof String )
+ {
+ String str = ( String ) value;
+ if ( str.charAt( 0 ) == '#' )
+ {
+ value = StringTools.toByteArray( str.substring( 1 ) );
+ }
+ else
+ {
+ value = str.trim();
+ }
+ }
switch( type )
{
case( AbstractExprNode.APPROXIMATE ):
case( AbstractExprNode.GREATEREQ ):
case( AbstractExprNode.LESSEQ ):
- node = new SimpleNode( attribute, ( ( String ) value).trim(), type );
+ if ( value instanceof String )
+ {
+ node = new SimpleNode( attribute, ( String ) value, type );
+ }
+ else if ( value instanceof byte[] )
+ {
+ node = new SimpleNode( attribute, ( byte[] ) value, type );
+ }
break;
case( AbstractExprNode.EQUALITY ):
if ( value instanceof String )
{
- node = new SimpleNode( attribute, ( ( String ) value ).trim(), type );
+ node = new SimpleNode( attribute, ( String ) value, type );
+ }
+ else if ( value instanceof byte[] )
+ {
+ node = new SimpleNode( attribute, ( byte[] ) value, type );
}
else
{
Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java?rev=437312&r1=437311&r2=437312&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java Sun Aug 27 00:03:57 2006
@@ -32,7 +32,7 @@
public class SimpleNode extends LeafNode
{
/** the value */
- private String value;
+ private Object value;
/**
@@ -47,7 +47,39 @@
*/
public SimpleNode( String attribute, byte[] value, int type )
{
- this( attribute, StringTools.utf8ToString( value ), type );
+// this( attribute, StringTools.utf8ToString( value ), type );
+ super( attribute, type );
+ this.value = value;
+
+ switch ( type )
+ {
+ case ( APPROXIMATE ):
+ break;
+
+ case ( EQUALITY ):
+ break;
+
+ case ( EXTENSIBLE ):
+ throw new IllegalArgumentException( "Assertion type supplied is "
+ + "extensible. Use ExtensibleNode instead." );
+
+ case ( GREATEREQ ):
+ break;
+
+ case ( LESSEQ ):
+ break;
+
+ case ( PRESENCE ):
+ throw new IllegalArgumentException( "Assertion type supplied is "
+ + "presence. Use PresenceNode instead." );
+
+ case ( SUBSTRING ):
+ throw new IllegalArgumentException( "Assertion type supplied is "
+ + "substring. Use SubstringNode instead." );
+
+ default:
+ throw new IllegalArgumentException( "Attribute value assertion type is undefined." );
+ }
}
@@ -103,7 +135,7 @@
*
* @return the value
*/
- public final String getValue()
+ public final Object getValue()
{
return value;
}
@@ -112,10 +144,9 @@
/**
* Sets the value of this node.
*
- * @param value
- * the value for this node
+ * @param value the value for this node
*/
- public void setValue( String value )
+ public void setValue( Object value )
{
this.value = value;
}
Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java?rev=437312&r1=437311&r2=437312&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java Sun Aug 27 00:03:57 2006
@@ -62,7 +62,7 @@
* @throws NamingException
* if there is a recognition problem or a syntax issue
*/
- String normalizeByName( String attributeName, String value ) throws NamingException;
+ Object normalizeByName( String attributeName, String value ) throws NamingException;
/**
@@ -77,7 +77,7 @@
* @throws NamingException
* if there is a recognition problem or a syntax issue
*/
- String normalizeByName( String attributeName, byte[] value ) throws NamingException;
+ Object normalizeByName( String attributeName, byte[] value ) throws NamingException;
/**
@@ -91,7 +91,7 @@
* @throws NamingException
* if there is a recognition problem or a syntax issue
*/
- String normalizeByOid( String attributeOid, String value ) throws NamingException;
+ Object normalizeByOid( String attributeOid, String value ) throws NamingException;
/**
@@ -105,5 +105,5 @@
* @throws NamingException
* if there is a recognition problem or a syntax issue
*/
- String normalizeByOid( String attributeOid, byte[] value ) throws NamingException;
+ Object normalizeByOid( String attributeOid, byte[] value ) throws NamingException;
}
Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java?rev=437312&r1=437311&r2=437312&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java Sun Aug 27 00:03:57 2006
@@ -53,27 +53,27 @@
}
- public String normalizeByName( String name, String val ) throws NamingException
+ public Object normalizeByName( String name, String val ) throws NamingException
{
- return ( String ) normalizer.normalize( val );
+ return normalizer.normalize( val );
}
- public String normalizeByName( String name, byte[] val ) throws NamingException
+ public Object normalizeByName( String name, byte[] val ) throws NamingException
{
- return ( String ) normalizer.normalize( val );
+ return normalizer.normalize( val );
}
- public String normalizeByOid( String oid, String val ) throws NamingException
+ public Object normalizeByOid( String oid, String val ) throws NamingException
{
- return ( String ) normalizer.normalize( val );
+ return normalizer.normalize( val );
}
- public String normalizeByOid( String oid, byte[] val ) throws NamingException
+ public Object normalizeByOid( String oid, byte[] val ) throws NamingException
{
- return ( String ) normalizer.normalize( val );
+ return normalizer.normalize( val );
}
Added: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java?rev=437312&view=auto
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java (added)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java Sun Aug 27 00:03:57 2006
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema;
+
+
+import java.util.Comparator;
+
+
+/**
+ * A comparator for byte[]s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ByteArrayComparator implements Comparator
+{
+ public static final ByteArrayComparator INSTANCE = new ByteArrayComparator();
+
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare( Object byteArray1, Object byteArray2 )
+ {
+ byte[] b1 = ( byte[] ) byteArray1;
+ byte[] b2 = ( byte[] ) byteArray2;
+
+ // -------------------------------------------------------------------
+ // Handle some basis cases
+ // -------------------------------------------------------------------
+
+ if ( b1 == null && b2 == null )
+ {
+ return 0;
+ }
+
+ if ( b1 != null && b2 == null )
+ {
+ return 1;
+ }
+
+ if ( b1 == null && b2 != null )
+ {
+ return -1;
+ }
+
+ if ( b1.length == b2.length )
+ {
+ for ( int ii = 0; ii < b1.length; ii++ )
+ {
+ if ( b1[ii] > b2[ii] )
+ {
+ return 1;
+ }
+ else if ( b1[ii] < b2[ii] )
+ {
+ return -1;
+ }
+ }
+
+ return 0;
+ }
+
+ int minLength = Math.min( b1.length, b2.length );
+ for ( int ii = 0; ii < minLength; ii++ )
+ {
+ if ( b1[ii] > b2[ii] )
+ {
+ return 1;
+ }
+ else if ( b1[ii] < b2[ii] )
+ {
+ return -1;
+ }
+ }
+
+ // b2 is longer w/ b1 as prefix
+ if ( b1.length == minLength )
+ {
+ return -1;
+ }
+
+ // b1 is longer w/ b2 as prefix
+ if ( b2.length == minLength )
+ {
+ return 1;
+ }
+
+ return 0;
+ }
+}
Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NoOpNormalizer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NoOpNormalizer.java?rev=437312&r1=437311&r2=437312&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NoOpNormalizer.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NoOpNormalizer.java Sun Aug 27 00:03:57 2006
@@ -31,8 +31,9 @@
*/
public class NoOpNormalizer implements Normalizer, Serializable
{
+ public static final NoOpNormalizer INSTANCE = new NoOpNormalizer();
static final long serialVersionUID = -7817763636668562489L;
-
+
/**
* Creates a do nothing normalizer.
Added: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/schema/ByteArrayComparatorTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/schema/ByteArrayComparatorTest.java?rev=437312&view=auto
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/schema/ByteArrayComparatorTest.java (added)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/schema/ByteArrayComparatorTest.java Sun Aug 27 00:03:57 2006
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Testcase to test the ByteArrayComparator.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ByteArrayComparatorTest extends TestCase
+{
+ public void testBothNull()
+ {
+ assertEquals( 0, ByteArrayComparator.INSTANCE.compare( null, null ) );
+ }
+
+
+ public void testB2Null()
+ {
+ assertEquals( 1, ByteArrayComparator.INSTANCE.compare( new byte[0], null ) );
+ }
+
+
+ public void testB1Null()
+ {
+ assertEquals( -1, ByteArrayComparator.INSTANCE.compare( null, new byte[0] ) );
+ }
+
+
+ public void testBothEmpty()
+ {
+ assertEquals( 0, ByteArrayComparator.INSTANCE.compare( new byte[0], new byte[0] ) );
+ }
+
+
+ public void testBothEqualLengthOne()
+ {
+ assertEquals( 0, ByteArrayComparator.INSTANCE.compare( new byte[1], new byte[1] ) );
+ }
+
+
+ public void testBothEqualLengthTen()
+ {
+ assertEquals( 0, ByteArrayComparator.INSTANCE.compare( new byte[10], new byte[10] ) );
+ }
+
+
+ public void testB1PrefixOfB2()
+ {
+ byte[] b1 = new byte[] { 0, 1, 2 };
+ byte[] b2 = new byte[] { 0, 1, 2, 3 };
+
+ assertEquals( -1, ByteArrayComparator.INSTANCE.compare( b1, b2 ) );
+ }
+
+
+ public void testB2PrefixOfB1()
+ {
+ byte[] b1 = new byte[] { 0, 1, 2, 3 };
+ byte[] b2 = new byte[] { 0, 1, 2 };
+
+ assertEquals( 1, ByteArrayComparator.INSTANCE.compare( b1, b2 ) );
+ }
+
+
+ public void testB1GreaterThanB2()
+ {
+ byte[] b1 = new byte[] { 0, 5 };
+ byte[] b2 = new byte[] { 0, 1, 2 };
+
+ assertEquals( 1, ByteArrayComparator.INSTANCE.compare( b1, b2 ) );
+ }
+
+
+ public void testB1GreaterThanB2SameLength()
+ {
+ byte[] b1 = new byte[] { 0, 5 };
+ byte[] b2 = new byte[] { 0, 1 };
+
+ assertEquals( 1, ByteArrayComparator.INSTANCE.compare( b1, b2 ) );
+ }
+
+
+ public void testB2GreaterThanB1()
+ {
+ byte[] b1 = new byte[] { 0, 1, 2 };
+ byte[] b2 = new byte[] { 0, 5 };
+
+ assertEquals( -1, ByteArrayComparator.INSTANCE.compare( b1, b2 ) );
+ }
+
+
+ public void testB2GreaterThanB1SameLength()
+ {
+ byte[] b1 = new byte[] { 0, 1 };
+ byte[] b2 = new byte[] { 0, 5 };
+
+ assertEquals( -1, ByteArrayComparator.INSTANCE.compare( b1, b2 ) );
+ }
+}