directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1065432 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap: codec/BasicControlDecorator.java codec/DefaultLdapCodecService.java codec/search/controls/pagedSearch/PagedResultsFactory.java model/ldif/LdifEntry.java
Date Mon, 31 Jan 2011 00:03:31 GMT
Author: akarasulu
Date: Mon Jan 31 00:03:31 2011
New Revision: 1065432

URL: http://svn.apache.org/viewvc?rev=1065432&view=rev
Log:
adding opaque control handling decorator and added some new factories

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsFactory.java
Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/DefaultLdapCodecService.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java?rev=1065432&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
Mon Jan 31 00:03:31 2011
@@ -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;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.Asn1Object;
+import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.asn1.EncoderException;
+import org.apache.directory.shared.ldap.model.message.controls.BasicControl;
+
+
+/**
+ * A decorator for an opaque control where we know nothing about encoded values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BasicControlDecorator implements ICodecControl<BasicControl>, IDecorator<BasicControl>
+{
+    private byte[] value;
+    
+    private BasicControl control;
+    private ILdapCodecService codec;
+    
+    
+    public BasicControlDecorator( ILdapCodecService codec, BasicControl control )
+    {
+        this.codec = codec;
+        this.control = control;
+    }
+    
+    
+    public String getOid()
+    {
+        return control.getOid();
+    }
+
+    
+    public boolean isCritical()
+    {
+        return control.isCritical();
+    }
+
+    
+    public void setCritical( boolean isCritical )
+    {
+        control.setCritical( isCritical );
+    }
+
+    
+    public BasicControl getDecorated()
+    {
+        return control;
+    }
+
+    
+    public int computeLength()
+    {
+        return 0;
+    }
+
+    
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        return null;
+    }
+
+    
+    public ILdapCodecService getCodecService()
+    {
+        return codec;
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    {
+        return null;
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasValue()
+    {
+        return value != null;
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        return value;
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setValue( byte[] value )
+    {
+        this.value = value;
+    }
+}

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/DefaultLdapCodecService.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/DefaultLdapCodecService.java?rev=1065432&r1=1065431&r2=1065432&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/DefaultLdapCodecService.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/DefaultLdapCodecService.java
Mon Jan 31 00:03:31 2011
@@ -208,7 +208,7 @@ public class DefaultLdapCodecService imp
             
             if ( factory == null )
             {
-                return (E)new BasicControl( oid );
+                return ( E ) new BasicControl( oid );
             }
             
             return ( E ) factory.newControl();
@@ -230,7 +230,10 @@ public class DefaultLdapCodecService imp
             
             if ( factory == null )
             {
-                return null; // Here, instanciate a default factory
+                org.apache.directory.shared.ldap.model.message.controls.BasicControl basic
= 
+                    new org.apache.directory.shared.ldap.model.message.controls.BasicControl(
control.getOid() );
+                basic.setCritical( control.isCritical() );
+                return new BasicControlDecorator( this, basic ); 
             }
             
             return factory.decorate( control );

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsFactory.java?rev=1065432&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsFactory.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsFactory.java
Mon Jan 31 00:03:31 2011
@@ -0,0 +1,117 @@
+/*
+ *   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.search.controls.pagedSearch;
+
+
+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;
+import org.apache.directory.shared.ldap.model.message.controls.PagedResults;
+import org.apache.directory.shared.ldap.model.message.controls.PagedResultsImpl;
+
+
+/**
+ * A {@link IControlFactory} for {@link EntryChange} controls.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PagedResultsFactory implements IControlFactory<PagedResults, PagedResultsDecorator>
+{
+    /** The LDAP codec service */
+    private ILdapCodecService codec;
+
+    
+    /**
+     * Creates a new instance of PagedResultsFactory.
+     *
+     * @param codec The LDAP codec.
+     */
+    public PagedResultsFactory( ILdapCodecService codec )
+    {
+        this.codec = codec;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getOid()
+    {
+        return PagedResults.OID;
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public PagedResultsDecorator newCodecControl()
+    {
+        return new PagedResultsDecorator( codec );
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public PagedResultsDecorator decorate( PagedResults control )
+    {
+        return new PagedResultsDecorator( codec, control );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public PagedResults newControl()
+    {
+        return new PagedResultsImpl();
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public Control toJndiControl( PagedResults control ) throws EncoderException
+    {
+        PagedResultsDecorator decorator = decorate( control );
+        ByteBuffer bb = ByteBuffer.allocate( decorator.computeLength() );
+        decorator.encode( bb );
+        bb.flip();
+        return new BasicControl( PagedResults.OID, control.isCritical(), bb.array() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public PagedResults fromJndiControl( Control control ) throws DecoderException
+    {
+        PagedResultsDecorator decorator = new PagedResultsDecorator( codec );
+        decorator.setValue( control.getEncodedValue() );
+        return decorator;
+    }
+}

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java?rev=1065432&r1=1065431&r2=1065432&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
Mon Jan 31 00:03:31 2011
@@ -605,8 +605,17 @@ public class LdifEntry implements Clonea
             {
                 this.controls = new ConcurrentHashMap<String, LdifControl>();
             }
-    
-            this.controls.put( control.getOid(), ( LdifControl ) control );
+            
+            if ( control instanceof LdifControl )
+            {
+                this.controls.put( control.getOid(), ( LdifControl ) control );
+            }
+            else
+            {
+                LdifControl ldifControl = new LdifControl( control.getOid() );
+                ldifControl.setCritical( control.isCritical() );
+                this.controls.put( control.getOid(), new LdifControl( control.getOid() )
);
+            }
         }
     }
 



Mime
View raw message