directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r369966 - in /directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls: SubEntryControl.java SubEntryControlContainer.java SubEntryControlDecoder.java SubEntryControlGrammar.java SubEntryControlStatesEnum.java
Date Wed, 18 Jan 2006 00:05:24 GMT
Author: elecharny
Date: Tue Jan 17 16:05:19 2006
New Revision: 369966

URL: http://svn.apache.org/viewcvs?rev=369966&view=rev
Log:
Added the SubEntry control

Added:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControl.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlContainer.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlDecoder.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlGrammar.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlStatesEnum.java

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControl.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControl.java?rev=369966&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControl.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControl.java
Tue Jan 17 16:05:19 2006
@@ -0,0 +1,93 @@
+/*
+ *   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.Value;
+import org.apache.asn1.codec.EncoderException;
+
+
+/**
+ * A searchRequest control.
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubEntryControl extends Asn1Object
+{
+    private boolean visibility = false;
+    
+    /**
+     * Check if the subEntry is visible
+     * @return true or false.
+     */
+    public boolean isVisible() 
+    {
+        return visibility;
+    }
+
+    /**
+     * Set the visibility flag
+     * @param visibility The visibility flag : true or false
+     */
+    public void setVisibility(boolean visibility) 
+    {
+        this.visibility = visibility;
+    }
+
+    /**
+     * Compute the SubEntryControl length
+     * 0x01 0x01 [0x00|0xFF]
+     */
+    public int computeLength()
+    {
+        return 1 + 1 + 1;
+    }
+
+    /**
+     * Encodes the subEntry 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() );
+        Value.encode( bb, visibility );
+
+        return bb;
+    }
+
+
+    /**
+     * Return a String representing this EntryChangeControl.
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        sb.append( "    SubEntry Control\n" );
+        sb.append( "        Visibility   : '" ).append( visibility ).append("'\n");
+
+        return sb.toString();
+    }
+}

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlContainer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlContainer.java?rev=369966&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlContainer.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlContainer.java
Tue Jan 17 16:05:19 2006
@@ -0,0 +1,80 @@
+/*
+ *   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@directory.apache.org">Apache Directory Project</a>
+ */
+public class SubEntryControlContainer extends AbstractContainer implements IAsn1Container

