You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/07/28 16:54:05 UTC

svn commit: r798550 [3/5] - in /directory: apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-jndi/src/main/java/org/apache...

Added: directory/apacheds/trunk/server-integ/src/test/java/MultiThreadedTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/MultiThreadedTest.java?rev=798550&view=auto
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/MultiThreadedTest.java (added)
+++ directory/apacheds/trunk/server-integ/src/test/java/MultiThreadedTest.java Tue Jul 28 14:54:01 2009
@@ -0,0 +1,203 @@
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.naming.CommunicationException;
+import javax.naming.Context;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+
+//import com.telelogic.tds.common.TDSConstants;
+//import com.telelogic.tds.common.TDSProperties;
+//import com.telelogic.tds.engine.ldap.jndi.TDSDirObjectConstants;
+
+public class MultiThreadedTest extends Thread {
+
+    private Logger _logger;
+
+    private FileAppender _appender;
+
+
+    public MultiThreadedTest(int i) {
+        super();
+        this.setName("Worker-Thread" + i);
+    }
+
+    @Override
+    public void run() {
+
+        try {
+            _logger = Logger.getLogger(this.getName());
+            _appender =
+                new FileAppender(new SimpleLayout(), "C:\\threadlog\\"
+                    + this.getName() + ".txt", false);
+            _logger.addAppender(_appender);
+            _logger.setLevel((Level) Level.ERROR);
+
+            LdapContext tdsContext = getContext();
+            LdapContext cntx;
+
+            // Create the initial context
+            Map<String, Object> hMap = new HashMap<String, Object>();
+            hMap.put("data", "dsfdfd");
+
+            // authenticate user
+            int delay = 1;
+
+            for (int i = 0; i < 100000; i++) {
+                if ( i % 100 == 0 )
+                {
+                    System.out.println( "Thread[" + getName() + "]:" + i );
+                }
+                try {
+
+                    //System.out.println(" Ops started " + getName());
+
+                    cntx = tdsContext.newInstance(null);
+
+                    setUserPreferences(cntx, "adsadminPref_" + getName(), hMap,
+                        i);
+
+                    /*System.out.println(" Preferences SET "
+                        + getName()
+                        + " "
+                        + getId()
+                        + " SIZE-- "
+                        + ((hMap.get("data") != null) ? hMap.get("data")
+                            .toString().length() : 0));*/
+
+                    cntx.close();
+
+                    //System.out.println(" Ops conducted successfully "
+                    //    + getName());
+
+                } catch (NamingException e) {
+                    //System.out.println(new Date() + " NAMING EXCETPION"
+                    //    + getName() + " " + getId());
+                    _logger.log(Level.ERROR, this.getName() + " : loop " + i);
+                    break;
+                    //e.printStackTrace();
+                } catch (Exception ex) {
+                    //System.out.println(new Date() + " NAMING EXCETPION"
+                    //    + getName() + " " + getId());
+                    _logger.log(Level.ERROR, this.getName() + " : loop " + i);
+                    break;
+                    //ex.printStackTrace();
+                }
+
+                //Thread.sleep(delay);
+            }
+        } catch (Throwable e) {
+            e.printStackTrace();
+        }
+        
+        System.out.println( "Thread[" + getName() + "] ended at " + (System.currentTimeMillis() % 1000 ) );
+        
+    }
+
+    public static String getStackTrace(Throwable t) {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw, true);
+        t.printStackTrace(pw);
+        pw.flush();
+        sw.flush();
+        return sw.toString();
+    }
+
+    private static LdapContext getContext() {
+        Hashtable<String, String> env = new Hashtable<String, String>();
+        LdapContext context = null;
+        String adminName = "uid=admin,ou=system";
+        String adminPassword = "secret";
+
+        env.put(Context.INITIAL_CONTEXT_FACTORY,
+            "com.sun.jndi.ldap.LdapCtxFactory");
+        env.put(Context.SECURITY_AUTHENTICATION, "simple");
+        env.put(Context.SECURITY_PRINCIPAL, adminName);
+        env.put(Context.SECURITY_CREDENTIALS, adminPassword);
+        //env.put(Context.PROVIDER_URL, "ldap://10.255.0.40:389");
+        env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
+        //env.put(TDSConstants.JNDI_LDAP_CONNECTION_TIMEOUT, TDSProperties
+        //    .getProperty(TDSConstants.LDAP_CONNECTION_TIMEOUT, "2000"));
+
+        env.put("com.sun.jndi.ldap.connect.pool", "true");
+
+        try {
+            context = new InitialLdapContext(env, null);
+        } catch (NamingException ne) {
+            System.exit(1);
+        }
+        return context;
+    }
+
+    public void setUserPreferences(LdapContext context, String userName,
+        Map<String, Object> attributes, int count) throws NamingException {
+
+        LdapContext derivedContext = context;
+
+        String bindOp = "cn=" + userName + "," + "ou=system";
+
+        try {
+
+            try {
+                // Step 1: Unbind the user preferences data
+                //System.out.println("Unbind[" + count + "]" + bindOp);
+                _logger.info("Unbind[" + count + "]" + bindOp);
+                derivedContext.unbind(bindOp);
+            } catch (CommunicationException ce) {
+                System.out.println("Trying to re-connect to RDS");
+                _logger.info("Trying to re-connect to RDS");
+                //Impl reconnect logic
+
+            } catch (NameNotFoundException nnf) {
+                System.out.println("User: " + userName
+                    + " cannot be found in the Ldap server");
+                _logger.info("User: " + userName
+                    + " cannot be found in the Ldap server");
+            }
+
+            try {
+                // Step 2: Bind the user preferences data
+                //System.out.println("Bind[" + count + "]" + bindOp);
+                derivedContext.bind(bindOp, attributes);
+            } catch (CommunicationException ce) {
+                System.out.println("Trying to re-connect to RDS");
+            } catch (NameAlreadyBoundException nab) {
+                System.out.println("User: " + userName
+                    + " already exists in the Ldap server");
+            }
+
+            //derivedContext.rebind(bindOp, attributes);
+        } catch (NamingException ne) {
+            //System.out.println("Could not set user profile for user: "
+            //    + userName);
+            //ne.printStackTrace();
+            _logger.log(Level.ERROR,  count);
+            throw ne;
+        }
+    }
+
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+        Thread t1 = null;
+        
+        System.out.println( System.currentTimeMillis() % 1000 );
+        for (int i = 0; i < 20; ++i) {
+            t1 = new MultiThreadedTest(i);
+            t1.start();
+        }
+    }
+
+}

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=798550&r1=798549&r2=798550&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 Tue Jul 28 14:54:01 2009
@@ -226,7 +226,7 @@
                 String serverValue = ((Value<String>)value).getNormalizedValue();
                 String nodeValue = null;
                 
-                if ( node.getValue() instanceof ClientBinaryValue )
+                if ( node.getValue().isBinary() )
                 {
                     nodeValue = StringTools.utf8ToString( ((Value<byte[]>)node.getValue()).getNormalizedValue() );
                 }

