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/04/15 07:48:10 UTC

svn commit: r161405 - directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java

Author: elecharny
Date: Thu Apr 14 22:48:10 2005
New Revision: 161405

URL: http://svn.apache.org/viewcvs?view=rev&rev=161405
Log:
Added a new class to handle the commons behavior of all Containers

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java?view=auto&rev=161405
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java Thu Apr 14 22:48:10 2005
@@ -0,0 +1,197 @@
+/*
+ *   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.asn1.ber;
+
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.util.pools.LocalPoolManager;
+import org.apache.asn1.util.pools.PoolObject;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbstractContainer extends PoolObject implements IAsn1Container {
+    /** The grammars that are used.
+     * It's a stack as we can switch grammars */
+    protected IGrammar[] grammarStack;
+    
+    /** All the possible grammars */
+    protected IGrammar[] grammars;
+    
+    /** The number of stored grammars */ 
+    protected int nbGrammars;
+    
+    /** The current grammar */
+    protected int currentGrammar;
+
+    /** The current state of the decoding */
+    protected int state;
+
+    /** The current transition */
+    protected int transition;
+
+    /** The pool that is associated with this container */
+    protected LocalPoolManager poolManager;
+
+    /** The current TLV */
+    protected TLV tlv;
+
+    /**
+     * @return Returns the grammar used to decode a LdapMessage.
+     */
+    public IGrammar getGrammar()
+    {
+        return grammarStack[currentGrammar];
+    }
+
+    /**
+     * Add a IGrammar to use
+     *
+     * @param grammar The grammar to add.
+     */
+    public void addGrammar( IGrammar grammar )
+    {
+        grammars[nbGrammars++] = grammar;
+    }
+
+    /**
+     * Switch to another grammar
+     *
+     * @param grammar The grammar to add.
+     */
+    public void switchGrammar( int grammar )
+    {
+        currentGrammar ++;
+        grammarStack[currentGrammar] = grammars[(grammar >> 8) - 1];
+    }
+
+    /**
+     * restore the previous grammar (the one before a switch has occured)
+     *
+     * @param grammar The grammar to add.
+     */
+    public void restoreGrammar()
+    {
+        grammarStack[currentGrammar] = null;
+        currentGrammar --;
+    }
+
+    /**
+     * Associate a pool Manager to the container
+     *
+     * @param poolManager The pool manager
+     */
+    public void setPoolManager( LocalPoolManager poolManager )
+    {
+        this.poolManager = poolManager;
+    }
+
+    /**
+     * @return The poolManager associated with this container
+     */
+    public LocalPoolManager getPoolManager()
+    {
+        return poolManager;
+    }
+
+    /**
+     * @return Returns the current grammar state
+     */
+    public int getState()
+    {
+        return state;
+    }
+
+    /**
+     * Set the new current state
+     *
+     * @param state The new state
+     */
+    public void setState( int state )
+    {
+        this.state = state;
+    }
+
+    /**
+     * @return Returns the transition from the previous state to the new 
+     * state
+     */
+    public int getTransition()
+    {
+        return transition;
+    }
+
+    /**
+     * Update the transition from a state to another
+     *
+     * @param transition The transition to set
+     */
+    public void setTransition( int transition )
+    {
+        this.transition = transition;
+    }
+    
+    /**
+     * @return Returns the currentGrammar.
+     */
+    public int getCurrentGrammar() {
+        return currentGrammar;
+    }
+
+    /**
+     * @return Returns the current Grammar type, or -1 if not found.
+     */
+    public int getCurrentGrammarType() {
+        for ( int i = 0; i < grammars.length; i++)
+        {
+            if (grammars[i] == grammarStack[currentGrammar])
+                {
+                return i;
+                }
+        }
+        
+        return -1;
+    }
+
+    /**
+     * @return Set the grammar that will be used to start a decoding.
+     */
+    public void setInitGrammar(int grammar) {
+        currentGrammar ++;
+        grammarStack[currentGrammar] = grammars[grammar];
+    }
+
+    /**
+     * Set the current TLV
+     *
+     * @param tlv The current TLV
+     */
+    public void setCurrentTLV( TLV tlv )
+    {
+        this.tlv = tlv;
+    }
+
+    /**
+     * @return Returns the current TLV being decoded
+     */
+    public TLV getCurrentTLV()
+    {
+
+        return this.tlv;
+    }
+}