You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/12/03 22:08:29 UTC
svn commit: r352017 - in
/directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec:
./ grammar/ utils/
Author: ersiner
Date: Sat Dec 3 13:08:17 2005
New Revision: 352017
URL: http://svn.apache.org/viewcvs?rev=352017&view=rev
Log:
Cleaning up.
We still have a build problem.
I could not import asn1new stuff from ldap-protocol. I'm not sure if this dependency makes things fails. We'll figure it out.
Added:
directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureCodecTest.java
directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureContainer.java
directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureDecoder.java
directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/grammar/StoredProcedureGrammar.java
directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/utils/StoredProcedureEnum.java
Added: directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureCodecTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureCodecTest.java?rev=352017&view=auto
==============================================================================
--- directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureCodecTest.java (added)
+++ directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureCodecTest.java Sat Dec 3 13:08:17 2005
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+package org.apache.asn1new.ldap.codec;
+
+
+import java.lang.reflect.InvocationTargetException;
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.util.StringUtils;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.ldap.common.message.extended.ParameterPojo;
+import org.apache.ldap.common.message.extended.StoredProcedurePojo;
+
+
+
+public class StoredProcedureCodecTest extends TestCase
+{
+ public void testDecodeStoredProcedure() throws NamingException
+ {
+ Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x3E );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x3C,
+ 0x04, 0x04, 'J', 'a', 'v', 'a',
+ 0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e',
+ 0x30, 0x2B,
+ 0x04, 0x03, 'i', 'n', 't',
+ 0x04, 0x01, 0x01,
+
+ 0x04, 0x07, 'b', 'o', 'o', 'l', 'e', 'a', 'n',
+ 0x04, 0x04, 't', 'r', 'u', 'e',
+
+ 0x04, 0x06, 'S', 't', 'r', 'i', 'n', 'g',
+ 0x04, 0x0A, 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r', '3'
+ } );
+
+ // String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a StoredProcedure Container
+ IAsn1Container storedProcedureContainer = new StoredProcedureContainer();
+
+ // Decode a StoredProcedure message
+ try
+ {
+ storedProcedureDecoder.decode( stream, storedProcedureContainer );
+ }
+ catch (DecoderException de)
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ StoredProcedurePojo pojo = ( ( StoredProcedureContainer ) storedProcedureContainer )
+ .getStoredProcedurePojo();
+
+ // Check the decoded message
+ Assert.assertEquals( "execute", StringUtils
+ .utf8ToString( pojo.getProcedure() ) );
+
+ Assert.assertNotNull( pojo.getParameters() );
+ Assert.assertEquals( 3, pojo.getParameters().size() );
+
+ ParameterPojo param = ( ParameterPojo ) pojo.getParameters().get( 0 );
+
+ Assert.assertEquals( "int", StringUtils.utf8ToString( param.getType() ) );
+ Assert.assertEquals( 1, param.getValue()[0] );
+
+ param = ( ParameterPojo ) pojo.getParameters().get( 1 );
+
+ Assert.assertEquals( "boolean", StringUtils.utf8ToString( param.getType() ) );
+ Assert.assertEquals( "true", StringUtils.utf8ToString( param.getValue() ) );
+
+ param = ( ParameterPojo ) pojo.getParameters().get( 2 );
+
+ Assert.assertEquals( "String", StringUtils.utf8ToString( param.getType() ) );
+ Assert.assertEquals( "parameter3", StringUtils
+ .utf8ToString( param.getValue() ) );
+
+ // Unrelated Stuff...
+ try
+ {
+ System.out.println(((Class.forName( "java.lang.String" ).getConstructor( new Class[] { String.class } )).newInstance(new Object[]{ "ersin" })).toString());
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (InstantiationException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (IllegalAccessException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (InvocationTargetException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (SecurityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (NoSuchMethodException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (ClassNotFoundException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
Added: directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureContainer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureContainer.java?rev=352017&view=auto
==============================================================================
--- directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureContainer.java (added)
+++ directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureContainer.java Sat Dec 3 13:08:17 2005
@@ -0,0 +1,77 @@
+package org.apache.asn1new.ldap.codec;
+
+
+
+import org.apache.asn1new.ber.AbstractContainer;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ldap.codec.grammar.StoredProcedureGrammar;
+import org.apache.asn1new.ldap.codec.utils.StoredProcedureEnum;
+import org.apache.ldap.common.message.extended.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;
+ }
+}
Added: directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureDecoder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureDecoder.java?rev=352017&view=auto
==============================================================================
--- directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureDecoder.java (added)
+++ directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/StoredProcedureDecoder.java Sat Dec 3 13:08:17 2005
@@ -0,0 +1,20 @@
+package org.apache.asn1new.ldap.codec;
+
+
+import org.apache.asn1new.ber.Asn1Decoder;
+
+/**
+ * The Ldap decoder. This class does the initialisation of the object's pools.
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoredProcedureDecoder extends Asn1Decoder {
+
+ /**
+ * Standard LdapDecoder constructor.
+ *
+ */
+ public StoredProcedureDecoder()
+ {
+ }
+}
+
Added: directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/grammar/StoredProcedureGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/grammar/StoredProcedureGrammar.java?rev=352017&view=auto
==============================================================================
--- directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/grammar/StoredProcedureGrammar.java (added)
+++ directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/grammar/StoredProcedureGrammar.java Sat Dec 3 13:08:17 2005
@@ -0,0 +1,363 @@
+package org.apache.asn1new.ldap.codec.grammar;
+
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.AbstractGrammar;
+import org.apache.asn1new.ber.grammar.GrammarAction;
+import org.apache.asn1new.ber.grammar.GrammarTransition;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.ldap.codec.StoredProcedureContainer;
+import org.apache.asn1new.ldap.codec.utils.StoredProcedureEnum;
+import org.apache.asn1.codec.util.StringUtils;
+import org.apache.ldap.common.message.extended.ParameterPojo;
+import org.apache.ldap.common.message.extended.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
+ {
+ // Only this field's type is String by default
+ String language = StringUtils.utf8ToString( tlv.getValue().getData() );
+
+ storedProcedurePojo = new StoredProcedurePojo();
+
+ storedProcedurePojo.setLanguage( language );
+//
+// 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
+ {
+ byte[] procedure = tlv.getValue().getData();
+
+ storedProcedurePojo.setProcedure( procedure );
+
+// 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
+ {
+ byte[] parameterType = tlv.getValue().getData();
+
+ 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 : " + StringUtils.dumpBytes( parameterType ) );
+ }
+
+// 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;
+ }
+}
+
Added: directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/utils/StoredProcedureEnum.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/utils/StoredProcedureEnum.java?rev=352017&view=auto
==============================================================================
--- directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/utils/StoredProcedureEnum.java (added)
+++ directory/sandbox/ersiner/ldap-common-with-stored-procs/apache2-provider/src/main/java/org/apache/asn1new/ldap/codec/utils/StoredProcedureEnum.java Sat Dec 3 13:08:17 2005
@@ -0,0 +1,195 @@
+package org.apache.asn1new.ldap.codec.utils;
+
+
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.grammar.IStates;
+import org.apache.asn1new.ldap.codec.grammar.StoredProcedureGrammar;
+
+
+/**
+ * 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";
+ }
+ }
+ }
+}
+