Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 21685 invoked from network); 26 Aug 2004 16:41:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 26 Aug 2004 16:41:42 -0000 Received: (qmail 26817 invoked by uid 500); 26 Aug 2004 16:41:42 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 26775 invoked by uid 500); 26 Aug 2004 16:41:42 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: directory-dev@incubator.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 26760 invoked by uid 99); 26 Aug 2004 16:41:41 -0000 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Thu, 26 Aug 2004 09:41:41 -0700 Received: (qmail 21648 invoked by uid 65534); 26 Aug 2004 16:41:40 -0000 Date: 26 Aug 2004 16:41:40 -0000 Message-ID: <20040826164140.21643.qmail@minotaur.apache.org> From: akarasulu@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: rev 37089 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap java/org/apache/snickers/ldap/encoder/extended test/org/apache/snickers/ldap/encoder/extended X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 Apache Directory + * Project + * @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 Apache Directory + * Project + * @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() ) ); + } +}