commits@directory.apache.org
[Top] [All Lists]

svn commit: r366108 - in /directory/trunk: apacheds/src/main/java/org/ap

Subject: svn commit: r366108 - in /directory/trunk: apacheds/src/main/java/org/apache/ldap/server/partition/ ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/
From:
Date: Thu, 05 Jan 2006 07:26:19 -0000
Author: akarasulu
Date: Wed Jan  4 23:26:12 2006
New Revision: 366108

URL: http://svn.apache.org/viewcvs?rev=366108&view=rev
Log:
added new codec for entry change reponse control

Added:
    
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/ChangeType.java
   (with props)
    
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControl.java
   (with props)
    
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlContainer.java
   (with props)
    
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlDecoder.java
   (with props)
    
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlGrammar.java
   (with props)
    
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlStatesEnum.java
   (with props)
Modified:
    
directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java

Modified: 
directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java?rev=366108&r1=366107&r2=366108&view=diff
==============================================================================
--- 
directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
 (original)
+++ 
directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
 Wed Jan  4 23:26:12 2006
@@ -129,6 +129,11 @@
         rootDSE.put( attr );
         attr.add( "1.3.6.1.4.1.4203.1.5.1" );
 
+        attr = new LockableAttributeImpl( "supportedControls" );
+        rootDSE.put( attr );
+        attr.add( "2.16.840.1.113730.3.4.3" );  // PersistentSearch control
+        attr.add( "2.16.840.1.113730.3.4.7" );  // EntryChangeNotification 
control
+
         attr = new LockableAttributeImpl( "objectClass" );
         rootDSE.put( attr );
         attr.add( "top" );

Added: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/ChangeType.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/ChangeType.java?rev=366108&view=auto
==============================================================================
--- 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/ChangeType.java
 (added)
+++ 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/ChangeType.java
 Wed Jan  4 23:26:12 2006
