directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 21103 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap java/org/apache/snickers/ldap/search test/org/apache/snickers/ldap/search
Date Fri, 11 Jun 2004 16:13:49 GMT
Author: akarasulu
Date: Fri Jun 11 09:13:48 2004
New Revision: 21103

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/RequestedAttributesRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/RequestedAttributesStateChangeRule.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/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Log:
Commit changes ...

 o more search request handling
 o added two new rules to process attributes to return in searches
   - RequestedAttributesRule adds attributes only no state changes
   - when all attributes have been added the RequestedAttributesStateChangeRule
     changes the state from ATTRIBUTES_STATE to CONTROLS_STATE
 o finished off test case to test adding attributes to SearchRequest object

To do ...

 o finish filter 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
Fri Jun 11 09:13:48 2004
@@ -121,12 +121,12 @@
 
     private void adddeletes( BERDigester digester )
     {
-        int[] pattern = new int[2] ;
+        int[] pattern = new int[2];
 
         // set pattern and addRule for the SearchRequest
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
-        pattern[1] = LdapTag.SEARCH_REQUEST.getPrimitiveTag() ;
-        digester.addRule( pattern, new SearchRequestRule() ) ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag();
+        pattern[1] = LdapTag.SEARCH_REQUEST.getPrimitiveTag();
+        digester.addRule( pattern, new SearchRequestRule() );
 
         // setup pattern to set the dn of the entry added
         pattern = new int[3];
@@ -145,6 +145,16 @@
 
         pattern[2] = UniversalTag.BOOLEAN.getPrimitiveTag();
         digester.addRule( pattern, new TypesOnlyRule() );
+
+        pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag();
+        digester.addRule( pattern, new RequestedAttributesStateChangeRule() );
+
+        pattern = new int[4] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.SEARCH_REQUEST.getPrimitiveTag();
+        pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag();
+        pattern[3] = UniversalTag.OCTET_STRING.getPrimitiveTag();
+        digester.addRule( pattern, new RequestedAttributesRule() );
     }
 
 

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/RequestedAttributesRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/RequestedAttributesRule.java
Fri Jun 11 09:13:48 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.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.ldap.common.message.SearchRequestImpl;
+
+
+/**
+ * Document this class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class RequestedAttributesRule extends PrimitiveOctetStringRule
+{
+    public RequestedAttributesRule()
+    {
+        super( UniversalTag.OCTET_STRING ) ;
+    }
+
+
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at SearchRequest underneath processing obj whose octets we set
+        SearchRequestImpl req = ( SearchRequestImpl ) getDigester().peek( 1 );
+
+        byte[] octets = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            octets = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            octets = new byte[buf.remaining()];
+            buf.get( octets );
+        }
+
+        req.addAttribute( new String( octets ) );
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/RequestedAttributesStateChangeRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/RequestedAttributesStateChangeRule.java
Fri Jun 11 09:13:48 2004
@@ -0,0 +1,47 @@
+/*
+ *   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.search;
+
+
+import org.apache.snickers.ber.TypeClass;
+
+
+/**
+ * Document this class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class RequestedAttributesStateChangeRule extends BaseSearchRequestRule
+{
+    public RequestedAttributesStateChangeRule()
+    {
+        super( 3 );
+    }
+
+
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass );
+
+        if ( getProcessing().getState() != getProcessing().ATTRIBUTES_STATE )
+        {
+            setEnabled( false );
+        }
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Fri Jun 11 09:13:48 2004
@@ -14,22 +14,18 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ldap.search ;
+package org.apache.snickers.ldap.search;
 
 
-import java.util.HashSet ;
-import java.util.Iterator ;
-import java.util.Collection ;
-import javax.naming.directory.Attribute ;
-import javax.naming.directory.DirContext ;
-import javax.naming.directory.ModificationItem ;
+import java.util.Collection;
+import java.util.Iterator;
 
-import org.apache.ldap.common.message.* ;
+import org.apache.ldap.common.message.*;
 import org.apache.ldap.common.filter.ExprNode;
 import org.apache.ldap.common.filter.FilterParserImpl;
 
-import org.apache.snickers.ldap.testutils.TestUtils ;
-import org.apache.snickers.ldap.testutils.RuleTestCase ;
+import org.apache.snickers.ldap.testutils.TestUtils;
+import org.apache.snickers.ldap.testutils.RuleTestCase;
 
 
 /**
@@ -46,44 +42,50 @@
      */
     public void testSearchRequest() throws Exception
     {
-        SearchRequestImpl req = new SearchRequestImpl( 33 ) ;
-        req.setBase( "dc=example,dc=com" ) ;
-        req.setDerefAliases( DerefAliasesEnum.DEREFINSEARCHING ) ;
-        req.setScope( ScopeEnum.SINGLELEVEL ) ;
-        req.setSizeLimit( 2 ) ;
-        req.setTimeLimit( 3 ) ;
-        req.setTypesOnly( true ) ;
-
-        //req.addAttribute( "attr0" ) ;
-        //req.addAttribute( "attr1" ) ;
-        //req.addAttribute( "attr2" ) ;
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
 
 
-        FilterParserImpl parser = new FilterParserImpl() ;
+        FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
         node = parser.parse(
-                  "(ou=Human Resources)" ) ;
-                //"( & ( ou = Human Resources ) ( l = SunnyVale ) "
-                //+ " ( | ( uid = akarasulu ) ( ! ( uid = jbean ) ) ) )" ) ;
-        req.setFilter( node ) ;
+                "( & ( ou = Human Resources ) ( l = SunnyVale ) "
+                + " ( | ( uid = akarasulu ) ( ! ( uid = jbean ) ) ) )" );
+        req.setFilter( node );
 
-        System.out.println( "Generated SearchRequest for test:" ) ;
-        System.out.println( TestUtils.printTupleTree( req ) ) ;
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
 
         SearchRequest decoded = ( SearchRequest )
-                snickersDecode( snaccEncode( req ) ) ;
-        assertNotNull( decoded ) ;
-        assertEquals( req.getBase(), decoded.getBase() ) ;
-        assertEquals( req.getScope(), decoded.getScope() ) ;
-        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() ) ;
-        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() ) ;
-        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() ) ;
-        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() ) ;
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
 
-        /*
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
 
-        NOT COMPLETE YET!
-
-        */
+        // control test should fail
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
     }
 }

Mime
View raw message