directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r349658 - in /directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs: ./ codec/
Date Tue, 29 Nov 2005 06:40:30 GMT
Author: ersiner
Date: Mon Nov 28 22:40:19 2005
New Revision: 349658

URL: http://svn.apache.org/viewcvs?rev=349658&view=rev
Log:
Added Emmanuels JavaStoredProcedure codec.
And some clean up.


Modified:
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/ParameterPojo.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureContainer.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureEnum.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java Mon Nov 28 22:40:19 2005
@@ -22,6 +22,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
+import javax.naming.NamingException;
+
 import org.apache.ldap.server.jndi.ServerLdapContext;
 
 
@@ -42,7 +44,7 @@
     public JavaStoredProcedure( 
             ServerLdapContext ctx, 
             String fullyQualifiedSPName, 
-            Class[] parameterTypes ) throws ClassNotFoundException, SecurityException, NoSuchMethodException
+            Class[] parameterTypes ) throws ClassNotFoundException, SecurityException, NoSuchMethodException, NamingException
     {
         this.ctx = ctx;
         this.fQSPName = fullyQualifiedSPName;

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java Mon Nov 28 22:40:19 2005
@@ -43,10 +43,9 @@
 public class LdapClassLoader extends ClassLoader
 {
     private static final Logger log = LoggerFactory.getLogger( LdapClassLoader.class );
-    private static String defaultSearchContextsConfig="cn=ClassLoaderDefaultSearchContexts,ou=configuration,ou=system";
+    private static String defaultSearchContextsConfig = "cn=ClassLoaderDefaultSearchContexts,ou=configuration,ou=system";
     private ServerLdapContext RootDSE;
 
-    
     public LdapClassLoader( ServerLdapContext RootDSE ) throws NamingException
     {
         this.RootDSE = ( ( ServerLdapContext ) RootDSE.lookup( "" ) );
@@ -110,7 +109,7 @@
             catch ( NamingException e )
             {
                 log.debug( "No configuration data found for class loader default search contexts." );
-            };
+            }
             
             if ( defaultSearchContextsConfigContext != null )
             {

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/ParameterPojo.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/ParameterPojo.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/ParameterPojo.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/ParameterPojo.java Mon Nov 28 22:40:19 2005
@@ -1,20 +1,21 @@
-package org.apache.ldap.server.storedprocs;
-
-public class ParameterPojo {
-	private String type;
-	
-	private byte[] value;
-	
-	public String getType() {
-		return type;
-	}
-	public void setType(String type) {
-		this.type = type;
-	}
-	public byte[] getValue() {
-		return value;
-	}
-	public void setValue(byte[] value) {
-		this.value = value;
-	}
-}
+package org.apache.ldap.server.storedprocs;
+
+public class ParameterPojo {
+	private String type;
+	
+	private byte[] value;
+	
+	public String getType() {
+		return type;
+	}
+	public void setType(String type) {
+		this.type = type;
+	}
+	public byte[] getValue() {
+		return value;
+	}
+	public void setValue(byte[] value) {
+		this.value = value;
+	}
+}
+

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java Mon Nov 28 22:40:19 2005
@@ -1,31 +1,41 @@
-package org.apache.ldap.server.storedprocs;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class StoredProcedurePojo {
-	private String procedure;
-	private Set parameters;
-	
-	public String getProcedure() {
-		return procedure;
-	}
-	
-	public void setProcedure(String procedure) {
-		this.procedure = procedure;
-	}
-	
-	public Set getParameters() {
-		return parameters;
-	}
-	
-	public void addParameter( ParameterPojo parameter )
-	{
-		if ( parameters == null )
-		{
-			parameters = new HashSet();
-		}
-		
-		parameters.add( parameter );
-	}
-}
+package org.apache.ldap.server.storedprocs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class StoredProcedurePojo {
+	private String procedure;
+	private ArrayList parameters;
+	private transient ParameterPojo currentParameter;
+	
+	public String getProcedure() {
+		return procedure;
+	}
+	
+	public void setProcedure(String procedure) {
+		this.procedure = procedure;
+	}
+	
+	public List getParameters() {
+		return parameters;
+	}
+	
+	public void addParameter( ParameterPojo parameter )
+	{
+		if ( parameters == null )
+		{
+			parameters = new ArrayList();
+		}
+		
+		parameters.add( parameter );
+	}
+
+	public ParameterPojo getCurrentParameter() {
+		return currentParameter;
+	}
+
+	public void setCurrentParameter(ParameterPojo currentParameter) {
+		this.currentParameter = currentParameter;
+	}
+}
+

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureContainer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureContainer.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureContainer.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureContainer.java Mon Nov 28 22:40:19 2005
@@ -1,87 +1,88 @@
-/*
- *   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.server.storedprocs.codec;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.asn1new.ber.AbstractContainer;
-import org.apache.asn1new.ber.containers.IAsn1Container;
-import org.apache.asn1new.ber.grammar.IGrammar;
-import org.apache.asn1.codec.util.StringUtils;
-import org.apache.ldap.server.storedprocs.StoredProcedurePojo;
-
-
-/**
- *  
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class StoredProcedureContainer extends AbstractContainer implements IAsn1Container
-{
-    //~ Instance fields ----------------------------------------------------------------------------
-
-    /** The pojo */
-    private StoredProcedurePojo storedProcedurePojo;
-    
-    //~ Constructors -------------------------------------------------------------------------------
-
-    /**
-     */
-    public StoredProcedureContainer()
-    {
-        super( );
-        currentGrammar = 0;
-        grammars = new IGrammar[1];
-        grammarStack = new IGrammar[1];
-        stateStack = new int[1];
-        nbGrammars = 0;
-
-        grammars[StoredProcedureEnum.STORED_PROCEDURE_GRAMMAR] = StoredProcedureGrammar.getInstance(); 
-
-        grammarStack[currentGrammar] = grammars[StoredProcedureEnum.STORED_PROCEDURE_GRAMMAR];
-        
-        states = StoredProcedureEnum.getInstance();
-    }
-
-    //~ Methods ------------------------------------------------------------------------------------
-    /**
-     * @return Returns the ldapMessage.
-     */
-    public StoredProcedurePojo getStoredProcedurePojo()
-    {
-
-        return storedProcedurePojo;
-    }
-
-    /**
-     * Set a ldapMessage Object into the container. It will be completed
-     * by the ldapDecoder .
-     *
-     * @param ldapMessage The ldapMessage to set.
-     */
-    public void setStoredProcedurePojo( StoredProcedurePojo storedProcedurePojo )
-    {
-        this.storedProcedurePojo = storedProcedurePojo;
-    }
-    
-    public void clean()
-    {
-    	super.clean();
-    	
-    	storedProcedurePojo = null;
-    }
-}
+/*
+ *   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.server.storedprocs.codec;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.asn1new.ber.AbstractContainer;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1.codec.util.StringUtils;
+import org.apache.ldap.server.storedprocs.StoredProcedurePojo;
+
+
+/**
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoredProcedureContainer extends AbstractContainer implements IAsn1Container
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The pojo */
+    private StoredProcedurePojo storedProcedurePojo;
+    
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     */
+    public StoredProcedureContainer()
+    {
+        super( );
+        currentGrammar = 0;
+        grammars = new IGrammar[1];
+        grammarStack = new IGrammar[1];
+        stateStack = new int[1];
+        nbGrammars = 0;
+
+        grammars[StoredProcedureEnum.STORED_PROCEDURE_GRAMMAR] = StoredProcedureGrammar.getInstance(); 
+
+        grammarStack[currentGrammar] = grammars[StoredProcedureEnum.STORED_PROCEDURE_GRAMMAR];
+        
+        states = StoredProcedureEnum.getInstance();
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+    /**
+     * @return Returns the ldapMessage.
+     */
+    public StoredProcedurePojo getStoredProcedurePojo()
+    {
+
+        return storedProcedurePojo;
+    }
+
+    /**
+     * Set a ldapMessage Object into the container. It will be completed
+     * by the ldapDecoder .
+     *
+     * @param ldapMessage The ldapMessage to set.
+     */
+    public void setStoredProcedurePojo( StoredProcedurePojo storedProcedurePojo )
+    {
+        this.storedProcedurePojo = storedProcedurePojo;
+    }
+    
+    public void clean()
+    {
+    	super.clean();
+    	
+    	storedProcedurePojo = null;
+    }
+}
+

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureEnum.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureEnum.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureEnum.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureEnum.java Mon Nov 28 22:40:19 2005
@@ -1,208 +1,209 @@
-/*
- *   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.server.storedprocs.codec;
-
-import org.apache.asn1new.ber.grammar.IGrammar;
-import org.apache.asn1new.ber.grammar.IStates;
-
-
-/**
- * This class store the Ldap grammar's constants.
- * It is also used for debugging purpose
- * 
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class StoredProcedureEnum implements IStates
-{
-    //~ Static fields/initializers -----------------------------------------------------------------
-
-    //=========================================================================
-    // StoredProcedure
-    //=========================================================================
-    /** StoredProcedure Tag */
-    public static int STORED_PROCEDURE_TAG = 0;
-
-    /** StoredProcedure Value */
-    public static int STORED_PROCEDURE_VALUE = 1;
-
-    // Language ---------------------------------------------------------------
-    /** Language Tag */
-    public static int LANGUAGE_TAG = 2;
-
-    /** Language Value */
-    public static int LANGUAGE_VALUE = 3;
-
-    // Procedure --------------------------------------------------------------
-    /** Procedure Tag */
-    public static int PROCEDURE_TAG = 4;
-
-    /** Procedure Value */
-    public static int PROCEDURE_VALUE = 5;
-
-    // Parameters -------------------------------------------------------------
-    /** Parameters Tag */
-    public static int PARAMETERS_TAG = 6;
-
-    /** Parameters Value */
-    public static int PARAMETERS_VALUE = 7;
-
-    // Parameter type ---------------------------------------------------------
-    /** Parameter type Tag */
-    public static int PARAMETER_TYPE_TAG = 8;
-
-    /** Parameter type Value */
-    public static int PARAMETER_TYPE_VALUE = 9;
-
-    // Parameters value -------------------------------------------------------
-    /** Parameter value Tag */
-    public static int PARAMETER_VALUE_TAG = 10;
-
-    /** Parameter value Value */
-    public static int PARAMETER_VALUE_VALUE = 11;
-    
-    public static int LAST_STORED_PROCEDURE_STATE = 12;
-    
-    //=========================================================================
-    // Grammars declaration.
-    //=========================================================================
-    /** Ldap Message Grammar */
-    public static final int STORED_PROCEDURE_GRAMMAR_SWITCH = 0x0100;
-
-    /** LdapMessage grammar number */
-    public static final int STORED_PROCEDURE_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[]
-        {
-            "STORED_PROCEDURE_GRAMMAR_SWITCH", 
-        };
-
-    //=========================================================================
-    // States debug strings 
-    //=========================================================================
-    /** A string representation of all the states */
-    private static String[] StoredProcedureString =
-        new String[]
-        {
-        	"STORED_PROCEDURE_TAG",
-        	"STORED_PROCEDURE_VALUE",
-        	"LANGUAGE_TAG",
-        	"LANGUAGE_VALUE",
-        	"PROCEDURE_TAG",
-        	"PROCEDURE_VALUE",
-        	"PARAMETERS_TAG",
-        	"PARAMETERS_VALUE",
-        	"PARAMETER_TYPE_TAG",
-        	"PARAMETER_TYPE_VALUE",
-        	"PARAMETER_VALUE_TAG",
-        	"PARAMETER_VALUE_VALUE"
-        };
-
-    /** The instance */
-    private static StoredProcedureEnum instance = new StoredProcedureEnum();
-
-    //~ Constructors -------------------------------------------------------------------------------
-
-    /**
-     * This is a private constructor. This class is a singleton
-     *
-     */
-    private StoredProcedureEnum()
-    {
-    }
-
-    //~ Methods ------------------------------------------------------------------------------------
-
-    /**
-     * Get an instance of this class
-     * @return An instance on this class
-     */
-    public static IStates getInstance()
-    {
-        return instance;
-    }
-    
-    /**
-     * Get the grammar name
-     * @param The grammar code
-     * @return The grammar name
-     */
-    public String getGrammarName(int grammar)
-    {
-        switch (grammar)
-        {
-            case STORED_PROCEDURE_GRAMMAR            : return "STORED_PROCEDURE_GRAMMAR";
-
-        	default                              : return "UNKNOWN";
-        }
-    }
-
-    /**
-     * Get the grammar name
-     * @param The grammar class
-     * @return The grammar name
-     */
-    public String getGrammarName(IGrammar grammar)
-    {
-        if (grammar instanceof StoredProcedureGrammar)
-        {
-            return "STORED_PROCEDURE_GRAMMAR";
-        }
-        else 
-        {
-            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 STORED_PROCEDURE_GRAMMAR :
-                    return ( ( state == GRAMMAR_END ) ? "STORED_PROCEDURE_END_STATE" : StoredProcedureString[state] );
-
-                default :
-                    return "UNKNOWN";
-            }
-        }
-    }
-}
+/*
+ *   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.server.storedprocs.codec;
+
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.grammar.IStates;
+
+
+/**
+ * This class store the Ldap grammar's constants.
+ * It is also used for debugging purpose
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoredProcedureEnum implements IStates
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    //=========================================================================
+    // StoredProcedure
+    //=========================================================================
+    /** StoredProcedure Tag */
+    public static int STORED_PROCEDURE_TAG = 0;
+
+    /** StoredProcedure Value */
+    public static int STORED_PROCEDURE_VALUE = 1;
+
+    // Language ---------------------------------------------------------------
+    /** Language Tag */
+    public static int LANGUAGE_TAG = 2;
+
+    /** Language Value */
+    public static int LANGUAGE_VALUE = 3;
+
+    // Procedure --------------------------------------------------------------
+    /** Procedure Tag */
+    public static int PROCEDURE_TAG = 4;
+
+    /** Procedure Value */
+    public static int PROCEDURE_VALUE = 5;
+
+    // Parameters -------------------------------------------------------------
+    /** Parameters Tag */
+    public static int PARAMETERS_TAG = 6;
+
+    /** Parameters Value */
+    public static int PARAMETERS_VALUE = 7;
+
+    // Parameter type ---------------------------------------------------------
+    /** Parameter type Tag */
+    public static int PARAMETER_TYPE_TAG = 8;
+
+    /** Parameter type Value */
+    public static int PARAMETER_TYPE_VALUE = 9;
+
+    // Parameters value -------------------------------------------------------
+    /** Parameter value Tag */
+    public static int PARAMETER_VALUE_TAG = 10;
+
+    /** Parameter value Value */
+    public static int PARAMETER_VALUE_VALUE = 11;
+    
+    public static int LAST_STORED_PROCEDURE_STATE = 12;
+    
+    //=========================================================================
+    // Grammars declaration.
+    //=========================================================================
+    /** Ldap Message Grammar */
+    public static final int STORED_PROCEDURE_GRAMMAR_SWITCH = 0x0100;
+
+    /** LdapMessage grammar number */
+    public static final int STORED_PROCEDURE_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[]
+        {
+            "STORED_PROCEDURE_GRAMMAR_SWITCH", 
+        };
+
+    //=========================================================================
+    // States debug strings 
+    //=========================================================================
+    /** A string representation of all the states */
+    private static String[] StoredProcedureString =
+        new String[]
+        {
+        	"STORED_PROCEDURE_TAG",
+        	"STORED_PROCEDURE_VALUE",
+        	"LANGUAGE_TAG",
+        	"LANGUAGE_VALUE",
+        	"PROCEDURE_TAG",
+        	"PROCEDURE_VALUE",
+        	"PARAMETERS_TAG",
+        	"PARAMETERS_VALUE",
+        	"PARAMETER_TYPE_TAG",
+        	"PARAMETER_TYPE_VALUE",
+        	"PARAMETER_VALUE_TAG",
+        	"PARAMETER_VALUE_VALUE"
+        };
+
+    /** The instance */
+    private static StoredProcedureEnum instance = new StoredProcedureEnum();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * This is a private constructor. This class is a singleton
+     *
+     */
+    private StoredProcedureEnum()
+    {
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get an instance of this class
+     * @return An instance on this class
+     */
+    public static IStates getInstance()
+    {
+        return instance;
+    }
+    
+    /**
+     * Get the grammar name
+     * @param The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName(int grammar)
+    {
+        switch (grammar)
+        {
+            case STORED_PROCEDURE_GRAMMAR            : return "STORED_PROCEDURE_GRAMMAR";
+
+        	default                              : return "UNKNOWN";
+        }
+    }
+
+    /**
+     * Get the grammar name
+     * @param The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName(IGrammar grammar)
+    {
+        if (grammar instanceof StoredProcedureGrammar)
+        {
+            return "STORED_PROCEDURE_GRAMMAR";
+        }
+        else 
+        {
+            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 STORED_PROCEDURE_GRAMMAR :
+                    return ( ( state == GRAMMAR_END ) ? "STORED_PROCEDURE_END_STATE" : StoredProcedureString[state] );
+
+                default :
+                    return "UNKNOWN";
+            }
+        }
+    }
+}
+

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java?rev=349658&r1=349657&r2=349658&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java Mon Nov 28 22:40:19 2005
@@ -1,370 +1,354 @@
-/*
- *   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.server.storedprocs.codec;
-
-import javax.naming.InvalidNameException;
-
-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.asn1.codec.util.StringUtils;
-import org.apache.ldap.server.storedprocs.StoredProcedurePojo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * This class implements the SearchResultEntry LDAP message. All the actions are declared in this
- * class. As it is a singleton, these declaration are only done once.
- * 
- * We have to deal with empty elements, as stated by rfc 2251 :
- * 
- * -- implementors should note that the PartialAttributeList may
- * -- have zero elements (if none of the attributes of that entry
- * -- were requested, or could be returned), and that the vals set
- * -- may also have zero elements (if types only was requested, or
- * -- all values were excluded from the result.)
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class StoredProcedureGrammar extends AbstractGrammar implements IGrammar
-{
-    //~ Static fields/initializers -----------------------------------------------------------------
-
-    /** The logger */
-    private static final Logger log = LoggerFactory.getLogger( StoredProcedureGrammar.class );
-
-    /** The instance of grammar. SearchResultEntryGrammar is a singleton */
-    private static IGrammar instance = new StoredProcedureGrammar();
-
-    //~ Constructors -------------------------------------------------------------------------------
-
-    /**
-     * Creates a new SearchResultEntryGrammar object.
-     */
-    private StoredProcedureGrammar()
-    {
-        name       = StoredProcedureGrammar.class.getName();
-        statesEnum = StoredProcedureEnum.getInstance();
-
-        // Create the transitions table
-        super.transitions = new GrammarTransition[StoredProcedureEnum.LAST_STORED_PROCEDURE_STATE][256];
-
-        //============================================================================================
-        // StoredProcedure Message
-        //============================================================================================
-        // StoredProcedure ::= SEQUENCE { (Tag)
-        //   ...
-        // Nothing to do.
-        super.transitions[StoredProcedureEnum.STORED_PROCEDURE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-        		StoredProcedureEnum.STORED_PROCEDURE_TAG, StoredProcedureEnum.STORED_PROCEDURE_VALUE,
-                null );
-
-        // StoredProcedure ::= SEQUENCE { (Value)
-        //   ...
-        // Nothing to do.
-        super.transitions[StoredProcedureEnum.STORED_PROCEDURE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-        		StoredProcedureEnum.STORED_PROCEDURE_VALUE,
-        		StoredProcedureEnum.LANGUAGE_TAG, null );
-
-        //    language OCTETSTRING, (Tag)
-        //    ...
-        // Nothing to do
-        super.transitions[StoredProcedureEnum.LANGUAGE_TAG][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-            		StoredProcedureEnum.LANGUAGE_TAG,
-            		StoredProcedureEnum.LANGUAGE_VALUE, null );
-
-        //    language OCTETSTRING, (Tag)
-        //    ...
-        // Store the language.
-        super.transitions[StoredProcedureEnum.LANGUAGE_VALUE][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-            		StoredProcedureEnum.LANGUAGE_VALUE,
-            		StoredProcedureEnum.PROCEDURE_TAG,
-                new GrammarAction( "Create the pojo" )
-                {
-                    public void action( IAsn1Container container ) throws DecoderException
-                    {
-
-                        StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer )
-                            container;
-
-                        TLV                  tlv                  =
-                        	storedProcedureContainer.getCurrentTLV();
-
-                        // Store the value.
-                        if ( tlv.getLength().getLength() == 0 )
-                        {
-                        	// This is supposed to be Java
-                            StoredProcedurePojo storedProcedurePojo = new StoredProcedurePojo();
-                        }
-                        else
-                        {
-                        	String language = StringUtils.toUtf8( tlv.getValue().getData() );
-                            
-                        	if ( "java".compareToIgnoreCase( language ) == 0 )
-                        	{
-                        		StoredProcedurePojo storedProcedurePojo = new StoredProcedurePojo();
-                        	}
-                        	else
-                        	{
-                                log.error( "The language " + StringUtils.dumpBytes( tlv.getValue().getData() ) + " is invalid" );
-                                throw new DecoderException( "The language " + StringUtils.dumpBytes( tlv.getValue().getData() ) + " is invalid" );
-                        	}
-                        }
-
-                        if ( log.isDebugEnabled() )
-                        {
-                            log.debug( "Language found : java " );
-                        }
-                    }
-                } );
-
-/*
-        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
-        //    attributes      PartialAttributeList }
-        // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
-        //    ...
-        // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG][UniversalTag.SEQUENCE_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE, null );
-
-        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
-        //    attributes      PartialAttributeList }
-        // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
-        //    ...
-        // We may have many attributes. Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE][UniversalTag.SEQUENCE_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG, null );
-
-        // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
-        //    ...
-        // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG][UniversalTag.SEQUENCE_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE, null );
-
-        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
-        //    attributes      PartialAttributeList }
-        // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
-        //    ...
-        // Loop.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][UniversalTag.SEQUENCE_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE, null );
-
-        // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Value)
-        //    ...
-        // We may have many attributes. We also have to store a previously decoded AttributeValue
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE][UniversalTag.SEQUENCE_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG,
-                new GrammarAction( "Store attributeValue" )
-                {
-                    public void action( IAsn1Container container ) throws DecoderException
-                    {
-
-                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
-                            container;
-                        LdapMessage          ldapMessage          =
-                            ldapMessageContainer.getLdapMessage();
-                        SearchResultEntry    searchResultEntry    =
-                            ldapMessage.getSearchResultEntry();
-
-                        searchResultEntry.addPartialAttributeList();
-                    }
-                } );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    type    AttributeDescription, (Tag)
-        //    ...
-        // Nothing to do.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE, null );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    type    AttributeDescription, (Value)
-        //    ...
-        // Store the attribute's name.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG,
-                new GrammarAction( "Store search result entry object name Value" )
-                {
-                    public void action( IAsn1Container container ) throws DecoderException
-                    {
-
-                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
-                            container;
-                        LdapMessage          ldapMessage          =
-                            ldapMessageContainer.getLdapMessage();
-                        SearchResultEntry    searchResultEntry    =
-                            ldapMessage.getSearchResultEntry();
-
-                        TLV                  tlv                  =
-                            ldapMessageContainer.getCurrentTLV();
-
-                        LdapString type = LdapString.EMPTY_STRING;
-
-                        // Store the name
-                        if ( tlv.getLength().getLength() == 0 )
-                        {
-                            searchResultEntry.addAttributeValues( type );
-                        }
-                        else
-                        {
-                            try
-                            {
-                                type = new LdapString( tlv.getValue().getData() );
-                                searchResultEntry.addAttributeValues( type );
-                            }
-                            catch ( LdapStringEncodingException lsee )
-                            {
-                                log.error( "Invalid attribute type : " + StringUtils.dumpBytes( tlv.getValue().getData() ) );
-                                throw new DecoderException( "The attribute type is invalid : " + lsee.getMessage() );
-                            }
-                        }
-                        
-                        if ( log.isDebugEnabled() )
-                        {
-                            log.debug( "Attribute type : " + type );
-                        }
-                    }
-                } );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    ...
-        //    vals    *SET OF* AttributeValue} (Tag)
-        // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG][UniversalTag.SET_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE, null );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    ...
-        //    vals    *SET OF* AttributeValue} (Value)
-        // We may have many values. Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE][UniversalTag.SET_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG, null );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    ...
-        //    vals    SET OF *AttributeValue*} (Tag)
-        // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE, null );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    ...
-        //    vals    SET OF *AttributeValue*} (Tag)
-        // The loop.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE, null );
-
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-        //    ...
-        //    vals    SET OF *AttributeValue*} (Value)
-        // We may have many values. Store the current one in the current Attribute Value
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE][UniversalTag.OCTET_STRING_TAG] =
-            new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE,
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
-                new GrammarAction( "Store Attribute Value value" )
-                {
-                    public void action( IAsn1Container container ) throws DecoderException
-                    {
-
-                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
-                            container;
-                        LdapMessage          ldapMessage          =
-                            ldapMessageContainer.getLdapMessage();
-                        SearchResultEntry    searchResultEntry    =
-                            ldapMessage.getSearchResultEntry();
-
-                        TLV                  tlv                  =
-                            ldapMessageContainer.getCurrentTLV();
-
-                        // Store the value
-                        Object value = null;
-                        
-                        if ( tlv.getLength().getLength() == 0 )
-                        {
-                            searchResultEntry.addAttributeValue( "" );
-                        }
-                        else
-                        {
-                            if (ldapMessageContainer.isBinary( searchResultEntry.getCurrentAttributeValueType() ) )
-                            {
-                                value = tlv.getValue().getData();
-                                
-                                if ( log.isDebugEnabled() )
-                                {
-                                    log.debug( "Attribute value " + StringUtils.dumpBytes( (byte[])value ) );
-                                }
-                            }
-                            else
-                            {
-                                value = StringUtils.toUtf8( tlv.getValue().getData() );
-
-                                if ( log.isDebugEnabled() )
-                                {
-                                    log.debug( "Attribute value " + value );
-                                }
-                            }
-
-                            searchResultEntry.addAttributeValue( value );
-                        }
-                    }
-                } );
-*/
-    }
-
-    //~ Methods ------------------------------------------------------------------------------------
-
-    /**
-     * Get the instance of this grammar
-     *
-     * @return An instance on the SearchResultEntry Grammar
-     */
-    public static IGrammar getInstance()
-    {
-        return instance;
-    }
-}
+/*
+ *   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.server.storedprocs.codec;
+
+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.asn1.codec.util.StringUtils;
+import org.apache.ldap.server.storedprocs.ParameterPojo;
+import org.apache.ldap.server.storedprocs.StoredProcedurePojo;
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the SearchResultEntry LDAP message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * We have to deal with empty elements, as stated by rfc 2251 :
+ * 
+ * -- implementors should note that the PartialAttributeList may
+ * -- have zero elements (if none of the attributes of that entry
+ * -- were requested, or could be returned), and that the vals set
+ * -- may also have zero elements (if types only was requested, or
+ * -- all values were excluded from the result.)
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoredProcedureGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    //private static final Logger log = LoggerFactory.getLogger( StoredProcedureGrammar.class );
+    private static final Logger log = Logger.getLogger( StoredProcedureGrammar.class );
+    
+
+    /** The instance of grammar. SearchResultEntryGrammar is a singleton */
+    private static IGrammar instance = new StoredProcedureGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new SearchResultEntryGrammar object.
+     */
+    private StoredProcedureGrammar()
+    {
+        name       = StoredProcedureGrammar.class.getName();
+        statesEnum = StoredProcedureEnum.getInstance();
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[StoredProcedureEnum.LAST_STORED_PROCEDURE_STATE][256];
+
+        //============================================================================================
+        // StoredProcedure Message
+        //============================================================================================
+        // StoredProcedure ::= SEQUENCE { (Tag)
+        //   ...
+        // Nothing to do.
+        super.transitions[StoredProcedureEnum.STORED_PROCEDURE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+        		StoredProcedureEnum.STORED_PROCEDURE_TAG, StoredProcedureEnum.STORED_PROCEDURE_VALUE,
+                null );
+
+        // StoredProcedure ::= SEQUENCE { (Value)
+        //   ...
+        // Nothing to do.
+        super.transitions[StoredProcedureEnum.STORED_PROCEDURE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+        		StoredProcedureEnum.STORED_PROCEDURE_VALUE,
+        		StoredProcedureEnum.LANGUAGE_TAG, null );
+
+        //    language OCTETSTRING, (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[StoredProcedureEnum.LANGUAGE_TAG][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.LANGUAGE_TAG,
+            		StoredProcedureEnum.LANGUAGE_VALUE, null );
+
+        //    language OCTETSTRING, (value)
+        //    ...
+        // Store the language.
+        super.transitions[StoredProcedureEnum.LANGUAGE_VALUE][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.LANGUAGE_VALUE,
+            		StoredProcedureEnum.PROCEDURE_TAG,
+                new GrammarAction( "Stores the language" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer )
+                            container;
+
+                        TLV tlv = storedProcedureContainer.getCurrentTLV();
+                        
+                        StoredProcedurePojo storedProcedurePojo = null;
+
+                        // Store the value.
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                        	// This is supposed to be Java
+                        	// We can create the object
+                            storedProcedurePojo = new StoredProcedurePojo();
+                        }
+                        else
+                        {
+                        	String language = StringUtils.toUtf8( tlv.getValue().getData() );
+                            
+                        	if ( "java".compareToIgnoreCase( language ) == 0 )
+                        	{
+                            	// We can create the object
+                        		storedProcedurePojo = new StoredProcedurePojo();
+                        	}
+                        	else
+                        	{
+                                log.error( "The language " + StringUtils.dumpBytes( tlv.getValue().getData() ) + " is invalid" );
+                                throw new DecoderException( "The language " + StringUtils.dumpBytes( tlv.getValue().getData() ) + " is invalid" );
+                        	}
+                        }
+                        
+                        storedProcedureContainer.setStoredProcedurePojo( storedProcedurePojo );
+
+                        if ( log.isDebugEnabled() )
+                        {
+                            log.debug( "Language found : java " );
+                        }
+                    }
+                } );
+
+        //    procedure OCTETSTRING, (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[StoredProcedureEnum.PROCEDURE_TAG][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PROCEDURE_TAG,
+            		StoredProcedureEnum.PROCEDURE_VALUE, null );
+
+        //    procedure OCTETSTRING, (Value)
+        //    ...
+        // Store the procedure.
+        super.transitions[StoredProcedureEnum.PROCEDURE_VALUE][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PROCEDURE_VALUE,
+            		StoredProcedureEnum.PARAMETERS_TAG,
+                new GrammarAction( "Stores the procedure" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer )
+                            container;
+
+                        TLV tlv = storedProcedureContainer.getCurrentTLV();
+                        StoredProcedurePojo storedProcedurePojo = storedProcedureContainer.getStoredProcedurePojo();
+
+                        // Store the value.
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                        	// We can't have a void procedure !
+                            log.error( "The procedure can't be null" );
+                            throw new DecoderException( "The procedure can't be null" );
+                        }
+                        else
+                        {
+                        	String procedure = StringUtils.toUtf8( tlv.getValue().getData() );
+                            
+                        	if ( procedure.trim().length() != 0 )
+                        	{
+                        		storedProcedurePojo.setProcedure( procedure );
+                        	}
+                        	else
+                        	{
+                                log.error( "The procedure is empty. This is not allowed." );
+                                throw new DecoderException( "The procedure is empty. This is not allowed." );
+                        	}
+                        }
+
+                        if ( log.isDebugEnabled() )
+                        {
+                            log.debug( "Procedure found : " + storedProcedurePojo.getProcedure() );
+                        }
+                    }
+                } );
+
+        // parameters SEQUENCE OF Parameter { (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[StoredProcedureEnum.PARAMETERS_TAG][UniversalTag.SEQUENCE_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PARAMETERS_TAG,
+            		StoredProcedureEnum.PARAMETERS_VALUE, null );
+
+        // parameters SEQUENCE OF Parameter { (Value)
+        //    ...
+        // Nothing to do. The list of parameters will be created with the first parameter.
+        super.transitions[StoredProcedureEnum.PARAMETERS_VALUE][UniversalTag.SEQUENCE_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PARAMETERS_VALUE,
+            		StoredProcedureEnum.PARAMETER_TYPE_TAG, null );
+        
+        // Parameter ::= {
+        //    type OCTETSTRING, (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[StoredProcedureEnum.PARAMETER_TYPE_TAG][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PARAMETER_TYPE_TAG,
+            		StoredProcedureEnum.PARAMETER_TYPE_VALUE, null );
+
+        // Parameter ::= {
+        //    type OCTETSTRING, (Value)
+        //    ...
+        // Nothing to do
+        super.transitions[StoredProcedureEnum.PARAMETER_TYPE_VALUE][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PARAMETER_TYPE_VALUE,
+            		StoredProcedureEnum.PARAMETER_VALUE_TAG, 
+            		new GrammarAction( "Store parameter type" )
+                    {
+                        public void action( IAsn1Container container ) throws DecoderException
+                        {
+	                        StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer )
+	                        container;
+
+		                    TLV tlv = storedProcedureContainer.getCurrentTLV();
+		                    StoredProcedurePojo storedProcedurePojo = storedProcedureContainer.getStoredProcedurePojo();
+		
+		                    // Store the value.
+		                    if ( tlv.getLength().getLength() == 0 )
+		                    {
+		                    	// We can't have a void parameter type !
+		                        log.error( "The parameter type can't be null" );
+		                        throw new DecoderException( "The parameter type can't be null" );
+		                    }
+		                    else
+		                    {
+		                    	String parameterType = StringUtils.toUtf8( tlv.getValue().getData() );
+		                        
+		                    	if ( parameterType.trim().length() != 0 )
+		                    	{
+		                    		ParameterPojo parameterPojo = new ParameterPojo();
+		                    		parameterPojo.setType( parameterType );
+		                    		
+		                    		// We stores the type in the current parameter.
+		                    		storedProcedurePojo.setCurrentParameter( parameterPojo );
+
+				                    if ( log.isDebugEnabled() )
+				                    {
+				                        log.debug( "Parameter type found : " + parameterType );
+				                    }
+		                    	}
+		                    	else
+		                    	{
+		                            log.error( "The parameter type is empty. This is not allowed." );
+		                            throw new DecoderException( "The parameter type is empty. This is not allowed." );
+		                    	}
+		                    }
+		                }
+                    } );
+
+        // Parameter ::= {
+        //    ...
+        //    value OCTETSTRING (Tag)
+        // }
+        // Nothing to do
+        super.transitions[StoredProcedureEnum.PARAMETER_VALUE_TAG][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PARAMETER_VALUE_TAG,
+            		StoredProcedureEnum.PARAMETER_VALUE_VALUE, null );
+
+        // Parameter ::= {
+        //    ...
+        //    value OCTETSTRING (Tag)
+        // }
+        // Stores the parameter value
+        super.transitions[StoredProcedureEnum.PARAMETER_VALUE_VALUE][UniversalTag.OCTET_STRING_TAG] =
+            new GrammarTransition(
+            		StoredProcedureEnum.PARAMETER_VALUE_VALUE,
+            		StoredProcedureEnum.PARAMETER_TYPE_TAG, 
+            		new GrammarAction( "Store parameter value" )
+                    {
+                        public void action( IAsn1Container container ) throws DecoderException
+                        {
+	                        StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer )
+	                        container;
+
+		                    TLV tlv = storedProcedureContainer.getCurrentTLV();
+		                    StoredProcedurePojo storedProcedurePojo = storedProcedureContainer.getStoredProcedurePojo();
+		
+		                    // Store the value.
+		                    if ( tlv.getLength().getLength() == 0 )
+		                    {
+		                    	// We can't have a void parameter value !
+		                        log.error( "The parameter value can't be null" );
+		                        throw new DecoderException( "The parameter value can't be null" );
+		                    }
+		                    else
+		                    {
+		                    	byte[] parameterValue = tlv.getValue().getData();
+		                        
+		                    	if ( parameterValue.length != 0 )
+		                    	{
+		                    		ParameterPojo parameterPojo = storedProcedurePojo.getCurrentParameter();
+		                    		parameterPojo.setValue( parameterValue );
+		                    		
+		                    		// We can now add a new Parameter to the pojo
+		                    		storedProcedurePojo.addParameter( parameterPojo );
+
+				                    if ( log.isDebugEnabled() )
+				                    {
+				                        log.debug( "Parameter value found : " + StringUtils.dumpBytes( parameterValue ) );
+				                    }
+		                    	}
+		                    	else
+		                    	{
+		                            log.error( "The parameter value is empty. This is not allowed." );
+		                            throw new DecoderException( "The parameter value is empty. This is not allowed." );
+		                    	}
+		                    }
+		                }
+                    } );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the SearchResultEntry Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}
+



Mime
View raw message