Modified: directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java Tue Jul 28 14:54:01 2009
@@ -297,7 +297,8 @@
             {
                 checkNotClosed( "previous()" );
                 IndexEntry<?,ServerEntry> candidate = userIdxCursor.get();
-                if ( greaterEqEvaluator.getComparator().compare( candidate.getValue(), greaterEqEvaluator.getExpression().getValue().get() ) >= 0 )
+                if ( greaterEqEvaluator.getComparator().compare( candidate.getValue(), 
+                    greaterEqEvaluator.getExpression().getValue().get() ) >= 0 )
                 {
                     return available = true;
                 }

Added: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/FilterNormalizingVisitor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/FilterNormalizingVisitor.java?rev=798550&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/FilterNormalizingVisitor.java (added)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/FilterNormalizingVisitor.java Tue Jul 28 14:54:01 2009
@@ -0,0 +1,523 @@
+/*
+ *  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.server.xdbm.search.impl;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.filter.AndNode;
+import org.apache.directory.shared.ldap.filter.BranchNode;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.ExtensibleNode;
+import org.apache.directory.shared.ldap.filter.FilterVisitor;
+import org.apache.directory.shared.ldap.filter.LeafNode;
+import org.apache.directory.shared.ldap.filter.NotNode;
+import org.apache.directory.shared.ldap.filter.PresenceNode;
+import org.apache.directory.shared.ldap.filter.SimpleNode;
+import org.apache.directory.shared.ldap.filter.SubstringNode;
+import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A filter visitor which normalizes leaf node values as it visits them.  It also removes
+ * leaf nodes from branches whose attributeType is undefined.  It obviously cannot remove
+ * a leaf node from a filter which is only a leaf node.  Checks to see if a filter is a
+ * leaf node with undefined attributeTypes should be done outside this visitor.
+ *
+ * Since this visitor may remove filter nodes it may produce negative results on filters,
+ * like NOT branch nodes without a child or AND and OR nodes with one or less children.  This
+ * might make some partition implementations choke.  To avoid this problem we clean up branch
+ * nodes that don't make sense.  For example all BranchNodes without children are just
+ * removed.  An AND and OR BranchNode with a single child is replaced with it's child for
+ * all but the topmost branchnode which we cannot replace.  So again the top most branch
+ * node must be inspected by code outside of this visitor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 770988 $
+ */
+public class FilterNormalizingVisitor implements FilterVisitor
+{
+    /** logger used by this class */
+    private static final Logger log = LoggerFactory.getLogger( FilterNormalizingVisitor.class );
+
+    /** the name component normalizer used by this visitor */
+    private final NameComponentNormalizer ncn;
+
+    /** the global registries used to resolve OIDs for attributeType ids */
+    private final Registries registries;
+
+
+    /**
+     * Chars which need to be escaped in a filter
+     * '\0' | '(' | ')' | '*' | '\'
+     */
+    private static final boolean[] FILTER_CHAR =
+        { 
+            true,  false, false, false, false, false, false, false, // 00 -> 07 NULL
+            false, false, false, false, false, false, false, false, // 08 -> 0F
+            false, false, false, false, false, false, false, false, // 10 -> 17
+            false, false, false, false, false, false, false, false, // 18 -> 1F
+            false, false, false, false, false, false, false, false, // 20 -> 27
+            true,  true,  true,  false, false, false, false, false, // 28 -> 2F '(', ')', '*'
+            false, false, false, false, false, false, false, false, // 30 -> 37
+            false, false, false, false, false, false, false, false, // 38 -> 3F 
+            false, false, false, false, false, false, false, false, // 40 -> 47
+            false, false, false, false, false, false, false, false, // 48 -> 4F
+            false, false, false, false, false, false, false, false, // 50 -> 57
+            false, false, false, false, true,  false, false, false, // 58 -> 5F '\'
+            false, false, false, false, false, false, false, false, // 60 -> 67
+            false, false, false, false, false, false, false, false, // 68 -> 6F
+            false, false, false, false, false, false, false, false, // 70 -> 77
+            false, false, false, false, false, false, false, false  // 78 -> 7F
+        };
+    
+    /**
+     * Check if the given char is a filter escaped char
+     * &lt;filterEscapedChars&gt; ::= '\0' | '(' | ')' | '*' | '\'
+     *
+     * @param c the char we want to test
+     * @return true if the char is a pair char only
+     */
+    public static boolean isFilterChar( char c )
+    {
+        return ( ( ( c | 0x7F ) == 0x7F ) && FILTER_CHAR[c & 0x7f] );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of NormalizingVisitor.
+     *
+     * @param ncn The name component normalizer to use
+     * @param registries The global registries
+     */
+    public FilterNormalizingVisitor( NameComponentNormalizer ncn, Registries registries )
+    {
+        this.ncn = ncn;
+        this.registries = registries;
+    }
+
+
+    /**
+     * A private method used to normalize a value. At this point, the value
+     * is a Value<byte[]>, we have to translate it to a Value<String> if its
+     * AttributeType is H-R. Then we have to normalize the value accordingly
+     * to the AttributeType Normalizer.
+     * 
+     * @param attribute The attribute's ID
+     * @param value The value to normalize
+     * @return the normalized value
+     */
+    private Value<?> normalizeValue( String attribute, Value<?> value )
+    {
+        try
+        {
+            Value<?> normalized = null;
+
+            AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( attribute );
+
+            if ( attributeType.getSyntax().isHumanReadable() )
+            {
+                normalized = new ClientStringValue( 
+                    (String) ncn.normalizeByName( attribute, value.getString() ) );
+            }
+            else
+            {
+                normalized = new ClientBinaryValue( 
+                    (byte[]) ncn.normalizeByName( attribute, value.getBytes() ) );
+            }
+
+            return normalized;
+        }
+        catch ( NamingException ne )
+        {
+            log.warn( "Failed to normalize filter value: {}", ne.getMessage(), ne );
+            return null;
+        }
+    }
+
+
+    /**
+     * Visit a PresenceNode. If the attribute exists, the node is returned, otherwise
+     * null is returned.
+     * 
+     * @param node the node to visit
+     * @return The visited node
+     */
+    private ExprNode visitPresenceNode( PresenceNode node )
+    {
+        try
+        {
+            node.setAttribute( registries.getOidRegistry().getOid( node.getAttribute() ) );
+            return node;
+        }
+        catch ( NamingException ne )
+        {
+            log.warn( "Failed to normalize filter node attribute: {}, error: {}", node.getAttribute(), ne.getMessage() );
+            return null;
+        }
+    }
+
+
+    /**
+     * Visit a SimpleNode. If the attribute exists, the node is returned, otherwise
+     * null is returned. SimpleNodes are :
+     *  - ApproximateNode
+     *  - EqualityNode
+     *  - GreaterEqNode
+     *  - LesserEqNode
+     *  
+     * @param node the node to visit
+     * @return the visited node
+     */
+    private ExprNode visitSimpleNode( SimpleNode node )
+    {
+        // still need this check here in case the top level is a leaf node
+        // with an undefined attributeType for its attribute
+        if ( !ncn.isDefined( node.getAttribute() ) )
+        {
+            return null;
+        }
+
+        Value<?> normalized = normalizeValue( node.getAttribute(), node.getValue() );
+
+        if ( normalized == null )
+        {
+            return null;
+        }
+
+        try
+        {
+            node.setAttribute( registries.getOidRegistry().getOid( node.getAttribute() ) );
+            node.setValue( normalized );
+            return node;
+        }
+        catch ( NamingException ne )
+        {
+            log.warn( "Failed to normalize filter node attribute: {}, error: {}", node.getAttribute(), ne.getMessage() );
+            return null;
+        }
+    }
+
+
+    /**
+     * Visit a SubstringNode. If the attribute exists, the node is returned, otherwise
+     * null is returned. 
+     * 
+     * Normalizing substring value is pretty complex. It's not currently implemented...
+     * 
+     * @param node the node to visit
+     * @return the visited node
+     */
+    private ExprNode visitSubstringNode( SubstringNode node )
+    {
+        // still need this check here in case the top level is a leaf node
+        // with an undefined attributeType for its attribute
+        if ( !ncn.isDefined( node.getAttribute() ) )
+        {
+            return null;
+        }
+
+        Value<?> normInitial = null;
+
+        if ( node.getInitial() != null )
+        {
+            normInitial = normalizeValue( node.getAttribute(), new ClientStringValue( node.getInitial() ) );
+
+            if ( normInitial == null )
+            {
+                return null;
+            }
+        }
+
+        List<String> normAnys = null;
+
+        if ( ( node.getAny() != null ) && ( node.getAny().size() != 0 ) )
+        {
+            normAnys = new ArrayList<String>( node.getAny().size() );
+
+            for ( String any : node.getAny() )
+            {
+                Value<?> normAny = normalizeValue( node.getAttribute(), new ClientStringValue( any ) );
+
+                if ( normAny != null )
+                {
+                    normAnys.add( normAny.getString() );
+                }
+            }
+
+            if ( normAnys.size() == 0 )
+            {
+                return null;
+            }
+        }
+
+        Value<?> normFinal = null;
+
+        if ( node.getFinal() != null )
+        {
+            normFinal = normalizeValue( node.getAttribute(), new ClientStringValue( node.getFinal() ) );
+
+            if ( normFinal == null )
+            {
+                return null;
+            }
+        }
+
+        try
+        {
+            node.setAttribute( registries.getOidRegistry().getOid( node.getAttribute() ) );
+
+            if ( normInitial != null )
+            {
+                node.setInitial( normInitial.getString() );
+            }
+            else
+            {
+                node.setInitial( null );
+            }
+
+            node.setAny( normAnys );
+
+            if ( normFinal != null )
+            {
+                node.setFinal( normFinal.getString() );
+            }
+            else
+            {
+                node.setFinal( null );
+            }
+
+            return node;
+        }
+        catch ( NamingException ne )
+        {
+            log.warn( "Failed to normalize filter node attribute: {}, error: {}", node.getAttribute(), ne.getMessage() );
+            return null;
+        }
+    }
+
+
+    /**
+     * Visit a ExtensibleNode. If the attribute exists, the node is returned, otherwise
+     * null is returned. 
+     * 
+     * TODO implement the logic for ExtensibleNode
+     * 
+     * @param node the node to visit
+     * @return the visited node
+     */
+    private ExprNode visitExtensibleNode( ExtensibleNode node )
+    {
+        try
+        {
+            node.setAttribute( registries.getOidRegistry().getOid( node.getAttribute() ) );
+            return node;
+        }
+        catch ( NamingException ne )
+        {
+            log.warn( "Failed to normalize filter node attribute: {}, error: {}", node.getAttribute(), ne.getMessage() );
+            return null;
+        }
+    }
+
+
+    /**
+     * Visit a BranchNode. BranchNodes are :
+     *  - AndNode
+     *  - NotNode
+     *  - OrNode
+     *  
+     * @param node the node to visit
+     * @return the visited node
+     */
+    private ExprNode visitBranchNode( BranchNode node )
+    {
+        // Two differente cases :
+        // - AND or OR
+        // - NOT
+
+        if ( node instanceof NotNode )
+        {
+            // Manage the NOT
+            ExprNode child = node.getFirstChild();
+
+            ExprNode result = ( ExprNode ) visit( child );
+
+            if ( result == null )
+            {
+                return null;
+            }
+            else if ( result instanceof BranchNode )
+            {
+                List<ExprNode> newChildren = new ArrayList<ExprNode>( 1 );
+                newChildren.add( result );
+                node.setChildren( newChildren );
+                return node;
+            }
+            else if ( result instanceof LeafNode )
+            {
+                List<ExprNode> newChildren = new ArrayList<ExprNode>( 1 );
+                newChildren.add( result );
+                node.setChildren( newChildren );
+                return node;
+            }
+        }
+        else
+        {
+            // Manage AND and OR nodes.
+            BranchNode branchNode = node;
+            List<ExprNode> children = node.getChildren();
+
+            // For AND and OR, we may have more than one children.
+            // We may have to remove some of them, so let's create
+            // a new handler to store the correct nodes.
+            List<ExprNode> newChildren = new ArrayList<ExprNode>( children.size() );
+
+            // Now, iterate through all the children
+            for ( int i = 0; i < children.size(); i++ )
+            {
+                ExprNode child = children.get( i );
+
+                ExprNode result = ( ExprNode ) visit( child );
+
+                if ( result != null )
+                {
+                    // As the node is correct, add it to the children 
+                    // list.
+                    newChildren.add( result );
+                }
+            }
+
+            if ( ( branchNode instanceof AndNode ) && ( newChildren.size() != children.size() ) )
+            {
+                return null;
+            }
+
+            if ( newChildren.size() == 0 )
+            {
+                // No more children, return null
+                return null;
+            }
+            else if ( newChildren.size() == 1 )
+            {
+                // As we only have one child, return it
+                // to the caller.
+                return newChildren.get( 0 );
+            }
+            else
+            {
+                branchNode.setChildren( newChildren );
+            }
+        }
+
+        return node;
+    }
+
+
+    /**
+     * Visit the tree, normalizing the leaves and recusrsively visit the branches.
+     * 
+     * Here are the leaves we are visiting :
+     * - PresenceNode ( attr =* )
+     * - ExtensibleNode ( ? )
+     * - SubStringNode ( attr = *X*Y* )
+     * - ApproximateNode ( attr ~= value )
+     * - EqualityNode ( attr = value )
+     * - GreaterEqNode ( attr >= value )
+     * - LessEqNode ( attr <= value )
+     * 
+     * The PresencNode is managed differently from other nodes, as it just check
+     * for the attribute, not the value.
+     * 
+     * @param node the node to visit
+     * @return the visited node
+     */
+    public Object visit( ExprNode node )
+    {
+        // -------------------------------------------------------------------
+        // Handle PresenceNodes
+        // -------------------------------------------------------------------
+
+        if ( node instanceof PresenceNode )
+        {
+            return visitPresenceNode( ( PresenceNode ) node );
+        }
+
+        // -------------------------------------------------------------------
+        // Handle BranchNodes (AndNode, NotNode and OrNode)
+        // -------------------------------------------------------------------
+
+        else if ( node instanceof BranchNode )
+        {
+            return visitBranchNode( ( BranchNode ) node );
+        }
+
+        // -------------------------------------------------------------------
+        // Handle SimpleNodes (ApproximateNode, EqualityNode, GreaterEqNode,
+        // and LesserEqNode) 
+        // -------------------------------------------------------------------
+
+        else if ( node instanceof SimpleNode )
+        {
+            return visitSimpleNode( ( SimpleNode ) node );
+        }
+        else if ( node instanceof ExtensibleNode )
+        {
+            return visitExtensibleNode( ( ExtensibleNode ) node );
+        }
+        else if ( node instanceof SubstringNode )
+        {
+            return visitSubstringNode( ( SubstringNode ) node );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    public boolean canVisit( ExprNode node )
+    {
+        return true;
+    }
+
+
+    public boolean isPrefix()
+    {
+        return false;
+    }
+
+
+    public List<ExprNode> getOrder( BranchNode node, List<ExprNode> children )
+    {
+        return children;
+    }
+}

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java Tue Jul 28 14:54:01 2009
@@ -28,6 +28,7 @@
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
 import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.schema.ConcreteNameComponentNormalizer;
 import org.apache.directory.server.schema.SerializableComparator;
 import org.apache.directory.server.schema.bootstrap.ApacheSchema;
 import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
@@ -48,6 +49,7 @@
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.*;
 import static org.junit.Assert.*;
@@ -73,6 +75,7 @@
     EvaluatorBuilder evaluatorBuilder;
     CursorBuilder cursorBuilder;
     Optimizer optimizer;
+    FilterNormalizingVisitor visitor;
 
     
     public NestedFilterTest() throws Exception
@@ -92,6 +95,9 @@
         bootstrapSchemas.add( new CollectiveSchema() );
         loader.loadWithDependencies( bootstrapSchemas, registries );
         attributeRegistry = registries.getAttributeTypeRegistry();
+        
+        NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( attributeRegistry, oidRegistry );
+        visitor = new FilterNormalizingVisitor( ncn, registries );
     }
 
     
@@ -149,6 +155,7 @@
         String filter = "(|(&(cn=J*)(sn=w*))(ou=apache))";
 
         ExprNode exprNode = FilterParser.parse( filter );
+        exprNode.accept( visitor );
         optimizer.annotate( exprNode );
         
         IndexCursor<?,ServerEntry> cursor = cursorBuilder.build( exprNode );
@@ -161,14 +168,12 @@
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( long ) cursor.get().getId() );
-        assertEquals( "apache", 
-            StringTools.utf8ToString( (byte[])cursor.get().getValue() ) );
+        assertEquals( "apache", cursor.get().getValue());
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 9, ( long ) cursor.get().getId() );
-        assertEquals( "apache", 
-            StringTools.utf8ToString( (byte[])cursor.get().getValue() ) );
+        assertEquals( "apache", cursor.get().getValue() );
 
         assertFalse( cursor.next() );
     }

