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/08/24 04:12:01 UTC
svn commit: rev 36797 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder java/org/apache/snickers/ldap/encoder/search test/org/apache/snickers/ldap/encoder/search
Author: akarasulu
Date: Mon Aug 23 19:12:00 2004
New Revision: 36797
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/AttributeEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/AttributesEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseEntryEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseEntryEncoderTest.java
Log:
Commit changes ...
o created an Attribute encoder -> AttributeTypeAndValues (2251) TupleNode tree
o created an Attributes encoder -> AttributeList (2251) TupleNode tree
o created a SearchResponseEntry encoder -> SearchResultEntry (2251) TN tree
o created and passed unit tests for SearchResponseEntry encoder
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/AttributeEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/AttributeEncoder.java Mon Aug 23 19:12:00 2004
@@ -0,0 +1,96 @@
+/*
+ * 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.encoder;
+
+
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+
+
+/**
+ * An Attribute to a TupleNode tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a> $Rev$
+ */
+public class AttributeEncoder
+{
+ /** a thread safe instance of this encoder */
+ public static final AttributeEncoder INSTANCE = new AttributeEncoder();
+
+
+ /**
+ * Encodes an attribute into a TupleNode tree. The following ASN.1
+ * structure is the result:
+ * <code>
+ * SEQUENCE
+ * {
+ * type AttributeDescription,
+ * vals SET OF AttributeValue
+ * }
+ * </code>
+ *
+ * @param attr the Attribute to encode
+ * @return the root TupleNode of the tlv tree
+ */
+ public TupleNode encode( Attribute attr )
+ {
+ DefaultMutableTupleNode top =
+ new DefaultMutableTupleNode( new Tuple() );
+ top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+ top.getTuple().setLength( Length.INDEFINATE );
+
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( attr.getID() );
+ top.addLast( child );
+ child.setParent( top );
+
+ NamingEnumeration list = null;
+ try
+ {
+ list = attr.getAll();
+ }
+ catch ( NamingException e )
+ {
+ e.printStackTrace();
+ }
+
+ DefaultMutableTupleNode setOf =
+ new DefaultMutableTupleNode( new Tuple() );
+ setOf.getTuple().setTag( UniversalTag.SET_SET_OF, false );
+ setOf.getTuple().setLength( Length.INDEFINATE );
+
+ while ( list.hasMoreElements() )
+ {
+ child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( ( String ) list.nextElement() );
+ setOf.addLast( child );
+ child.setParent( setOf );
+ }
+
+ top.addLast( setOf );
+ setOf.setParent( top );
+ return top;
+ }
+}
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/AttributesEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/AttributesEncoder.java Mon Aug 23 19:12:00 2004
@@ -0,0 +1,67 @@
+/*
+ * 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.encoder;
+
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingEnumeration;
+
+
+/**
+ * An Attributes to TupleNode tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a> $Rev$
+ */
+public class AttributesEncoder
+{
+ /** a thread safe instance of this encoder */
+ public static final AttributesEncoder INSTANCE = new AttributesEncoder();
+
+
+ /**
+ * Encodes a set of Attributes into a TupleNode tree.
+ *
+ * @param attrs the Attributes to encode
+ * @return the root TupleNode of the tlv tree
+ */
+ public TupleNode encode( Attributes attrs )
+ {
+ DefaultMutableTupleNode top =
+ new DefaultMutableTupleNode( new Tuple() );
+ top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+ top.getTuple().setLength( Length.INDEFINATE );
+
+ NamingEnumeration list = attrs.getAll();
+ while ( list.hasMoreElements() )
+ {
+ Attribute attr = ( Attribute ) list.nextElement();
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ AttributeEncoder.INSTANCE.encode( attr );
+ top.addLast( child );
+ child.setParent( top );
+ }
+
+ return top;
+ }
+}
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseEntryEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseEntryEncoder.java Mon Aug 23 19:12:00 2004
@@ -0,0 +1,88 @@
+/*
+ * 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.encoder.search;
+
+
+import org.apache.ldap.common.message.SearchResponseEntry;
+
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ldap.encoder.AttributesEncoder;
+
+
+/**
+ * A SearchResponseEntry stub to tuple tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a> $Rev$
+ */
+public class SearchResponseEntryEncoder
+{
+ /** a thread safe instance of this encoder */
+ public static final SearchResponseEntryEncoder INSTANCE =
+ new SearchResponseEntryEncoder();
+
+
+ /**
+ * Encodes a SearchResponseEntry stub into a tree of TupleNodes.
+ *
+ * @param resp the SearchResponseEntry stub to encode
+ * @return the root TupleNode of the tlv tree
+ */
+ public TupleNode encode( SearchResponseEntry resp )
+ {
+ /// Create the top level TupleNode of the PDU
+ DefaultMutableTupleNode top =
+ new DefaultMutableTupleNode( new Tuple() );
+ top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+ top.getTuple().setLength( Length.INDEFINATE );
+
+ // Create and add the message id to response PDU
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( resp.getMessageId() );
+ top.addLast( child );
+ child.setParent( top );
+
+ // Create the search result entry response sequence of TLV tuple
+ DefaultMutableTupleNode entryResp =
+ new DefaultMutableTupleNode( new Tuple() );
+ entryResp.getTuple().setTag( LdapTag.SEARCH_RESULT_ENTRY, false );
+ entryResp.getTuple().setLength( Length.INDEFINATE );
+
+ // Create object name under the search entry sequence
+ child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( resp.getObjectName() );
+ entryResp.addLast( child );
+ child.setParent( entryResp );
+
+ // Encode the attributes and add them to the tree
+ child = ( DefaultMutableTupleNode )
+ AttributesEncoder.INSTANCE.encode( resp.getAttributes() );
+ entryResp.addLast( child );
+ child.setParent( top );
+
+ top.addLast( entryResp );
+ entryResp.setParent( top );
+ return top;
+ }
+}
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseEntryEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseEntryEncoderTest.java Mon Aug 23 19:12:00 2004
@@ -0,0 +1,55 @@
+/*
+ * 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.encoder.search;
+
+
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.ldap.common.message.*;
+
+
+/**
+ * TestCase for the SearchResponseEntryEncoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a> $Rev$
+ */
+public class SearchResponseEntryEncoderTest extends AbstractEncoderTestCase
+{
+ /**
+ * Tests the encoder's encode() method.
+ */
+ public void testEncode()
+ {
+ // Construct the Search response
+ SearchResponseEntryImpl response = new SearchResponseEntryImpl( 45 );
+ response.setObjectName( "dc=example,dc=com" );
+ LockableAttributesImpl attrs = new LockableAttributesImpl( response );
+ attrs.put( "objectClass", "top" );
+ attrs.put( "objectClass", "dcObject" );
+ attrs.put( "dc", "example.com" );
+ response.setAttributes( attrs );
+
+ // Encode stub into tuple tree then into the accumulator
+ TupleNode node = SearchResponseEntryEncoder.INSTANCE.encode( response );
+ encode( ( DefaultMutableTupleNode ) node );
+
+ // Test to see if original stub equals the round trip generated stub
+ assertTrue( response.equals( decode() ) );
+ }
+}