directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20673 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap
Date Mon, 31 May 2004 02:32:00 GMT
Author: akarasulu
Date: Sun May 30 19:32:00 2004
New Revision: 20673

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseReferenceRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseReferralRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseReferenceRuleTest.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
Log:
finished and tested the search result referrence pdu rules

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
Sun May 30 19:32:00 2004
@@ -93,8 +93,31 @@
         addModifyDnResponseRules( digester ) ;
         addModifyResponseRules( digester ) ;
         addSearchResponseDoneRules( digester ) ;
+        addSearchResponseReferenceRules( digester ) ;
 
         return digester ;
+    }
+
+
+    private void addSearchResponseReferenceRules( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+
+        // set pattern and addRule for the SearchResponseReference
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.SEARCH_RESULT_REFERENCE.getPrimitiveTag() ;
+        digester.addRule( pattern, new SearchResponseReferenceRule() ) ;
+        digester.addRule( pattern, new SearchResponseReferralRule() ) ;
+
+
+        // expand the pattern for 3 elements
+        pattern = new int[3] ;
+
+        // set pattern for the SearchResponseReference
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.SEARCH_RESULT_REFERENCE.getPrimitiveTag() ;
+        pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new ReferralUrlRule() ) ;
     }
 
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
Sun May 30 19:32:00 2004
@@ -19,8 +19,7 @@
 
 import org.apache.ldap.common.message.LdapResult ;
 import org.apache.ldap.common.message.ReferralImpl ;
-import org.apache.ldap.common.message.BindResponse;
-import org.apache.ldap.common.message.ResultResponse;
+import org.apache.ldap.common.message.ResultResponse ;
 
 import org.apache.snickers.ber.TagEnum ;
 import org.apache.snickers.ber.TypeClass ;
@@ -31,7 +30,8 @@
  * A BERDigester Rule that creates and pushes a Referral onto the object Stack
  * to be populated by ReferralUrlRule invokations.
  * 
- * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
  * @version $Rev$
  */
 public class ReferralRule extends AbstractRule
@@ -39,7 +39,6 @@
     /** the tag for a Referral within an LDAPResult */
     private static final TagEnum TAG = new TagEnum( "Referral",
             0x83000000, 3 ) {} ;
-
 
     /**
      * Creates and sets the Referral for an LdapResult to use.  It does so

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseReferenceRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseReferenceRule.java
Sun May 30 19:32:00 2004
@@ -0,0 +1,66 @@
+/*
+ *   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.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+
+import org.apache.ldap.common.message.SearchResponseReferenceImpl ;
+
+
+/**
+ * Creates an instance of an LDAP SearchResponseReference bean using a message
+ * Id stored on the primitive integer stack.  As a side effect the integer is
+ * popped off of the stack and the SearchResponseReference is pushed onto the
+ * Object stack.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseReferenceRule extends AbstractRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        LdapTag tag = LdapTag.getLdapTagById( id ) ;
+
+        if ( LdapTag.SEARCH_RESULT_REFERENCE != tag )
+        {
+            throw new IllegalArgumentException(
+                    "Expected a SEARCH_RESULT_REFERENCE tag id but got a "
+                    + tag ) ;
+        }
+
+        SearchResponseReferenceImpl req =
+                new SearchResponseReferenceImpl( getDigester().popInt() ) ;
+        getDigester().push( req ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        getDigester().pop() ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseReferralRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseReferralRule.java
Sun May 30 19:32:00 2004
@@ -0,0 +1,80 @@
+/*
+ *   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.ReferralImpl ;
+import org.apache.ldap.common.message.SearchResponseReferenceImpl ;
+
+import org.apache.snickers.ber.TagEnum ;
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+import org.apache.snickers.ber.primitives.UniversalTag ;
+
+
+/**
+ * A BERDigester Rule that creates and pushes a Referral onto the object Stack
+ * to be populated by ReferralUrlRule invokations.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseReferralRule extends AbstractRule
+{
+    /** the tag to expect */
+    private static final TagEnum TAG = LdapTag.SEARCH_RESULT_REFERENCE ;
+
+    /**
+     * Creates and sets the Referral for an SearchResponseReference to use.
+     * It does so by first accessing the underlying SearchResponseReference
+     * object which is expected to be the top object on the objectStack.
+     * A peek is performed to get this obj.  It is then used to create the
+     * Referral object which is pushed onto the stack.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+
+        if ( id != TAG.getTagId() )
+        {
+            throw new IllegalArgumentException(
+                    "Expecting " + TAG.getName()
+                    + " with an id of " + TAG.getTagId()
+                    + " but instead got a tag id of " + id ) ;
+        }
+
+        SearchResponseReferenceImpl resp = ( SearchResponseReferenceImpl )
+                getDigester().getRoot() ;
+        ReferralImpl ref = new ReferralImpl( resp ) ;
+        resp.setReferral( ref ) ;
+        getDigester().push( ref ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+        getDigester().pop() ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseReferenceRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseReferenceRuleTest.java
Sun May 30 19:32:00 2004
@@ -0,0 +1,68 @@
+/*
+ *   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 java.util.Iterator ;
+
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
+
+import org.apache.ldap.common.message.* ;
+
+
+/**
+ * Tests the population of an LdapResult using a ResultRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseReferenceRuleTest extends RuleTestCase
+{
+    public void testSearchResponseReference() throws Exception
+    {
+        // build the PDU
+        SearchResponseReferenceImpl resp =
+                new SearchResponseReferenceImpl( 8 ) ;
+        ReferralImpl referral = new ReferralImpl( resp ) ;
+        resp.setReferral( referral ) ;
+        referral.addLdapUrl(
+           "ldap://directory.uga.edu/ou=students,o=uga,c=us?objectClass?one" ) ;
+        referral.addLdapUrl(
+           "ldap://directory.uga.edu/o=uga,c=us?creatorsname" ) ;
+        System.out.println( "Generated SearchResultReferrence for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+        SearchResponseReference decoded = ( SearchResponseReference )
+                snickersDecode( snaccEncode( resp ) ) ;
+
+        assertNotNull( decoded ) ;
+        assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
+        Referral decodedRef = decoded.getReferral() ;
+        Iterator urls = referral.getLdapUrls().iterator() ;
+        Iterator decodedUrls = decodedRef.getLdapUrls().iterator() ;
+
+        while( urls.hasNext() && decodedUrls.hasNext() )
+        {
+            assertEquals( urls.next(), decodedUrls.next() ) ;
+        }
+
+        assertFalse( urls.hasNext() ) ;
+        assertFalse( decodedUrls.hasNext() ) ;
+    }
+}
\ No newline at end of file

Mime
View raw message