@@ -0,0 +1,94 @@
+/*
+ *   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.ldap.common.codec.search.controls;
+
+
+/**
+ * Enumeration type for entry changes associates with the persistent search 
+ * control and the entry change control.  Used for the following ASN1 
enumeration:
+ * <pre>
+ *  changeType ENUMERATED 
+ *  {
+ *      add             (1),
+ *      delete          (2),
+ *      modify          (4),
+ *      modDN           (8)
+ *  }
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ * @version $Rev$
+ */
+public class ChangeType
+{
+    public static final int ADD_VALUE = 1;
+    public static final int DELETE_VALUE = 2;
+    public static final int MODIFY_VALUE = 4;
+    public static final int MODDN_VALUE = 8;
+    
+    public static final ChangeType ADD = new ChangeType( "ADD", ADD_VALUE );
+    public static final ChangeType DELETE = new ChangeType( "DELETE", 
DELETE_VALUE );
+    public static final ChangeType MODIFY = new ChangeType( "MODIFY", 
MODIFY_VALUE );
+    public static final ChangeType MODDN = new ChangeType( "MODDN", 
MODDN_VALUE );
+    
+    private final String label;
+    private final int value;
+    
+    
+    private ChangeType( String label, int value )
+    {
+        this.label = label;
+        this.value = value;
+    }
+
+    
+    public int getValue()
+    {
+        return value;
+    }
+    
+    
+    public String toString()
+    {
+        return( label );
+    }
+    
+    
+    /**
+     * Gets the changeType enumeration type for an integer value.
+     * 
+     * @param value the value to get the enumeration for
+     * @return the enueration type for the value if the value is valid
+     * @throws IllegalArgumentException if the value is undefined
+     */
+    public static ChangeType getChangeType( int value )
+    {
+        switch( value )
+        {
+            case( ADD_VALUE ):
+                return ADD;
+            case( DELETE_VALUE ):
+                return DELETE;
+            case( MODIFY_VALUE ):
+                return MODIFY;
+            case( MODDN_VALUE ):
+                return MODDN;
+            default:
+                throw new IllegalArgumentException( "Undefined changeType 
value: " + value );
+        }
+    }
+}

Propchange: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/ChangeType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControl.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControl.java?rev=366108&view=auto
==============================================================================
--- 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControl.java
 (added)
+++ 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControl.java
 Wed Jan  4 23:26:12 2006
@@ -0,0 +1,210 @@
+/*
+ *   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.ldap.common.codec.search.controls;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.UniversalTag;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1.util.Asn1StringUtils;
+import org.apache.ldap.common.codec.util.LdapString;
+import org.apache.ldap.common.codec.util.LdapStringEncodingException;
+
+
+/**
+ * A response control that may be returned by Persistent Search entry 
+ * responses.  It contains addition change information to descrive the
+ * exact change that occured to an entry.  The exact details of this 
+ * control are covered in section 5 of this (yes) expired draft:
+ * <a 
href="http://www3.ietf.org/proceedings/01aug/I-D/draft-ietf-ldapext-psearch-03.txt";>
+ * Persistent Search Draft v03</a> which is printed out below for 
+ * convenience:
+ * <pre>
+ *   5.  Entry Change Notification Control
+ *   
+ *   This control provides additional information about the change the caused
+ *   a particular entry to be returned as the result of a persistent search.
+ *   The controlType is "2.16.840.1.113730.3.4.7".  If the client set the
+ *   returnECs boolean to TRUE in the PersistentSearch control, servers MUST
+ *   include an EntryChangeNotification control in the Controls portion of
+ *   each SearchResultEntry that is returned due to an entry being added,
+ *   deleted, or modified.
+ *   
+ *              EntryChangeNotification ::= SEQUENCE 
+ *              {
+ *                        changeType ENUMERATED 
+ *                        {
+ *                                add             (1),
+ *                                delete          (2),
+ *                                modify          (4),
+ *                                modDN           (8)
+ *                        },
+ *                        previousDN   LDAPDN OPTIONAL,     -- modifyDN ops. 
only
+ *                        changeNumber INTEGER OPTIONAL     -- if supported
+ *              }
+ *   
+ *   changeType indicates what LDAP operation caused the entry to be
+ *   returned.
+ *   
+ *   previousDN is present only for modifyDN operations and gives the DN of
+ *   the entry before it was renamed and/or moved.  Servers MUST include this
+ *   optional field only when returning change notifications as a result of
+ *   modifyDN operations.
+ *
+ *   changeNumber is the change number [CHANGELOG] assigned by a server for
+ *   the change.  If a server supports an LDAP Change Log it SHOULD include
+ *   this field.
+ *   </pre>
+ * 
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ * @version $Rev$
+ */
+public class EntryChangeControl extends Asn1Object
+{
+    public static final int UNDEFINED_CHANGE_NUMBER = -1;
+    
+    private ChangeType changeType = ChangeType.ADD;
+    private int changeNumber = UNDEFINED_CHANGE_NUMBER;
+    private LdapString previousDn = null;
+    
+
+    private transient int eccSeqLength;
+
+    /**
+     * Compute the EnryChangeControl length
+     * 0x30 L1
+     *  |
+     *  +--> 0x0A 0x0(1-4) [1|2|4|8] (changeType)
+     *  +--> 0x04 L2 previousDN
+     *  +--> 0x02 0x0(1-4) [0..2^31-1] (changeNumber)
+     */
+    public int computeLength()
+    {
+        int changeTypesLength = 1 + 1 + Value.getNbBytes( 
changeType.getValue() );
+        int previousDnLength = 0;
+        int changeNumberLength = 0;
+        
+        if ( previousDn != null ) previousDnLength += previousDn.getNbBytes();
+        if ( changeNumber != UNDEFINED_CHANGE_NUMBER ) changeNumberLength += 
Value.getNbBytes( changeNumber );
+
+        eccSeqLength = changeTypesLength + previousDnLength + 
changeNumberLength;
+        
+        return  1 + Length.getNbBytes( eccSeqLength ) + eccSeqLength;
+    }
+
+
+    /**
+     * Encodes the entry change control.
+     * 
+     * @param buffer The encoded sink
+     * @return A ByteBuffer that contains the encoded PDU
+     * @throws EncoderException If anything goes wrong.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+        bb.put( UniversalTag.SEQUENCE_TAG );
+        bb.put( Length.getBytes( eccSeqLength ) );
+
+        Value.encode( bb, changeType.getValue() );
+        if ( previousDn != null )
+        {
+            Value.encode( bb, previousDn.getBytes() );
+        }
+        if ( changeNumber != UNDEFINED_CHANGE_NUMBER )
+        {
+            Value.encode( bb, changeNumber );
+        }
+        return bb;
+    }
+
+
+    /**
+     * Return a String representing this EntryChangeControl.
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        sb.append( "    Entry Change Control\n" );
+        sb.append( "        changeType   : '" ).append( changeType 
).append("'\n");
+        sb.append( "        previousDN   : '" ).append( previousDn ).append( 
"'\n");
+        if ( changeNumber == UNDEFINED_CHANGE_NUMBER )
+        {
+            sb.append( "        changeNumber : '" ).append( "UNDEFINED" 
).append( "'\n");
+        }
+        else
+        {
+            sb.append( "        changeNumber : '" ).append( changeNumber 
).append( "'\n");
+        }
+        return sb.toString();
+    }
+
+    
+    public ChangeType getChangeType()
+    {
+        return changeType;
+    }
+    
+
+    public void setChangeType( ChangeType changeType )
+    {
+        this.changeType = changeType;
+    }
+
+    
+    public String getPreviousDn()
+    {
+        return previousDn.getString();
+    }
+    
+    
+    public void setPreviousDn( String previousDn )
+    {
+        try
+        {
+            this.previousDn = new LdapString( Asn1StringUtils.getBytesUtf8( 
previousDn ) );
+        }
+        catch ( LdapStringEncodingException e )
+        {
+            e.printStackTrace();
+        }
+    }
+    
+    
+    public void setPreviousDn( LdapString previousDn )
+    {
+        this.previousDn = previousDn;
+    }
+    
+    
+    public int getChangeNumber()
+    {
+        return changeNumber;
+    }
+    
+    
+    public void setChangeNumber( int changeNumber )
+    {
+        this.changeNumber = changeNumber;
+    }
+}

Propchange: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlContainer.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlContainer.java?rev=366108&view=auto
==============================================================================
--- 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlContainer.java
 (added)
+++ 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlContainer.java
 Wed Jan  4 23:26:12 2006
@@ -0,0 +1,79 @@
+/*
+ *   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.ldap.common.codec.search.controls;
+
+
+import org.apache.asn1.ber.AbstractContainer;
+import org.apache.asn1.ber.IAsn1Container;
+import org.apache.asn1.ber.grammar.IGrammar;
+
+
+/**
+ *  
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ */
+public class EntryChangeControlContainer extends AbstractContainer implements 
IAsn1Container 
+{
+    /** EntryChangeControl */
+    private EntryChangeControl control;
+
+    /**
+     * Creates a new EntryChangeControlContainer object.
+     * We will store one grammar, it's enough ...
+     */
+    public EntryChangeControlContainer()
+    {
+        super( );
+        currentGrammar = 0;
+        grammars = new IGrammar[EntryChangeControlStatesEnum.NB_GRAMMARS];
+        grammarStack = new IGrammar[1];
+        stateStack = new int[1];
+        nbGrammars = 0;
+
+        grammars[EntryChangeControlStatesEnum.EC_GRAMMAR] = 
EntryChangeControlGrammar.getInstance();
+        grammarStack[currentGrammar] = 
grammars[EntryChangeControlStatesEnum.EC_GRAMMAR];
+        states = EntryChangeControlStatesEnum.getInstance();
+    }
+
+
+    /**
+     * @return Returns the EntryChangeControl.
+     */
+    public EntryChangeControl getEntryChangeControl()
+    {
+        return control;
+    }
+
+    
+    /**
+     * Set a EntryChangeControl Object into the container. It will be completed
+     * by the ldapDecoder.
+     *
+     * @param control the EntryChangeControl to set.
+     */
+    public void setEntryChangeControl( EntryChangeControl control )
+    {
+        this.control = control;
+    }
+
+    
+    public void clean()
+    {
+        super.clean();
+        control = null;
+    }
+}

Propchange: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlDecoder.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlDecoder.java?rev=366108&view=auto
==============================================================================
--- 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlDecoder.java
 (added)
+++ 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlDecoder.java
 Wed Jan  4 23:26:12 2006
@@ -0,0 +1,54 @@
+/*
+ *   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.ldap.common.codec.search.controls;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.codec.DecoderException;
+import org.apache.ldap.common.codec.ControlDecoder;
+
+
+/**
+ * A decoder for EntryChangeControls.
+ * 
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ */
+public class EntryChangeControlDecoder implements ControlDecoder
+{
+    private final static String CONTROL_TYPE_OID = "2.16.840.1.113730.3.4.7";
+    
+    
+    public String getControlType()
+    {
+        return CONTROL_TYPE_OID;
+    }
+
+
+    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    {
+        // @todo if Asn1Decoder is reusable and thread safe the we should 
reuse it
+        // instead of creating a new one every time.
+        Asn1Decoder decoder = new Asn1Decoder();
+        ByteBuffer bb = ByteBuffer.wrap( controlBytes );
+        EntryChangeControlContainer container = new 
EntryChangeControlContainer();
+        decoder.decode( bb, container );
+        return container.getEntryChangeControl();
+    }
+}

Propchange: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlGrammar.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlGrammar.java?rev=366108&view=auto
==============================================================================
--- 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlGrammar.java
 (added)
+++ 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlGrammar.java
 Wed Jan  4 23:26:12 2006
@@ -0,0 +1,213 @@
+/*
+ *   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.ldap.common.codec.search.controls;
+
+
+import org.apache.asn1.ber.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.tlv.UniversalTag;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.util.IntegerDecoder;
+import org.apache.asn1.util.IntegerDecoderException;
+import org.apache.ldap.common.codec.LdapStatesEnum;
+import org.apache.ldap.common.codec.util.LdapString;
+import org.apache.ldap.common.codec.util.LdapStringEncodingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+/**
+ * This class implements the EntryChangeControl. All the actions are declared 
in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ */
+public class EntryChangeControlGrammar extends AbstractGrammar implements 
IGrammar
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( 
EntryChangeControlGrammar.class );
+
+    /** The instance of grammar. EntryChangeControlGrammar is a singleton */
+    private static IGrammar instance = new EntryChangeControlGrammar();
+
+    /**
+     * Creates a new EntryChangeControlGrammar object.
+     */
+    private EntryChangeControlGrammar()
+    {
+        name = EntryChangeControlGrammar.class.getName();
+        statesEnum = EntryChangeControlStatesEnum.getInstance();
+
+        // Create the transitions table
+        super.transitions = new 
GrammarTransition[EntryChangeControlStatesEnum.LAST_EC_STATE][256];
+
+        
super.transitions[EntryChangeControlStatesEnum.EC_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.EC_SEQUENCE_TAG,
+                EntryChangeControlStatesEnum.EC_SEQUENCE_VALUE, null );
+
+        
super.transitions[EntryChangeControlStatesEnum.EC_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.EC_SEQUENCE_VALUE,
+                EntryChangeControlStatesEnum.CHANGE_TYPE_TAG, 
+                new GrammarAction( "Init EntryChangeControl" )
+                {
+                    public void action( IAsn1Container container ) 
+                    {
+                        EntryChangeControlContainer EntryChangeContainer = ( 
EntryChangeControlContainer ) container;
+                        EntryChangeControl control = new EntryChangeControl();
+                        EntryChangeContainer.setEntryChangeControl( control );
+                    }
+                }
+            );
+
+        
super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_TAG][UniversalTag.ENUMERATED_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.CHANGE_TYPE_TAG,
+                EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE, null );
+
+        GrammarAction setChangeTypeAction = new GrammarAction( "Set 
EntryChangeControl changeType" )
+        {
+            public void action( IAsn1Container container ) throws 
DecoderException
+            {
+                EntryChangeControlContainer EntryChangeContainer = ( 
EntryChangeControlContainer ) container;
+                Value value = EntryChangeContainer.getCurrentTLV().getValue();
+                
+                try
+                {
+                    ChangeType changeType = ChangeType.getChangeType( 
IntegerDecoder.parse( value ) );
+                    
+                    if ( log.isDebugEnabled() )
+                    {
+                        log.debug( "changeType = " + changeType );
+                    }
+                    
+                    
EntryChangeContainer.getEntryChangeControl().setChangeType( changeType );
+                }
+                catch ( IntegerDecoderException e )
+                {
+                    String msg = "failed to decode the changeType for 
EntryChangeControl";
+                    log.error( msg, e );
+                    throw new DecoderException( msg );
+                }
+            }
+        };
+        
+        // transition for when we have a previousDN value
+        
super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE][UniversalTag.ENUMERATED_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE, 
+                EntryChangeControlStatesEnum.PREVIOUS_DN_TAG, 
setChangeTypeAction );
+
+        // transition for when we do not have a previousDN value but we do 
have a changeNumber
+        
super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE][UniversalTag.ENUMERATED_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE, 
+                EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG, 
setChangeTypeAction );
+        
+        // transition for when we do not have a previousDN value nor do we 
have a changeNumber
+        
super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE][UniversalTag.ENUMERATED_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE, 
+                EntryChangeControlStatesEnum.GRAMMAR_END, setChangeTypeAction 
);
+
+        
super.transitions[EntryChangeControlStatesEnum.PREVIOUS_DN_TAG][UniversalTag.OCTET_STRING_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.PREVIOUS_DN_TAG,
+                EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE, null );
+
+        GrammarAction setPreviousDnAction = new GrammarAction( "Set 
EntryChangeControl previousDN" )
+        {
+            public void action( IAsn1Container container ) throws 
DecoderException
+            {
+                EntryChangeControlContainer EntryChangeContainer = ( 
EntryChangeControlContainer ) container;
+                Value value = EntryChangeContainer.getCurrentTLV().getValue();
+                LdapString previousDn;
+                try
+                {
+                    previousDn = new LdapString( value.getData() );
+                }
+                catch ( LdapStringEncodingException e )
+                {
+                    throw new DecoderException( "failed to encode string data" 
);
+                }
+                
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "previousDN = " + previousDn );
+                }
+                
+                EntryChangeContainer.getEntryChangeControl().setPreviousDn( 
previousDn );
+            }
+        };
+
+        // transition if we do have an optional changeNumber after this 
previousDN
+        
super.transitions[EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE][UniversalTag.OCTET_STRING_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE, 
+                EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG, 
setPreviousDnAction );
+
+        // transition if we do *NOT* have an optional changeNumber after this 
previousDN
+        
super.transitions[EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE][UniversalTag.OCTET_STRING_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE, 
+                EntryChangeControlStatesEnum.GRAMMAR_END, setPreviousDnAction 
);
+
+        // transition for processing changeNumber
+        
super.transitions[EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG][UniversalTag.INTEGER_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG,
+                EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE, null );
+
+        // transition to finish grammar and set the changeNumber
+        
super.transitions[EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE][UniversalTag.INTEGER_TAG]
 =