Modified: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/SearchResultEntryDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/SearchResultEntryDsml.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/SearchResultEntryDsml.java (original)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/SearchResultEntryDsml.java Tue Jul 28 14:54:01 2009
@@ -103,7 +103,7 @@
                 }
                 else
                 {
-                    attributeElement.addElement( "value" ).addText( value.get().toString() );
+                    attributeElement.addElement( "value" ).addText( value.getString() );
                 }
             }
         }

Modified: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/AddRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/AddRequestDsml.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/AddRequestDsml.java (original)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/AddRequestDsml.java Tue Jul 28 14:54:01 2009
@@ -111,7 +111,7 @@
                     }
                     else
                     {
-                        attributeElement.addElement( "value" ).addText( value.get().toString() );
+                        attributeElement.addElement( "value" ).addText( value.getString() );
                     }
                 }
             }

Modified: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/ModifyRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/ModifyRequestDsml.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/ModifyRequestDsml.java (original)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/ModifyRequestDsml.java Tue Jul 28 14:54:01 2009
@@ -119,7 +119,7 @@
                         }
                         else
                         {
-                            modElement.addElement( "value" ).setText( ( String ) value.get() );
+                            modElement.addElement( "value" ).setText( value.getString() );
                         }
                     }
                 }

Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/addRequest/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/addRequest/AddRequestTest.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/addRequest/AddRequestTest.java (original)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/addRequest/AddRequestTest.java Tue Jul 28 14:54:01 2009
@@ -368,7 +368,7 @@
         Iterator<Value<?>> valueIterator = attribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "top", value.get() );
