Author: elecharny
Date: Mon Mar 9 19:52:09 2009
New Revision: 751812
URL: http://svn.apache.org/viewvc?rev=751812&view=rev
Log:
o Created a StringComparator
o Fixed the Evaluator to do comparison accordingly to the AttributeType type, when no comparator
has been defined.
Added:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java
Modified:
directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
Modified: directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java?rev=751812&r1=751811&r2=751812&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
(original)
+++ directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
Mon Mar 9 19:52:09 2009
@@ -25,6 +25,7 @@
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
+import org.apache.directory.shared.ldap.schema.comparators.StringComparator;
import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.server.xdbm.IndexEntry;
@@ -32,8 +33,10 @@
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.server.core.entry.ServerBinaryValue;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
+import org.apache.directory.server.core.entry.ServerStringValue;
import java.util.Iterator;
import java.util.Comparator;
@@ -53,7 +56,16 @@
private final Registries registries;
private final AttributeType type;
private final Normalizer normalizer;
+
+ /** The comparator to use */
private final Comparator comparator;
+
+ /** The default byte[] comparator if no comparator has been defined */
+ private static final Comparator<byte[]> BINARY_COMPARATOR = ByteArrayComparator.INSTANCE;
+
+ /** The default String comparator if no comparator has been defined */
+ private static final Comparator<String> STRING_COMPARATOR = StringComparator.INSTANCE;
+
private final Index<T,ServerEntry> idx;
@@ -82,7 +94,7 @@
if ( mr == null )
{
normalizer = NoOpNormalizer.INSTANCE;
- comparator = ByteArrayComparator.INSTANCE;
+ comparator = null;
}
else
{
@@ -168,9 +180,9 @@
return evaluate ( db.lookup( id ) );
}
-
-
- // TODO - determine if comaparator and index entry should have the Value
+
+
+ // TODO - determine if comparator and index entry should have the Value
// wrapper or the raw normalized value
private boolean evaluate( ServerAttribute attribute ) throws Exception
{
@@ -180,14 +192,52 @@
* normalizer. The test uses the comparator obtained from the
* appropriate matching rule to perform the check.
*/
- for ( Value value : attribute )
+ for ( Value<?> value : attribute )
{
value.normalize( normalizer );
-
+
//noinspection unchecked
- if ( comparator.compare( value.getNormalizedValue(), node.getValue().getNormalizedValue()
) == 0 )
+ if ( value.isBinary() )
+ {
+ // Deal with a binary value
+ byte[] serverValue = ((Value<byte[]>)value).getNormalizedValue();
+ byte[] nodeValue = ((Value<byte[]>)node.getValue()).getNormalizedValue();
+
+ if ( comparator != null )
+ {
+ if ( ( comparator.compare( serverValue, nodeValue ) == 0 ) )
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if ( BINARY_COMPARATOR.compare( serverValue, nodeValue ) == 0 )
+ {
+ return true;
+ }
+ }
+ }
+ else
{
- return true;
+ // Deal with a String value
+ String serverValue = ((Value<String>)value).getNormalizedValue();
+ String nodeValue = ((Value<String>)node.getValue()).getNormalizedValue();
+
+ if ( comparator != null )
+ {
+ if ( comparator.compare( serverValue, nodeValue ) == 0 )
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if ( STRING_COMPARATOR.compare( serverValue, nodeValue ) == 0 )
+ {
+ return true;
+ }
+ }
}
}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java?rev=751812&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java
Mon Mar 9 19:52:09 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.comparators;
+
+
+import java.util.Comparator;
+
+
+/**
+ * A comparator for Strings.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class StringComparator implements Comparator<String>
+{
+ /** A static instance of this comparator */
+ public static final Comparator<String> INSTANCE = new StringComparator();
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare( String s1, String s2 )
+ {
+ // -------------------------------------------------------------------
+ // Handle some basis cases
+ // -------------------------------------------------------------------
+
+ if ( s1 == null )
+ {
+ return ( s2 == null ) ? 0 : -1;
+ }
+
+ if ( s2 == null )
+ {
+ return 1;
+ }
+
+ return s1.compareTo( s2 );
+ }
+}
|