directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r441569 - /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlListAsn1Ber.java
Date Fri, 08 Sep 2006 16:53:59 GMT
Author: elecharny
Date: Fri Sep  8 09:53:58 2006
New Revision: 441569

URL: http://svn.apache.org/viewvc?view=rev&rev=441569
Log:
Created to handle a list of controls

Added:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlListAsn1Ber.java

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlListAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlListAsn1Ber.java?view=auto&rev=441569
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlListAsn1Ber.java
(added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlListAsn1Ber.java
Fri Sep  8 09:53:58 2006
@@ -0,0 +1,128 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.directory.shared.ldap.codec.asn1ber.messages;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.ValueException;
+import org.apache.directory.shared.ldap.codec.Decoder;
+import org.apache.directory.shared.ldap.codec.Encoder;
+import org.apache.directory.shared.ldap.codec.EncoderException;
+import org.apache.directory.shared.ldap.messages.ControlDecorator;
+import org.apache.directory.shared.ldap.utils.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * This class is a ASN.1 BER codec decorator. It adds coding and decoding
+ * behavior to the Controls list object. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ControlListAsn1Ber extends ControlDecorator implements Encoder, Decoder
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    static final long serialVersionUID = 2L;
+
+    /** The logger */
+    private static Logger log = LoggerFactory.getLogger( ControlListAsn1Ber.class );
+
+    /** A speedup for logger */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+    
+    /** The control length */
+    private transient int controlLength;
+    
+    /** The ID bytes */
+    private transient byte[] idBytes;
+
+    /**
+     * 
+     * Creates a new instance of BindRequestAsn1Ber.
+     *
+     * @param Controls The list of control objects to decorate
+     */
+    public ControlListAsn1Ber( Control controls )
+    {
+        super( controls );
+    }
+    
+    /**
+     * Compute the Control length 
+     * 
+     * Control : 
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x04 L2 controlType
+     *  [+--> 0x01 0x01 criticality] 
+     *  [+--> 0x04 L3 controlValue] 
+     *  
+     * Control length = Length(0x30) + length(L1) + Length(0x04) 
+     *   + Length(L2) + L2 
+     *  [+ Length(0x01) + 1 + 1] 
+     *  [+ Length(0x04) + Length(L3) + L3]
+     */
+    public int computeLength()
+    {
+        // The control ID         
+        idBytes = StringTools.getBytesUtf8( getID() );
+
+        controlLength = 1 + Length.getNbBytes( idBytes.length ) + idBytes.length;
+
+        // The criticality, only if true
+        if ( isCritical() )
+        {
+            controlLength += 1 + 1 + 1; // Always 3 for a boolean
+        }
+
+        // The control value, if any
+        if ( getControlValue() != null )
+        {
+            controlLength += 1 + Length.getNbBytes( getControlValue().length ) + getControlValue().length;
+        }
+
+        int length = 1 + Length.getNbBytes( controlLength ) + controlLength;
+        
+        if ( IS_DEBUG )
+        {
+            log.debug( "Control length : {}", length );
+        }
+        
+        return length;
+    }
+    
+    /**
+     * Encode the Control to a PDU
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException, ValueException
+    {
+        return buffer;
+    }
+}



Mime
View raw message