+        assertEquals( "top", value.getString() );
     }
 
 
@@ -407,7 +407,7 @@
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
         assertTrue( value.isBinary() );
-        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) value.get() ) );
+        assertEquals( "DSMLv2.0 rocks!!", value.getString() );
     }
 
 
@@ -445,10 +445,10 @@
         Iterator<Value<?>> valueIterator = attribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "top", value.get() );
+        assertEquals( "top", value.getString() );
         assertTrue( valueIterator.hasNext() );
         value = valueIterator.next();
-        assertEquals( "person", value.get() );
+        assertEquals( "person", value.getString() );
         assertFalse( valueIterator.hasNext() );
     }
 
@@ -496,10 +496,10 @@
         Iterator<Value<?>> valueIterator = attribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "top", value.get() );
+        assertEquals( "top", value.getString() );
         assertTrue( valueIterator.hasNext() );
         value = valueIterator.next();
-        assertEquals( "person", value.get() );
+        assertEquals( "person", value.getString() );
         assertFalse( valueIterator.hasNext() );
     }
 

Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/modifyRequest/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/modifyRequest/ModifyRequestTest.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/modifyRequest/ModifyRequestTest.java (original)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/modifyRequest/ModifyRequestTest.java Tue Jul 28 14:54:01 2009
@@ -272,7 +272,7 @@
 
         EntryAttribute attribute = modification.getAttribute();
 
-        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ).get() );
+        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ).getString() );
     }
 
 
@@ -317,7 +317,7 @@
                 'a', 'r', 'n', 'y', ',', ' ', 'o', 'u', '=', 'p', 'e', 'o', 'p', 'l', 'e', ',', ' ', 'd', 'c', '=',
                 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', ' ', 'd', 'c', '=', 'c', 'o', 'm' }, "UTF-8" );
 
-        assertEquals( expected, new String( ( byte[] ) attribute.get( 0 ).get(), "UTF-8" ) );
+        assertEquals( expected, attribute.get( 0 ).getString() );
     }
 
 
@@ -356,7 +356,7 @@
 
         EntryAttribute attribute = modification.getAttribute();
 
-        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 0 ).get() );
+        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 0 ).getString() );
     }
 
 
@@ -541,8 +541,8 @@
         EntryAttribute attribute = modification.getAttribute();
 
         assertEquals( 2, attribute.size() );
-        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ).get() );
-        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 1 ).get() );
+        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ).getString() );
+        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 1 ).getString() );
     }
 
 
@@ -582,7 +582,7 @@
         EntryAttribute attribute = modification.getAttribute();
 
         assertEquals( 1, attribute.size() );
-        assertEquals( "", attribute.get( 0 ).get() );
+        assertEquals( "", attribute.get( 0 ).getString() );
     }
 
 

Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java (original)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java Tue Jul 28 14:54:01 2009
@@ -946,7 +946,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "foobar", assertion.getAssertionValue().get() );
+        assertEquals( "foobar", assertion.getAssertionValue().getString() );
     }
 
 
