You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/05/31 08:22:28 UTC
svn commit: rev 20686 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap
Author: akarasulu
Date: Sun May 30 23:22:27 2004
New Revision: 20686
Added:
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestAttributesRule.java
- copied, changed from rev 20680, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AttributesRule.java
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryAttributesRule.java (contents, props changed)
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryDnRule.java (contents, props changed)
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryRule.java (contents, props changed)
incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseEntryTest.java (contents, props changed)
Removed:
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AttributesRule.java
Modified:
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestRule.java
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/AddRequestTest.java
Log:
finished and tested the search result entry rules
Copied: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestAttributesRule.java (from rev 20680, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AttributesRule.java)
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AttributesRule.java (original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestAttributesRule.java Sun May 30 23:22:27 2004
@@ -33,27 +33,27 @@
* Project</a>
* @version $Rev$
*/
-public class AttributesRule extends AbstractRule
+public class AddRequestAttributesRule extends AbstractRule
{
/** the tag this rule expects to encounter */
private final TagEnum expected ;
/**
- * Creates a new AttributesRule using an expected tag to enforce.
+ * Creates a new AddRequestAttributesRule using an expected tag to enforce.
*
* @param expected the tag the rule must encounter to fire properly
*/
- public AttributesRule( TagEnum expected )
+ public AddRequestAttributesRule( TagEnum expected )
{
this.expected = expected ;
}
/**
- * Creates a new AttributesRule that expects a SEQUENCE tag.
+ * Creates a new AddRequestAttributesRule that expects a SEQUENCE tag.
*/
- public AttributesRule()
+ public AddRequestAttributesRule()
{
this.expected = UniversalTag.SEQUENCE_SEQUENCE_OF ;
}
Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestRule.java (original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddRequestRule.java Sun May 30 23:22:27 2004
@@ -59,5 +59,6 @@
public void finish()
{
super.finish() ;
+ getDigester().pop() ;
}
}
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 23:22:27 2004
@@ -97,11 +97,59 @@
addModifyResponseRules( digester ) ;
addSearchResponseDoneRules( digester ) ;
addSearchResponseReferenceRules( digester ) ;
+ addSearchResponseEntryRules( digester ) ;
return digester ;
}
+ private void addSearchResponseEntryRules( BERDigester digester )
+ {
+ int[] pattern = new int[2] ;
+
+ // set pattern and addRule for the AddRequest
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.SEARCH_RESULT_ENTRY.getPrimitiveTag() ;
+ digester.addRule( pattern, new SearchResponseEntryRule() ) ;
+
+ // setup pattern to set the dn of the entry added
+ pattern = new int[3] ;
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.SEARCH_RESULT_ENTRY.getPrimitiveTag() ;
+ pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+ digester.addRule( pattern, new SearchResponseEntryDnRule() ) ;
+
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.SEARCH_RESULT_ENTRY.getPrimitiveTag() ;
+ pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ digester.addRule( pattern, new SearchResponseEntryAttributesRule() ) ;
+
+ pattern = new int[4] ;
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.SEARCH_RESULT_ENTRY.getPrimitiveTag() ;
+ pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[3] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ digester.addRule( pattern, new PopOnFinish() ) ;
+
+ pattern = new int[5] ;
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.SEARCH_RESULT_ENTRY.getPrimitiveTag() ;
+ pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[3] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[4] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+ digester.addRule( pattern, new Octets2StringRule() ) ;
+
+ pattern = new int[6] ;
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.SEARCH_RESULT_ENTRY.getPrimitiveTag() ;
+ pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[3] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[4] = UniversalTag.SET_SET_OF.getPrimitiveTag() ;
+ pattern[5] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+ digester.addRule( pattern, new AddAttributeValueRule() ) ;
+ }
+
+
private void addAddRequestRules( BERDigester digester )
{
int[] pattern = new int[2] ;
@@ -121,7 +169,7 @@
pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
pattern[1] = LdapTag.ADD_REQUEST.getPrimitiveTag() ;
pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
- digester.addRule( pattern, new AttributesRule() ) ;
+ digester.addRule( pattern, new AddRequestAttributesRule() ) ;
pattern = new int[4] ;
pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryAttributesRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryAttributesRule.java Sun May 30 23:22:27 2004
@@ -0,0 +1,95 @@
+/*
+ * 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.TagEnum ;
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+import org.apache.snickers.ber.primitives.UniversalTag ;
+
+import org.apache.ldap.common.message.LockableAttributesImpl ;
+import org.apache.ldap.common.message.SearchResponseEntryImpl ;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseEntryAttributesRule extends AbstractRule
+{
+ /** the tag this rule expects to encounter */
+ private final TagEnum expected ;
+
+
+ /**
+ * Creates a new SearchResponseAttributesRule using an expected tag to
+ * enforce.
+ *
+ * @param expected the tag the rule must encounter to fire properly
+ */
+ public SearchResponseEntryAttributesRule( TagEnum expected )
+ {
+ this.expected = expected ;
+ }
+
+
+ /**
+ * Creates a new SearchResponseAttributesRule that expects a SEQUENCE tag.
+ */
+ public SearchResponseEntryAttributesRule()
+ {
+ this.expected = UniversalTag.SEQUENCE_SEQUENCE_OF ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.snickers.ber.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 != expected.getTagId() )
+ {
+ throw new IllegalArgumentException( "expected tag with id "
+ + expected.getTagId() + " for " + expected
+ + " but got " + id + "instead" ) ;
+ }
+
+ SearchResponseEntryImpl req = ( SearchResponseEntryImpl )
+ getDigester().peek() ;
+ LockableAttributesImpl attrs = new LockableAttributesImpl( req ) ;
+ req.setAttributes( attrs ); ;
+ getDigester().push( attrs ) ;
+ }
+
+
+ /* (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/java/org/apache/snickers/ldap/SearchResponseEntryDnRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryDnRule.java Sun May 30 23:22:27 2004
@@ -0,0 +1,82 @@
+/*
+ * 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.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.SearchResponseEntry ;
+
+import org.apache.snickers.ber.primitives.UniversalTag ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+
+/**
+ * A BERDigester rule to set the dn of the entry added with a
+ * SearchResponseEntry.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseEntryDnRule extends PrimitiveOctetStringRule
+{
+ public SearchResponseEntryDnRule()
+ {
+ 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 the SearchResponseEntry underneath whose octets we set
+ SearchResponseEntry req = ( SearchResponseEntry ) getDigester().peek() ;
+
+ 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.setObjectName( new String( octets ) ) ;
+ }
+}
Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseEntryRule.java Sun May 30 23:22:27 2004
@@ -0,0 +1,64 @@
+/*
+ * 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.SearchResponseEntryImpl ;
+
+
+/**
+ * A digester rule which fires to build SearchResponseEntry containment trees.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseEntryRule 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 )
+ {
+ super.tag( id, isPrimitive, typeClass ) ;
+
+ LdapTag tag = LdapTag.getLdapTagById( id ) ;
+
+ if ( LdapTag.SEARCH_RESULT_ENTRY != tag )
+ {
+ throw new IllegalArgumentException(
+ "Expected a SEARCH_RESULT_ENTRY tag id but got a " + tag ) ;
+ }
+
+ Object req = new SearchResponseEntryImpl( getDigester().popInt() ) ;
+ getDigester().push( req ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.snickers.ber.digester.Rule#finish()
+ */
+ public void finish()
+ {
+ super.finish() ;
+ getDigester().pop() ;
+ }
+}
Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AddRequestTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AddRequestTest.java (original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AddRequestTest.java Sun May 30 23:22:27 2004
@@ -28,7 +28,7 @@
/**
- * Tests the capability to end to end decode a BindRequest.
+ * Tests the capability to end to end decode a AddRequest.
*
* @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
* Project</a>
@@ -37,7 +37,7 @@
public class AddRequestTest extends RuleTestCase
{
/**
- * Tests a simple bind request decode.
+ * Tests an add request decode.
*/
public void testAddRequest() throws Exception
{
Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseEntryTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseEntryTest.java Sun May 30 23:22:27 2004
@@ -0,0 +1,78 @@
+/*
+ * 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.HashSet;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingEnumeration;
+
+import org.apache.ldap.common.message.*;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
+import org.apache.snickers.ldap.testutils.TestUtils;
+
+
+/**
+ * Tests the capability to end to end decode a SearchResultEntry.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseEntryTest extends RuleTestCase
+{
+ /**
+ * Tests a decode.
+ */
+ public void testAddRequest() throws Exception
+ {
+ SearchResponseEntryImpl resp = new SearchResponseEntryImpl( 33 ) ;
+ resp.setObjectName( "dc=example,dc=com" ) ;
+ LockableAttributesImpl attrs = new LockableAttributesImpl( resp ) ;
+ attrs.put( "objectClass", "top" ) ;
+ attrs.put( "objectClass", "dcObject" ) ;
+ attrs.put( "dc", "dc=example" ) ;
+ resp.setAttributes( attrs ); ;
+ System.out.println( "Generated SearchResultEntry for test:" ) ;
+ System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+ SearchResponseEntry decoded = ( SearchResponseEntry )
+ snickersDecode( snaccEncode( resp ) ) ;
+ assertNotNull( decoded ) ;
+ assertEquals( resp.getObjectName(), decoded.getObjectName() ) ;
+ Attributes decodedAttrs = decoded.getAttributes() ;
+ assertEquals( 2, decodedAttrs.size() ) ;
+ Attribute attr = decodedAttrs.get( "dc" ) ;
+ assertNotNull( attr ); ;
+ assertEquals( 1, attr.size() ) ;
+ assertEquals( "dc=example", attr.get() ) ;
+ attr = decodedAttrs.get( "objectClass" ) ;
+ assertEquals( 2, attr.size() ) ;
+
+ NamingEnumeration list = attr.getAll() ;
+ HashSet map = new HashSet() ;
+
+ while( list.hasMore() )
+ {
+ map.add( list.next() ) ;
+ }
+
+ assertTrue( map.contains( "top" ) ) ;
+ assertTrue( map.contains( "dcObject" ) ) ;
+ }
+}
\ No newline at end of file