directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20568 - incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap
Date Sat, 29 May 2004 02:22:42 GMT
Author: akarasulu
Date: Fri May 28 19:22:41 2004
New Revision: 20568

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapMessageFactory.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
Log:
Commit changes ...

 o moved factory method out of the LdapTag type safe enum
 o created new factory class with static factory method
 o massaged the docs for BindResponseRule and ResultResponseRule



Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
Fri May 28 19:22:41 2004
@@ -14,29 +14,39 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ldap;
+package org.apache.snickers.ldap ;
 
-import org.apache.ldap.common.message.BindResponse;
 
-import java.nio.ByteBuffer;
+import java.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.BindResponse ;
 
 
 /**
- * Put some documentation here.
+ * A digester rule which fires to build BindRespond containment trees.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class BindResponseRule extends ResultResponseRule
 {
+    /**
+     * Creates a digester rule which fires to build BindRespond containment
+     * trees.
+     */
     public BindResponseRule()
     {
         super( LdapTag.BIND_RESPONSE ) ;
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.snickers.ber.Rule#finish()
+    /**
+     * This final rule firing stage peeks at the object buffer to see if an
+     * optional SASL crendential is available.  If it is, the SASL
+     * crendentials are popped off of the object stack and used to populate
+     * the BindResponse, otherwise they are left as is: null.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
      */
     public void finish()
     {

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapMessageFactory.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapMessageFactory.java
Fri May 28 19:22:41 2004
@@ -0,0 +1,131 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import org.apache.ldap.common.message.* ;
+
+
+/**
+ * A static factory for creating LDAPv3 Message objects based on the LDAP tag
+ * of the specific LDAP message PDU.  The factory is static because its all
+ * hard coded as a switch on constants - it makes no sense to deal with
+ * instance methods or factory instances.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public final class LdapMessageFactory
+{
+    /**
+     * Creates an empty LDAP Message instance whose types corresponds to the
+     * tagId provided.  The only field that is populated is the final message
+     * identifier.
+     *
+     * @param tag the LDAPv3 APPLICATION tag for the PDU type
+     * @param messageId the unique identifier for messages within a session
+     * @return an empty LDAP Message (PDU) instance
+     */
+    static final Message create( LdapTag tag, int messageId )
+    {
+        return create( tag.getTagId(), messageId ) ;
+    }
+    
+
+    /**
+     * Creates an empty LDAP Message instance whose types corresponds to the
+     * tagId provided.  The only field that is populated is the final message
+     * identifier.
+     *
+     * @param tagId the LDAPv3 APPLICATION tagId for the PDU type
+     * @param messageId the unique identifier for messages within a session
+     * @return an empty LDAP Message (PDU) instance
+     */
+    static final Message create( int tagId, int messageId )
+    {
+        Message pdu = null ;
+
+        switch ( tagId )
+        {
+            case( LdapTag.BIND_REQUEST_ID ):
+                pdu = new BindRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.BIND_RESPONSE_ID ):
+                pdu = new BindResponseImpl( messageId ) ;
+                break ;
+            case( LdapTag.UNBIND_REQUEST_ID ):
+                pdu = new UnbindRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.SEARCH_REQUEST_ID ):
+                pdu = new SearchRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.SEARCH_RESULT_ENTRY_ID ):
+                pdu = new SearchResponseEntryImpl( messageId ) ;
+                break ;
+            case( LdapTag.SEARCH_RESULT_DONE_ID ):
+                pdu = new SearchResponseDoneImpl( messageId ) ;
+                break ;
+            case( LdapTag.SEARCH_RESULT_REFERENCE_ID ):
+                pdu = new SearchResponseReferenceImpl( messageId ) ;
+                break ;
+            case( LdapTag.MODIFY_REQUEST_ID ):
+                pdu = new ModifyRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.MODIFY_RESPONSE_ID ):
+                pdu = new ModifyResponseImpl( messageId ) ;
+                break ;
+            case( LdapTag.ADD_REQUEST_ID ):
+                pdu = new AddRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.ADD_RESPONSE_ID ):
+                pdu = new AddResponseImpl( messageId ) ;
+                break ;
+            case( LdapTag.DEL_REQUEST_ID ):
+                pdu = new DeleteRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.DEL_RESPONSE_ID ):
+                pdu = new DeleteResponseImpl( messageId ) ;
+                break ;
+            case( LdapTag.MODIFYDN_REQUEST_ID ):
+                pdu = new ModifyDnRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.MODIFYDN_RESPONSE_ID ):
+                pdu = new ModifyDnResponseImpl( messageId ) ;
+                break ;
+            case( LdapTag.COMPARE_REQUEST_ID ):
+                pdu = new CompareRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.COMPARE_RESPONSE_ID ):
+                pdu = new CompareResponseImpl( messageId ) ;
+                break ;
+            case( LdapTag.ABANDON_REQUEST_ID ):
+                pdu = new AbandonRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.EXTENDED_REQUEST_ID ):
+                pdu = new ExtendedRequestImpl( messageId ) ;
+                break ;
+            case( LdapTag.EXTENDED_RESPONSE_ID ):
+                pdu = new ExtendedResponseImpl( messageId ) ;
+                break ;
+            default:
+                throw new IllegalStateException(
+                        "shouldn't happen - if it does then we have issues" ) ;
+        }
+
+        return pdu ;
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
Fri May 28 19:22:41 2004
@@ -23,11 +23,10 @@
 import java.util.List ;
 
 import org.apache.snickers.ber.TagEnum ;