@@ -984,7 +984,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) assertion.getAssertionValue().get() ) );
+        assertEquals( "DSMLv2.0 rocks!!", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1087,7 +1087,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "foobar", assertion.getAssertionValue().get() );
+        assertEquals( "foobar", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1125,7 +1125,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) assertion.getAssertionValue().get() ) );
+        assertEquals( "DSMLv2.0 rocks!!", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1228,7 +1228,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "foobar", assertion.getAssertionValue().get() );
+        assertEquals( "foobar", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1266,7 +1266,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) assertion.getAssertionValue().get() ) );
+        assertEquals( "DSMLv2.0 rocks!!", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1369,7 +1369,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "foobar", assertion.getAssertionValue().get() );
+        assertEquals( "foobar", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1407,7 +1407,7 @@
 
         assertEquals( "sn", assertion.getAttributeDesc() );
 
-        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) assertion.getAssertionValue().get() ) );
+        assertEquals( "DSMLv2.0 rocks!!", assertion.getAssertionValue().getString() );
     }
 
 
@@ -1545,7 +1545,7 @@
 
         ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) filter;
 
-        assertEquals( "A Value", extensibleMatchFilter.getMatchValue().get() );
+        assertEquals( "A Value", extensibleMatchFilter.getMatchValue().getString() );
 
         assertEquals( false, extensibleMatchFilter.isDnAttributes() );
     }
@@ -1579,7 +1579,7 @@
 
         ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) filter;
 
-        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) extensibleMatchFilter.getMatchValue().get() ) );
+        assertEquals( "DSMLv2.0 rocks!!", extensibleMatchFilter.getMatchValue().getString() );
 
         assertEquals( false, extensibleMatchFilter.isDnAttributes() );
     }

Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java (original)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java Tue Jul 28 14:54:01 2009
@@ -349,7 +349,7 @@
         Iterator<Value<?>> valueIterator = attribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "example", value.get() );
+        assertEquals( "example", value.getString() );
     }
 
 
@@ -392,7 +392,7 @@
         String expected = new String( new byte[]
             { 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', 'L', ( byte ) 0xc3, ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n',
                 'y' }, "UTF-8" );
-        assertEquals( expected, new String( ( byte[] ) value.get(), "UTF-8" ) );
+        assertEquals( expected, value.getString() );
     }
 
 
@@ -430,7 +430,7 @@
         Iterator<Value<?>> valueIterator = attribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "", value.get() );
+        assertEquals( "", value.getString() );
     }
 
 
@@ -468,10 +468,10 @@
         Iterator<Value<?>> valueIterator = attribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "top", value.get() );
+        assertEquals( "top", value.getString() );
         assertTrue( valueIterator.hasNext() );
         value = valueIterator.next();
-        assertEquals( "domain", value.get() );
+        assertEquals( "domain", value.getString() );
         assertFalse( valueIterator.hasNext() );
     }
 
@@ -508,7 +508,7 @@
         Iterator<Value<?>> valueIterator = objectClassAttribute.iterator();
         assertTrue( valueIterator.hasNext() );
         Value<?> value = valueIterator.next();
-        assertEquals( "top", value.get() );
+        assertEquals( "top", value.getString() );
         assertFalse( valueIterator.hasNext() );
 
         EntryAttribute dcAttribute = entry.get( "dc" );
@@ -517,7 +517,7 @@
         valueIterator = dcAttribute.iterator();
         assertTrue( valueIterator.hasNext() );
         value = valueIterator.next();
-        assertEquals( "example", value.get() );
+        assertEquals( "example", value.getString() );
         assertFalse( valueIterator.hasNext() );
     }
 

