Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultDone/SearchResultDoneTest.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultDone/SearchResultDoneTest.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultDone/SearchResultDoneTest.java (original) +++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultDone/SearchResultDoneTest.java Mon Feb 1 15:04:10 2010 @@ -32,8 +32,8 @@ import org.apache.directory.shared.dsmlv2.AbstractResponseTest; import org.apache.directory.shared.dsmlv2.Dsmlv2ResponseParser; import org.apache.directory.shared.dsmlv2.reponse.SearchResponse; -import org.apache.directory.shared.ldap.codec.ControlCodec; import org.apache.directory.shared.ldap.codec.LdapResultCodec; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; import org.apache.directory.shared.ldap.codec.search.SearchResultDoneCodec; import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException; import org.apache.directory.shared.ldap.message.ResultCodeEnum; @@ -76,13 +76,13 @@ assertEquals( 1, searchResultDone.getControls().size() ); - ControlCodec control = searchResultDone.getCurrentControl(); + CodecControl control = searchResultDone.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.643", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); - assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) ); + assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getValue() ) ); } @@ -109,12 +109,12 @@ SearchResultDoneCodec searchResultDone = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse() ) .getSearchResultDone(); - ControlCodec control = searchResultDone.getCurrentControl(); + CodecControl control = searchResultDone.getCurrentControl(); assertEquals( 1, searchResultDone.getControls().size() ); - assertTrue( control.getCriticality() ); - assertEquals( "1.2.840.113556.1.4.643", control.getControlType() ); - assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() ); + assertTrue( control.isCritical() ); + assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); + assertFalse( control.hasValue() ); } @@ -144,13 +144,13 @@ assertEquals( 2, searchResultDone.getControls().size() ); - ControlCodec control = searchResultDone.getCurrentControl(); + CodecControl control = searchResultDone.getCurrentControl(); - assertFalse( control.getCriticality() ); + assertFalse( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.789", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.789", control.getOid() ); - assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) ); + assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getValue() ) ); } @@ -180,13 +180,13 @@ assertEquals( 3, searchResultDone.getControls().size() ); - ControlCodec control = searchResultDone.getCurrentControl(); + CodecControl control = searchResultDone.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.456", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.456", control.getOid() ); - assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() ); + assertFalse( control.hasValue() ); } Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java (original) +++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultEntry/SearchResultEntryTest.java Mon Feb 1 15:04:10 2010 @@ -21,23 +21,24 @@ package org.apache.directory.shared.dsmlv2.searchResponse.searchResultEntry; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.UnsupportedEncodingException; import java.util.Iterator; import org.apache.directory.shared.dsmlv2.AbstractResponseTest; import org.apache.directory.shared.dsmlv2.Dsmlv2ResponseParser; import org.apache.directory.shared.dsmlv2.reponse.SearchResponse; -import org.apache.directory.shared.ldap.codec.ControlCodec; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.util.StringTools; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assert.assertFalse; /** * Tests for the Search Result Entry Response parsing @@ -73,13 +74,13 @@ assertEquals( 1, searchResultEntry.getControls().size() ); - ControlCodec control = searchResultEntry.getCurrentControl(); + CodecControl control = searchResultEntry.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.643", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); - assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) ); + assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getValue() ) ); } @@ -106,12 +107,12 @@ SearchResultEntryCodec searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse() ) .getCurrentSearchResultEntry(); - ControlCodec control = searchResultEntry.getCurrentControl(); + CodecControl control = searchResultEntry.getCurrentControl(); assertEquals( 1, searchResultEntry.getControls().size() ); - assertTrue( control.getCriticality() ); - assertEquals( "1.2.840.113556.1.4.643", control.getControlType() ); - assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() ); + assertTrue( control.isCritical() ); + assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); + assertFalse( control.hasValue() ); } @@ -141,13 +142,13 @@ assertEquals( 2, searchResultEntry.getControls().size() ); - ControlCodec control = searchResultEntry.getCurrentControl(); + CodecControl control = searchResultEntry.getCurrentControl(); - assertFalse( control.getCriticality() ); + assertFalse( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.789", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.789", control.getOid() ); - assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) ); + assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getValue() ) ); } @@ -177,13 +178,13 @@ assertEquals( 3, searchResultEntry.getControls().size() ); - ControlCodec control = searchResultEntry.getCurrentControl(); + CodecControl control = searchResultEntry.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.456", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.456", control.getOid() ); - assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() ); + assertFalse( control.hasValue() ); } Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultReference/SearchResultReferenceTest.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultReference/SearchResultReferenceTest.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultReference/SearchResultReferenceTest.java (original) +++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchResponse/searchResultReference/SearchResultReferenceTest.java Mon Feb 1 15:04:10 2010 @@ -21,21 +21,22 @@ package org.apache.directory.shared.dsmlv2.searchResponse.searchResultReference; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.List; import org.apache.directory.shared.dsmlv2.AbstractResponseTest; import org.apache.directory.shared.dsmlv2.Dsmlv2ResponseParser; import org.apache.directory.shared.dsmlv2.reponse.SearchResponse; -import org.apache.directory.shared.ldap.codec.ControlCodec; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec; -import org.apache.directory.shared.ldap.util.LdapURL; import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException; +import org.apache.directory.shared.ldap.util.LdapURL; import org.apache.directory.shared.ldap.util.StringTools; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assert.assertFalse; /** * Tests for the Search Result Reference Response parsing @@ -71,13 +72,13 @@ assertEquals( 1, searchResultReference.getControls().size() ); - ControlCodec control = searchResultReference.getCurrentControl(); + CodecControl control = searchResultReference.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.643", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); - assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) ); + assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getValue() ) ); } @@ -107,13 +108,13 @@ assertEquals( 1, searchResultReference.getControls().size() ); - ControlCodec control = searchResultReference.getCurrentControl(); + CodecControl control = searchResultReference.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.643", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); - assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() ); + assertFalse( control.hasValue() ); } @@ -143,13 +144,13 @@ assertEquals( 2, searchResultReference.getControls().size() ); - ControlCodec control = searchResultReference.getCurrentControl(); + CodecControl control = searchResultReference.getCurrentControl(); - assertFalse( control.getCriticality() ); + assertFalse( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.789", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.789", control.getOid() ); - assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) ); + assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getValue() ) ); } @@ -179,13 +180,13 @@ assertEquals( 3, searchResultReference.getControls().size() ); - ControlCodec control = searchResultReference.getCurrentControl(); + CodecControl control = searchResultReference.getCurrentControl(); - assertTrue( control.getCriticality() ); + assertTrue( control.isCritical() ); - assertEquals( "1.2.840.113556.1.4.456", control.getControlType() ); + assertEquals( "1.2.840.113556.1.4.456", control.getOid() ); - assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() ); + assertFalse( control.hasValue() ); } Modified: directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/JndiUtils.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/JndiUtils.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/JndiUtils.java (original) +++ directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/JndiUtils.java Mon Feb 1 15:04:10 2010 @@ -22,8 +22,9 @@ import javax.naming.NamingException; import javax.naming.ldap.BasicControl; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; +import org.apache.directory.shared.ldap.codec.controls.CodecControlImpl; import org.apache.directory.shared.ldap.message.control.Control; -import org.apache.directory.shared.ldap.message.control.ControlImpl; /** * An utility class to convert back and forth JNDI classes to ADS classes. @@ -35,7 +36,7 @@ { public static javax.naming.ldap.Control toJndiControl( Control control ) { - byte[] value = control.getValue(); + byte[] value = ((CodecControl)control).getValue(); javax.naming.ldap.Control jndiControl = new BasicControl( control.getOid(), control.isCritical(), value ); return jndiControl; @@ -65,9 +66,8 @@ public static Control fromJndiControl( javax.naming.ldap.Control jndiControl ) { - Control control = new ControlImpl( jndiControl.getID() ); + Control control = new CodecControlImpl( jndiControl.getID() ); - control.setOid( jndiControl.getID() ); control.setValue( jndiControl.getEncodedValue() ); return control; Modified: directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java (original) +++ directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java Mon Feb 1 15:04:10 2010 @@ -20,7 +20,7 @@ package org.apache.directory.shared.ldap.ldif; -import org.apache.directory.shared.ldap.message.control.AbstractControl; +import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec; import org.apache.directory.shared.ldap.util.StringTools; /** @@ -30,15 +30,14 @@ * @author Apache Directory Project * @version $Rev$, $Date$ */ -public class LdifControl extends AbstractControl +public class LdifControl extends AbstractControlCodec { private static final long serialVersionUID = 1L; /** * Create a new Control * - * @param oid - * OID of the created control + * @param oid OID of the created control */ public LdifControl( String oid ) { Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java Mon Feb 1 15:04:10 2010 @@ -22,9 +22,10 @@ import java.nio.BufferOverflowException; import java.nio.ByteBuffer; - import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.directory.shared.asn1.AbstractAsn1Object; import org.apache.directory.shared.asn1.Asn1Object; @@ -39,6 +40,12 @@ import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec; import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec; import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; +import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControlCodec; +import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec; +import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlCodec; +import org.apache.directory.shared.ldap.codec.controls.replication.syncRequestValue.SyncRequestValueControlCodec; +import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlCodec; import org.apache.directory.shared.ldap.codec.del.DelRequestCodec; import org.apache.directory.shared.ldap.codec.del.DelResponseCodec; import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec; @@ -52,7 +59,11 @@ import org.apache.directory.shared.ldap.codec.search.SearchResultDoneCodec; import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec; import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec; +import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedResultsControlCodec; +import org.apache.directory.shared.ldap.codec.search.controls.persistentSearch.PersistentSearchControlCodec; +import org.apache.directory.shared.ldap.codec.search.controls.subentries.SubentriesControlCodec; import org.apache.directory.shared.ldap.codec.unbind.UnBindRequestCodec; +import org.apache.directory.shared.ldap.message.control.replication.SynchronizationInfoEnum; /** @@ -74,10 +85,10 @@ private Asn1Object protocolOp; /** The controls */ - private List controls; + private List controls; /** The current control */ - private ControlCodec currentControl; + private CodecControl currentControl; /** The LdapMessage length */ private int ldapMessageLength; @@ -88,6 +99,8 @@ /** The controls sequence length */ private int controlsSequenceLength; + private Map codecControls = new HashMap(); + // ~ Constructors // ------------------------------------------------------------------------------- @@ -99,6 +112,40 @@ { super(); // We should not create this kind of object directly + + // Initialize the different known Controls + CodecControl control = new PersistentSearchControlCodec(); + codecControls.put( control.getOid(), control ); + + control = new ManageDsaITControlCodec(); + codecControls.put( control.getOid(), control ); + + control = new SubentriesControlCodec(); + codecControls.put( control.getOid(), control ); + + control = new PagedResultsControlCodec(); + codecControls.put( control.getOid(), control ); + + control = new SyncDoneValueControlCodec(); + codecControls.put( control.getOid(), control ); + + control = new SyncInfoValueControlCodec( SynchronizationInfoEnum.NEW_COOKIE ); + codecControls.put( control.getOid(), control ); + + control = new SyncInfoValueControlCodec( SynchronizationInfoEnum.REFRESH_DELETE ); + codecControls.put( control.getOid(), control ); + + control = new SyncInfoValueControlCodec( SynchronizationInfoEnum.REFRESH_PRESENT ); + codecControls.put( control.getOid(), control ); + + control = new SyncInfoValueControlCodec( SynchronizationInfoEnum.SYNC_ID_SET ); + codecControls.put( control.getOid(), control ); + + control = new SyncRequestValueControlCodec(); + codecControls.put( control.getOid(), control ); + + control = new SyncStateValueControlCodec(); + codecControls.put( control.getOid(), control ); } @@ -111,7 +158,7 @@ * @param i The index of the Control Object to get * @return The selected Control Object */ - public ControlCodec getControls( int i ) + public CodecControl getControls( int i ) { if ( controls != null ) { @@ -129,7 +176,7 @@ * * @return The Control Objects */ - public List getControls() + public List getControls() { return controls; } @@ -140,10 +187,16 @@ * * @return The current Control Object */ - public ControlCodec getCurrentControl() + public CodecControl getCurrentControl() { return currentControl; } + + + public CodecControl getCodecControl( String oid ) + { + return codecControls.get( oid ); + } /** @@ -151,13 +204,13 @@ * * @param control The Control to add */ - public void addControl( ControlCodec control ) + public void addControl( CodecControl control ) { currentControl = control; if ( controls == null ) { - controls = new ArrayList(); + controls = new ArrayList(); } controls.add( control ); @@ -170,7 +223,7 @@ * * @param controls The list of Controls to set or add */ - public void addControls( List controls ) + public void addControls( List controls ) { if( this.controls == null ) { @@ -188,7 +241,7 @@ */ public void initControls() { - controls = new ArrayList(); + controls = new ArrayList(); } @@ -628,7 +681,7 @@ controlsSequenceLength = 0; // We may have more than one control. ControlsLength is L4. - for ( ControlCodec control:controls ) + for ( CodecControl control:controls ) { controlsSequenceLength += control.computeLength(); } @@ -657,6 +710,7 @@ * global PDU length * - second, we produce the PDU. * + *
      * 0x30 L1 
      *   | 
      *   +--> 0x02 L2 MessageId  
@@ -666,6 +720,7 @@
      * L2 = Length(MessageId)
      * L1 = Length(0x02) + Length(L2) + L2 + Length(ProtocolOp) + Length(Controls)
      * LdapMessageLength = Length(0x30) + Length(L1) + L1
+     * 
* * @param buffer The encoded PDU * @return A ByteBuffer that contaons the PDU @@ -703,7 +758,7 @@ bb.put( TLV.getBytes( controlsLength ) ); // Encode each control - for ( ControlCodec control:controls ) + for ( CodecControl control:controls ) { control.encode( bb ); } @@ -728,7 +783,7 @@ if ( controls != null ) { - for ( ControlCodec control:controls ) + for ( CodecControl control:controls ) { sb.append( control ); } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java Mon Feb 1 15:04:10 2010 @@ -21,6 +21,7 @@ import org.apache.directory.shared.asn1.ber.AbstractContainer; +import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec; import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector; @@ -47,7 +48,7 @@ private int messageId; /** The current control */ - private ControlCodec currentControl; + private AbstractControlCodec currentControl; // ~ Constructors // ------------------------------------------------------------------------------- @@ -147,7 +148,7 @@ /** * @return the current control being created */ - public ControlCodec getCurrentControl() + public AbstractControlCodec getCurrentControl() { return currentControl; } @@ -156,7 +157,7 @@ * Store a newly created control * @param currentControl The control to store */ - public void setCurrentControl( ControlCodec currentControl ) + public void setCurrentControl( AbstractControlCodec currentControl ) { this.currentControl = currentControl; } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Mon Feb 1 15:04:10 2010 @@ -79,6 +79,8 @@ import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication; import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec; import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; +import org.apache.directory.shared.ldap.codec.controls.CodecControlImpl; import org.apache.directory.shared.ldap.codec.del.DelRequestCodec; import org.apache.directory.shared.ldap.codec.del.DelResponseCodec; import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec; @@ -3470,7 +3472,6 @@ public void action( IAsn1Container container ) throws DecoderException { LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - LdapMessageCodec message = ldapMessageContainer.getLdapMessage(); TLV tlv = ldapMessageContainer.getCurrentTLV(); int expectedLength = tlv.getLength(); @@ -3483,12 +3484,6 @@ // This will generate a PROTOCOL_ERROR throw new DecoderException( "The length of a control must not be null" ); } - - // Create a new control - ControlCodec control = new ControlCodec(); - - // Store the control into the container - message.addControl( control ); } }; @@ -3522,7 +3517,7 @@ TLV tlv = ldapMessageContainer.getCurrentTLV(); // Get the current control - ControlCodec control = message.getCurrentControl(); + CodecControl control = null; // Store the type // We have to handle the special case of a 0 length OID @@ -3533,34 +3528,37 @@ // This will generate a PROTOCOL_ERROR throw new DecoderException( "The OID must not be null" ); } - else - { - byte[] value = tlv.getValue().getData(); - String oidValue = StringTools.asciiBytesToString( value ); - // The OID is encoded as a String, not an Object Id - try - { - new OID( oidValue ); - } - catch ( DecoderException de ) - { - log.error( "The control type " + StringTools.dumpBytes( value ) + " is not a valid OID : " - + de.getMessage() ); + byte[] value = tlv.getValue().getData(); + String oidValue = StringTools.asciiBytesToString( value ); - // This will generate a PROTOCOL_ERROR - throw de; - } + // The OID is encoded as a String, not an Object Id + if ( !OID.isOID( oidValue ) ) + { + log.error( "The control type " + StringTools.dumpBytes( value ) + " is not a valid OID" ); - control.setControlType( oidValue ); + // This will generate a PROTOCOL_ERROR + throw new DecoderException( "Invalid control OID : " + oidValue ); } + + // get the Control for this OID + control = message.getCodecControl( oidValue ); + + if ( control == null ) + { + // This control is unknown, we will create a neutral control + control = new CodecControlImpl( oidValue ); + } + + // The control may be null, if not known + message.addControl( control ); // We can have an END transition ldapMessageContainer.grammarEndAllowed( true ); if ( IS_DEBUG ) { - log.debug( "Control OID : " + control.getControlType() ); + log.debug( "Control OID : " + control.getOid() ); } } } ); @@ -3586,7 +3584,7 @@ TLV tlv = ldapMessageContainer.getCurrentTLV(); // Get the current control - ControlCodec control = message.getCurrentControl(); + CodecControl control = message.getCurrentControl(); // Store the criticality // We get the value. If it's a 0, it's a FALSE. If it's @@ -3599,7 +3597,7 @@ try { - control.setCriticality( BooleanDecoder.parse( value ) ); + control.setCritical( BooleanDecoder.parse( value ) ); } catch ( BooleanDecoderException bde ) { @@ -3615,7 +3613,7 @@ if ( IS_DEBUG ) { - log.debug( "Control criticality : " + control.getCriticality() ); + log.debug( "Control criticality : " + control.isCritical() ); } } } ); Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java Mon Feb 1 15:04:10 2010 @@ -38,11 +38,7 @@ import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication; import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec; import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec; -import org.apache.directory.shared.ldap.codec.controls.CascadeControlCodec; -import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec; -import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlCodec; -import org.apache.directory.shared.ldap.codec.controls.replication.syncRequestValue.SyncRequestValueControlCodec; -import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlCodec; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; import org.apache.directory.shared.ldap.codec.del.DelRequestCodec; import org.apache.directory.shared.ldap.codec.del.DelResponseCodec; import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec; @@ -64,9 +60,6 @@ import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec; import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec; import org.apache.directory.shared.ldap.codec.search.SubstringFilter; -import org.apache.directory.shared.ldap.codec.search.controls.pSearch.PSearchControlCodec; -import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedSearchControlCodec; -import org.apache.directory.shared.ldap.codec.search.controls.subEntry.SubEntryControlCodec; import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Modification; @@ -111,19 +104,7 @@ import org.apache.directory.shared.ldap.message.SearchResponseEntryImpl; import org.apache.directory.shared.ldap.message.SearchResponseReferenceImpl; import org.apache.directory.shared.ldap.message.UnbindRequestImpl; -import org.apache.directory.shared.ldap.message.control.CascadeControl; import org.apache.directory.shared.ldap.message.control.Control; -import org.apache.directory.shared.ldap.message.control.ControlImpl; -import org.apache.directory.shared.ldap.message.control.PagedSearchControl; -import org.apache.directory.shared.ldap.message.control.PersistentSearchControl; -import org.apache.directory.shared.ldap.message.control.SubentriesControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncDoneValueControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncInfoValueNewCookieControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncInfoValueRefreshDeleteControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncInfoValueRefreshPresentControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncInfoValueSyncIdSetControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncRequestValueControl; -import org.apache.directory.shared.ldap.message.control.replication.SyncStateValueControl; import org.apache.directory.shared.ldap.message.extended.GracefulShutdownRequest; import org.apache.directory.shared.ldap.name.LdapDN; import org.apache.directory.shared.ldap.util.LdapURL; @@ -883,7 +864,7 @@ case ( LdapConstants.EXTENDED_REQUEST ): internalMessage = transformExtendedRequest( codecMessage, messageId ); break; - + case ( LdapConstants.BIND_RESPONSE ): internalMessage = transformBindResponse( codecMessage, messageId ); break; @@ -901,165 +882,13 @@ // Nothing to do ! break; + default: throw new IllegalStateException( "shouldn't happen - if it does then we have issues" ); } // Transform the controls, too - List codecControls = codecMessage.getControls(); - - if ( codecControls != null ) - { - for ( final ControlCodec codecControl:codecControls ) - { - Control neutralControl = null; - - if ( codecControl.getControlValue() instanceof CascadeControlCodec ) - { - neutralControl = new CascadeControl(); - neutralControl.setCritical( codecControl.getCriticality() ); - } - else if ( codecControl.getControlValue() instanceof PSearchControlCodec ) - { - PersistentSearchControl neutralPsearch = new PersistentSearchControl(); - neutralControl = neutralPsearch; - PSearchControlCodec codecPsearch = ( PSearchControlCodec ) codecControl.getControlValue(); - neutralPsearch.setChangeTypes( codecPsearch.getChangeTypes() ); - neutralPsearch.setChangesOnly( codecPsearch.isChangesOnly() ); - neutralPsearch.setReturnECs( codecPsearch.isReturnECs() ); - neutralPsearch.setCritical( codecControl.getCriticality() ); - } - else if ( codecControl.getControlValue() instanceof SubEntryControlCodec ) - { - SubentriesControl neutralSubentriesControl = new SubentriesControl(); - SubEntryControlCodec codecSubentriesControl = ( SubEntryControlCodec ) codecControl.getControlValue(); - neutralControl = neutralSubentriesControl; - neutralSubentriesControl.setVisibility( codecSubentriesControl.isVisible() ); - neutralSubentriesControl.setCritical( codecControl.getCriticality() ); - } - else if ( codecControl.getControlValue() instanceof PagedSearchControlCodec ) - { - PagedSearchControl neutralPagedSearchControl = new PagedSearchControl(); - neutralControl = neutralPagedSearchControl; - PagedSearchControlCodec codecPagedSearchControl = (PagedSearchControlCodec)codecControl.getControlValue(); - neutralPagedSearchControl.setCookie( codecPagedSearchControl.getCookie() ); - neutralPagedSearchControl.setSize( codecPagedSearchControl.getSize() ); - neutralPagedSearchControl.setCritical( codecControl.getCriticality() ); - } - else if ( codecControl.getControlValue() instanceof SyncDoneValueControlCodec ) - { - SyncDoneValueControl neutralSyncDoneValueControl = new SyncDoneValueControl(); - SyncDoneValueControlCodec codecSyncDoneValueControl = (SyncDoneValueControlCodec)codecControl.getControlValue(); - neutralControl = neutralSyncDoneValueControl; - neutralSyncDoneValueControl.setCritical( codecControl.getCriticality() ); - neutralSyncDoneValueControl.setCookie( codecSyncDoneValueControl.getCookie() ); - neutralSyncDoneValueControl.setRefreshDeletes( codecSyncDoneValueControl.isRefreshDeletes() ); - } - else if ( codecControl.getControlValue() instanceof SyncInfoValueControlCodec ) - { - SyncInfoValueControlCodec codecSyncInfoValueControlCodec = (SyncInfoValueControlCodec)codecControl.getControlValue(); - - switch ( codecSyncInfoValueControlCodec.getType() ) - { - case NEW_COOKIE : - SyncInfoValueNewCookieControl neutralSyncInfoValueNewCookieControl = new SyncInfoValueNewCookieControl(); - neutralControl = neutralSyncInfoValueNewCookieControl; - neutralSyncInfoValueNewCookieControl.setCritical( codecControl.getCriticality() ); - neutralSyncInfoValueNewCookieControl.setCookie( codecSyncInfoValueControlCodec.getCookie() ); - - break; - - case REFRESH_DELETE : - SyncInfoValueRefreshDeleteControl neutralSyncInfoValueRefreshDeleteControl = new SyncInfoValueRefreshDeleteControl(); - neutralControl = neutralSyncInfoValueRefreshDeleteControl; - neutralSyncInfoValueRefreshDeleteControl.setCritical( codecControl.getCriticality() ); - neutralSyncInfoValueRefreshDeleteControl.setCookie( codecSyncInfoValueControlCodec.getCookie() ); - neutralSyncInfoValueRefreshDeleteControl.setRefreshDone( codecSyncInfoValueControlCodec.isRefreshDone() ); - - break; - - case REFRESH_PRESENT : - SyncInfoValueRefreshPresentControl neutralSyncInfoValueRefreshPresentControl = new SyncInfoValueRefreshPresentControl(); - neutralControl = neutralSyncInfoValueRefreshPresentControl; - neutralSyncInfoValueRefreshPresentControl.setCritical( codecControl.getCriticality() ); - neutralSyncInfoValueRefreshPresentControl.setCookie( codecSyncInfoValueControlCodec.getCookie() ); - neutralSyncInfoValueRefreshPresentControl.setRefreshDone( codecSyncInfoValueControlCodec.isRefreshDone() ); - - break; - - case SYNC_ID_SET : - SyncInfoValueSyncIdSetControl neutralSyncInfoValueSyncIdSetControl = new SyncInfoValueSyncIdSetControl(); - neutralControl = neutralSyncInfoValueSyncIdSetControl; - neutralSyncInfoValueSyncIdSetControl.setCritical( codecControl.getCriticality() ); - neutralSyncInfoValueSyncIdSetControl.setCookie( codecSyncInfoValueControlCodec.getCookie() ); - neutralSyncInfoValueSyncIdSetControl.setRefreshDeletes( codecSyncInfoValueControlCodec.isRefreshDeletes() ); - - List uuids = codecSyncInfoValueControlCodec.getSyncUUIDs(); - - if ( uuids != null ) - { - for ( byte[] uuid:uuids ) - { - neutralSyncInfoValueSyncIdSetControl.addSyncUUID( uuid ); - } - } - - break; - } - } - else if ( codecControl.getControlValue() instanceof SyncRequestValueControlCodec ) - { - SyncRequestValueControl neutralSyncRequestValueControl = new SyncRequestValueControl(); - SyncRequestValueControlCodec codecSyncDoneValueControlCodec = (SyncRequestValueControlCodec)codecControl.getControlValue(); - neutralControl = neutralSyncRequestValueControl; - neutralSyncRequestValueControl.setCritical( codecControl.getCriticality() ); - neutralSyncRequestValueControl.setMode( codecSyncDoneValueControlCodec.getMode() ); - neutralSyncRequestValueControl.setCookie( codecSyncDoneValueControlCodec.getCookie() ); - neutralSyncRequestValueControl.setReloadHint( codecSyncDoneValueControlCodec.isReloadHint() ); - } - else if ( codecControl.getControlValue() instanceof SyncStateValueControl ) - { - SyncStateValueControl neutralSyncStateValueControl = new SyncStateValueControl(); - SyncStateValueControlCodec codecSyncStateValueControlCodec = (SyncStateValueControlCodec)codecControl.getControlValue(); - neutralControl = neutralSyncStateValueControl; - neutralSyncStateValueControl.setCritical( codecControl.getCriticality() ); - neutralSyncStateValueControl.setSyncStateType( codecSyncStateValueControlCodec.getSyncStateType() ); - neutralSyncStateValueControl.setEntryUUID( codecSyncStateValueControlCodec.getEntryUUID() ); - neutralSyncStateValueControl.setCookie( codecSyncStateValueControlCodec.getCookie() ); - } - else if ( codecControl.getControlValue() instanceof byte[] ) - { - neutralControl = new ControlImpl( codecControl.getControlType() ) - { - public byte[] getValue() - { - return ( byte[] ) codecControl.getControlValue(); - } - }; - - // Codec : boolean criticality -> Internal : boolean - // m_isCritical - neutralControl.setCritical( codecControl.getCriticality() ); - } - else if ( codecControl.getControlValue() == null ) - { - neutralControl = new ControlImpl( codecControl.getControlType() ) - { - public byte[] getValue() - { - return ( byte[] ) codecControl.getControlValue(); - } - }; - - // Codec : boolean criticality -> Internal : boolean - // m_isCritical - neutralControl.setCritical( codecControl.getCriticality() ); - } - - - internalMessage.add( neutralControl ); - } - } + transformControlsCodecToInternal( codecMessage, internalMessage ); return internalMessage; } @@ -1460,12 +1289,15 @@ transformExtendedResponse( codecMessage, msg ); break; + case INTERMEDIATE_RESP : + //transformIntermediateResponse( codecMessage, msg ); + break; } // We also have to transform the controls... if ( !msg.getControls().isEmpty() ) { - transformControls( codecMessage, msg ); + transformControlsInternalToCodec( codecMessage, msg ); } if ( IS_DEBUG ) @@ -1478,22 +1310,22 @@ /** - * TODO finish this implementation. Takes Codec Controls, transforming + * TODO finish this implementation. Takes Codec Controls, transforming * them to Internal Controls and populates the Internal message with them. * * @param codecMessage the Codec message * @param msg the Internal message */ - private static void transformControlsCodecToInternal( LdapMessageCodec codecMessage, InternalMessage msg ) + private static void transformControlsCodecToInternal( LdapMessageCodec codecMessage, InternalMessage internalMessage ) { if ( codecMessage.getControls() == null ) { return; } - for ( ControlCodec control:codecMessage.getControls() ) + for ( final CodecControl codecControl:codecMessage.getControls() ) { - LOG.debug( "Not decoding response control: {}", control ); + internalMessage.add( codecControl ); } } @@ -1501,21 +1333,18 @@ /** * Transforms the controls * @param codecMessage The Codec SearchResultReference to produce - * @param msg The incoming Internal SearchResponseReference + * @param msg The incoming Internal Message */ - private static void transformControls( LdapMessageCodec codecMessage, InternalMessage msg ) + private static void transformControlsInternalToCodec( LdapMessageCodec codecMessage, InternalMessage internalMessage ) { - for ( Control control:msg.getControls().values() ) + if ( internalMessage.getControls() == null ) { - ControlCodec codecControl = new ControlCodec(); - codecMessage.addControl( codecControl ); - codecControl.setCriticality( control.isCritical() ); - - byte[] encodedValue = control.getValue(); - codecControl.setControlValue( encodedValue ); - codecControl.setEncodedValue( encodedValue ); - codecControl.setControlType( control.getOid() ); - codecControl.setParent( codecMessage ); + return; + } + + for ( Control control:internalMessage.getControls().values() ) + { + codecMessage.addControl( (CodecControl)control ); } } } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java Mon Feb 1 15:04:10 2010 @@ -20,28 +20,16 @@ package org.apache.directory.shared.ldap.codec.actions; -import java.util.HashMap; -import java.util.Map; - import org.apache.directory.shared.asn1.ber.IAsn1Container; import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; import org.apache.directory.shared.asn1.ber.tlv.TLV; import org.apache.directory.shared.asn1.ber.tlv.Value; import org.apache.directory.shared.asn1.codec.DecoderException; -import org.apache.directory.shared.ldap.codec.ControlCodec; -import org.apache.directory.shared.ldap.codec.ControlDecoder; import org.apache.directory.shared.ldap.codec.LdapMessageCodec; import org.apache.directory.shared.ldap.codec.LdapMessageContainer; -import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControlDecoder; -import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlDecoder; -import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlDecoder; -import org.apache.directory.shared.ldap.codec.controls.replication.syncRequestValue.SyncRequestValueControlDecoder; -import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlDecoder; -import org.apache.directory.shared.ldap.codec.search.controls.pSearch.PSearchControlDecoder; -import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedSearchControlDecoder; -import org.apache.directory.shared.ldap.codec.search.controls.subEntry.SubEntryControlDecoder; +import org.apache.directory.shared.ldap.codec.controls.CodecControl; +import org.apache.directory.shared.ldap.codec.controls.ControlDecoder; import org.apache.directory.shared.ldap.util.StringTools; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,39 +50,6 @@ /** Speedup for logs */ private static final boolean IS_DEBUG = log.isDebugEnabled(); - private static Map controlDecoders = new HashMap(); - - - public ControlValueAction() - { - super( "Sets the control value" ); - - ControlDecoder decoder; - decoder = new PSearchControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new ManageDsaITControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new SubEntryControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new PagedSearchControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new SyncDoneValueControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new SyncInfoValueControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new SyncRequestValueControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - - decoder = new SyncStateValueControlDecoder(); - controlDecoders.put( decoder.getControlType(), decoder ); - } - public void action( IAsn1Container container ) throws DecoderException { @@ -103,32 +58,27 @@ LdapMessageCodec message = ldapMessageContainer.getLdapMessage(); // Get the current control - ControlCodec control = message.getCurrentControl(); + CodecControl control = message.getCurrentControl(); Value value = tlv.getValue(); - ControlDecoder decoder = controlDecoders.get( control.getControlType() ); + ControlDecoder decoder = control.getDecoder(); // Store the value - have to handle the special case of a 0 length value if ( tlv.getLength() == 0 ) { - control.setControlValue( new byte[] - {} ); + control.setValue( StringTools.EMPTY_BYTES ); } else { - Object decoded; - - if ( decoder != null ) + if ( decoder == null ) { - decoded = decoder.decode( value.getData() ); + // No decoder : store the raw value + control.setValue( value.getData() ); } else { - decoded = value.getData(); + decoder.decode( value.getData(), control ); } - - control.setEncodedValue( value.getData() ); - control.setControlValue( decoded ); } // We can have an END transition @@ -136,18 +86,7 @@ if ( IS_DEBUG ) { - if ( control.getControlValue() instanceof byte[] ) - { - log.debug( "Control value : " + StringTools.dumpBytes( ( byte[] ) control.getControlValue() ) ); - } - else if ( control.getControlValue() instanceof String ) - { - log.debug( "Control value : " + ( String ) control.getControlValue() ); - } - else - { - log.debug( "Control value : " + control.getControlValue() ); - } + log.debug( "Control value : " + StringTools.dumpBytes( ( byte[] ) control.getValue() ) ); } } } Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControlCodec.java (from r903704, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ControlCodec.java) URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControlCodec.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControlCodec.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ControlCodec.java&r1=903704&r2=905297&rev=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ControlCodec.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/AbstractControlCodec.java Mon Feb 1 15:04:10 2010 @@ -17,14 +17,13 @@ * under the License. * */ -package org.apache.directory.shared.ldap.codec; +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.Asn1Object; import org.apache.directory.shared.asn1.ber.tlv.TLV; import org.apache.directory.shared.asn1.ber.tlv.UniversalTag; import org.apache.directory.shared.asn1.ber.tlv.Value; @@ -38,25 +37,26 @@ * @author Apache Directory Project * @version $Rev$, $Date$, */ -public class ControlCodec extends AbstractAsn1Object +public abstract class AbstractControlCodec extends AbstractAsn1Object implements CodecControl { // ~ Instance fields // ---------------------------------------------------------------------------- - /** The control type */ - private String controlType; + private String oid; /** The criticality (default value is false) */ private boolean criticality = false; - /** Optionnal control value */ - private Object controlValue; - - /** Optionnal control value in encoded form */ - private byte[] encodedValue; + /** Optional control value */ + protected byte[] value; + + /** The encoded value length */ + protected int valueLength; /** The control length */ private int controlLength; + + protected ControlDecoder decoder; // ~ Methods // ------------------------------------------------------------------------------------ @@ -64,30 +64,19 @@ /** * Default constructor. */ - public ControlCodec() - { - super(); - } - - /** - * Get the control type - * - * @return A string which represent the control type - */ - public String getControlType() + public AbstractControlCodec( String oid ) { - return controlType == null ? "" : controlType; + this.oid = oid; } - /** - * Set the control type + * Get the OID * - * @param controlType The OID to be stored + * @return A string which represent the control oid */ - public void setControlType( String controlType ) + public String getOid() { - this.controlType = controlType; + return oid == null ? "" : oid; } @@ -96,20 +85,9 @@ * * @return The control value */ - public Object getControlValue() + public byte[] getValue() { - if ( controlValue == null ) - { - return StringTools.EMPTY_BYTES; - } - else if ( controlValue instanceof String ) - { - return StringTools.getBytesUtf8( ( String ) controlValue ); - } - else - { - return controlValue; - } + return value; } @@ -118,44 +96,17 @@ * * @param encodedValue The encoded control value to store */ - public void setEncodedValue( byte[] encodedValue ) + public void setValue( byte[] value ) { - if ( encodedValue != null ) + if ( value != null ) { - this.encodedValue = new byte[ encodedValue.length ]; - System.arraycopy( encodedValue, 0, this.encodedValue, 0, encodedValue.length ); - } else { - this.encodedValue = null; - } - } - - - /** - * Get the raw control encoded bytes - * - * @return the encoded bytes for the control - */ - public byte[] getEncodedValue() - { - if ( encodedValue == null ) + this.value = new byte[ value.length ]; + System.arraycopy( value, 0, this.value, 0, value.length ); + } + else { - return StringTools.EMPTY_BYTES; + this.value = null; } - - final byte[] copy = new byte[ encodedValue.length ]; - System.arraycopy( encodedValue, 0, copy, 0, encodedValue.length ); - return copy; - } - - - /** - * Set the control value - * - * @param controlValue The control value to store - */ - public void setControlValue( Object controlValue ) - { - this.controlValue = controlValue; } @@ -164,7 +115,7 @@ * * @return true if the criticality flag is true. */ - public boolean getCriticality() + public boolean isCritical() { return criticality; } @@ -175,32 +126,29 @@ * * @param criticality The criticality value */ - public void setCriticality( boolean criticality ) + public void setCritical( boolean criticality ) { this.criticality = criticality; } - + /** - * 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] + * {@inheritDoc} */ public int computeLength() { - // The controlType - int controlTypeLengh = StringTools.getBytesUtf8( controlType ).length; - controlLength = 1 + TLV.getNbBytes( controlTypeLengh ) + controlTypeLengh; + return 0; + } + + + /** + * {@inheritDoc} + */ + public int computeLength( int valueLength ) + { + // The OID + int oidLengh = StringTools.getBytesUtf8( oid ).length; + controlLength = 1 + TLV.getNbBytes( oidLengh ) + oidLengh; // The criticality, only if true if ( criticality ) @@ -208,50 +156,27 @@ controlLength += 1 + 1 + 1; // Always 3 for a boolean } - // The control value, if any - if ( controlValue != null ) + this.valueLength = valueLength; + + if ( valueLength != 0 ) { - byte[] controlBytes; - if ( controlValue instanceof byte[] ) - { - controlBytes = ( byte[] ) controlValue; - controlLength += 1 + TLV.getNbBytes( controlBytes.length ) + controlBytes.length; - } - else if ( controlValue instanceof String ) - { - controlBytes = StringTools.getBytesUtf8( ( String ) controlValue ); - controlLength += 1 + TLV.getNbBytes( controlBytes.length ) + controlBytes.length; - } - else if ( controlValue instanceof Asn1Object ) - { - int length = ( ( Asn1Object ) controlValue ).computeLength(); - controlLength += 1 + TLV.getNbBytes( length ) + length; - } - else - { - throw new IllegalStateException( "Don't know how to handle control value class " - + controlValue.getClass() ); - } + controlLength += 1 + TLV.getNbBytes( valueLength ) + valueLength; } - + return 1 + TLV.getNbBytes( controlLength ) + controlLength; } /** - * Generate the PDU which contains the Control. - * Control : - * 0x30 LL - * 0x04 LL type - * [0x01 0x01 criticality] - * [0x04 LL value] - * - * @param buffer The encoded PDU - * @return A ByteBuffer that contaons the PDU - * @throws EncoderException If anything goes wrong. + * {@inheritDoc} */ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { + if ( buffer == null ) + { + throw new EncoderException( "Cannot put a PDU in a null buffer !" ); + } + try { // The LdapMessage Sequence @@ -266,7 +191,7 @@ } // The control type - Value.encode( buffer, getControlType().getBytes() ); + Value.encode( buffer, getOid().getBytes() ); // The control criticality, if true if ( criticality ) @@ -274,36 +199,23 @@ Value.encode( buffer, criticality ); } - // The control value, if any - if ( controlValue != null ) - { - byte[] controlBytes; - if ( controlValue instanceof byte[] ) - { - controlBytes = ( byte[] ) controlValue; - encodedValue = controlBytes; - } - else if ( controlValue instanceof String ) - { - controlBytes = StringTools.getBytesUtf8( ( String ) controlValue ); - encodedValue = controlBytes; - } - else if ( controlValue instanceof Asn1Object ) - { - controlBytes = ( ( Asn1Object ) controlValue ).encode( null ).array(); - encodedValue = controlBytes; - } - else - { - throw new IllegalStateException( "Don't know how to handle control value class " - + controlValue.getClass() ); - } - - Value.encode( buffer, controlBytes ); - } - return buffer; } + + + /** + * {@inheritDoc} + */ + public boolean hasValue() + { + return value != null; + } + + + public ControlDecoder getDecoder() + { + return decoder; + } /** @@ -314,21 +226,14 @@ StringBuffer sb = new StringBuffer(); sb.append( " Control\n" ); - sb.append( " Control type : '" ).append( controlType ).append( + sb.append( " Control oid : '" ).append( oid ).append( "'\n" ); sb.append( " Criticality : '" ).append( criticality ).append( "'\n" ); - if ( controlValue != null ) + if ( value != null ) { - if ( controlValue instanceof byte[] ) - { - sb.append( " Control value : '" ).append( StringTools.dumpBytes( ( byte[] ) controlValue ) ) - .append( "'\n" ); - } - else - { - sb.append( " Control value : '" ).append( controlValue ).append( "'\n" ); - } + sb.append( " Control value : '" ).append( StringTools.dumpBytes( value ) ) + .append( "'\n" ); } return sb.toString(); Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlCodec.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlCodec.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlCodec.java Mon Feb 1 15:04:10 2010 @@ -20,10 +20,6 @@ package org.apache.directory.shared.ldap.codec.controls; -import java.nio.ByteBuffer; - -import org.apache.directory.shared.asn1.AbstractAsn1Object; -import org.apache.directory.shared.asn1.codec.EncoderException; /** @@ -31,9 +27,10 @@ * @author Apache Directory Project * @version $Rev$ */ -public class CascadeControlCodec extends AbstractAsn1Object +public class CascadeControlCodec extends AbstractControlCodec { - private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate( 0 ); + /** The cascade control OID */ + public static final String CONTROL_OID = "1.3.6.1.4.1.18060.0.0.1"; /** * Default constructor @@ -41,23 +38,33 @@ */ public CascadeControlCodec() { - super(); + super( CONTROL_OID ); + + decoder = new CascadeControlDecoder(); } + /** - * Returns 0 everytime. + * Returns the default control length. */ public int computeLength() { - return 0; + // Call the super class to compute the global control length + return super.computeLength( 0 ); } - + /** - * Encodes the control: does nothing but returns an empty buffer. + * Return a String representing this Cascade Control. */ - public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException + public String toString() { - return EMPTY_BUFFER; + StringBuffer sb = new StringBuffer(); + + sb.append( " Cascade Control\n" ); + sb.append( " oid : " ).append( getOid() ).append( '\n' ); + sb.append( " critical : " ).append( isCritical() ).append( '\n' ); + + return sb.toString(); } } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlDecoder.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlDecoder.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CascadeControlDecoder.java Mon Feb 1 15:04:10 2010 @@ -22,8 +22,6 @@ import org.apache.directory.shared.asn1.Asn1Object; import org.apache.directory.shared.asn1.codec.DecoderException; -import org.apache.directory.shared.ldap.codec.ControlDecoder; -import org.apache.directory.shared.ldap.message.control.CascadeControl; /** @@ -34,13 +32,7 @@ */ public class CascadeControlDecoder implements ControlDecoder { - public String getControlType() - { - return CascadeControl.CONTROL_OID; - } - - - public Asn1Object decode( byte[] controlBytes ) throws DecoderException + public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException { return new CascadeControlCodec(); } Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControl.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControl.java?rev=905297&view=auto ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControl.java (added) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControl.java Mon Feb 1 15:04:10 2010 @@ -0,0 +1,77 @@ +/* + * 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.controls; + +import java.nio.ByteBuffer; + +import org.apache.directory.shared.asn1.codec.EncoderException; +import org.apache.directory.shared.ldap.message.control.Control; + +/** + * Define the transform method to be implemented by all the codec Controls + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public interface CodecControl extends Control +{ + /** + * Generate the PDU which contains the Control. + *
 
+     * Control : 
+     * 
+     * 0x30 LL
+     *   0x04 LL type 
+     *   [0x01 0x01 criticality]
+     *   [0x04 LL value]
+     * 
+ * @param buffer The encoded PDU + * @return A ByteBuffer that contaons the PDU + * @throws EncoderException If anything goes wrong. + */ + ByteBuffer encode( ByteBuffer buffer ) throws EncoderException; + + + /** + * 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]
+     * 
+ */ + int computeLength(); + + /** + * Get the associated decoder + * + * @return The Control decoder + */ + ControlDecoder getDecoder(); +} Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlImpl.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlImpl.java?rev=905297&view=auto ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlImpl.java (added) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/CodecControlImpl.java Mon Feb 1 15:04:10 2010 @@ -0,0 +1,124 @@ +/* + * 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.controls; + + +import java.nio.ByteBuffer; + +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.EncoderException; +import org.apache.directory.shared.ldap.util.StringTools; + + +/** + * A genericcodec Control. + * + * @author Apache Directory Project + * @version $Rev: 764131 $, $Date: 2009-04-11 03:03:00 +0200 (Sat, 11 Apr 2009) $, + */ +public class CodecControlImpl extends AbstractControlCodec +{ + /** + * Default constructor. + */ + public CodecControlImpl( String oid ) + { + super( oid ); + + decoder = null; + } + + + /** + * Set the encoded control value + * + * @param encodedValue 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 ); + } + else + { + this.value = null; + } + } + + + /** + * Get the raw control encoded bytes + * + * @return the encoded bytes for the control + */ + public byte[] getValue() + { + if ( value == null ) + { + return StringTools.EMPTY_BYTES; + } + + final byte[] copy = new byte[ value.length ]; + System.arraycopy( value, 0, copy, 0, value.length ); + return copy; + } + + + /** + * {@inheritDoc} + */ + @Override + public int computeLength() + { + if ( value != null ) + { + return super.computeLength( value.length ); + } + else + { + return super.computeLength( 0 ); + } + } + + + /** + * {@inheritDoc} + */ + public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException + { + if ( buffer == null ) + { + throw new EncoderException( "Cannot put a PDU in a null buffer !" ); + } + + // Encode the Control envelop + super.encode( buffer ); + + // If we have a value, encode it + if ( value != null ) + { + Value.encode( buffer, value ); + } + + return buffer; + } +} Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecoder.java (from r903704, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ControlDecoder.java) URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecoder.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecoder.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ControlDecoder.java&r1=903704&r2=905297&rev=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ControlDecoder.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecoder.java Mon Feb 1 15:04:10 2010 @@ -17,7 +17,7 @@ * under the License. * */ -package org.apache.directory.shared.ldap.codec; +package org.apache.directory.shared.ldap.codec.controls; import org.apache.directory.shared.asn1.Asn1Object; @@ -33,19 +33,12 @@ public interface ControlDecoder { /** - * The control type this decoder decodes. - * - * @return the control type (an OID string) - */ - String getControlType(); - - - /** * Decodes raw ASN.1 encoded bytes into an Asn1Object for the control. * * @param controlBytes the encoded control bytes + * @param control The control to feed * @return the decoded Asn1Object for the control * @throws DecoderException if anything goes wrong */ - Asn1Object decode( byte[] controlBytes ) throws DecoderException; + Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException; } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlCodec.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlCodec.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlCodec.java Mon Feb 1 15:04:10 2010 @@ -20,10 +20,6 @@ package org.apache.directory.shared.ldap.codec.controls; -import java.nio.ByteBuffer; - -import org.apache.directory.shared.asn1.AbstractAsn1Object; -import org.apache.directory.shared.asn1.codec.EncoderException; /** @@ -64,9 +60,10 @@ * @author Apache Directory Project * @version $Rev$ */ -public class ManageDsaITControlCodec extends AbstractAsn1Object +public class ManageDsaITControlCodec extends AbstractControlCodec { - private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate( 0 ); + /** This control OID */ + public static final String CONTROL_OID = "2.16.840.1.113730.3.4.2"; /** * Default constructor @@ -74,23 +71,32 @@ */ public ManageDsaITControlCodec() { - super(); + super( CONTROL_OID ); + + decoder = new ManageDsaITControlDecoder(); } /** - * Returns 0 everytime. + * Returns 0 every time. */ public int computeLength() { - return 0; + // Call the super class to compute the global control length + return super.computeLength( 0 ); } /** - * Encodes the control: does nothing but returns an empty buffer. + * Return a String representing this ManageDsaIt Control. */ - public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException + public String toString() { - return EMPTY_BUFFER; + StringBuffer sb = new StringBuffer(); + + sb.append( " ManageDsaIt Control\n" ); + sb.append( " oid : " ).append( getOid() ).append( '\n' ); + sb.append( " critical : " ).append( isCritical() ).append( '\n' ); + + return sb.toString(); } } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlDecoder.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlDecoder.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ManageDsaITControlDecoder.java Mon Feb 1 15:04:10 2010 @@ -22,8 +22,6 @@ import org.apache.directory.shared.asn1.Asn1Object; import org.apache.directory.shared.asn1.codec.DecoderException; -import org.apache.directory.shared.ldap.codec.ControlDecoder; -import org.apache.directory.shared.ldap.message.control.ManageDsaITControl; /** @@ -34,13 +32,7 @@ */ public class ManageDsaITControlDecoder implements ControlDecoder { - public String getControlType() - { - return ManageDsaITControl.CONTROL_OID; - } - - - public Asn1Object decode( byte[] controlBytes ) throws DecoderException + public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException { return new ManageDsaITControlCodec(); }