Author: akarasulu
Date: Thu Aug 26 08:37:42 2004
New Revision: 37085
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/ExtendedRequestEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/ExtendedRequestEncoderTest.java
Log:
Commit changes ...
o a lil convention cleanup
o added the complete ExtendedRequest encoder
o added and passed unit tests
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/ExtendedRequestEncoder.java
==============================================================================
--- (empty file)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/ExtendedRequestEncoder.java
Thu Aug 26 08:37:42 2004
@@ -0,0 +1,91 @@
+/*
+ * 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.extended;
+
+
+import org.apache.ldap.common.message.ExtendedRequest;
+
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+
+/**
+ * An extended request stub to tlv tree encoder.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedRequestEncoder
+{
+ /** thread safe (flyweight) instance of this encoder */
+ public static final ExtendedRequestEncoder INSTANCE =
+ new ExtendedRequestEncoder();
+
+
+ /**
+ * Encodes an ExtendedRequest stub into a TupleNode tree representing the
+ * tlv nesting of an ExtendedRequest PDU.
+ *
+ * @param request the ExtendedRequest to encode
+ * @return the root TupleNode of the tree
+ */
+ public TupleNode encode( ExtendedRequest request )
+ {
+ /// 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 PDU
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( request.getMessageId() );
+ top.addLast( child );
+ child.setParent( top );
+
+ // Create the search request sequence of TLV tuple
+ DefaultMutableTupleNode extendedReq =
+ new DefaultMutableTupleNode( new Tuple() );
+ extendedReq.getTuple().setTag( LdapTag.EXTENDED_REQUEST, false );
+ extendedReq.getTuple().setLength( Length.INDEFINATE );
+
+ // Add the tuple for the LDAPOID representing requestName
+ child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+ LdapTag.CONTEXT_SPECIFIC_TAG_0, request.getOid() );
+ extendedReq.addLast( child );
+ child.setParent( extendedReq );
+
+ // If it exists add the OPTIONAL extended request's requestValue
+ if ( request.getPayload() != null )
+ {
+ child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+ LdapTag.CONTEXT_SPECIFIC_TAG_1, request.getPayload() );
+ extendedReq.addLast( child );
+ child.setParent( extendedReq );
+ }
+
+ top.addLast( extendedReq );
+ extendedReq.setParent( top );
+ return top;
+ }
+}
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/ExtendedRequestEncoderTest.java
==============================================================================
--- (empty file)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/ExtendedRequestEncoderTest.java
Thu Aug 26 08:37:42 2004
@@ -0,0 +1,50 @@
+/*
+ * 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.extended;
+
+
+import junit.framework.TestCase;
+import org.apache.ldap.common.message.ExtendedRequestImpl;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ldap.encoder.search.SearchRequestEncoder;
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+
+
+/**
+ * TestCase for the ExtendedRequestEncoder class.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedRequestEncoderTest extends AbstractEncoderTestCase
+{
+ public void testEncode()
+ {
+ ExtendedRequestImpl request = new ExtendedRequestImpl( 23 );
+ request.setOid( "1.1.1.1" );
+ request.setPayload( "Hello World!".getBytes() );
+
+ // Encode stub into tuple tree then into the accumulator
+ TupleNode node = ExtendedRequestEncoder.INSTANCE.encode( request );
+ encode( ( DefaultMutableTupleNode ) node );
+
+ // Test to see if original stub equals the round trip generated stub
+ assertTrue( request.equals( decode() ) );
+ }
+}