Modified: directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g Tue Jul 28 14:54:01 2009
@@ -28,6 +28,8 @@
 
 import javax.naming.InvalidNameException;
 import javax.naming.NameParser;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
 import org.apache.directory.shared.ldap.schema.parsers.ParserMonitor;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -295,7 +297,18 @@
         {
             try
             {
-                rdn.addAttributeTypeAndValue( type, type, value.upValue, value.normValue );
+                if ( value.normValue instanceof String )
+                {
+                    rdn.addAttributeTypeAndValue( type, type, 
+                        new ClientStringValue( value.upValue ), 
+                        new ClientStringValue( (String)value.normValue ) );
+                }
+                else
+                {
+                    rdn.addAttributeTypeAndValue( type, type, 
+                        new ClientStringValue( value.upValue ), 
+                        new ClientBinaryValue( (byte[])value.normValue ) );
+                }
                 { upName += value.upValue + value.trailingSpaces; }
             }
             catch ( InvalidNameException e )

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestCodec.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestCodec.java Tue Jul 28 14:54:01 2009
@@ -35,8 +35,6 @@
 import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -297,16 +295,8 @@
 
                     for ( org.apache.directory.shared.ldap.entry.Value<?> value : attribute )
                     {
-                        if ( value instanceof ClientStringValue )
-                        {
-                            int valueLength = StringTools.getBytesUtf8( ( String ) value.get() ).length;
-                            localValuesLength += 1 + TLV.getNbBytes( valueLength ) + valueLength;
-                        }
-                        else
-                        {
-                            int valueLength = ( ( byte[] ) value.get() ).length;
-                            localValuesLength += 1 + TLV.getNbBytes( valueLength ) + valueLength;
-                        }
+                        int valueLength = value.getBytes().length;
+                        localValuesLength += 1 + TLV.getNbBytes( valueLength ) + valueLength;
                     }
 
                     localAttributeLength += 1 + TLV.getNbBytes( localValuesLength ) + localValuesLength;
@@ -404,13 +394,13 @@
                     {
                         for ( org.apache.directory.shared.ldap.entry.Value<?> value : attribute )
                         {
-                            if ( value instanceof ClientBinaryValue )
+                            if ( value.isBinary() )
                             {
-                                Value.encode( buffer, ( byte[] ) value.get() );
+                                Value.encode( buffer, value.getBytes() );
                             }
                             else
                             {
-                                Value.encode( buffer, ( String ) value.get() );
+                                Value.encode( buffer, value.getString() );
                             }
                         }
                     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java Tue Jul 28 14:54:01 2009
@@ -363,16 +363,8 @@
                 {
                     for ( org.apache.directory.shared.ldap.entry.Value<?> value:modification.getAttribute() )
                     {
-                        if ( value instanceof ClientStringValue )
-                        {
-                            int valueLength = StringTools.getBytesUtf8( (String)value.get() ).length;
-                            localValuesLength += 1 + TLV.getNbBytes( valueLength ) + valueLength;
-                        }
-                        else
-                        {
-                            localValuesLength += 1 + TLV.getNbBytes( ( ( byte[] ) value.getReference() ).length )
-                                + ( ( byte[] ) value.getReference() ).length;
-                        }
+                        localValuesLength += 1 + TLV.getNbBytes( value.getBytes().length )
+                            + value.getBytes().length;
                     }
                 }
 
@@ -486,13 +478,13 @@
                     {
                         for ( org.apache.directory.shared.ldap.entry.Value<?> value:modification.getAttribute() )
                         {
-                            if ( value instanceof ClientStringValue )
+                            if ( !value.isBinary() )
                             {
-                                Value.encode( buffer, ( String ) value.get() );
+                                Value.encode( buffer, value.getString() );
                             }
                             else
                             {
-                                Value.encode( buffer, ( byte[] ) value.getReference() );
+                                Value.encode( buffer, value.getBytes() );
                             }
                         }
                     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java Tue Jul 28 14:54:01 2009
@@ -28,9 +28,6 @@
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.AttributeValueAssertion;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
-import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
@@ -159,14 +156,7 @@
 
         int assertionValueLength = 0;
 
-        if ( assertionValue instanceof ClientStringValue )
-        {
-            assertionValueLength = StringTools.getBytesUtf8( ((ClientStringValue)assertionValue).get() ).length;
-        }
-        else
-        {
-            assertionValueLength = ((ClientBinaryValue)assertionValue).get().length;
-        }
+        assertionValueLength = assertionValue.getBytes().length;
 
         avaLength += 1 + TLV.getNbBytes( assertionValueLength ) + assertionValueLength;
 
@@ -231,13 +221,13 @@
         Value.encode( buffer, assertion.getAttributeDesc() );
 
         // The assertion desc
-        if ( assertion.getAssertionValue().get() instanceof String )
+        if ( assertion.getAssertionValue().isBinary() )
         {
-            Value.encode( buffer, ( String ) assertion.getAssertionValue().get() );
+            Value.encode( buffer, assertion.getAssertionValue().getString() );
         }
         else
         {
-            Value.encode( buffer, ( byte[] ) assertion.getAssertionValue().get() );
+            Value.encode( buffer, assertion.getAssertionValue().getBytes() );
         }
 
         return buffer;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java Tue Jul 28 14:54:01 2009
@@ -27,8 +27,6 @@
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -215,7 +213,7 @@
     {
         if ( matchingRule != null )
         {
-            matchingRuleBytes = StringTools.getBytesUtf8(  matchingRule );
+            matchingRuleBytes = StringTools.getBytesUtf8( matchingRule );
             extensibleMatchLength = 1 + TLV.getNbBytes( matchingRuleBytes.length ) + matchingRuleBytes.length;
         }
 
@@ -227,16 +225,8 @@
 
         if ( matchValue != null )
         {
-            if ( matchValue instanceof ClientStringValue )
-            {
-                int matchValueLength = (( ClientStringValue ) matchValue ).get().length();
-                extensibleMatchLength += 1 + TLV.getNbBytes( matchValueLength ) + matchValueLength;
-            }
-            else
-            {
-                int bytesLength = ( (ClientBinaryValue) matchValue ).get().length;
-                extensibleMatchLength += 1 + TLV.getNbBytes( bytesLength ) + bytesLength;
-            }
+            int bytesLength = matchValue.getBytes().length;
+            extensibleMatchLength += 1 + TLV.getNbBytes( bytesLength ) + bytesLength;
         }
 
         if ( dnAttributes )
@@ -306,25 +296,13 @@
             {
                 buffer.put( ( byte ) LdapConstants.MATCH_VALUE_TAG );
 
-                if ( matchValue instanceof ClientStringValue )
-                {
-                    byte[] matchValueBytes = StringTools.getBytesUtf8( (( ClientStringValue ) matchValue).get() );
-                    buffer.put( TLV.getBytes( matchValueBytes.length ) );
+                byte[] bytes = matchValue.getBytes();
+                int bytesLength = bytes.length;
+                buffer.put( TLV.getBytes( bytesLength ) );
 
-                    if ( matchValueBytes.length != 0 )
-                    {
-                        buffer.put( matchValueBytes );
-                    }
-                }
-                else
+                if ( bytesLength != 0 )
                 {
-                    int bytesLength = ( ( ClientBinaryValue ) matchValue ).get().length;
-                    buffer.put( TLV.getBytes( bytesLength ) );
-
-                    if ( bytesLength != 0 )
-                    {
-                        buffer.put( ((ClientBinaryValue)matchValue).get() );
-                    }
+                    buffer.put( bytes );
                 }
 
             }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java Tue Jul 28 14:54:01 2009
@@ -274,19 +274,8 @@
 
                         for ( org.apache.directory.shared.ldap.entry.Value<?> value : attribute )
                         {
-                            if ( value instanceof ClientStringValue )
-                            {
-                                String stringValue = ( String ) value.get();
-
-                                int stringLength = StringTools.getBytesUtf8( stringValue ).length;
-                                localValuesLength += 1 + TLV.getNbBytes( stringLength ) + stringLength;
-                            }
-                            else
-                            {
-                                byte[] binaryValue = ( byte[] ) value.get();
-                                localValuesLength += 1 + TLV.getNbBytes( binaryValue.length ) + binaryValue.length;
-                            }
-
+                            byte[] binaryValue = value.getBytes();
+                            localValuesLength += 1 + TLV.getNbBytes( binaryValue.length ) + binaryValue.length;
                         }
 
                         localAttributeLength += 1 + TLV.getNbBytes( localValuesLength ) + localValuesLength;
@@ -394,13 +383,13 @@
                         {
                             for ( org.apache.directory.shared.ldap.entry.Value<?> value : attribute )
                             {
-                                if ( value instanceof ClientStringValue )
+                                if ( !value.isBinary() )
                                 {
-                                    Value.encode( buffer, ( String ) value.get() );
+                                    Value.encode( buffer, value.getString() );
                                 }
                                 else
                                 {
-                                    Value.encode( buffer, ( byte[] ) value.get() );
+                                    Value.encode( buffer, value.getBytes() );
                                 }
                             }
                         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java Tue Jul 28 14:54:01 2009
@@ -66,6 +66,25 @@
     
     
     /**
+     * Get the wrapped value as a byte[]. If the original value
+     * is binary, this method will return a copy of the wrapped byte[]
+     *
+     * @return the wrapped value as a byte[]
+     */
+    byte[] getBytes();
+    
+    
+    /**
+     * Get the wrapped value as a String. If the original value
+     * is binary, this method will return the value as if it was 
+     * an UTF-8 encoded String.
+     *
+     * @return the wrapped value as a String
+     */
+    String getString();
+    
+    
+    /**
      * Get a reference on the stored value.
      *
      * @return a reference on the wrapped value.

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java Tue Jul 28 14:54:01 2009
@@ -192,7 +192,7 @@
             }
             else
             {
-                normalizedValue = (byte[])normalizer.normalize( wrapped );
+                normalizedValue = normalizer.normalize( this ).getBytes();
                 normalized = true;
             }
         }
@@ -360,6 +360,29 @@
 
 
     /**
+     * Get the wrapped value as a byte[]. This method returns a copy of 
+     * the wrapped byte[].
+     * 
+     * @return the wrapped value as a byte[]
+     */
+    public byte[] getBytes()
+    {
+        return getCopy();
+    }
+    
+    
+    /**
+     * Get the wrapped value as a String.
+     *
+     * @return the wrapped value as a String
+     */
+    public String getString()
+    {
+        return StringTools.utf8ToString( wrapped );
+    }
+    
+    
+    /**
      * @see Externalizable#readExternal(ObjectInput)
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java Tue Jul 28 14:54:01 2009
@@ -30,6 +30,7 @@
 import org.apache.directory.shared.ldap.entry.AbstractValue;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -107,7 +108,7 @@
     {
         // Why should we invalidate the normalized value if it's we're setting the
         // wrapper to it's current value?
-        if ( ( wrapped != null ) && wrapped.equals( get() ) )
+        if ( !StringTools.isEmpty( wrapped ) && wrapped.equals( getString() ) )
         {
             return;
         }
@@ -303,6 +304,27 @@
     
     
     /**
+     * Get the wrapped value as a byte[].
+     * @return the wrapped value as a byte[]
+     */
+    public byte[] getBytes()
+    {
+        return StringTools.getBytesUtf8( wrapped );
+    }
+    
+    
+    /**
+     * Get the wrapped value as a String.
+     *
+     * @return the wrapped value as a String
+     */
+    public String getString()
+    {
+        return wrapped != null ? wrapped : "";
+    }
+    
+    
+    /**
      * @see Externalizable#readExternal(ObjectInput)
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java Tue Jul 28 14:54:01 2009
@@ -108,7 +108,7 @@
         {
             for ( Value<?> val:vals )
             {
-                if ( ( val instanceof ClientStringValue ) || ( val instanceof ClientBinaryValue ) )
+                if ( ( val instanceof ClientStringValue ) || ( val.isBinary() ) )
                 {
                     add( val );
                 }
@@ -161,9 +161,9 @@
     {
         Value<?> value = get();
         
-        if ( value instanceof ClientBinaryValue )
+        if ( value.isBinary() )
         {
-            return (byte[])value.get();
+            return value.getBytes();
         }
         else
         {
@@ -192,7 +192,7 @@
         
         if ( value instanceof ClientStringValue )
         {
-            return (String)value.get();
+            return value.getString();
         }
         else
         {
@@ -454,7 +454,7 @@
                         // The attributeType is binary, convert the
                         // value to a BinaryValue
                         ClientBinaryValue cbv = new ClientBinaryValue();
-                        cbv.set( StringTools.getBytesUtf8( (String)val.get() ) );
+                        cbv.set( val.getBytes() );
                         
                         if ( !contains( cbv ) )
                         {
@@ -496,7 +496,7 @@
                         // The attribute Type is HR, convert the
                         // value to a StringValue
                         ClientStringValue csv = new ClientStringValue();
-                        csv.set( StringTools.utf8ToString( (byte[])val.get() ) );
+                        csv.set( val.getString() );
                         
                         if ( !contains( csv ) )
                         {
@@ -704,7 +704,7 @@
                 }
                 else
                 {
-                    byte[] binaryVal = (byte[])val.get();
+                    byte[] binaryVal = val.getBytes();
                     
                     // We have to convert the binary value to a String
                     if ( ! values.contains( new ClientStringValue( StringTools.utf8ToString( binaryVal ) ) ) )
@@ -721,7 +721,7 @@
             // contained in the object
             for ( Value<?> val:vals )
             {
-                if ( val instanceof ClientBinaryValue )
+                if ( val.isBinary() )
                 {
                     if ( !values.contains( val ) )
                     {
@@ -730,7 +730,7 @@
                 }
                 else
                 {
-                    String stringVal = (String)val.get();
+                    String stringVal = val.getString();
                     
                     // We have to convert the binary value to a String
                     if ( ! values.contains( new ClientBinaryValue( StringTools.getBytesUtf8( stringVal ) ) ) )
@@ -1039,7 +1039,7 @@
                 else
                 {
                     // Convert the binary value to a string value
-                    byte[] binaryVal = (byte[])val.get();
+                    byte[] binaryVal = val.getBytes();
                     removed &= values.remove( new ClientStringValue( StringTools.utf8ToString( binaryVal ) ) );
                 }
             }
@@ -1048,15 +1048,7 @@
         {
             for ( Value<?> val:vals )
             {
-                if ( val instanceof ClientBinaryValue )
-                {
-                    removed &= values.remove( val );
-                }
-                else
-                {
-                    String stringVal = (String)val.get();
-                    removed &= values.remove( new ClientBinaryValue( StringTools.getBytesUtf8( stringVal ) ) );
-                }
+                removed &= values.remove( val );
             }
         }
         

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java Tue Jul 28 14:54:01 2009
@@ -154,7 +154,7 @@
         StringBuilder sb = null;
         String val;
 
-        if ( !( value instanceof ClientStringValue ) )
+        if ( value.isBinary() )
         {
             sb = new StringBuilder( ((ClientBinaryValue)value).getReference().length * 3 );
             
@@ -205,7 +205,7 @@
             return new ClientStringValue( sb.toString() );
         }
 
-        val = ( ( ClientStringValue ) value ).get();
+        val = ( ( ClientStringValue ) value ).getString();
         
         for ( int i = 0; i < val.length(); i++ )
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java Tue Jul 28 14:54:01 2009
@@ -153,7 +153,7 @@
      */
     public Value<?> getEscapedValue()
     {
-        if ( value instanceof ClientStringValue )
+        if ( !value.isBinary() )
         {
             return AbstractExprNode.escapeFilterValue( value );
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Tue Jul 28 14:54:01 2009
@@ -24,7 +24,6 @@
 
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.Position;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -296,7 +295,7 @@
             {
                 // We have a substring starting with a value : val*...
                 // Set the initial value. It must be a String
-                String initialStr = StringTools.utf8ToString( (byte[])initial.get() );
+                String initialStr = initial.getString();
                 node.setInitial( initialStr );
             }
 
@@ -314,7 +313,7 @@
                     // this is the final
                     if ( !assertionValue.isNull() )
                     {
-                        String finalStr = StringTools.utf8ToString( (byte[])assertionValue.get() );
+                        String finalStr = assertionValue.getString();
                         node.setFinal( finalStr );
                     }
 
@@ -327,7 +326,7 @@
                     // one consecutive '*' : do nothing in this case.
                     if ( !assertionValue.isNull() )
                     {
-                        String anyStr = StringTools.utf8ToString( (byte[])assertionValue.get() );
+                        String anyStr = assertionValue.getString();
                         node.addAny( anyStr );
                     }
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java Tue Jul 28 14:54:01 2009
@@ -121,15 +121,6 @@
     }
 
 
-    /** 
-     * @return representation of the inital, escaped for use in a filter if required 
-     *
-    public String getEscapedInitial()
-    {
-        return AbstractExprNode.escapeFilterValue( initialPattern );
-    }
-    
-    
     /**
      * Gets the initial fragment.
      * 
@@ -160,20 +151,6 @@
     }
 
 
-    /** 
-     * @return representation of the final, escaped for use in a filter if required 
-     *
-    public Value<?> getEscapedFinal()
-    {
-        if ( finalPattern instanceof ClientStringValue )
-        {
-            return AbstractExprNode.escapeFilterValue( finalPattern );
-        }
-        
-        return finalPattern;
-    }
-    
-    
     /**
      * Set the final pattern
      * @param finalPattern The final pattern
@@ -184,30 +161,6 @@
     }
 
 
-    /** 
-     * @return representation of the any, escaped for use in a filter if required 
-     *
-    public List<Value<?>> getEscapedAny()
-    {
-        if ( anyPattern != null )
-        {
-            List<Value<?>> anyEscaped = new ArrayList<Value<?>>(anyPattern.size() );
-            
-            for ( Value<?> value:anyPattern )
-            {
-                if ( value instanceof ClientStringValue )
-                {
-                    anyEscaped.add( AbstractExprNode.escapeFilterValue( value ) );
-                }
-            }
-            
-            return anyEscaped;
-        }
-        
-        return anyPattern;
-    }
-    
-    
     /**
      * Gets the list of wildcard surrounded any fragments.
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java Tue Jul 28 14:54:01 2009
@@ -563,13 +563,13 @@
             
             for ( Value<?> value:attribute )
             {
-                if ( value instanceof ClientStringValue )
+                if ( !value.isBinary() )
                 {
-                    sb.append(  "            " ).append( value.get() ).append('\n' );
+                    sb.append(  "            " ).append( value.getString() ).append('\n' );
                 }
                 else
                 {
-                    sb.append(  "            " ).append( StringTools.dumpBytes( (byte[])value.get() ) ).append('\n' );
+                    sb.append(  "            " ).append( StringTools.dumpBytes( value.getBytes() ) ).append('\n' );
                 }
             }
         }
@@ -615,13 +615,13 @@
             {
                 for ( Value<?> value:attribute )
                 {
-                    if ( value instanceof ClientStringValue )
+                    if ( !value.isBinary() )
                     {
-                        sb.append(  "                " ).append( (String)value.get() ).append('\n' );
+                        sb.append(  "                " ).append( value.getString() ).append('\n' );
                     }
                     else
                     {
-                        sb.append(  "                " ).append( StringTools.dumpBytes( (byte[]) value.get() ) ).append('\n' );
+                        sb.append(  "                " ).append( StringTools.dumpBytes( value.getBytes() ) ).append('\n' );
                     }
                 }
             }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java Tue Jul 28 14:54:01 2009
@@ -345,14 +345,14 @@
         {
             // No need to add something which has already been added
             // in the previous modification
-            if ( !entry.contains( ava.getNormType(), (String)ava.getNormValue() ) &&
+            if ( !entry.contains( ava.getNormType(), ava.getNormValue().getString() ) &&
                  !(ava.getNormType().equals( oldRdn.getNormType() ) &&
                    ava.getNormValue().equals( oldRdn.getNormValue() ) ) )
             {
                 // Create the modification, which is an Add
                 Modification modification = new ClientModification( 
                     ModificationOperation.REMOVE_ATTRIBUTE, 
-                    new DefaultClientAttribute( oldRdn.getUpType(), (String)ava.getUpValue() ) );
+                    new DefaultClientAttribute( oldRdn.getUpType(), ava.getUpValue().getString() ) );
                 
                 restored.addModificationItem( modification );
             }
@@ -494,7 +494,7 @@
                     }
                     else
                     {
-                        if ( entry.contains( atav.getNormType(), (String)atav.getNormValue() ) )
+                        if ( entry.contains( atav.getNormType(), atav.getNormValue().getString() ) )
                         {
                             existInEntry = true;
                         }
@@ -574,7 +574,7 @@
                     {
                         overlapping = true;
                     }
-                    else if ( entry.contains( atav.getNormType(), (String)atav.getNormValue() ) )
+                    else if ( entry.contains( atav.getNormType(), atav.getNormValue().getString() ) )
                     {
                         existInEntry = true;
                     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Tue Jul 28 14:54:01 2009
@@ -28,8 +28,6 @@
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
@@ -477,21 +475,21 @@
             lineBuffer.append( attr.getId() );
             
             // First, deal with null value (which is valid)
-            if ( value == null )
+            if ( value.isNull() )
             {
                 lineBuffer.append( ':' );
             }
-            else if ( value instanceof ClientBinaryValue )
+            else if ( value.isBinary() )
             {
                 // It is binary, so we have to encode it using Base64 before adding it
-                char[] encoded = Base64.encode( ( byte[] ) value.get() );
+                char[] encoded = Base64.encode( value.getBytes() );
                 
                 lineBuffer.append( ":: " + new String( encoded ) );                            
             }
-            else if ( value instanceof ClientStringValue )
+            else if ( !value.isBinary() )
             {
                 // It's a String but, we have to check if encoding isn't required
-                String str = (String) value.get();
+                String str = value.getString();
                 
                 if ( !LdifUtils.isLDIFSafe( str ) )
                 {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java Tue Jul 28 14:54:01 2009
@@ -285,13 +285,13 @@
         sb.append( "        Attribute description : '" ).append( attrId ).append( "'\n" );
         sb.append( "        Attribute value : '" );
         
-        if ( attrVal instanceof ClientStringValue )
+        if ( !attrVal.isBinary() )
         {
             sb.append( attrVal.get() );
         }
         else
         {
-            byte[] binVal = (byte[])attrVal.get();
+            byte[] binVal = attrVal.getBytes();
             sb.append( StringTools.utf8ToString( binVal ) ).append( '/' ).append(
                 StringTools.dumpBytes( binVal ) ).append( "'\n" );
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AtavSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AtavSerializer.java?rev=798550&r1=798549&r2=798550&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AtavSerializer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AtavSerializer.java Tue Jul 28 14:54:01 2009
@@ -23,6 +23,9 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,8 +75,8 @@
              StringTools.isEmpty( atav.getNormType() ) ||
              ( atav.getStart() < 0 ) ||
              ( atav.getLength() < 2 ) ||             // At least a type and '='
-             ( atav.getUpValue() == null ) ||
-             ( atav.getNormValue() == null ) )
+             ( atav.getUpValue().isNull() ) ||
+             ( atav.getNormValue().isNull() ) )
         {
             String message = "Cannot serialize an wrong ATAV, ";
             
@@ -97,11 +100,11 @@
             {
                 message += "the length should not be < 2";
             }
-            else if ( atav.getUpValue() == null )
+            else if ( atav.getUpValue().isNull() )
             {
                 message += "the upValue should not be null";
             }
-            else if ( atav.getNormValue() == null )
+            else if ( atav.getNormValue().isNull() )
             {
                 message += "the value should not be null";
             }
@@ -116,21 +119,21 @@
         out.writeUTF( atav.getUpType() );
         out.writeUTF( atav.getNormType() );
         
-        boolean isHR = ( atav.getNormValue() instanceof String );
+        boolean isHR = !atav.getNormValue().isBinary();
         
         out.writeBoolean( isHR );
         
         if ( isHR )
         {
-            out.writeUTF( (String)atav.getUpValue() );
-            out.writeUTF( (String)atav.getNormValue() );
+            out.writeUTF( atav.getUpValue().getString() );
+            out.writeUTF( atav.getNormValue().getString() );
         }
         else
         {
-            out.writeInt( ((byte[])atav.getUpValue()).length );
-            out.write( (byte[])atav.getUpValue() );
-            out.writeInt( ((byte[])atav.getNormValue()).length );
-            out.write( (byte[])atav.getNormValue() );
+            out.writeInt( atav.getUpValue().length() );
+            out.write( atav.getUpValue().getBytes() );
+            out.writeInt( atav.getNormValue().length() );
+            out.write( atav.getNormValue().getBytes() );
         }
     }
     
@@ -158,8 +161,8 @@
         
         if ( isHR )
         {
-            String upValue = in.readUTF();
-            String normValue = in.readUTF();
+            Value<String> upValue = new ClientStringValue( in.readUTF() );
+            Value<String> normValue = new ClientStringValue( in.readUTF() );
             AttributeTypeAndValue atav = 
                 new AttributeTypeAndValue( upType, normType, upValue, normValue, start, length, upName );
             
@@ -176,7 +179,9 @@
             in.readFully( normValue );
 
             AttributeTypeAndValue atav = 
-                new AttributeTypeAndValue( upType, normType, upValue, normValue, start, length, upName );
+                new AttributeTypeAndValue( upType, normType, 
+                    new ClientBinaryValue( upValue) , 
+                    new ClientBinaryValue( normValue ), start, length, upName );
             
             return atav;
         }