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/26 12:13:14 UTC

svn commit: rev 37072 - incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare

Author: akarasulu
Date: Thu Aug 26 03:13:11 2004
New Revision: 37072

Added:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/CompareRequestEncoder.java
Log:
adding initial compare request encoder

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/CompareRequestEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/CompareRequestEncoder.java	Thu Aug 26 03:13:11 2004
@@ -0,0 +1,103 @@
+/*
+ *   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.compare;
+
+
+import org.apache.ldap.common.message.CompareRequest;
+
+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.LdapTag;
+
+
+/**
+ * Encoder for CompareRequest stubs which generates a tree of tlv TupleNodes.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class CompareRequestEncoder
+{
+    /** thread safe (flyweight) instance of this encoder */
+    public static final CompareRequestEncoder INSTANCE =
+            new CompareRequestEncoder();
+
+
+    /**
+     * Ecodes CompareRequest stubs into TupleNode trees.
+     *
+     * @param request the CompareRequest stub to encode
+     * @return the root of the TupleNode tree
+     */
+    public TupleNode encode ( CompareRequest 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 top level TupleNode of the PDU
+        DefaultMutableTupleNode compareReq =
+                new DefaultMutableTupleNode( new Tuple() );
+        compareReq.getTuple().setTag( LdapTag.COMPARE_REQUEST, false );
+        compareReq.getTuple().setLength( Length.INDEFINATE );
+
+        // Add the compare name LDAPDN to the compareRequest
+        child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( request.getName() );
+        compareReq.addLast( child );
+        child.setParent( compareReq );
+
+        // Create the AttributeValueAssertion node
+        DefaultMutableTupleNode ava =
+                new DefaultMutableTupleNode( new Tuple() );
+        ava.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+        ava.getTuple().setLength( Length.INDEFINATE );
+
+        // Start adding the AttributeValueAssertion pair
+        child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( request.getAttributeId() );
+        ava.addLast( child );
+        child.setParent( ava );
+
+        child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( request.getAssertionValue() );
+        ava.addLast( child );
+        child.setParent( ava );
+
+        // Add the ava request to the compareRequest
+        compareReq.addLast( ava );
+        ava.setParent( compareReq );
+
+        // Add the compare Request to the top
+        top.addLast( compareReq );
+        compareReq.setParent( top );
+        return top;
+    }
+}