+            new GrammarTransition( 
EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE, 
+                LdapStatesEnum.GRAMMAR_END, 
+                new GrammarAction( "Set EntryChangeControl changeNumber" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+                        EntryChangeControlContainer EntryChangeContainer = ( 
EntryChangeControlContainer ) container;
+                        Value value = 
EntryChangeContainer.getCurrentTLV().getValue();
+                        
+                        try
+                        {
+                            int changeNumber = IntegerDecoder.parse( value );
+                            
+                            if ( log.isDebugEnabled() )
+                            {
+                                log.debug( "changeNumber = " + changeNumber );
+                            }
+                            
+                            
EntryChangeContainer.getEntryChangeControl().setChangeNumber( changeNumber );
+                        }
+                        catch ( IntegerDecoderException e )
+                        {
+                            String msg = "failed to decode the changeNumber 
for EntryChangeControl";
+                            log.error( msg, e );
+                            throw new DecoderException( msg );
+                        }
+                    }
+                }
+            );
+    }
+
+    /**
+     * This class is a singleton.
+     *
+     * @return An instance on this grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Propchange: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlGrammar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlStatesEnum.java
URL: 
http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlStatesEnum.java?rev=366108&view=auto
==============================================================================
--- 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlStatesEnum.java
 (added)
+++ 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlStatesEnum.java
 Wed Jan  4 23:26:12 2006
@@ -0,0 +1,181 @@
+/*
+ *   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.ldap.common.codec.search.controls;
+
+
+import org.apache.asn1.ber.grammar.IStates;
+import org.apache.asn1.ber.grammar.IGrammar;
+
+
+/**
+ * This class store the EntryChangeControl's grammar constants.
+ * It is also used for debugging purposes.
+ *
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ */
+public class EntryChangeControlStatesEnum implements IStates
+{
+    //~ Static fields/initializers 
-----------------------------------------------------------------
+
+    //=========================================================================
+    // Entry change control grammar states 
+    //=========================================================================
+
+    /** Sequence Tag */
+    public static int EC_SEQUENCE_TAG = 0;
+
+    /** Sequence Value */
+    public static int EC_SEQUENCE_VALUE = 1;
+
+    /** changeType Tag */
+    public static int CHANGE_TYPE_TAG = 2;
+
+    /** changeType Value */
+    public static int CHANGE_TYPE_VALUE = 3;
+
+    /** previousDN Tag */
+    public static int PREVIOUS_DN_TAG = 4;
+
+    /** previousDN Value */
+    public static int PREVIOUS_DN_VALUE = 5;
+
+    /** changeNumber Tag */
+    public static int CHANGE_NUMBER_TAG = 6;
+
+    /** changeNumber Value */
+    public static int CHANGE_NUMBER_VALUE = 7;
+    
+    /** terminal state */
+    public static int LAST_EC_STATE = 8;
+
+    //=========================================================================
+    // Grammars declaration.
+    //=========================================================================
+    /** Entry change grammar */
+    public static final int EC_GRAMMAR_SWITCH = 0x0100;
+
+    /** Entry change grammar number */
+    public static final int EC_GRAMMAR = 0;
+
+    /** The total number of grammars used */
+    public static final int NB_GRAMMARS = 1;
+
+    //=========================================================================
+    // Grammar switches debug strings 
+    //=========================================================================
+    /** A string representation of grammars */
+    private static String[] GrammarSwitchString = new String[] { 
"EC_GRAMMAR_SWITCH" };
+
+    //=========================================================================
+    // States debug strings 
+    //=========================================================================
+    /** A string representation of all the states */
+    private static String[] EcString = new String[]
+    {
+        "EC_SEQUENCE_TAG",
+        "EC_SEQUENCE_VALUE",
+        "CHANGE_TYPE_TAG",
+        "CHANGE_TYPE_VALUE",
+        "PREVIOUS_DN_TAG",
+        "PREVIOUS_DN_VALUE",
+        "CHANGE_NUMBER_TAG",
+        "CHANGE_NUMBER_VALUE"
+    };
+
+    /** The instance */
+    private static EntryChangeControlStatesEnum instance = new 
EntryChangeControlStatesEnum();
+
+    //~ Constructors 
-------------------------------------------------------------------------------
+
+    /**
+     * This is a private constructor. This class is a singleton
+     *
+     */
+    private EntryChangeControlStatesEnum()
+    {
+    }
+
+    //~ Methods 
------------------------------------------------------------------------------------
+
+    /**
+     * Get an instance of this class
+     * @return An instance on this class
+     */
+    public static IStates getInstance()
+    {
+        return instance;
+    }
+
+    /**
+     * Get the grammar name
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        switch ( grammar )
+        {
+            case EC_GRAMMAR: return "EC_GRAMMAR";
+            default: return "UNKNOWN";
+        }
+    }
+
+    /**
+     * Get the grammar name
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( IGrammar grammar )
+    {
+        if ( grammar instanceof EntryChangeControlGrammar )
+        {
+            return "EC_GRAMMAR";
+        }
+        
+        return "UNKNOWN GRAMMAR";
+    }
+
+    /**
+     * Get the string representing the state
+     * 
+     * @param grammar The current grammar being used
+     * @param state The state number
+     * @return The String representing the state
+     */
+    public String getState( int grammar, int state )
+    {
+
+        if ( ( state & GRAMMAR_SWITCH_MASK ) != 0 )
+        {
+            return ( state == END_STATE ) ? "END_STATE"
+                : GrammarSwitchString[( ( state & GRAMMAR_SWITCH_MASK ) >> 8 ) 
- 1];
+        }
+        else
+        {
+
+            switch ( grammar )
+            {
+
+                case EC_GRAMMAR :
+                    return ( ( state == GRAMMAR_END ) ? "EC_END_STATE" : 
EcString[state] );
+
+                default :
+                    return "UNKNOWN";
+            }
+        }
+    }
+}

Propchange: 
directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/EntryChangeControlStatesEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native


<Prev in Thread] Current Thread [Next in Thread>
  • svn commit: r366108 - in /directory/trunk: apacheds/src/main/java/org/apache/ldap/server/partition/ ldap-common/src/main/java/org/apache/ldap/common/codec/search/controls/, akarasulu <=