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/09/09 23:43:24 UTC
svn commit: r279887 [5/15] - in
/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider: ./
conf/ perfs/ perfs/org/ perfs/org/apache/ perfs/org/apache/asn1new/
perfs/org/apache/asn1new/ber/ src/ src/java/ src/java/main/
src/java/main/org/ sr...
Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapMessageGrammar.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapMessageGrammar.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapMessageGrammar.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapMessageGrammar.java Fri Sep 9 14:41:22 2005
@@ -0,0 +1,375 @@
+/*
+ * 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.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.ber.tlv.Value;
+import org.apache.asn1new.util.IntegerDecoder;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.LdapMessageContainer;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the LdapMessage message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ *
+ * If an action is to be added or modified, this is where the work is to be done !
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessageGrammar extends AbstractGrammar implements IGrammar
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ /** The logger */
+ private static final Logger log = LoggerFactory.getLogger( LdapMessageGrammar.class );
+
+ /** The instance of grammar. LdapMessageGrammar is a singleton */
+ private static IGrammar instance = new LdapMessageGrammar();
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * Creates a new LdapMessageGrammar object.
+ */
+ private LdapMessageGrammar()
+ {
+
+ name = LdapMessageGrammar.class.getName();
+ statesEnum = LdapStatesEnum.getInstance();
+
+ // We have 9 differents states, so 8 transitions between states.
+ super.transitions = new GrammarTransition[LdapStatesEnum.LAST_LDAP_MESSAGE_STATE][256];
+
+ //============================================================================================
+ // LdapMessage
+ //============================================================================================
+ // LDAPMessage --> SEQUENCE { ... (Tag)
+ // We have a LDAPMessage, and the tag must be 0x30
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_TAG, LdapStatesEnum.LDAP_MESSAGE_VALUE,
+ new GrammarAction( "LdapMessage Tag" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+
+ // First, create a empty LdapMessage Object
+ LdapMessage ldapMessage = new LdapMessage();
+
+ // Then stores it into the container
+ ldapMessageContainer.setLdapMessage( ldapMessage );
+
+ return;
+ }
+ } );
+
+ // LDAPMessage --> SEQUENCE { ... (Value)
+ // Nothing to do, it's a constructed TLV. It's just a phantom transition ...
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_VALUE, LdapStatesEnum.LDAP_MESSAGE_ID_TAG, null );
+
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage Message ID
+ //--------------------------------------------------------------------------------------------
+ // LDAPMessage --> ... MessageId ...(Tag)
+ // The tag must be 0x02. Nothing special to do.
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_ID_TAG, LdapStatesEnum.LDAP_MESSAGE_ID_VALUE, null );
+
+ // LDAPMessage --> ... MessageId ...(Value)
+ // Checks that MessageId is in [0 .. 2147483647] and store the value in the LdapMessage Object
+ // (2147483647 = Integer.MAX_VALUE)
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_VALUE][UniversalTag.INTEGER_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_ID_VALUE, LdapStatesEnum.PROTOCOL_OP_TAG,
+ new GrammarAction( "Store MessageId" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+
+ // The current TLV should be a integer
+ // We get it and store it in MessageId
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ Value value = tlv.getValue();
+
+ int messageId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
+
+ ldapMessage.setMessageId( messageId );
+
+ return;
+ }
+ } );
+
+ //********************************************************************************************
+ // If the Tag is 0x42, then it's an UnBindRequest.
+ // If the Tag is 0x4A, then it's a DelRequest.
+ // If the Tag is 0x50, then it's an AbandonRequest.
+ // If the Tag is 0x60, then it's a BindRequest.
+ // If the Tag is 0x61, then it's a BindResponse.
+ // If the Tag is 0x63, then it's a SearchRequest.
+ // If the Tag is 0x64, then it's a SearchResultEntry.
+ // If the Tag is 0x65, then it's a SearchResultDone
+ // If the Tag is 0x66, then it's a ModifyRequest
+ // If the Tag is 0x67, then it's a ModifyResponse.
+ // If the Tag is 0x68, then it's an AddRequest.
+ // If the Tag is 0x69, then it's an AddResponse.
+ // If the Tag is 0x6B, then it's a DelResponse.
+ // If the Tag is 0x6C, then it's a ModifyDNRequest.
+ // If the Tag is 0x6D, then it's a ModifyDNResponse.
+ // If the Tag is 0x6E, then it's a CompareRequest
+ // If the Tag is 0x6F, then it's a CompareResponse.
+ // If the Tag is 0x73, then it's a SearchResultReference.
+ // If the Tag is 0x77, then it's an ExtendedRequest.
+ // If the Tag is 0x78, then it's an ExtendedResponse.
+ //********************************************************************************************
+
+ //--------------------------------------------------------------------------------------------
+ // UnBindRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... UnBindRequest ...
+ // unbindRequest ::= [APPLICATION 2] NULL (Tag)
+ // We have to switch to the UnBindRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.UNBIND_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.UNBIND_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // DelRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... DelRequest ...
+ // delRequest ::= [APPLICATION 10] LDAPDN (Tag)
+ // We have to switch to the DelRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.DEL_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.DEL_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // AbandonRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... AbandonRequest ...
+ // AbandonRequest ::= [APPLICATION 16] MessageID (Tag)
+ // We have to switch to the AbandonRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.ABANDON_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ABANDON_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // BindRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... BindRequest ...
+ // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Tag)
+ // Nothing to do while the length is not checked.
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.BIND_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.BIND_REQUEST_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // BindResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... BindResponse ...
+ // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Tag)
+ // We have to switch to the BindResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.BIND_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.BIND_RESPONSE_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // SearchRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... SearchRequest ...
+ // SearchRequest ::= [APPLICATION 3] SEQUENCE { ... (Tag)
+ // Nothing to do while the length is not checked.
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.SEARCH_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.SEARCH_REQUEST_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // SearchResultEntry Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... SearchResultEntry ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { ... (Tag)
+ // Nothing to do while the length is not checked.
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.SEARCH_RESULT_ENTRY_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.SEARCH_RESULT_ENTRY_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // SearchResultDone Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... SearchResultDone ...
+ // SearchResultDone ::= [APPLICATION 5] SEQUENCE { ... (Tag)
+ // We have to switch to the SearchResultDone grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.SEARCH_RESULT_DONE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.SEARCH_RESULT_DONE_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // ModifyRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ModifyRequest ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE { ... (Tag)
+ // We have to switch to the ModifyRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.MODIFY_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // ModifydResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ModifyResponse ...
+ // ModifyResponse ::= [APPLICATION 7] SEQUENCE { ... (Tag)
+ // We have to switch to the ModifyResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.MODIFY_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_RESPONSE_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // AddRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... AddRequest ...
+ // AddRequest ::= [APPLICATION 8] SEQUENCE { ... (Tag)
+ // We have to switch to the AddRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.ADD_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ADD_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // AddResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... AddResponse ...
+ // AddResponse ::= [APPLICATION 9] LDAPResult (Tag)
+ // We have to switch to the AddResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.ADD_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ADD_RESPONSE_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // DelResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... DelResponse ...
+ // DelResponse ::= [APPLICATION 11] LDAPResult (Tag)
+ // We have to switch to the DelResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.DEL_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.DEL_RESPONSE_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // ModifydDNRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ModifyDNRequest ...
+ // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { ... (Tag)
+ // We have to switch to the ModifyDNRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.MODIFY_DN_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_DN_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // ModifydResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ModifyDNResponse ...
+ // ModifyDNResponse ::= [APPLICATION 13] SEQUENCE { ... (Tag)
+ // We have to switch to the ModifyDNResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.MODIFY_DN_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_DN_RESPONSE_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // CompareResquest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... CompareRequest ...
+ // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // We have to switch to the CompareRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.COMPARE_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.COMPARE_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // CompareResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... CompareResponse ...
+ // CompareResponse ::= [APPLICATION 15] LDAPResult (Tag)
+ // We have to switch to the CompareResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.COMPARE_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.COMPARE_RESPONSE_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // SearchResultReference Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... SearchResultReference ...
+ // SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL (Tag)
+ // We have to switch to the SearchResultReference grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.SEARCH_RESULT_REFERENCE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.SEARCH_RESULT_REFERENCE_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // ExtendedRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ExtendedRequest ...
+ // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // We have to switch to the ExtendedRequest grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.EXTENDED_REQUEST_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.EXTENDED_REQUEST_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // ExtendedRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ExtendedResponse ...
+ // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+ // We have to switch to the ExtendedResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.EXTENDED_RESPONSE_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.EXTENDED_RESPONSE_GRAMMAR_SWITCH,
+ null );
+
+ //--------------------------------------------------------------------------------------------
+ // Controls
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... extendedResp ExtendedResponse },
+ // controls [0] Controls OPTIONAL }
+ //
+ // We have to switch to the Controls grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.LDAP_CONTROL_GRAMMAR_SWITCH,
+ null );
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the LdapMessage Grammar
+ */
+ public static IGrammar getInstance()
+ {
+ return instance;
+ }
+}
Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapMessageGrammar.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapResultGrammar.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapResultGrammar.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapResultGrammar.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapResultGrammar.java Fri Sep 9 14:41:22 2005
@@ -0,0 +1,393 @@
+/*
+ * 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.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.ber.tlv.Value;
+import org.apache.asn1new.util.IntegerDecoder;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.LdapMessageContainer;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+import org.apache.asn1new.ldap.codec.primitives.LdapURL;
+import org.apache.asn1new.ldap.codec.utils.LdapResultEnum;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.LdapResponse;
+import org.apache.asn1new.ldap.pojo.LdapResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the LdapResult LDAP message. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ *
+ * If an action is to be added or modified, this is where the work is to be done !
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapResultGrammar extends AbstractGrammar implements IGrammar
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ /** The logger */
+ private static final Logger log = LoggerFactory.getLogger( LdapResultGrammar.class );
+
+ /** The instance of grammar. LdapResultGrammar is a singleton */
+ private static IGrammar instance = new LdapResultGrammar();
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * Creates a new LdapResultGrammar object.
+ */
+ private LdapResultGrammar()
+ {
+ name = LdapResultGrammar.class.getName();
+ statesEnum = LdapStatesEnum.getInstance();
+
+ super.transitions = new GrammarTransition[LdapStatesEnum.LAST_LDAP_RESULT_STATE][256];
+
+ //============================================================================================
+ // LdapResult
+ //============================================================================================
+ // LDAPResult --> SEQUENCE {
+ // resultCode ENUMERATED { ... (Tag)
+ // We have a LDAPResult, and the tag may be 0x0A
+ // Nothing to do
+ super.transitions[LdapStatesEnum.LDAP_RESULT_CODE_TAG][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_CODE_TAG, LdapStatesEnum.LDAP_RESULT_CODE_VALUE, null );
+
+ // LDAPResult --> SEQUENCE {
+ // resultCode ENUMERATED { ... (Value)
+ // The result code. The different values are :
+ // success (0),
+ // operationsError (1),
+ // protocolError (2),
+ // timeLimitExceeded (3),
+ // sizeLimitExceeded (4),
+ // compareFalse (5),
+ // compareTrue (6),
+ // authMethodNotSupported (7),
+ // strongAuthRequired (8),
+ // -- 9 reserved --
+ // referral (10), -- new
+ // adminLimitExceeded (11), -- new
+ // unavailableCriticalExtension (12), -- new
+ // confidentialityRequired (13), -- new
+ // saslBindInProgress (14), -- new
+ // noSuchAttribute (16),
+ // undefinedAttributeType (17),
+ // inappropriateMatching (18),
+ // constraintViolation (19),
+ // attributeOrValueExists (20),
+ // invalidAttributeSyntax (21),
+ // -- 22-31 unused --
+ // noSuchObject (32),
+ // aliasProblem (33),
+ // invalidDNSyntax (34),
+ // -- 35 reserved for undefined isLeaf --
+ // aliasDereferencingProblem (36),
+ // -- 37-47 unused --
+ // inappropriateAuthentication (48),
+ // invalidCredentials (49),
+ // insufficientAccessRights (50),
+ // busy (51),
+ // unavailable (52),
+ // unwillingToPerform (53),
+ // loopDetect (54),
+ // -- 55-63 unused --
+ // namingViolation (64),
+ // objectClassViolation (65),
+ // notAllowedOnNonLeaf (66),
+ // notAllowedOnRDN (67),
+ // entryAlreadyExists (68),
+ // objectClassModsProhibited (69),
+ // -- 70 reserved for CLDAP --
+ // affectsMultipleDSAs (71), -- new
+ // -- 72-79 unused --
+ // other (80) },
+ // -- 81-90 reserved for APIs --
+ //
+ super.transitions[LdapStatesEnum.LDAP_RESULT_CODE_VALUE][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_CODE_VALUE, LdapStatesEnum.LDAP_RESULT_MATCHED_DN_TAG,
+ new GrammarAction( "Store resultCode" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ LdapResponse response = ldapMessage.getLdapResponse();
+ LdapResult ldapResult = new LdapResult();
+ response.setLdapResult( ldapResult );
+
+ // We don't have to allocate a LdapResult first.
+
+ // The current TLV should be a integer
+ // We get it and store it in MessageId
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ Value value = tlv.getValue();
+
+ int resultCode = IntegerDecoder.parse( value, 0, 90 );
+
+ // Treat the 'normal' cases !
+ switch ( resultCode )
+ {
+
+ case LdapResultEnum.SUCCESS :
+ case LdapResultEnum.OPERATIONS_ERROR :
+ case LdapResultEnum.PROTOCOL_ERROR :
+ case LdapResultEnum.TIME_LIMIT_EXCEEDED :
+ case LdapResultEnum.SIZE_LIMIT_EXCEEDED :
+ case LdapResultEnum.COMPARE_FALSE :
+ case LdapResultEnum.COMPARE_TRUE :
+ case LdapResultEnum.AUTH_METHOD_NOT_SUPPORTED :
+ case LdapResultEnum.STRONG_AUTH_REQUIRED :
+ case LdapResultEnum.REFERRAL :
+ case LdapResultEnum.ADMIN_LIMIT_EXCEEDED :
+ case LdapResultEnum.UNAVAILABLE_CRITICAL_EXTENSION :
+ case LdapResultEnum.CONFIDENTIALITY_REQUIRED :
+ case LdapResultEnum.SASL_BIND_IN_PROGRESS :
+ case LdapResultEnum.NO_SUCH_ATTRIBUTE :
+ case LdapResultEnum.UNDEFINED_ATTRIBUTE_TYPE :
+ case LdapResultEnum.INAPPROPRIATE_MATCHING :
+ case LdapResultEnum.CONSTRAINT_VIOLATION :
+ case LdapResultEnum.ATTRIBUTE_OR_VALUE_EXISTS :
+ case LdapResultEnum.INVALID_ATTRIBUTE_SYNTAX :
+ case LdapResultEnum.NO_SUCH_OBJECT :
+ case LdapResultEnum.ALIAS_PROBLEM :
+ case LdapResultEnum.INVALID_DN_SYNTAX :
+ case LdapResultEnum.ALIAS_DEREFERENCING_PROBLEM :
+ case LdapResultEnum.INAPPROPRIATE_AUTHENTICATION :
+ case LdapResultEnum.INVALID_CREDENTIALS :
+ case LdapResultEnum.INSUFFICIENT_ACCESS_RIGHTS :
+ case LdapResultEnum.BUSY :
+ case LdapResultEnum.UNAVAILABLE :
+ case LdapResultEnum.UNWILLING_TO_PERFORM :
+ case LdapResultEnum.LOOP_DETECT :
+ case LdapResultEnum.NAMING_VIOLATION :
+ case LdapResultEnum.OBJECT_CLASS_VIOLATION :
+ case LdapResultEnum.NOT_ALLOWED_ON_NON_LEAF :
+ case LdapResultEnum.NOT_ALLOWED_ON_RDN :
+ case LdapResultEnum.ENTRY_ALREADY_EXISTS :
+ case LdapResultEnum.AFFECTS_MULTIPLE_DSAS :
+ ldapResult.setResultCode( resultCode );
+ break;
+
+ default :
+ throw new DecoderException(
+ "Error <" + LdapResultEnum.errorCode( resultCode ) +
+ "> not allowed" );
+ }
+ }
+ } );
+
+ // LDAPResult --> SEQUENCE {
+ // ...
+ // matchedDN LDAPDN, (Tag)
+ // The tag is 0x04. Nothing to do
+ super.transitions[LdapStatesEnum.LDAP_RESULT_MATCHED_DN_TAG][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_MATCHED_DN_TAG,
+ LdapStatesEnum.LDAP_RESULT_MATCHED_DN_VALUE, null );
+
+ // LDAPResult --> SEQUENCE {
+ // ...
+ // matchedDN LDAPDN, (Value)
+ // We store the LDAPDN after having checked that it is valid.
+ super.transitions[LdapStatesEnum.LDAP_RESULT_MATCHED_DN_VALUE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_MATCHED_DN_VALUE,
+ LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_TAG,
+ new GrammarAction( "Store Ldap Result matched DN" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ LdapResponse response = ldapMessage.getLdapResponse();
+ LdapResult ldapResult = response.getLdapResult();
+
+ // Get the Value and store it in the BindResponse
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ // We have to handle the special case of a 0 length matched DN
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ ldapResult.setMatchedDN( LdapDN.EMPTY_STRING );
+ }
+ else
+ {
+ ldapResult.setMatchedDN( new LdapDN( tlv.getValue().getData() ) );
+ }
+
+ return;
+ }
+ } );
+
+ // LDAPResult --> SEQUENCE {
+ // ...
+ // errorMessage LDAPString, (Tag)
+ // The tag is 0x04. Nothing to do
+ super.transitions[LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_TAG][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_TAG,
+ LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_VALUE, null );
+
+ // LDAPResult --> SEQUENCE {
+ // ...
+ // errorMessage LDAPString, (Value)
+ // Stores the value.
+ super.transitions[LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_VALUE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition( LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_VALUE,
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_SEQUENCE_TAG,
+ new GrammarAction( "Store Ldap Result error message" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ LdapResponse response = ldapMessage.getLdapResponse();
+ LdapResult ldapResult = response.getLdapResult();
+
+ // Get the Value and store it in the BindResponse
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ // We have to handle the special case of a 0 length error message
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ ldapResult.setErrorMessage( LdapString.EMPTY_STRING );
+ }
+ else
+ {
+ ldapResult.setErrorMessage( new LdapString(
+ tlv.getValue().getData() ) );
+ }
+
+ return;
+ }
+ } );
+
+ // LDAPResult --> SEQUENCE {
+ // ...
+ // referral [3] Referral OPTIONAL } (Tag)
+ //
+ // The next state could be one of the following :
+ // - 0x83 : a referral, in a LdapResult.
+ // - 0x8A : an extended response
+ // - GRAMMAR_END : this is implicitly deducted by the fact that we don't have anymore byte...
+ //
+ // We don't deal with all of this values, we just have to treat the 0x83, because
+ // referral is a part of the LdapResult grammar. In all other cases, we just quit
+ // the grammar.
+ // As referral is optionnal, we may transoit from a error message state
+
+ // This is a referral.
+ super.transitions[LdapStatesEnum.LDAP_RESULT_REFERRAL_SEQUENCE_TAG][LdapConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG] =
+ new GrammarTransition( LdapStatesEnum.LDAP_RESULT_REFERRAL_SEQUENCE_TAG,
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_TAG, null );
+
+ // In case we are coming from a error message state
+ super.transitions[LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_VALUE][LdapConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG] =
+ new GrammarTransition( LdapStatesEnum.LDAP_RESULT_ERROR_MESSAGE_VALUE,
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_TAG, null );
+
+ // Referral ::= SEQUENCE OF LDAPURL (Tag)
+ // This is a SEQUENCE, we will have at least one referral, but may be many.
+ // As this is the tag, we don't have anything to do.
+ super.transitions[LdapStatesEnum.LDAP_RESULT_REFERRAL_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_TAG,
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_VALUE, null );
+
+ // Referral ::= SEQUENCE OF LDAPURL (Length)
+ // We may have other referrals, but wa may also have finished to read the LdapResult.
+ // To handle those different cases, we have to transit to a special state, which
+ // will do this brancing.
+ // Here, we store the referral in the ldapResult.
+ super.transitions[LdapStatesEnum.LDAP_RESULT_REFERRAL_VALUE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_VALUE,
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_LOOP_TAG,
+ new GrammarAction( "Store Ldap Result referral" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessage ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+ LdapResponse response = ldapMessage.getLdapResponse();
+ LdapResult ldapResult = response.getLdapResult();
+
+ TLV tlv =
+ ldapMessageContainer.getCurrentTLV();
+
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ ldapResult.addReferral( LdapURL.EMPTY_STRING );
+ }
+ else
+ {
+ ldapResult.addReferral( new LdapURL( tlv.getValue().getData() ) );
+ }
+ }
+ } );
+
+ // Referral ::= SEQUENCE OF LDAPURL (Tag)
+ // We may have another referral, but we could also have something else :
+ // - 0x04 : a referral, in a LdapResult.
+ // - GRAMMAR_END : this is implicitly deducted by the fact that we don't have any more valid byte...
+ // Those different cases are handled here.
+
+ // This is a referral. We have to transit to its Length state
+ super.transitions[LdapStatesEnum.LDAP_RESULT_REFERRAL_LOOP_TAG][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition(
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_LOOP_TAG,
+ LdapStatesEnum.LDAP_RESULT_REFERRAL_VALUE, null );
+
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * This class is a singleton.
+ *
+ * @return An instance on this grammar
+ */
+ public static IGrammar getInstance()
+ {
+ return instance;
+ }
+}
Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/LdapResultGrammar.java
------------------------------------------------------------------------------
svn:eol-style = native