-import org.apache.ldap.common.message.*;
 
 
 /**
- * Prefabricated LDAP tags encoded as integers.
+ * Prefabricated LDAP APPLICATION type class tags encoded as integers.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -91,54 +90,54 @@
 
 
     /** the bind request id as an integer */
-    private static final int BIND_REQUEST_ID =               0 ;
+    static final int BIND_REQUEST_ID =               0 ;
     /** the bind response id as an integer */
-    private static final int BIND_RESPONSE_ID =              1 ;
+    static final int BIND_RESPONSE_ID =              1 ;
 
     /** the unbind request id as an integer */
-    private static final int UNBIND_REQUEST_ID =             2 ;
+    static final int UNBIND_REQUEST_ID =             2 ;
 
     /** the search request id as an integer */
-    private static final int SEARCH_REQUEST_ID =             3 ;
+    static final int SEARCH_REQUEST_ID =             3 ;
     /** the search result entry response id as an integer */
-    private static final int SEARCH_RESULT_ENTRY_ID =        4 ;
+    static final int SEARCH_RESULT_ENTRY_ID =        4 ;
     /** the search result done id as an integer */
-    private static final int SEARCH_RESULT_DONE_ID =         5 ;
+    static final int SEARCH_RESULT_DONE_ID =         5 ;
     /** the search result reference response id as an integer */
-    private static final int SEARCH_RESULT_REFERENCE_ID =    19 ;
+    static final int SEARCH_RESULT_REFERENCE_ID =    19 ;
 
     /** the modify request id as an integer */
-    private static final int MODIFY_REQUEST_ID =             6 ;
+    static final int MODIFY_REQUEST_ID =             6 ;
     /** the modify response id as an integer */
-    private static final int MODIFY_RESPONSE_ID =            7 ;
+    static final int MODIFY_RESPONSE_ID =            7 ;
 
     /** the add request id as an integer */
-    private static final int ADD_REQUEST_ID =                8 ;
+    static final int ADD_REQUEST_ID =                8 ;
     /** the add response id as an integer */
-    private static final int ADD_RESPONSE_ID =               9 ;
+    static final int ADD_RESPONSE_ID =               9 ;
 
     /** the delete request id as an integer */
-    private static final int DEL_REQUEST_ID =                10 ;
+    static final int DEL_REQUEST_ID =                10 ;
     /** the delete response id as an integer */
-    private static final int DEL_RESPONSE_ID =               11 ;
+    static final int DEL_RESPONSE_ID =               11 ;
 
     /** the modify dn request id as an integer */
-    private static final int MODIFYDN_REQUEST_ID =           12 ;
+    static final int MODIFYDN_REQUEST_ID =           12 ;
     /** the modify dn response id as an integer */
