directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1065852 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue: SyncInfoValueDecorator.java SyncInfoValueFactory.java
Date Mon, 31 Jan 2011 23:26:10 GMT
Author: akarasulu
Date: Mon Jan 31 23:26:09 2011
New Revision: 1065852

URL: http://svn.apache.org/viewvc?rev=1065852&view=rev
Log:
adding sync info value factory

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueFactory.java
Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueDecorator.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueDecorator.java?rev=1065852&r1=1065851&r2=1065852&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueDecorator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueDecorator.java
Mon Jan 31 23:26:09 2011
@@ -60,6 +60,15 @@ public class SyncInfoValueDecorator exte
     {
         super( codec, new SyncInfoValue() );
     }
+
+    
+    /**
+     * The constructor for this codec. Dont't forget to set the type.
+     */
+    public SyncInfoValueDecorator( ILdapCodecService codec, ISyncInfoValue control )
+    {
+        super( codec, control );
+    }
     
     
     /**

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueFactory.java?rev=1065852&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueFactory.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueFactory.java
Mon Jan 31 23:26:09 2011
@@ -0,0 +1,120 @@
+/*
+ *   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.replication.syncInfoValue;
+
+
+import java.nio.ByteBuffer;
+
+import javax.naming.ldap.BasicControl;
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.asn1.EncoderException;
+import org.apache.directory.shared.ldap.codec.IControlFactory;
+import org.apache.directory.shared.ldap.codec.ILdapCodecService;
+
+
+/**
+ * A {@link IControlFactory} which creates {@link ISyncInfoValue} controls.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncInfoValueFactory implements IControlFactory<ISyncInfoValue, SyncInfoValueDecorator>
+{
+    
+    private ILdapCodecService codec;
+    
+
+    /**
+     * Creates a new instance of SyncInfoValueFactory.
+     *
+     */
+    public SyncInfoValueFactory( ILdapCodecService codec )
+    {
+        this.codec = codec;
+    }
+    
+
+    /**
+     * 
+     * {@inheritDoc}
+     */
+    public String getOid()
+    {
+        return ISyncInfoValue.OID;
+    }
+
+    
+    /**
+     * 
+     * {@inheritDoc}
+     */
+    public SyncInfoValueDecorator newCodecControl()
+    {
+        return new SyncInfoValueDecorator( codec );
+    }
+    
+
+    public SyncInfoValueDecorator decorate( ISyncInfoValue control )
+    {
+        SyncInfoValueDecorator decorator = null;
+        
+        // protect against double decoration
+        if ( control instanceof SyncInfoValueDecorator )
+        {
+            decorator = ( SyncInfoValueDecorator ) control;
+        }
+        else
+        {
+            decorator = new SyncInfoValueDecorator( codec, control );
+        }
+        
+        return decorator;
+    }
+
+    
+    public ISyncInfoValue newControl()
+    {
+        return new SyncInfoValue();
+    }
+    
+
+    public Control toJndiControl( ISyncInfoValue control ) throws EncoderException
+    {
+        SyncInfoValueDecorator decorator = decorate( control );
+        ByteBuffer bb = ByteBuffer.allocate( decorator.computeLength() );
+        decorator.encode( bb );
+        bb.flip();
+        return new BasicControl( control.getOid(), control.isCritical(), decorator.getValue()
);
+    }
+
+    
+    public ISyncInfoValue fromJndiControl( Control jndi ) throws DecoderException
+    {
+        SyncInfoValueDecorator decorator = newCodecControl();
+        decorator.setCritical( jndi.isCritical() );
+        decorator.setValue( jndi.getEncodedValue() );
+        byte[] controlBytes = new byte[ decorator.computeLength() ];
+        decorator.decode( controlBytes );
+        return decorator.getDecorated();
+    }
+
+}



Mime
View raw message