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 2011/01/23 23:59:25 UTC
svn commit: r1062565 -
/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlDecorator.java
Author: akarasulu
Date: Sun Jan 23 22:59:25 2011
New Revision: 1062565
URL: http://svn.apache.org/viewvc?rev=1062565&view=rev
Log:
an example for email being sent
Added:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlDecorator.java
- copied, changed from r1062546, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControl.java
Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlDecorator.java (from r1062546, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControl.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlDecorator.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlDecorator.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControl.java&r1=1062546&r2=1062565&rev=1062565&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControl.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlDecorator.java Sun Jan 23 22:59:25 2011
@@ -20,9 +20,6 @@
package org.apache.directory.shared.ldap.codec.controls;
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-
import org.apache.directory.shared.asn1.AbstractAsn1Object;
import org.apache.directory.shared.asn1.EncoderException;
import org.apache.directory.shared.asn1.ber.tlv.TLV;
@@ -32,42 +29,45 @@ import org.apache.directory.shared.i18n.
import org.apache.directory.shared.ldap.model.message.Control;
import org.apache.directory.shared.util.Strings;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
/**
- * A Asn1Object to store a Control.
+ * Example to show decorator application. The decorator interface is CodecControl which
+ * adds the additional functionality. This class would be the concrete decorator for the
+ * CodecControl. The decorated component is Control, and an example of a concrete
+ * decorated component would be LdifControl.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public abstract class AbstractControl extends AbstractAsn1Object implements Control, CodecControl
+public class CodecControlDecorator extends AbstractAsn1Object implements Control, CodecControl
{
// ~ Instance fields
// ----------------------------------------------------------------------------
- /** The control type */
- private String oid;
- /** The criticality (default value is false) */
- private boolean criticality = false;
+ /** The decorated Control */
+ private final Control decoratedComponent;
- /** Optional control value */
- protected byte[] value;
-
/** The encoded value length */
protected int valueLength;
/** The control length */
private int controlLength;
-
+
/** The control decoder */
protected ControlDecoder decoder;
+
/**
* Default constructor.
*/
- public AbstractControl( String oid )
+ public CodecControlDecorator( Control decoratedComponent)
{
- this.oid = oid;
+ this.decoratedComponent = decoratedComponent;
}
+
/**
* Get the OID
*
@@ -75,7 +75,7 @@ public abstract class AbstractControl ex
*/
public String getOid()
{
- return oid == null ? "" : oid;
+ return decoratedComponent.getOid();
}
@@ -86,25 +86,26 @@ public abstract class AbstractControl ex
*/
public byte[] getValue()
{
- return value;
+ return decoratedComponent.getValue();
}
/**
* Set the encoded control value
*
- * @param encodedValue The encoded control value to store
+ * @param value The encoded control value to store
*/
public void setValue( byte[] value )
{
if ( value != null )
{
- this.value = new byte[ value.length ];
- System.arraycopy( value, 0, this.value, 0, value.length );
+ byte[] copy = new byte[ value.length ];
+ System.arraycopy( value, 0, copy, 0, value.length );
+ decoratedComponent.setValue( copy );
}
else
{
- this.value = null;
+ decoratedComponent.setValue( null );
}
}
@@ -116,7 +117,7 @@ public abstract class AbstractControl ex
*/
public boolean isCritical()
{
- return criticality;
+ return decoratedComponent.isCritical();
}
@@ -127,7 +128,7 @@ public abstract class AbstractControl ex
*/
public void setCritical( boolean criticality )
{
- this.criticality = criticality;
+ decoratedComponent.setCritical( criticality );
}
@@ -146,11 +147,11 @@ public abstract class AbstractControl ex
public int computeLength( int valueLength )
{
// The OID
- int oidLengh = Strings.getBytesUtf8(oid).length;
+ int oidLengh = Strings.getBytesUtf8( getOid() ).length;
controlLength = 1 + TLV.getNbBytes( oidLengh ) + oidLengh;
// The criticality, only if true
- if ( criticality )
+ if ( isCritical() )
{
controlLength += 1 + 1 + 1; // Always 3 for a boolean
}
@@ -193,9 +194,9 @@ public abstract class AbstractControl ex
Value.encode( buffer, getOid().getBytes() );
// The control criticality, if true
- if ( criticality )
+ if ( isCritical() )
{
- Value.encode( buffer, criticality );
+ Value.encode( buffer, isCritical() );
}
return buffer;
@@ -207,7 +208,7 @@ public abstract class AbstractControl ex
*/
public boolean hasValue()
{
- return value != null;
+ return decoratedComponent.hasValue();
}
@@ -242,12 +243,12 @@ public abstract class AbstractControl ex
Control otherControl = ( Control ) o;
- if ( !oid.equalsIgnoreCase( otherControl.getOid() ) )
+ if ( !getOid().equalsIgnoreCase( otherControl.getOid() ) )
{
return false;
}
-
- if ( criticality != otherControl.isCritical() )
+
+ if ( isCritical() != otherControl.isCritical() )
{
return false;
}
@@ -264,13 +265,13 @@ public abstract class AbstractControl ex
StringBuffer sb = new StringBuffer();
sb.append( " Control\n" );
- sb.append( " Control oid : '" ).append( oid ).append(
+ sb.append( " Control oid : '" ).append( getOid() ).append(
"'\n" );
- sb.append( " Criticality : '" ).append( criticality ).append( "'\n" );
+ sb.append( " Criticality : '" ).append( isCritical() ).append( "'\n" );
- if ( value != null )
+ if ( getValue() != null )
{
- sb.append( " Control value : '" ).append( Strings.dumpBytes(value) )
+ sb.append( " Control value : '" ).append( Strings.dumpBytes( getValue() ) )
.append( "'\n" );
}