Author: akarasulu
Date: Thu Aug 26 09:41:40 2004
New Revision: 37089
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/ExtendedResponseEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/ExtendedResponseEncoderTest.java
Modified:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
Log:
Commit changes ...
o created complete ExtendedResponse encoder
o created test case for encoder and passed tests
o added extra CONTEXT_SPECIFIC tags for extended responses to LdapTag
Modified:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
==============================================================================
---
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
(original)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
Thu Aug 26 09:41:40 2004
@@ -202,11 +202,19 @@
EXTENDED_RESPONSE_ID ) ;
- /** Context specific 6 tag */
+ /** Context specific 8 tag */
+ public static final ContextSpecificTag CONTEXT_SPECIFIC_TAG_11 =
+ new ContextSpecificTag( 11, true );
+
+ /** Context specific 8 tag */
+ public static final ContextSpecificTag CONTEXT_SPECIFIC_TAG_10 =
+ new ContextSpecificTag( 10, true );
+
+ /** Context specific 8 tag */
public static final ContextSpecificTag CONTEXT_SPECIFIC_TAG_8 =
new ContextSpecificTag( 8, true );
- /** Context specific 6 tag */
+ /** Context specific 7 tag */
public static final ContextSpecificTag CONTEXT_SPECIFIC_TAG_7 =
new ContextSpecificTag( 7, true );
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/ExtendedResponseEncoder.java
==============================================================================
--- (empty file)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/extended/ExtendedResponseEncoder.java
Thu Aug 26 09:41:40 2004
@@ -0,0 +1,98 @@
+/*
+ * 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.ExtendedResponse;
+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 org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ldap.encoder.LdapResultEncoder;
+import org.apache.snickers.ldap.LdapTag;
+
+/**
+ * An encoder that transforms a stub into a TupleNode tree representing the
+ * tlv nesting heirarchy.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedResponseEncoder
+{
+ /** thread safe (fly wieght) intance of this encoder */
+ public static final ExtendedResponseEncoder INSTANCE =
+ new ExtendedResponseEncoder();
+
+
+ /**
+ * Encodes an ExtendedResponse stub corresponding to a ExtendedResponse
+ * PDU into a TupleTree representing the TLV nesting heirarchy.
+ *
+ * @param response the ExtendedResponse to encode
+ * @return the root TLV tuple for the encoded SearchResultDone PDU
+ */
+ public TupleNode encode( ExtendedResponse response )
+ {
+ /// 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( response.getMessageId() );
+ top.addLast( child );
+ child.setParent( top );
+
+ // Create the extended response sequence of TLV tuple
+ DefaultMutableTupleNode extResp =
+ new DefaultMutableTupleNode( new Tuple() );
+ extResp.getTuple().setTag( LdapTag.EXTENDED_RESPONSE, false );
+ extResp.getTuple().setLength( Length.INDEFINATE );
+
+ // Stuff sequence of TLV tuple with the Components of the LDAPResult
+ LdapResultEncoder.INSTANCE.encode( extResp, response.getLdapResult() );
+
+ // add the response name nodes conditionally since they are OPTIONAL
+ if ( response.getResponseName() != null )
+ {
+ child = ( DefaultMutableTupleNode ) EncoderUtils
+ .encode( LdapTag.CONTEXT_SPECIFIC_TAG_10,
+ response.getResponseName() );
+ extResp.addLast( child );
+ child.setParent( extResp );
+ }
+
+ // add the response payload node conditionally since it is OPTIONAL
+ if ( response.getResponse() != null )
+ {
+ child = ( DefaultMutableTupleNode ) EncoderUtils
+ .encode( LdapTag.CONTEXT_SPECIFIC_TAG_11,
+ response.getResponse() );
+ extResp.addLast( child );
+ child.setParent( extResp );
+ }
+
+ top.addLast( extResp );
+ extResp.setParent( top );
+ return top;
+ }
+}
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/ExtendedResponseEncoderTest.java
==============================================================================
--- (empty file)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/extended/ExtendedResponseEncoderTest.java
Thu Aug 26 09:41:40 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 ExtendedResponseEncoderTest 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() ) );
+ }
+}