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/06/26 22:13:10 UTC
svn commit: r201899 -
/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java
Author: elecharny
Date: Sun Jun 26 13:13:10 2005
New Revision: 201899
URL: http://svn.apache.org/viewcvs?rev=201899&view=rev
Log:
Created the ModifyRequest grammar
Added:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java
Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java?rev=201899&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java Sun Jun 26 13:13:10 2005
@@ -0,0 +1,404 @@
+/*
+ * 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.ldap.codec.grammars;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.codec.primitives.LdapDN;
+import org.apache.asn1.ldap.codec.primitives.LdapString;
+import org.apache.asn1.ldap.codec.utils.IntegerDecoder;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.ldap.pojo.ModifyRequest;
+import org.apache.asn1.primitives.OctetString;
+
+import org.apache.log4j.Logger;
+
+import javax.naming.directory.DirContext;
+
+
+/**
+ * This class implements the ModifyRequest LDAP message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyRequestGrammar extends AbstractGrammar implements IGrammar
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ /** The logger */
+ private static final Logger log = Logger.getLogger( ModifyRequestGrammar.class );
+
+ /** Logging speed up */
+ private static final boolean DEBUG = log.isDebugEnabled();
+
+ /** The instance of grammar. ModifyRequestGrammar is a singleton */
+ private static IGrammar instance = new ModifyRequestGrammar();
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * Creates a new ModifyRequestGrammar object.
+ */
+ private ModifyRequestGrammar()
+ {
+ name = ModifyRequestGrammar.class.getName();
+ statesEnum = LdapStatesEnum.getInstance();
+
+ // Intitialisation
+ super.transitions = new GrammarTransition[LdapStatesEnum.LAST_MODIFY_REQUEST_STATE][256];
+
+ //============================================================================================
+ // ModifyRequest Message
+ //============================================================================================
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE { (Tag)
+ // Nothing to do.
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_TAG][0x66] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_VALUE, null );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE { (Value)
+ // Create the structure
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_VALUE][0x66] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_VALUE, LdapStatesEnum.MODIFY_REQUEST_OBJECT_TAG,
+ new GrammarAction( "Init ModifyRequest" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+
+ // Now, we can allocate the ModifyRequest Object
+ // And we associate it to the ldapMessage Object
+ ldapMessage.setProtocolOP( new ModifyRequest() );
+ }
+ } );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // object LDAPDN, (Tag)
+ // ...
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_OBJECT_TAG][0x04] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_OBJECT_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_OBJECT_VALUE, null );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // object LDAPDN, (Value)
+ // ...
+ // Store the object name.
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_OBJECT_VALUE][0x04] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_OBJECT_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_TAG,
+ new GrammarAction( "Store Modify request object Value" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ ModifyRequest modifyRequest = ldapMessage.getModifyRequest();
+
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ // Store the value.
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ modifyRequest.setObject( LdapDN.EMPTY_STRING );
+ }
+ else
+ {
+ modifyRequest.setObject( new LdapDN(
+ tlv.getValue().getData() ) );
+ }
+ }
+ } );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // ...
+ // modification *SEQUENCE* OF SEQUENCE { (Tag)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_TAG][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_VALUE, null );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // ...
+ // modification *SEQUENCE* OF SEQUENCE { (Value)
+ // Allocates the array list
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_VALUE][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_TAG,
+ new GrammarAction( "Init modifications array list" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ ModifyRequest modifyRequest = ldapMessage.getModifyRequest();
+
+ modifyRequest.initModifications();
+ }
+ } );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // ...
+ // modification SEQUENCE OF *SEQUENCE* { (Tag)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_TAG][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE, null );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // ...
+ // modification SEQUENCE OF *SEQUENCE* { (Tag)
+ // Nothing to do
+ // This is a loop, when dealing with more than one modification
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE, null );
+
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ // ...
+ // modification SEQUENCE OF *SEQUENCE* { (Value)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_OPERATION_TAG, null );
+
+ // ...
+ // modification SEQUENCE OF SEQUENCE {
+ // operation ENUMERATED { (Tag)
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // ...
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_OPERATION_TAG][0x0A] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_OPERATION_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_OPERATION_VALUE, null );
+
+ // ...
+ // modification SEQUENCE OF SEQUENCE {
+ // operation ENUMERATED { (Value)
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // ...
+ // Store the operation type. We put it in a temporary storage,
+ // because we can't allocate a ModificationItem before knowing
+ // the attributes'name.
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_OPERATION_VALUE][0x0A] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_OPERATION_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_TAG,
+ new GrammarAction( "Store operation type" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ ModifyRequest modifyRequest = ldapMessage.getModifyRequest();
+
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ // Decode the operation type
+ int operation = IntegerDecoder.parse( tlv.getValue(),
+ DirContext.ADD_ATTRIBUTE, DirContext.REPLACE_ATTRIBUTE );
+
+ // Store the current operation.
+ modifyRequest.setCurrentOperation( operation );
+ }
+ } );
+
+ // ...
+ // modification SEQUENCE OF SEQUENCE {
+ // modification AttributeTypeAndValues } }
+ // AttributeTypeAndValues ::= SEQUENCE { (Tag)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_TAG][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_VALUE, null );
+
+ // ...
+ // modification SEQUENCE OF SEQUENCE {
+ // modification AttributeTypeAndValues } }
+ // AttributeTypeAndValues ::= SEQUENCE { (Value)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_VALUE][0x30] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_TYPE_TAG, null );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // type AttributeDescription, (Tag)
+ // ...
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_TYPE_TAG][0x04] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_TYPE_TAG, LdapStatesEnum.MODIFY_REQUEST_TYPE_VALUE,
+ null );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // type AttributeDescription, (Value)
+ // ...
+ // Store a new attribute type and values.
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_TYPE_VALUE][0x04] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_TYPE_VALUE, LdapStatesEnum.MODIFY_REQUEST_VALS_TAG,
+ new GrammarAction( "Store type" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ ModifyRequest modifyRequest = ldapMessage.getModifyRequest();
+
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ // Store the value. It can't be null
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ throw new DecoderException( "The type can't be null" );
+ }
+ else
+ {
+ modifyRequest.addAttributeTypeAndValues( new LdapString(
+ tlv.getValue().getData() ) );
+ }
+ }
+ } );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // ...
+ // vals SET OF AttributeValue } (Tag)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_VALS_TAG][0x31] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_VALS_TAG, LdapStatesEnum.MODIFY_REQUEST_VALS_VALUE,
+ null );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // ...
+ // vals SET OF AttributeValue } (Value)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_VALS_VALUE][0x31] = new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_VALS_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_TAG, null );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // ...
+ // vals SET OF AttributeValue }
+ // AttributeValue ::= OCTET STRING (Tag)
+ // Nothing to do
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_TAG][0x04] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE, null );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // ...
+ // vals SET OF AttributeValue }
+ // AttributeValue ::= OCTET STRING (Tag)
+ // This is a loop, when dealing with multi-valued attributes
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG][0x04] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG,
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE, null );
+
+ // AttributeTypeAndValues ::= SEQUENCE {
+ // ...
+ // vals SET OF AttributeValue }
+ // AttributeValue ::= OCTET STRING (Value)
+ // Store a new attribute value.
+ super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE][0x04] =
+ new GrammarTransition(
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE,
+ LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG,
+ new GrammarAction( "Store value" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ ModifyRequest modifyRequest = ldapMessage.getModifyRequest();
+
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ // Store the value. It can't be null
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ modifyRequest.addAttributeValue( OctetString.EMPTY_STRING );
+ }
+ else
+ {
+ modifyRequest.addAttributeValue( new OctetString(
+ tlv.getValue().getData() ) );
+ }
+ }
+ } );
+
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the SearchResultEntry Grammar
+ */
+ public static IGrammar getInstance()
+ {
+ return instance;
+ }
+}