+{
+    /** PSearchControl */
+    private SubEntryControl control;
+
+    /**
+     * Creates a new SubEntryControlContainer object.
+     * We will store one grammar, it's enough ...
+     */
+    public SubEntryControlContainer()
+    {
+        super( );
+        currentGrammar = 0;
+        grammars = new IGrammar[SubEntryControlStatesEnum.NB_GRAMMARS];
+        grammarStack = new IGrammar[1];
+        stateStack = new int[1];
+        nbGrammars = 0;
+
+        grammars[SubEntryControlStatesEnum.SUB_ENTRY_GRAMMAR] = SubEntryControlGrammar.getInstance();
+        grammarStack[currentGrammar] = grammars[SubEntryControlStatesEnum.SUB_ENTRY_GRAMMAR];
+        states = SubEntryControlStatesEnum.getInstance();
+    }
+
+
+    /**
+     * @return Returns the persistent search control.
+     */
+    public SubEntryControl getSubEntryControl()
+    {
+
+        return control;
+    }
+
+    
+    /**
+     * Set a SubEntryControl Object into the container. It will be completed
+     * by the ldapDecoder.
+     *
+     * @param control the SubEntryControl to set.
+     */
+    public void setSubEntryControl( SubEntryControl control )
+    {
+        this.control = control;
+    }
+
+    
+    public void clean()
+    {
+        super.clean();
+        control = null;
+    }
+}

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlDecoder.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlDecoder.java?rev=369966&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlDecoder.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlDecoder.java
Tue Jan 17 16:05:19 2006
@@ -0,0 +1,52 @@
+/*
+ *   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 SubEntryControls.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SubEntryControlDecoder implements ControlDecoder
+{
+    private final static String CONTROL_TYPE_OID = "1.3.6.1.4.1.4203.1.10.1";
+    
+    private static final Asn1Decoder decoder = new Asn1Decoder();
+    
+    public String getControlType()
+    {
+        return CONTROL_TYPE_OID;
+    }
+
+
+    public Asn1Object decode(byte[] controlBytes) throws DecoderException
+    {
+        ByteBuffer bb = ByteBuffer.wrap( controlBytes );
+        SubEntryControlContainer container = new SubEntryControlContainer();
+        decoder.decode( bb, container );
+        return container.getSubEntryControl();
+    }
+}

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlGrammar.java?rev=369966&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlGrammar.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlGrammar.java
Tue Jan 17 16:05:19 2006
@@ -0,0 +1,114 @@
+/*
+ *   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.TLV;
+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.BooleanDecoder;
+import org.apache.asn1.util.BooleanDecoderException;
+import org.apache.ldap.common.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+/**
+ * This class implements the SubEntryControl. 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 SubEntryControlGrammar extends AbstractGrammar implements IGrammar
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( SubEntryControlGrammar.class
);
+
+    /** The instance of grammar. SubEntryControlGrammar is a singleton */
+    private static IGrammar instance = new SubEntryControlGrammar();
+
+    /**
+     * Creates a new SubEntryGrammar object.
+     */
+    private SubEntryControlGrammar()
+    {
+        name = SubEntryControlGrammar.class.getName();
+        statesEnum = SubEntryControlStatesEnum.getInstance();
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[SubEntryControlStatesEnum.LAST_SUB_ENTRY_STATE][256];
+
+        super.transitions[SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_TAG][UniversalTag.BOOLEAN_TAG]
=
+            new GrammarTransition( SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_TAG,
+                    SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_VALUE, null );
+
+        super.transitions[SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_VALUE][UniversalTag.BOOLEAN_TAG]
=
+            new GrammarTransition( SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_VALUE,
+                    SubEntryControlStatesEnum.GRAMMAR_END, 
+                new GrammarAction( "SubEntryControl visibility" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        SubEntryControlContainer subEntryContainer = ( SubEntryControlContainer
) container;
+                        SubEntryControl control = new SubEntryControl();
+                        subEntryContainer.setSubEntryControl( control );
+                        
+                        TLV tlv = subEntryContainer.getCurrentTLV();
+                        
+                        // We get the value. If it's a 0, it's a FALSE. If it's
+                        // a FF, it's a TRUE. Any other value should be an error,
+                        // but we could relax this constraint. So if we have something
+                        // which is not 0, it will be interpreted as TRUE, but we
+                        // will generate a warning.
+                        Value value        = tlv.getValue();
+
+                        try
+                        {
+                            control.setVisibility( BooleanDecoder.parse( value ) );
+
+                            // We can have an END transition
+                            container.grammarEndAllowed( true );
+                        }
+                        catch ( BooleanDecoderException bde )
+                        {
+                            log.error( "The visibility flag {} is invalid : {}. It should
be 0 or 255",
+                                    StringTools.dumpBytes( value.getData() ), 
+                                    bde.getMessage() );
+                        
+                            throw new DecoderException( bde.getMessage() );
+                        }
+                    }
+                }
+            );
+    }
+
+    /**
+     * This class is a singleton.
+     *
+     * @return An instance on this grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlStatesEnum.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlStatesEnum.java?rev=369966&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlStatesEnum.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/controls/SubEntryControlStatesEnum.java
Tue Jan 17 16:05:19 2006
@@ -0,0 +1,162 @@
+/*
+ *   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 SubEntryControl's grammar constants.
+ * It is also used for debugging purposes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SubEntryControlStatesEnum implements IStates
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    //=========================================================================
+    // Sub entry control grammar states 
+    //=========================================================================
+
+    /** Visibility Tag */
+    public static int SUB_ENTRY_VISIBILITY_TAG = 0;
+
+    /** Visibility Value */
+    public static int SUB_ENTRY_VISIBILITY_VALUE = 1;
+
+    
+    /** terminal state */
+    public static int LAST_SUB_ENTRY_STATE = 2;
+
+    //=========================================================================
+    // Grammars declaration.
+    //=========================================================================
+    /** PSsearch grammar */
+    public static final int SUB_ENTRY_GRAMMAR_SWITCH = 0x0100;
+
+    /** PSearch grammar number */
+    public static final int SUB_ENTRY_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[]
+        {
+            "SUB_ENTRY_GRAMMAR_SWITCH"
+        };
+
+    //=========================================================================
+    // States debug strings 
+    //=========================================================================
+    /** A string representation of all the states */
+    private static String[] SubEntryString = new String[]
+    {
+        "SUB_ENTRY_VISIBILITY_TAG",
+        "SUB_ENTRY_VISIBILITY_VALUE",
+    };
+
+    /** The instance */
+    private static SubEntryControlStatesEnum instance = new SubEntryControlStatesEnum();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * This is a private constructor. This class is a singleton
+     *
+     */
+    private SubEntryControlStatesEnum()
+    {
+    }
+
+    //~ 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 SUB_ENTRY_GRAMMAR: return "SUB_ENTRY_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 SubEntryControlGrammar )
+        {
+            return "SUB_ENTRY_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 SUB_ENTRY_GRAMMAR :
+                    return ( ( state == GRAMMAR_END ) ? "SUB_ENTRY_END_STATE" : SubEntryString[state]
);
+
+                default :
+                    return "UNKNOWN";
+            }
+        }
+    }
+}



Mime
View raw message