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 2005/09/09 23:43:24 UTC

svn commit: r279887 [2/15] - in /directory/shared/ldap/branches/elecharny-cleanup/apache2-provider: ./ conf/ perfs/ perfs/org/ perfs/org/apache/ perfs/org/apache/asn1new/ perfs/org/apache/asn1new/ber/ src/ src/java/ src/java/main/ src/java/main/org/ sr...

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixTransformer.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixTransformer.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixTransformer.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixTransformer.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,1087 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+import org.apache.asn1new.ldap.codec.primitives.LdapURL;
+import org.apache.asn1new.ldap.pojo.AbandonRequest;
+import org.apache.asn1new.ldap.pojo.AddRequest;
+import org.apache.asn1new.ldap.pojo.AddResponse;
+import org.apache.asn1new.ldap.pojo.AttributeValueAssertion;
+import org.apache.asn1new.ldap.pojo.BindRequest;
+import org.apache.asn1new.ldap.pojo.BindResponse;
+import org.apache.asn1new.ldap.pojo.CompareRequest;
+import org.apache.asn1new.ldap.pojo.CompareResponse;
+import org.apache.asn1new.ldap.pojo.Control;
+import org.apache.asn1new.ldap.pojo.DelRequest;
+import org.apache.asn1new.ldap.pojo.DelResponse;
+import org.apache.asn1new.ldap.pojo.ExtendedRequest;
+import org.apache.asn1new.ldap.pojo.ExtendedResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.LdapResult;
+import org.apache.asn1new.ldap.pojo.ModifyDNRequest;
+import org.apache.asn1new.ldap.pojo.ModifyDNResponse;
+import org.apache.asn1new.ldap.pojo.ModifyRequest;
+import org.apache.asn1new.ldap.pojo.ModifyResponse;
+import org.apache.asn1new.ldap.pojo.SaslCredentials;
+import org.apache.asn1new.ldap.pojo.SearchRequest;
+import org.apache.asn1new.ldap.pojo.SearchResultDone;
+import org.apache.asn1new.ldap.pojo.SearchResultEntry;
+import org.apache.asn1new.ldap.pojo.SearchResultReference;
+import org.apache.asn1new.ldap.pojo.SimpleAuthentication;
+import org.apache.asn1new.ldap.pojo.filters.AndFilter;
+import org.apache.asn1new.ldap.pojo.filters.AttributeValueAssertionFilter;
+import org.apache.asn1new.ldap.pojo.filters.ConnectorFilter;
+import org.apache.asn1new.ldap.pojo.filters.ExtensibleMatchFilter;
+import org.apache.asn1new.ldap.pojo.filters.Filter;
+import org.apache.asn1new.ldap.pojo.filters.NotFilter;
+import org.apache.asn1new.ldap.pojo.filters.OrFilter;
+import org.apache.asn1new.ldap.pojo.filters.PresentFilter;
+import org.apache.asn1new.ldap.pojo.filters.SubstringFilter;
+import org.apache.asn1new.primitives.OID;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.ldap.common.filter.AbstractExprNode;
+import org.apache.ldap.common.filter.BranchNode;
+import org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.common.filter.ExtensibleNode;
+import org.apache.ldap.common.filter.LeafNode;
+import org.apache.ldap.common.filter.PresenceNode;
+import org.apache.ldap.common.filter.SimpleNode;
+import org.apache.ldap.common.filter.SubstringNode;
+import org.apache.ldap.common.message.AbandonRequestImpl;
+import org.apache.ldap.common.message.AddRequestImpl;
+import org.apache.ldap.common.message.AddResponseImpl;
+import org.apache.ldap.common.message.BindRequestImpl;
+import org.apache.ldap.common.message.BindResponseImpl;
+import org.apache.ldap.common.message.CompareRequestImpl;
+import org.apache.ldap.common.message.CompareResponseImpl;
+import org.apache.ldap.common.message.ControlImpl;
+import org.apache.ldap.common.message.DeleteRequestImpl;
+import org.apache.ldap.common.message.DeleteResponseImpl;
+import org.apache.ldap.common.message.DerefAliasesEnum;
+import org.apache.ldap.common.message.ExtendedRequestImpl;
+import org.apache.ldap.common.message.ExtendedResponseImpl;
+import org.apache.ldap.common.message.LdapResultImpl;
+import org.apache.ldap.common.message.Message;
+import org.apache.ldap.common.message.MessageTypeEnum;
+import org.apache.ldap.common.message.ModifyDnRequestImpl;
+import org.apache.ldap.common.message.ModifyDnResponseImpl;
+import org.apache.ldap.common.message.ModifyRequestImpl;
+import org.apache.ldap.common.message.ModifyResponseImpl;
+import org.apache.ldap.common.message.Referral;
+import org.apache.ldap.common.message.ReferralImpl;
+import org.apache.ldap.common.message.ScopeEnum;
+import org.apache.ldap.common.message.SearchRequestImpl;
+import org.apache.ldap.common.message.SearchResponseDoneImpl;
+import org.apache.ldap.common.message.SearchResponseEntryImpl;
+import org.apache.ldap.common.message.SearchResponseReferenceImpl;
+import org.apache.ldap.common.message.UnbindRequestImpl;
+import org.apache.ldap.common.message.spi.Provider;
+import org.apache.ldap.common.message.spi.TransformerSpi;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A Twix to Snickers Message transformer. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory
+ *         Project</a> $Rev: 157671 $
+ */
+public class TwixTransformer implements TransformerSpi
+{
+	/** The logger */
+    private static Logger log = LoggerFactory.getLogger( TwixTransformer.class );
+    
+    /** the provider this transformer is part of */
+    private final Provider provider;
+
+
+    /**
+     * Creates a passthrough transformer that really does nothing at all.
+     *
+     * @param provider the povider for this transformer
+     */
+    public TwixTransformer( Provider provider )
+    {
+        this.provider = provider;
+    }
+
+
+    /**
+     * Gets the Provider associated with this SPI implementation object.
+     *
+     * @return Provider.
+     */
+    public Provider getProvider()
+    {
+        return provider;
+    }
+
+    /**
+     * Transform an AbandonRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers AbandonRequestImpl
+     */
+    private Message transformAbandonRequest(LdapMessage twixMessage, int messageId)
+    {
+    	AbandonRequestImpl snickersMessage = new AbandonRequestImpl( messageId ) ;
+    	AbandonRequest abandonRequest = twixMessage.getAbandonRequest();
+
+    	// Twix : int abandonnedMessageId -> Snickers : int abandonId
+    	snickersMessage.setAbandoned( abandonRequest.getAbandonedMessageId() );
+    	
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform an AddRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers AddRequestImpl
+     */
+    private Message transformAddRequest(LdapMessage twixMessage, int messageId)
+    {
+    	AddRequestImpl snickersMessage = new AddRequestImpl( messageId ) ;
+    	AddRequest addRequest = twixMessage.getAddRequest();
+
+    	// Twix : LdapDN entry -> Snickers : String name
+    	snickersMessage.setName( addRequest.getEntry() );
+    	
+    	// Twix : Attributes attributes -> Snickers : Attributes entry
+    	snickersMessage.setEntry( addRequest.getAttributes() );
+    	
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform a BindRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers BindRequestImpl
+     */
+    private Message transformBindRequest(LdapMessage twixMessage, int messageId)
+    {
+    	BindRequestImpl snickersMessage = new BindRequestImpl( messageId ) ;
+    	BindRequest bindRequest = twixMessage.getBindRequest();
+    	
+    	// Twix : int version -> Snickers : boolean isVersion3
+    	snickersMessage.setVersion3( bindRequest.isLdapV3() );
+    	
+    	// Twix : LdapDN name -> Snickers : String name
+    	snickersMessage.setName( bindRequest.getName() );
+    	
+    	// Twix : Asn1Object authentication instanceOf SimpleAuthentication -> Snickers : boolean isSimple
+    	// Twix : SimpleAuthentication OctetString simple -> Snickers : byte [] credentials
+    	Asn1Object authentication = bindRequest.getAuthentication();
+    	
+    	if ( authentication instanceof SimpleAuthentication)
+    	{
+    		snickersMessage.setSimple( true );
+    		snickersMessage.setCredentials( ( (SimpleAuthentication)authentication).getSimple().getValue() );
+    	}
+    	else
+    	{
+    		snickersMessage.setSimple( false );
+    		snickersMessage.setCredentials( ( (SaslCredentials)authentication).getCredentials().getValue() );
+    		snickersMessage.setMechanism( ( (SaslCredentials)authentication).getMechanism() );
+    	}
+
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform a CompareRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers CompareRequestImpl
+     */
+    private Message transformCompareRequest(LdapMessage twixMessage, int messageId)
+    {
+    	CompareRequestImpl snickersMessage = new CompareRequestImpl( messageId ) ;
+    	CompareRequest compareRequest = twixMessage.getCompareRequest();
+
+    	// Twix : LdapDN entry -> Snickers : private String name
+    	snickersMessage.setName( compareRequest.getEntry() );
+    	
+    	// Twix : LdapString attributeDesc -> Snickers : String attrId
+    	snickersMessage.setAttributeId( compareRequest.getAttributeDesc() );
+    	
+    	// Twix : OctetString assertionValue -> Snickers : byte[] attrVal
+    	snickersMessage.setAssertionValue( compareRequest.getAssertionValue().getValue() );
+    	
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform a DelRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers DeleteRequestImpl
+     */
+    private Message transformDelRequest(LdapMessage twixMessage, int messageId)
+    {
+    	DeleteRequestImpl snickersMessage = new DeleteRequestImpl( messageId ) ;
+    	DelRequest delRequest = twixMessage.getDelRequest();
+
+    	// Twix : LdapDN entry -> Snickers : String name
+    	snickersMessage.setName( delRequest.getEntry() );
+    	
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform an ExtendedRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers ExtendedRequestImpl
+     */
+    private Message transformExtendedRequest(LdapMessage twixMessage, int messageId)
+    {
+    	ExtendedRequestImpl snickersMessage = new ExtendedRequestImpl( messageId ) ;
+    	ExtendedRequest extendedRequest = twixMessage.getExtendedRequest();
+
+    	// Twix : OID requestName -> Snickers : String oid
+    	snickersMessage.setOid( extendedRequest.getRequestName() );
+    	
+    	// Twix : OctetString requestValue -> Snickers : byte [] payload
+    	snickersMessage.setPayload( extendedRequest.getRequestValue().getValue() );
+
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform a ModifyDNRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers ModifyDNRequestImpl
+     */
+    private Message transformModifyDNRequest(LdapMessage twixMessage, int messageId)
+    {
+    	ModifyDnRequestImpl snickersMessage = new ModifyDnRequestImpl( messageId ) ;
+    	ModifyDNRequest modifyDNRequest = twixMessage.getModifyDNRequest();
+
+    	// Twix : LdapDN entry -> Snickers : String m_name
+    	snickersMessage.setName( modifyDNRequest.getEntry() );
+    	
+    	// Twix : RelativeLdapDN newRDN -> Snickers : String m_newRdn
+    	snickersMessage.setNewRdn( modifyDNRequest.getNewRDN() );
+
+    	// Twix : boolean deleteOldRDN -> Snickers : boolean m_deleteOldRdn
+    	snickersMessage.setDeleteOldRdn( modifyDNRequest.isDeleteOldRDN() );
+    	
+    	// Twix : LdapDN newSuperior -> Snickers : String m_newSuperior
+    	snickersMessage.setNewSuperior( modifyDNRequest.getNewSuperior() );
+
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform a ModifyRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers ModifyRequestImpl
+     */
+    private Message transformModifyRequest(LdapMessage twixMessage, int messageId)
+    {
+    	ModifyRequestImpl snickersMessage = new ModifyRequestImpl( messageId ) ;
+    	ModifyRequest modifyRequest = twixMessage.getModifyRequest();
+
+    	// Twix : LdapDN object -> Snickers : String name
+    	snickersMessage.setName( modifyRequest.getObject() );
+    	
+    	// Twix : ArrayList modifications -> Snickers : ArrayList mods
+    	if ( modifyRequest.getModifications() != null )
+    	{
+	    	Iterator modifications = modifyRequest.getModifications().iterator();
+	   
+	    	// Loop through the modifications
+	    	while (modifications.hasNext())
+	    	{
+	    		snickersMessage.addModification( (ModificationItem)modifications.next() );
+	    	}
+    	}
+
+    	return snickersMessage;
+    }
+    
+    /**
+     * Transform the Filter part of a SearchRequest to en ExprNode
+     * @param twixFilter The filter to be transformed
+     * @return An ExprNode
+     */
+    private ExprNode transformFilter(Filter twixFilter)
+    {
+    	if ( twixFilter != null )
+    	{
+    		// Transform OR, AND or NOT leaves
+    		if ( twixFilter instanceof ConnectorFilter )
+    		{
+    			BranchNode branch = null;
+    			
+    			if ( twixFilter instanceof AndFilter )
+    			{
+    				branch = new BranchNode( BranchNode.AND );
+    			}
+    			else if ( twixFilter instanceof OrFilter )
+    			{
+    				branch = new BranchNode( BranchNode.OR ); 
+    			}
+    			else if ( twixFilter instanceof NotFilter )
+    			{
+    				branch = new BranchNode( BranchNode.NOT ); 
+    			}
+    			
+				ArrayList filtersSet = ((ConnectorFilter)twixFilter).getFilterSet();
+				
+				// Loop on all AND/OR children
+				if ( filtersSet != null )
+				{
+					Iterator filters = filtersSet.iterator();
+					
+					while ( filters.hasNext() )
+					{
+						branch.addNode( transformFilter( (Filter)filters.next() ) );
+					}
+				}
+
+				return branch;
+    		}
+    		else
+    		{
+    			// Transform PRESENT or ATTRIBUTE_VALUE_ASSERTION
+    			LeafNode branch = null;
+    			
+    			if ( twixFilter instanceof PresentFilter )
+    			{
+    				branch = new PresenceNode( ( (PresentFilter) twixFilter ).getAttributeDescription().toString() );
+    			}
+    			else if ( twixFilter instanceof AttributeValueAssertionFilter )
+    			{
+    				AttributeValueAssertion ava = ( (AttributeValueAssertionFilter) twixFilter ).getAssertion();
+    				
+    				// Transform =, >=, <=, ~= filters
+    				switch ( ( (AttributeValueAssertionFilter) twixFilter ).getFilterType() )
+    				{
+    					case LdapConstants.EQUALITY_MATCH_FILTER : 
+    	    				branch = new SimpleNode( ava.getAttributeDesc().toString(), 
+    	    										 ava.getAssertionValue().toString(), 
+    	    										 AbstractExprNode.EQUALITY );
+    	    				break;
+    						
+    					case LdapConstants.GREATER_OR_EQUAL_FILTER : 
+    	    				branch = new SimpleNode( ava.getAttributeDesc().toString(), 
+    	    										 ava.getAssertionValue().toString(), 
+    	    										 AbstractExprNode.GREATEREQ );
+    	    				break;
+
+    					case LdapConstants.LESS_OR_EQUAL_FILTER : 
+    	    				branch = new SimpleNode( ava.getAttributeDesc().toString(), 
+    	    										 ava.getAssertionValue().toString(), 
+    	    										 AbstractExprNode.LESSEQ );
+    	    				break;
+
+    					case LdapConstants.APPROX_MATCH_FILTER : 
+    	    				branch = new SimpleNode( ava.getAttributeDesc().toString(), 
+    	    										 ava.getAssertionValue().toString(), 
+    	    										 AbstractExprNode.APPROXIMATE );
+    	    				break;
+    				}
+    				
+    			}
+    			else if ( twixFilter instanceof SubstringFilter )
+    			{
+    				// Transform Substring filters
+    				SubstringFilter filter = (SubstringFilter)twixFilter;
+    				String initialString = null;
+    				String finalString = null;
+    				ArrayList anyString = null;
+    				
+    				
+    				if ( filter.getInitialSubstrings() != null )
+    				{
+    					initialString = filter.getInitialSubstrings().toString();
+    				}
+    				
+    				if ( filter.getFinalSubstrings() != null )
+    				{
+    					finalString = filter.getFinalSubstrings().toString();
+    				}
+    				
+    				if ( filter.getAnySubstrings() != null )
+    				{
+    					Iterator iter = filter.getAnySubstrings().iterator();
+    					anyString = new ArrayList();
+    					
+    					while ( iter.hasNext() )
+    					{
+    						anyString.add( iter.next() );
+    					}
+    				}
+    				
+    				branch = new SubstringNode(anyString, filter.getType().toString(), initialString, finalString );
+    			}
+    			else if ( twixFilter instanceof ExtensibleMatchFilter )
+    			{
+    				// Transform Extensible Match Filter
+    				ExtensibleMatchFilter filter = (ExtensibleMatchFilter)twixFilter;
+    				String attribute = null;
+    				String value = null;
+    				String matchingRule = null;
+    				
+    				if ( filter.getType() != null )
+    				{
+    					attribute = filter.getType().toString(); 
+    				}
+
+    				if ( filter.getMatchValue() != null )
+    				{
+    					value = filter.getMatchValue().toString(); 
+    				}
+
+    				if ( filter.getMatchingRule() != null )
+    				{
+    					matchingRule = filter.getMatchingRule().toString(); 
+    				}
+
+    				branch = new ExtensibleNode( attribute, value, matchingRule, filter.isDnAttributes() );
+    			}
+    			
+    			return branch;
+    		}
+    	}
+    	else
+    	{
+    		// We have found nothing to transform. Return null then.
+    		return null;
+    	}
+    }
+
+    /**
+     * Transform a SearchRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers SearchRequestImpl
+     */
+    private Message transformSearchRequest(LdapMessage twixMessage, int messageId)
+    {
+    	SearchRequestImpl snickersMessage = new SearchRequestImpl( messageId ) ;
+    	SearchRequest searchRequest = twixMessage.getSearchRequest();
+    	
+    	// Twix : LdapDN baseObject -> Snickers : String baseDn
+    	snickersMessage.setBase( searchRequest.getBaseObject() );
+    	
+    	// Twix : int scope -> Snickers : ScopeEnum scope
+    	switch ( searchRequest.getScope() )
+    	{
+    		case LdapConstants.SCOPE_BASE_OBJECT :
+    			snickersMessage.setScope( ScopeEnum.BASEOBJECT );
+    			break;
+    			
+    		case LdapConstants.SCOPE_SINGLE_LEVEL :
+    			snickersMessage.setScope( ScopeEnum.SINGLELEVEL );
+    			break;
+    			
+    		case LdapConstants.SCOPE_WHOLE_SUBTREE :
+    			snickersMessage.setScope( ScopeEnum.WHOLESUBTREE );
+    			break;
+    	}
+    	
+    	// Twix : int derefAliases -> Snickers : DerefAliasesEnum derefAliases
+    	switch ( searchRequest.getDerefAliases() )
+    	{
+    		case LdapConstants.DEREF_ALWAYS :
+    			snickersMessage.setDerefAliases( DerefAliasesEnum.DEREFALWAYS );
+    			break;
+    			
+    		case LdapConstants.DEREF_FINDING_BASE_OBJ :
+    			snickersMessage.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+    			break;
+    			
+    		case LdapConstants.DEREF_IN_SEARCHING :
+    			snickersMessage.setDerefAliases( DerefAliasesEnum.DEREFINSEARCHING );
+    			break;
+
+    		case LdapConstants.NEVER_DEREF_ALIASES :
+    			snickersMessage.setDerefAliases( DerefAliasesEnum.NEVERDEREFALIASES );
+    			break;
+    	}
+    	
+    	// Twix : int sizeLimit -> Snickers : int sizeLimit
+    	snickersMessage.setSizeLimit( searchRequest.getSizeLimit() );
+
+    	// Twix : int timeLimit -> Snickers : int timeLimit
+    	snickersMessage.setTimeLimit( searchRequest.getTimeLimit() );
+
+    	// Twix : boolean typesOnly -> Snickers : boolean typesOnly
+    	snickersMessage.setTypesOnly( searchRequest.isTypesOnly() );
+
+    	// Twix : Filter filter -> Snickers : ExprNode filter
+    	Filter twixFilter = searchRequest.getFilter();
+    	
+    	snickersMessage.setFilter( transformFilter( twixFilter ) );
+    	
+    	// Twix : ArrayList attributes -> Snickers : ArrayList attributes
+    	if ( searchRequest.getAttributes() != null )
+    	{
+	    	NamingEnumeration attributes = searchRequest.getAttributes().getAll();
+	    	
+	    	if ( attributes != null )
+	    	{
+	    		while ( attributes.hasMoreElements() )
+	    		{
+	    			Attribute attribute = (BasicAttribute)attributes.nextElement();
+	    			
+	    			if ( attribute != null )
+	    			{
+		    	    	snickersMessage.addAttribute( attribute.getID() );
+	    			}
+	    		}
+	    	}
+    	}
+    	
+    	return snickersMessage;
+    }
+
+    /**
+     * Transform an UnBindRequest message from a TwixMessage to a SnickersMessage
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return A Snickers UnBindRequestImpl
+     */
+    private Message transformUnBindRequest(LdapMessage twixMessage, int messageId)
+    {
+    	return new UnbindRequestImpl( messageId ) ;
+    }
+    
+    /**
+     * Transform the Twix message to a Snickers message.
+     *
+     * @param obj the object to transform
+     * @return the object transformed
+     */
+    public Message transform( Object obj )
+    {
+    	LdapMessage twixMessage = (LdapMessage) obj;
+    	int messageId = twixMessage.getMessageId();
+    	
+    	if ( log.isDebugEnabled() )
+    	{
+    		log.debug( "Transforming LdapMessage <" + messageId + ", " + twixMessage.getMessageTypeName() + "> from Twix to Snickers.");
+    	}
+    	
+        Message snickersMessage = null ;
+        
+        int messageType = twixMessage.getMessageType();
+
+        switch ( messageType )
+        {
+            case( LdapConstants.BIND_REQUEST ):
+            	snickersMessage = transformBindRequest( twixMessage, messageId );
+                break ;
+                
+            case( LdapConstants.UNBIND_REQUEST ):
+            	snickersMessage = transformUnBindRequest( twixMessage, messageId );
+                break ;
+                
+            case( LdapConstants.SEARCH_REQUEST ):
+            	snickersMessage = transformSearchRequest( twixMessage, messageId );
+                break ;
+                
+            case( LdapConstants.MODIFY_REQUEST ):
+            	snickersMessage = transformModifyRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.ADD_REQUEST ):
+            	snickersMessage = transformAddRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.DEL_REQUEST ):
+            	snickersMessage = transformDelRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.MODIFYDN_REQUEST ):
+            	snickersMessage = transformModifyDNRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.COMPARE_REQUEST ):
+            	snickersMessage = transformCompareRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.ABANDON_REQUEST ):
+            	snickersMessage = transformAbandonRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.EXTENDED_REQUEST ):
+            	snickersMessage = transformExtendedRequest( twixMessage, messageId ) ;
+                break ;
+                
+            case( LdapConstants.BIND_RESPONSE ):
+            case( LdapConstants.SEARCH_RESULT_ENTRY ):
+            case( LdapConstants.SEARCH_RESULT_DONE ):
+            case( LdapConstants.SEARCH_RESULT_REFERENCE ):
+            case( LdapConstants.MODIFY_RESPONSE ):
+            case( LdapConstants.ADD_RESPONSE ):
+            case( LdapConstants.DEL_RESPONSE ):
+            case( LdapConstants.MODIFYDN_RESPONSE ):
+            case( LdapConstants.COMPARE_RESPONSE ):
+            case( LdapConstants.EXTENDED_RESPONSE ):
+            	// Nothing to do !
+                break ;
+                
+            default:
+                throw new IllegalStateException(
+                        "shouldn't happen - if it does then we have issues" ) ;
+        }
+        
+        // Transform the controls, too
+        ArrayList twixControls = twixMessage.getControls();
+        
+        if ( twixControls != null )
+        {
+        	Iterator controls = twixControls.iterator();
+        	
+        	while ( controls.hasNext() )
+        	{
+        		Control twixControl = (Control)controls.next();
+        		
+                ControlImpl snickersControl = new ControlImpl( snickersMessage )
+                {
+                	// Just to avoid a compilation warning !!!
+                	public static final long serialVersionUID = 1L;
+                	
+                	
+                    public byte[] getEncodedValue()
+                    {
+                        return null;
+                    }        	
+                };
+                
+            	// Twix : boolean criticality -> Snickers : boolean m_isCritical
+                snickersControl.setCritical( twixControl.getCriticality() );
+
+            	// Twix : OID controlType -> Snickers : String m_oid
+                snickersControl.setType( twixControl.getControlType() );
+                
+            	// Twix : OctetString controlValue -> Snickers : byte [] m_value
+                snickersControl.setValue( twixControl.getControlValue() );
+                
+                snickersMessage.add( snickersControl );
+        	}
+        }
+
+        return  snickersMessage;
+    }
+
+    /**
+     * Transform a Ldapresult part of a Snickers Response to a Twix LdapResult
+     * @param snickersLdapResult The Snickers LdapResult to transform
+     * @return A Twix LdapResult
+     */
+    private LdapResult transformLdapResult(LdapResultImpl snickersLdapResult)
+    {
+		LdapResult twixLdapResult = new LdapResult();
+		
+	    // Snickers : ResultCodeEnum resultCode -> Twix : int resultCode
+		twixLdapResult.setResultCode( snickersLdapResult.getResultCode().getValue() );
+		
+	    // Snickers : String errorMessage -> Twix : LdapString errorMessage
+		try 
+		{
+			String errorMessage = snickersLdapResult.getErrorMessage();
+			
+			if ( ( errorMessage == null ) || ( errorMessage.length() == 0 ) )
+			{
+				twixLdapResult.setErrorMessage( LdapString.EMPTY_STRING );
+			}
+			else
+			{
+				twixLdapResult.setErrorMessage( new LdapString( snickersLdapResult.getErrorMessage().getBytes() ) );
+			}
+		}
+		catch ( DecoderException de ) 
+		{
+			log.warn( "The error message " + snickersLdapResult.getErrorMessage() + " is invalid : " + de.getMessage() );
+			twixLdapResult.setErrorMessage( LdapString.EMPTY_STRING );
+		}
+
+	    // Snickers : String matchedDn -> Twix : LdapDN matchedDN
+		try 
+		{
+			String matchedDn = snickersLdapResult.getMatchedDn();
+
+			if ( ( matchedDn == null ) || ( matchedDn.length() == 0 ) )
+			{
+				twixLdapResult.setMatchedDN( LdapDN.EMPTY_STRING );
+			}
+			else
+			{
+				twixLdapResult.setMatchedDN( new LdapDN( snickersLdapResult.getMatchedDn().getBytes() ) );
+			}
+		}
+		catch ( DecoderException de ) 
+		{
+			log.warn( "The DN  " + snickersLdapResult.getMatchedDn() + " is invalid : " + de.getMessage() );
+			twixLdapResult.setMatchedDN( LdapDN.EMPTY_STRING );
+		}
+
+	    // Snickers : Referral referral -> Twix : ArrayList referrals
+		ReferralImpl snisckersReferrals = (ReferralImpl)snickersLdapResult.getReferral();
+		
+		if ( snisckersReferrals != null )
+		{
+			Iterator referrals = snisckersReferrals.getLdapUrls().iterator();
+			
+			while ( referrals.hasNext() )
+			{
+				String referral = (String)referrals.next();
+				
+	    		try 
+	    		{
+	    			LdapURL ldapUrl = new LdapURL( referral.getBytes() );
+	    			twixLdapResult.addReferral( ldapUrl );
+	    		}
+				catch ( DecoderException de )
+				{
+					log.warn( "The referral " + referral + " is invalid : " + de.getMessage() );
+					twixLdapResult.addReferral( LdapURL.EMPTY_STRING );
+				}
+			}
+		}
+		
+		return twixLdapResult;
+    }
+
+    /**
+     * Transform a Snickers AddResponse to a Twix AddResponse
+     * @param twixMessage The Twix AddResponse to produce 
+     * @param snickersMessage The incoming Snickers AddResponse
+     */
+    private void transformAddResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+		AddResponseImpl snickersAddResponse = (AddResponseImpl)snickersMessage;
+		
+		AddResponse addResponse = new AddResponse();
+		
+		// Transform the ldapResult
+		addResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersAddResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( addResponse );
+    }
+    
+    /**
+     * Transform a Snickers BindResponse to a Twix BindResponse
+     * @param twixMessage The Twix BindResponse to produce 
+     * @param snickersMessage The incoming Snickers BindResponse
+     */
+    private void transformBindResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+		BindResponseImpl snickersBindResponse = (BindResponseImpl)snickersMessage;
+		
+		BindResponse bindResponse = new BindResponse();
+		
+	    // Snickers : byte [] serverSaslCreds -> Twix : OctetString serverSaslCreds
+		byte[] serverSaslCreds = snickersBindResponse.getServerSaslCreds();
+		
+		if ( serverSaslCreds != null )
+		{
+    		bindResponse.setServerSaslCreds( new OctetString( serverSaslCreds ) );
+		}
+		
+		// Transform the ldapResult
+		bindResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersBindResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( bindResponse );
+    }
+    
+    /**
+     * Transform a Snickers CompareResponse to a Twix CompareResponse
+     * @param twixMessage The Twix CompareResponse to produce 
+     * @param snickersMessage The incoming Snickers CompareResponse
+     */
+    private void transformCompareResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	CompareResponseImpl snickersCompareResponse = (CompareResponseImpl)snickersMessage;
+		
+    	CompareResponse compareResponse = new CompareResponse();
+		
+		// Transform the ldapResult
+    	compareResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersCompareResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( compareResponse );
+    }
+    
+    /**
+     * Transform a Snickers DelResponse to a Twix DelResponse
+     * @param twixMessage The Twix DelResponse to produce 
+     * @param snickersMessage The incoming Snickers DelResponse
+     */
+    private void transformDelResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	DeleteResponseImpl snickersDelResponse = (DeleteResponseImpl)snickersMessage;
+		
+    	DelResponse delResponse = new DelResponse();
+		
+		// Transform the ldapResult
+    	delResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersDelResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( delResponse );
+    }
+    
+    /**
+     * Transform a Snickers ExtendedResponse to a Twix ExtendedResponse
+     * @param twixMessage The Twix ExtendedResponse to produce 
+     * @param snickersMessage The incoming Snickers ExtendedResponse
+     */
+    private void transformExtendedResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	ExtendedResponseImpl snickersExtendedResponse = (ExtendedResponseImpl)snickersMessage;
+		
+    	ExtendedResponse extendedResponse = new ExtendedResponse();
+		
+	    // Snickers : String oid -> Twix : OID responseName
+    	try 
+    	{
+    		extendedResponse.setResponseName( new OID( snickersExtendedResponse.getResponseName() ) );
+    	}
+    	catch ( DecoderException de )
+    	{
+    		log.warn( "The OID " + snickersExtendedResponse.getResponseName() + " is invalid : " + de.getMessage() );
+    		extendedResponse.setResponseName( null );
+    	}
+
+	    // Snickers : byte [] value -> Twix : OctetString response
+    	extendedResponse.setResponse( new OctetString( snickersExtendedResponse.getResponse() ) );
+
+    	// Transform the ldapResult
+    	extendedResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersExtendedResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( extendedResponse );
+    }
+    
+    /**
+     * Transform a Snickers ModifyResponse to a Twix ModifyResponse
+     * @param twixMessage The Twix ModifyResponse to produce 
+     * @param snickersMessage The incoming Snickers ModifyResponse
+     */
+    private void transformModifyResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	ModifyResponseImpl snickersModifyResponse = (ModifyResponseImpl)snickersMessage;
+		
+    	ModifyResponse modifyResponse = new ModifyResponse();
+		
+    	// Transform the ldapResult
+    	modifyResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersModifyResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( modifyResponse );
+    }
+    
+    /**
+     * Transform a Snickers ModifyDNResponse to a Twix ModifyDNResponse
+     * @param twixMessage The Twix ModifyDNResponse to produce 
+     * @param snickersMessage The incoming Snickers ModifyDNResponse
+     */
+    private void transformModifyDNResponse( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	ModifyDnResponseImpl snickersModifyDNResponse = (ModifyDnResponseImpl)snickersMessage;
+		
+    	ModifyDNResponse modifyDNResponse = new ModifyDNResponse();
+		
+    	// Transform the ldapResult
+    	modifyDNResponse.setLdapResult( transformLdapResult( (LdapResultImpl)snickersModifyDNResponse.getLdapResult() ) );
+		
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( modifyDNResponse );
+    }
+    
+    /**
+     * Transform a Snickers SearchResponseDone to a Twix SearchResultDone
+     * @param twixMessage The Twix SearchResultDone to produce 
+     * @param snickersMessage The incoming Snickers SearchResponseDone
+     */
+    private void transformSearchResultDone( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	SearchResponseDoneImpl snickersSearchResponseDone = (SearchResponseDoneImpl)snickersMessage;
+    	SearchResultDone searchResultDone = new SearchResultDone(); 
+    	
+		// Transform the ldapResult
+    	searchResultDone.setLdapResult( transformLdapResult( (LdapResultImpl)snickersSearchResponseDone.getLdapResult() ) );
+
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( searchResultDone );
+    }
+    
+    /**
+     * Transform a Snickers SearchResponseEntry to a Twix SearchResultEntry
+     * @param twixMessage The Twix SearchResultEntry to produce 
+     * @param snickersMessage The incoming Snickers SearchResponseEntry
+     */
+    private void transformSearchResultEntry( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	SearchResponseEntryImpl snickersSearchResultResponse = (SearchResponseEntryImpl)snickersMessage;
+    	SearchResultEntry searchResultEntry = new SearchResultEntry(); 
+    	
+	    // Snickers : String dn -> Twix : LdapDN objectName
+    	try 
+    	{
+    		searchResultEntry.setObjectName( new LdapDN( snickersSearchResultResponse.getObjectName().getBytes() ) );
+    	}
+    	catch (DecoderException de)
+    	{
+			log.warn( "The DN " + snickersSearchResultResponse.getObjectName() + " is invalid : " + de.getMessage() );
+    		searchResultEntry.setObjectName( LdapDN.EMPTY_STRING );
+    	}
+    	
+    	// Snickers : Attributes attributes -> Twix : ArrayList partialAttributeList
+    	searchResultEntry.setPartialAttributeList( snickersSearchResultResponse.getAttributes() );
+    	
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( searchResultEntry );
+    }
+    
+    /**
+     * Transform a Snickers SearchResponseReference to a Twix SearchResultReference
+     * @param twixMessage The Twix SearchResultReference to produce 
+     * @param snickersMessage The incoming Snickers SearchResponseReference
+     */
+    private void transformSearchResultReference( LdapMessage twixMessage, Message snickersMessage )
+    {
+    	SearchResponseReferenceImpl snickersSearchResponseReference = (SearchResponseReferenceImpl)snickersMessage;
+    	SearchResultReference searchResultReference = new SearchResultReference(); 
+    	
+	    // Snickers : Referral m_referral -> Twix: ArrayList searchResultReferences
+    	Referral referrals = snickersSearchResponseReference.getReferral();
+    	
+    	// Loop on all referals
+    	if ( referrals != null )
+    	{
+    		Collection urls = referrals.getLdapUrls();
+    		
+    		if ( urls != null )
+    		{
+    			Iterator url = urls.iterator();
+    			
+    			while ( url.hasNext() )
+    			{
+					String urlValue = (String)url.next();
+
+					try
+    				{
+    					searchResultReference.addSearchResultReference( new LdapURL( urlValue ) );
+    				}
+    				catch ( DecoderException de )
+    				{
+    					log.warn( "The LdapURL " + urlValue + " is incorrect : " + de.getMessage() );
+    				}
+    			}
+    		}
+    	}
+
+		// Set the operation into the LdapMessage
+		twixMessage.setProtocolOP( searchResultReference );
+    }
+    
+    /**
+     * Transform the Snickers message to a Twix message.
+     *
+     * @param msg the message to transform
+     * @return the msg transformed
+     */
+    public Object transform( Message msg )
+    {
+    	if (log.isDebugEnabled())
+    	{
+    		log.debug("Transforming message type " + msg.getType());
+    	}
+    	
+    	LdapMessage twixMessage = new LdapMessage();
+    	
+    	twixMessage.setMessageId( msg.getMessageId() );
+    	
+    	if ( msg.getType() == MessageTypeEnum.SEARCHRESENTRY)
+    	{
+    		transformSearchResultEntry( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.SEARCHRESDONE)
+    	{
+    		transformSearchResultDone( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.SEARCHRESREF)
+    	{
+    		transformSearchResultReference( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.BINDRESPONSE)
+    	{
+    		transformBindResponse( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.ADDRESPONSE)
+    	{
+    		transformAddResponse( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.COMPARERESPONSE)
+    	{
+    		transformCompareResponse( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.DELRESPONSE)
+    	{
+    		transformDelResponse( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.MODIFYRESPONSE)
+    	{
+    		transformModifyResponse( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.MODDNRESPONSE)
+    	{
+    		transformModifyDNResponse( twixMessage, msg );
+    	}
+    	else if ( msg.getType() == MessageTypeEnum.EXTENDEDRESP)
+    	{
+    		transformExtendedResponse( twixMessage, msg );
+    	}
+        
+		// We also have to transform the controls...
+		//transformControls( twixMessage, msg );
+		
+    	if (log.isDebugEnabled())
+    	{
+    		log.debug( "Transformed message : " + twixMessage );
+    	}
+    	
+    	return twixMessage;
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapConstants.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapConstants.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapConstants.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,118 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapConstants {
+    /** The scope constants */
+    public static final int SCOPE_BASE_OBJECT   = 0;
+    public static final int SCOPE_SINGLE_LEVEL  = 1;
+    public static final int SCOPE_WHOLE_SUBTREE = 2;
+    
+    /** The DerefAlias constants */
+    public static final int NEVER_DEREF_ALIASES    = 0;
+    public static final int DEREF_IN_SEARCHING     = 1;
+    public static final int DEREF_FINDING_BASE_OBJ = 2;
+    public static final int DEREF_ALWAYS           = 3;
+    
+    /** The operations */
+    public static final int OPERATION_ADD     = 0;
+    public static final int OPERATION_DELETE  = 1;
+    public static final int OPERATION_REPLACE = 2;
+    
+    /** The filters */
+    public static final int EQUALITY_MATCH_FILTER   = 0;
+    public static final int GREATER_OR_EQUAL_FILTER = 1;
+    public static final int LESS_OR_EQUAL_FILTER    = 2;
+    public static final int APPROX_MATCH_FILTER     = 3;
+    
+    /** LDAP contextual tags */
+    public static final byte UNBIND_REQUEST_TAG          = 0x42;
+    public static final byte DEL_REQUEST_TAG             = 0x4A;
+    public static final byte ABANDON_REQUEST_TAG         = 0x50;
+    public static final byte BIND_REQUEST_TAG            = 0x60;
+    public static final byte BIND_RESPONSE_TAG           = 0x61;
+    public static final byte SEARCH_REQUEST_TAG          = 0x63;
+    public static final byte SEARCH_RESULT_ENTRY_TAG     = 0x64;
+    public static final byte SEARCH_RESULT_DONE_TAG      = 0x65;
+    public static final byte MODIFY_REQUEST_TAG          = 0x66;
+    public static final byte MODIFY_RESPONSE_TAG         = 0x67;
+    public static final byte ADD_REQUEST_TAG             = 0x68;
+    public static final byte ADD_RESPONSE_TAG            = 0x69;
+    public static final byte DEL_RESPONSE_TAG            = 0x6B;
+    public static final byte MODIFY_DN_REQUEST_TAG       = 0x6C;
+    public static final byte MODIFY_DN_RESPONSE_TAG      = 0x6D;
+    public static final byte COMPARE_REQUEST_TAG         = 0x6E;
+    public static final byte COMPARE_RESPONSE_TAG        = 0x6F;
+    public static final byte SEARCH_RESULT_REFERENCE_TAG = 0x73;
+    public static final byte EXTENDED_REQUEST_TAG        = 0x77;
+    public static final byte EXTENDED_RESPONSE_TAG       = 0x78;
+    // The following tags are ints, because bytes above 127 are negative
+    // numbers, and we can't use them as array indexes.
+    public static final int BIND_REQUEST_SIMPLE_TAG             = 0x80;
+    public static final int EXTENDED_REQUEST_NAME_TAG           = 0x80;
+    public static final int MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG  = 0x80;
+    public static final int SEARCH_SUBSTRINGS_INITIAL_TAG       = 0x80;
+    public static final int EXTENDED_REQUEST_VALUE_TAG          = 0x81;
+    public static final int SEARCH_MATCHING_RULE_TAG            = 0x81;
+    public static final int SEARCH_SUBSTRINGS_ANY_TAG           = 0x81;
+    public static final int SEARCH_TYPE_TAG                     = 0x82;
+    public static final int SEARCH_SUBSTRINGS_FINAL_TAG         = 0x82;
+    public static final int SEARCH_MATCH_VALUE_TAG              = 0x83;
+    public static final int BIND_REQUEST_SASL_TAG               = 0x83;
+    public static final int LDAP_RESULT_REFERRAL_SEQUENCE_TAG   = 0x83;
+    public static final int DN_ATTRIBUTES_FILTER_TAG            = 0x84;
+    public static final int SERVER_SASL_CREDENTIAL_TAG          = 0x87;
+    public static final int PRESENT_FILTER_TAG                  = 0x87;
+    public static final int EXTENDED_RESPONSE_RESPONSE_NAME_TAG = 0x8A;
+    public static final int EXTENDED_RESPONSE_RESPONSE_TAG      = 0x8B;
+    public static final int CONTROLS_TAG                        = 0xA0;
+    public static final int AND_FILTER_TAG                      = 0xA0;
+    public static final int OR_FILTER_TAG                       = 0xA1;
+    public static final int NOT_FILTER_TAG                      = 0xA2;
+    public static final int EQUALITY_MATCH_FILTER_TAG           = 0xA3;
+    public static final int SUBSTRINGS_FILTER_TAG               = 0xA4;
+    public static final int GREATER_OR_EQUAL_FILTER_TAG         = 0xA5;
+    public static final int LESS_OR_EQUAL_FILTER_TAG            = 0xA6;
+    public static final int APPROX_MATCH_FILTER_TAG             = 0xA8;
+    public static final int EXTENSIBLE_MATCH_FILTER_TAG         = 0xA9;
+    
+    // The messages types
+    public static final int ABANDON_REQUEST         = 0;
+    public static final int ADD_REQUEST             = 1;
+    public static final int ADD_RESPONSE            = 2;
+    public static final int BIND_REQUEST            = 3;
+    public static final int BIND_RESPONSE           = 4;
+    public static final int COMPARE_REQUEST         = 5;
+    public static final int COMPARE_RESPONSE        = 6;
+    public static final int DEL_REQUEST             = 7;
+    public static final int DEL_RESPONSE            = 8;
+    public static final int EXTENDED_REQUEST        = 9;
+    public static final int EXTENDED_RESPONSE       = 10;
+    public static final int MODIFYDN_REQUEST        = 11;
+    public static final int MODIFYDN_RESPONSE       = 12;
+    public static final int MODIFY_REQUEST          = 13;
+    public static final int MODIFY_RESPONSE         = 14;
+    public static final int SEARCH_REQUEST          = 15;
+    public static final int SEARCH_RESULT_DONE      = 16;
+    public static final int SEARCH_RESULT_ENTRY     = 17;
+    public static final int SEARCH_RESULT_REFERENCE = 18;
+    public static final int UNBIND_REQUEST          = 19;
+    public static final int UNKNOWN                 = -1; // Just in case ...
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapDecoder.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapDecoder.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapDecoder.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapDecoder.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,34 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec;
+
+import org.apache.asn1new.ber.Asn1Decoder;
+
+/**
+ * The Ldap decoder. This class does the initialisation of the object's pools.
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapDecoder extends Asn1Decoder {
+    
+    /**
+     * Standard LdapDecoder constructor. 
+     *
+     */
+    public LdapDecoder()
+    {
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapMessageContainer.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapMessageContainer.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapMessageContainer.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapMessageContainer.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,136 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec;
+
+import org.apache.asn1new.ber.AbstractContainer;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ldap.codec.grammar.AbandonRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.AddRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.AddResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.BindRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.BindResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.CompareRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.CompareResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.DelRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.DelResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.ExtendedRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.ExtendedResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.FilterGrammar;
+import org.apache.asn1new.ldap.codec.grammar.LdapControlGrammar;
+import org.apache.asn1new.ldap.codec.grammar.LdapMessageGrammar;
+import org.apache.asn1new.ldap.codec.grammar.LdapResultGrammar;
+import org.apache.asn1new.ldap.codec.grammar.LdapStatesEnum;
+import org.apache.asn1new.ldap.codec.grammar.ModifyDNRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.ModifyDNResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.ModifyRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.ModifyResponseGrammar;
+import org.apache.asn1new.ldap.codec.grammar.SearchRequestGrammar;
+import org.apache.asn1new.ldap.codec.grammar.SearchResultDoneGrammar;
+import org.apache.asn1new.ldap.codec.grammar.SearchResultEntryGrammar;
+import org.apache.asn1new.ldap.codec.grammar.SearchResultReferenceGrammar;
+import org.apache.asn1new.ldap.codec.grammar.UnBindRequestGrammar;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+
+
+/**
+ * The LdapMessage container stores all the messages decoded by the
+ * Asn1Decoder. When dealing whith an incoding PDU, we will obtain
+ * a LdapMessage in the ILdapContainer.
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessageContainer extends AbstractContainer implements IAsn1Container //extends AbstractLdapContainer
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The ldap message */
+    private LdapMessage ldapMessage;
+    
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapMessageContainer object.
+     * We will store ten grammars, it's enough ...
+     */
+    public LdapMessageContainer()
+    {
+        super( );
+        currentGrammar = 0;
+        grammars = new IGrammar[LdapStatesEnum.NB_GRAMMARS];
+        grammarStack = new IGrammar[10];
+        stateStack = new int[10];
+        nbGrammars = 0;
+
+        grammars[LdapStatesEnum.LDAP_MESSAGE_GRAMMAR] = LdapMessageGrammar.getInstance(); 
+        grammars[LdapStatesEnum.LDAP_CONTROL_GRAMMAR] = LdapControlGrammar.getInstance(); 
+        grammars[LdapStatesEnum.BIND_REQUEST_GRAMMAR] = BindRequestGrammar.getInstance(); 
+        grammars[LdapStatesEnum.LDAP_RESULT_GRAMMAR]  = LdapResultGrammar.getInstance(); 
+        grammars[LdapStatesEnum.BIND_RESPONSE_GRAMMAR] = BindResponseGrammar.getInstance(); 
+        grammars[LdapStatesEnum.UNBIND_REQUEST_GRAMMAR] = UnBindRequestGrammar.getInstance(); 
+        grammars[LdapStatesEnum.ABANDON_REQUEST_GRAMMAR] = AbandonRequestGrammar.getInstance(); 
+        grammars[LdapStatesEnum.ADD_RESPONSE_GRAMMAR] = AddResponseGrammar.getInstance(); 
+        grammars[LdapStatesEnum.COMPARE_RESPONSE_GRAMMAR] = CompareResponseGrammar.getInstance(); 
+        grammars[LdapStatesEnum.DEL_RESPONSE_GRAMMAR] = DelResponseGrammar.getInstance(); 
+        grammars[LdapStatesEnum.MODIFY_RESPONSE_GRAMMAR] = ModifyResponseGrammar.getInstance();
+        grammars[LdapStatesEnum.MODIFY_DN_RESPONSE_GRAMMAR] = ModifyDNResponseGrammar.getInstance();
+        grammars[LdapStatesEnum.SEARCH_RESULT_DONE_GRAMMAR] = SearchResultDoneGrammar.getInstance();
+        grammars[LdapStatesEnum.SEARCH_REQUEST_GRAMMAR] = SearchRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.FILTER_GRAMMAR] = FilterGrammar.getInstance();
+        grammars[LdapStatesEnum.SEARCH_RESULT_ENTRY_GRAMMAR] = SearchResultEntryGrammar.getInstance();
+        grammars[LdapStatesEnum.MODIFY_REQUEST_GRAMMAR] = ModifyRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.SEARCH_RESULT_REFERENCE_GRAMMAR] = SearchResultReferenceGrammar.getInstance();
+        grammars[LdapStatesEnum.ADD_REQUEST_GRAMMAR] = AddRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.MODIFY_DN_REQUEST_GRAMMAR] = ModifyDNRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.DEL_REQUEST_GRAMMAR] = DelRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.COMPARE_REQUEST_GRAMMAR] = CompareRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.EXTENDED_REQUEST_GRAMMAR] = ExtendedRequestGrammar.getInstance();
+        grammars[LdapStatesEnum.EXTENDED_RESPONSE_GRAMMAR] = ExtendedResponseGrammar.getInstance();
+
+        grammarStack[currentGrammar] = grammars[LdapStatesEnum.LDAP_MESSAGE_GRAMMAR];
+        
+        states = LdapStatesEnum.getInstance();
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+    /**
+     * @return Returns the ldapMessage.
+     */
+    public LdapMessage getLdapMessage()
+    {
+
+        return ldapMessage;
+    }
+
+    /**
+     * Set a ldapMessage Object into the container. It will be completed
+     * by the ldapDecoder .
+     *
+     * @param ldapMessage The ldapMessage to set.
+     */
+    public void setLdapMessage( LdapMessage ldapMessage )
+    {
+        this.ldapMessage = ldapMessage;
+    }
+    
+    public void clean()
+    {
+    	super.clean();
+    	
+        ldapMessage = null;
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/LdapMessageContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AbandonRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AbandonRequestGrammar.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AbandonRequestGrammar.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AbandonRequestGrammar.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,137 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec.grammar;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.AbstractGrammar;
+import org.apache.asn1new.ber.grammar.GrammarAction;
+import org.apache.asn1new.ber.grammar.GrammarTransition;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.util.IntegerDecoder;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.LdapMessageContainer;
+import org.apache.asn1new.ldap.pojo.AbandonRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AbandonRequest LDAP message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * If an action is to be added or modified, this is where the work is to be done !
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbandonRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( AbandonRequestGrammar.class );
+
+    /** The instance of grammar. AbandonRequestGrammar is a singleton */
+    private static IGrammar instance = new AbandonRequestGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new AbandonRequestGrammar object.
+     */
+    private AbandonRequestGrammar()
+    {
+
+        name       = AbandonRequestGrammar.class.getName();
+
+        statesEnum = LdapStatesEnum.getInstance();
+
+        // The transitions table
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_ABANDON_REQUEST_STATE][256];
+
+        //--------------------------------------------------------------------------------------------
+        // AbandonRequest Message ID
+        //--------------------------------------------------------------------------------------------
+        // AbandonRequest ::= [APPLICATION 16] MessageID (Tag)
+        // The tag must be 0x50. It codes for an integer, as we use
+        // IMPLICIT tags (we won't have a 0x02 tag to code the integer).
+        // Nothing special to do.
+        super.transitions[LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_TAG][LdapConstants.ABANDON_REQUEST_TAG] =
+            new GrammarTransition( LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_TAG,
+                LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_VALUE, null );
+
+        // AbandonRequest ::= [APPLICATION 16] MessageID (Value)
+        // (2147483647 = Integer.MAX_VALUE)
+        // Checks that MessageId is in [0 .. 2147483647] and store the value in the AbandonRequest Object
+        // This is the last state.
+        super.transitions[LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_VALUE][LdapConstants.ABANDON_REQUEST_TAG] =
+            new GrammarTransition( LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_VALUE,
+            		LdapStatesEnum.GRAMMAR_END, new GrammarAction( "Store MessageId" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // The current TLV should be a integer
+                        // We get it and store it in MessageId
+                        TLV   tlv       = ldapMessageContainer.getCurrentTLV();
+
+                        Value value     = tlv.getValue();
+
+                        int   abandonnedMessageId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
+
+                        if ( ( abandonnedMessageId < 0 ) || ( abandonnedMessageId > Integer.MAX_VALUE ) )
+                        {
+                            throw new DecoderException(
+                                "The message ID must be between (0 .. 2 147 483 647)" );
+                        }
+                        else
+                        {
+
+                            // Ok, the Message ID is correct. We have to store it
+                            // in the AbandonRequest object
+                            // Object in the LDAPMessage
+                            AbandonRequest abandonRequest = new AbandonRequest();
+                            abandonRequest.setAbandonedMessageId( abandonnedMessageId );
+                            ldapMessage.setProtocolOP( abandonRequest );
+
+                            return;
+                        }
+                    }
+                } );
+
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the AbandonRequest Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AbandonRequestGrammar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddRequestGrammar.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddRequestGrammar.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddRequestGrammar.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,324 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec.grammar;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.AbstractGrammar;
+import org.apache.asn1new.ber.grammar.GrammarAction;
+import org.apache.asn1new.ber.grammar.GrammarTransition;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.LdapMessageContainer;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+import org.apache.asn1new.ldap.pojo.AddRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AddRequest LDAP message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( AddRequestGrammar.class );
+
+    /** The instance of grammar. AddRequestGrammar is a singleton */
+    private static IGrammar instance = new AddRequestGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new AddRequestGrammar object.
+     */
+    private AddRequestGrammar()
+    {
+        name       = AddRequestGrammar.class.getName();
+        statesEnum = LdapStatesEnum.getInstance();
+
+        // Intitialisation
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_ADD_REQUEST_STATE][256];
+
+        //============================================================================================
+        // AddRequest Message
+        //============================================================================================
+        // LdapMessage ::= ... AddRequest ...
+        // AddRequest ::= [APPLICATION 8] SEQUENCE { (Tag)
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.ADD_REQUEST_TAG][LdapConstants.ADD_REQUEST_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_TAG, LdapStatesEnum.ADD_REQUEST_VALUE, null );
+
+        // LdapMessage ::= ... AddRequest ...
+        // AddRequest ::= [APPLICATION 8] SEQUENCE { (Value)
+        // Create the structure
+        super.transitions[LdapStatesEnum.ADD_REQUEST_VALUE][LdapConstants.ADD_REQUEST_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_VALUE, LdapStatesEnum.ADD_REQUEST_ENTRY_TAG,
+                new GrammarAction( "Init addRequest" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // Now, we can allocate the ModifyRequest Object
+                        // And we associate it to the ldapMessage Object
+                        ldapMessage.setProtocolOP( new AddRequest() );
+                    }
+                } );
+
+        // AddRequest ::= [APPLICATION 8] SEQUENCE {
+        //    entry      LDAPDN, (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ENTRY_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ENTRY_TAG, LdapStatesEnum.ADD_REQUEST_ENTRY_VALUE,
+                null );
+
+        // AddRequest ::= [APPLICATION 8] SEQUENCE {
+        //    entry      LDAPDN, (Value)
+        //    ...
+        // Store the object name.
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ENTRY_VALUE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ENTRY_VALUE, LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TAG,
+                new GrammarAction( "Store add request object Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        AddRequest           addRequest           = ldapMessage.getAddRequest();
+
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
+
+                        // Store the entry. It can't be null
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            throw new DecoderException( "The DN can't be null" );
+                        }
+                        else
+                        {
+                            addRequest.setEntry( new LdapDN(
+                                    tlv.getValue().getData() ) );
+                        }
+                    }
+                } );
+
+        // AddRequest ::= [APPLICATION 8] SEQUENCE {
+        //    ...
+        //    attributes      AttributeList }
+        // AttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TAG][UniversalTag.SEQUENCE_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TAG,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALUE, null );
+
+        // AddRequest ::= [APPLICATION 8] SEQUENCE {
+        //    ...
+        //    attributes      AttributeList }
+        // AttributeList ::= *SEQUENCE* OF SEQUENCE { (Value)
+        // Allocate the attributes ArrayList
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALUE][UniversalTag.SEQUENCE_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALUE,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_TAG,
+                new GrammarAction( "Init attributes array list" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        AddRequest           addRequest           = ldapMessage.getAddRequest();
+
+                        addRequest.initAttributes();
+                    }
+                } );
+
+        // AttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
+        //     ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_TAG,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE, null );
+
+        // AttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
+        //     ...
+        // Nothing to do
+        // This is a loop, when dealing with more than one attribute
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END][UniversalTag.SEQUENCE_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE, null );
+
+        // AttributeList ::= SEQUENCE OF *SEQUENCE* { (Value)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE][UniversalTag.SEQUENCE_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_TAG, null );
+
+        // AttributeList ::= SEQUENCE OF *SEQUENCE* {
+        //    type    AttributeDescription, (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_TAG][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_TAG,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_VALUE, null );
+
+        // AttributeList ::= SEQUENCE OF *SEQUENCE* {
+        //    type    AttributeDescription, (Value)
+        //    ...
+        // Store the attribute type.
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_VALUE][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_VALUE,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_TAG,
+                new GrammarAction( "Store attribute type" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
+
+                        AddRequest           addRequest           = ldapMessage.getAddRequest();
+
+                        // Store the type. It can't be null.
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            throw new DecoderException( "The type can't be null" );
+                        }
+                        else
+                        {
+                            addRequest.addAttributeType( new LdapString(
+                                    tlv.getValue().getData() ) );
+                        }
+                    }
+                } );
+
+        // AttributeTypeAndValues ::= SEQUENCE {
+        //     ...
+        //     vals    *SET OF* AttributeValue } (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_TAG][UniversalTag.SET_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_TAG,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_VALUE, null );
+
+        // AttributeTypeAndValues ::= SEQUENCE {
+        //     ...
+        //     vals    *SET OF* AttributeValue } (Value)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_VALUE][UniversalTag.SET_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_VALUE,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_TAG, null );
+
+        // AttributeTypeAndValues ::= SEQUENCE {
+        //     ...
+        //     vals    SET OF *AttributeValue* } (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_TAG][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_TAG,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE, null );
+
+        // AttributeTypeAndValues ::= SEQUENCE {
+        //     ...
+        //     vals    SET OF *AttributeValue* } (Loop)
+        // This is a loop, when dealing with multi-valued attributes
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE, null );
+
+        // AttributeTypeAndValues ::= SEQUENCE {
+        //     ...
+        //     vals    SET OF AttributeValue }
+        // AttributeValue ::= OCTET STRING (Value)
+        // Store a new attribute value.
+        super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE,
+                LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END,
+                new GrammarAction( "Store attribute value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        AddRequest           addRequest           = ldapMessage.getAddRequest();
+
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
+
+                        // Store the value. It can't be null
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            addRequest.addAttributeValue( OctetString.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            addRequest.addAttributeValue( new OctetString(
+                                    tlv.getValue().getData() ) );
+                        }
+                    }
+                } );
+
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the SearchResultEntry Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddRequestGrammar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddResponseGrammar.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddResponseGrammar.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddResponseGrammar.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,122 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec.grammar;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.AbstractGrammar;
+import org.apache.asn1new.ber.grammar.GrammarAction;
+import org.apache.asn1new.ber.grammar.GrammarTransition;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.LdapMessageContainer;
+import org.apache.asn1new.ldap.pojo.AddResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AddResponse LDAP message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddResponseGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( AddResponseGrammar.class );
+
+    /** The instance of grammar. AddResponseGrammar is a singleton */
+    private static IGrammar instance = new AddResponseGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new AddResponseGrammar object.
+     */
+    private AddResponseGrammar()
+    {
+        name = AddResponseGrammar.class.getName();
+        statesEnum = LdapStatesEnum.getInstance();
+
+        // Intitialisation
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_ADD_RESPONSE_STATE][256];
+
+        //============================================================================================
+        // AddResponse Message
+        //============================================================================================
+        // LdapMessage ::= ... AddResponse ...
+        // AddResponse ::= [APPLICATION 9] LDAPResult (Tag)
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.ADD_RESPONSE_TAG][LdapConstants.ADD_RESPONSE_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_RESPONSE_TAG, LdapStatesEnum.ADD_RESPONSE_VALUE, null );
+
+        // LdapMessage ::= ... AddResponse ...
+        // AddResponse ::= [APPLICATION 9] LDAPResult (Value)
+        // The next Tag will be the LDAPResult Tag (0x0A).
+        // We will switch the grammar then.
+        super.transitions[LdapStatesEnum.ADD_RESPONSE_VALUE][LdapConstants.ADD_RESPONSE_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_RESPONSE_VALUE, LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT, 
+                new GrammarAction( "Init AddResponse" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // Now, we can allocate the AddRequest Object
+                        AddResponse addResponse = new AddResponse();
+
+                        // As this is a new Constructed object, we have to init its length
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+                        int expectedLength = tlv.getLength().getLength();
+                        addResponse.setExpectedLength( expectedLength );
+                        addResponse.setCurrentLength( 0 );
+                        addResponse.setParent( ldapMessage );
+
+                        // And we associate it to the ldapMessage Object
+                        ldapMessage.setProtocolOP( addResponse );
+                    }
+                } );
+
+        // LdapMessage ::= ... AddResponse ...
+        // AddResponse ::= [APPLICATION 9] LDAPResult (Value)
+        // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
+        super.transitions[LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
+                LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the LdapMessage Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/AddResponseGrammar.java
------------------------------------------------------------------------------
    svn:eol-style = native