-    private static final int MODIFYDN_RESPONSE_ID =          13 ;
+    static final int MODIFYDN_RESPONSE_ID =          13 ;
 
     /** the compare request id as an integer */
-    private static final int COMPARE_REQUEST_ID =            14 ;
+    static final int COMPARE_REQUEST_ID =            14 ;
     /** the compare response id as an integer */
-    private static final int COMPARE_RESPONSE_ID =           15 ;
+    static final int COMPARE_RESPONSE_ID =           15 ;
 
     /** the abandon request id as an integer */
-    private static final int ABANDON_REQUEST_ID =            16 ;
+    static final int ABANDON_REQUEST_ID =            16 ;
 
     /** the extended request id as an integer */
-    private static final int EXTENDED_REQUEST_ID =           23 ;
+    static final int EXTENDED_REQUEST_ID =           23 ;
     /** the extended response id as an integer */
-    private static final int EXTENDED_RESPONSE_ID =          24 ;
+    static final int EXTENDED_RESPONSE_ID =          24 ;
 
     
     // -----------------------------------------------------------------------
@@ -242,7 +241,7 @@
 
 
     /**
-     * Gets the ASN.1 LDAPv3 APPLICATION type tag's enum using a tag value.
+     * Gets a Factory.
      *
      * @param value the first octet of the TLV
      * @return the valued enum for the LDAPv3 ASN.1 type tag
@@ -416,87 +415,6 @@
                 }
 
                 throw new IllegalArgumentException( msg ) ;
-        }
-
-        return type ;
-    }
-
-
-    /**
-     * Factory method used to create a skeletal message instance.
-     *
-     * @param messageId the message id to use for the message
-     * @return the newly created skeletal mesage instance
-     */
-    public Message create( int messageId )
-    {
-        Message type = null ;
-
-        switch ( this.getTagId() )
-        {
-            case( BIND_REQUEST_ID ):
-                type = new BindRequestImpl( messageId ) ;
-                break ;
-            case( BIND_RESPONSE_ID ):
-                type = new BindResponseImpl( messageId ) ;
-                break ;
-            case( UNBIND_REQUEST_ID ):
-                type = new UnbindRequestImpl( messageId ) ;
-                break ;
-            case( SEARCH_REQUEST_ID ):
-                type = new SearchRequestImpl( messageId ) ;
-                break ;
-            case( SEARCH_RESULT_ENTRY_ID ):
-                type = new SearchResponseEntryImpl( messageId ) ;
-                break ;
-            case( SEARCH_RESULT_DONE_ID ):
-                type = new SearchResponseDoneImpl( messageId ) ;
-                break ;
-            case( SEARCH_RESULT_REFERENCE_ID ):
-                type = new SearchResponseReferenceImpl( messageId ) ;
-                break ;
-            case( MODIFY_REQUEST_ID ):
-                type = new ModifyRequestImpl( messageId ) ;
-                break ;
-            case( MODIFY_RESPONSE_ID ):
-                type = new ModifyResponseImpl( messageId ) ;
-                break ;
-            case( ADD_REQUEST_ID ):
-                type = new AddRequestImpl( messageId ) ;
-                break ;
-            case( ADD_RESPONSE_ID ):
-                type = new AddResponseImpl( messageId ) ;
-                break ;
-            case( DEL_REQUEST_ID ):
-                type = new DeleteRequestImpl( messageId ) ;
-                break ;
-            case( DEL_RESPONSE_ID ):
-                type = new DeleteResponseImpl( messageId ) ;
-                break ;
-            case( MODIFYDN_REQUEST_ID ):
-                type = new ModifyDnRequestImpl( messageId ) ;
-                break ;
-            case( MODIFYDN_RESPONSE_ID ):
-                type = new ModifyDnResponseImpl( messageId ) ;
-                break ;
-            case( COMPARE_REQUEST_ID ):
-                type = new CompareRequestImpl( messageId ) ;
-                break ;
-            case( COMPARE_RESPONSE_ID ):
-                type = new CompareResponseImpl( messageId ) ;
-                break ;
-            case( ABANDON_REQUEST_ID ):
-                type = new AbandonRequestImpl( messageId ) ;
-                break ;
-            case( EXTENDED_REQUEST_ID ):
-                type = new ExtendedRequestImpl( messageId ) ;
-                break ;
-            case( EXTENDED_RESPONSE_ID ):
-                type = new ExtendedResponseImpl( messageId ) ;
-                break ;
-            default:
-                throw new IllegalStateException(
-                        "should not happen - if it does we have issues" ) ;
         }
 
         return type ;

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
Fri May 28 19:22:41 2004
@@ -25,39 +25,90 @@
 
 
 /**
- * A rule that creates, pushes and pops a ResultRequest.
- * 
+ * A rule base class used to build LDAPv3 response messages carrying operation
+ * result information.  This PDU class is referred to as a ResultResponses.
+ * This rule creates one and places the message on the object stack.  This rule
+ * performs the following tasks in the firing stage method specified:
+ *
+ * <ul>
+ *   <li>tag(): pops the primitive int stack to get the messageId</li>
+ *   <li>tag(): instantiates a ResultResponse message with the messageId</li>
+ *   <li>tag(): populates the ResultResponse with a new LdapResult object</li>
+ *   <li>tag(): pushes the ResultResponse message onto the object stack</li>
+ *   <li>finish(): pops object stack if top object is a ResultResponse</li>
+ * </ul>
+ *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev: 10091 $
  */
-public class ResultResponseRule extends AbstractRule
+public abstract class ResultResponseRule extends AbstractRule
 {
+    /** the LdapTag associated with the message type */
     private final LdapTag tag ;
 
 
-    ResultResponseRule( LdapTag tag )
+    /**
+     * Creates a ResultResponse instantiating rule for a specific LDAP
+     * APPLICTION tag.
+     *
+     * @param tag the ASN.1 application tag for the LDAP message type
+     */
+    protected ResultResponseRule( LdapTag tag )
     {
         this.tag = tag ;
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+    /**
+     * Rule firing stage called first when a PDU response with a result is
+     * encountered.  The tag id must equal the tag id of this Rule.  If the
+     * tag id matches then the following tasks are performed in this stage:
+     *
+     * <ul>
+     *   <li>pops the primitive int stack to get the messageId</li>
+     *   <li>instantiates a ResultResponse message with the messageId</li>
+     *   <li>populates the ResultResponse with a new LdapResult object</li>
+     *   <li>pushes the ResultResponse message onto the object stack</li>
+     * </ul>
+     *
+     * @throws IllegalStateException if the id does not eqaul tag.getTagId()
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
      * org.apache.snickers.ber.TypeClass)
      */
     public void tag( int id, boolean isPrimitive, TypeClass typeClass )
     {
+        if ( tag.getTagId() != id )
+        {
+            throw new IllegalStateException( "Rule firing stage method "
+                    + this + ".tag() expected an id of " + tag.getTagId()
+                    + " for tag " + tag + " but instead encountered a tag id "
+                    + " of " + id ) ;
+        }
+
+        ResultResponse resp ;
         super.tag( id, isPrimitive, typeClass ) ;
-        ResultResponse resp = ( ResultResponse ) tag.create(
-                getDigester().popInt() ) ;
-        LdapResultImpl result = new LdapResultImpl( resp ) ;
-        resp.setLdapResult( result ) ;
+
+        // pop the message id off of the int stack
+        int messageId = getDigester().popInt() ;
+
+        // create the ResultResponse object
+        resp = ( ResultResponse ) LdapMessageFactory.create( id, messageId ) ;
+
+        // instantiate an set the LdapResult object
+        resp.setLdapResult( new LdapResultImpl( resp ) ) ;
+
+        // push the pdu onto the object stack
         getDigester().push( resp ) ;
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.snickers.ber.Rule#finish()
+
+    /**
+     * Final rule firing stage method which checks to see if the top of the
+     * object stack is an instance of ResultResponse, if so the object is
+     * popped.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
      */
     public void finish()
     {

Mime
View raw message