Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 11124 invoked from network); 31 Jan 2011 00:03:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Jan 2011 00:03:53 -0000 Received: (qmail 85340 invoked by uid 500); 31 Jan 2011 00:03:53 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 85296 invoked by uid 500); 31 Jan 2011 00:03:53 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 85289 invoked by uid 99); 31 Jan 2011 00:03:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 00:03:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 00:03:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 939AB23888FE; Mon, 31 Jan 2011 00:03:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110131000331.939AB23888FE@eris.apache.org> 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 Apache Directory Project + * @version $Rev$, $Date$ + */ +public class BasicControlDecorator implements ICodecControl, IDecorator +{ + 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 Apache Directory Project + * @version $Rev$, $Date$ + */ +public class PagedResultsFactory implements IControlFactory +{ + /** 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(); } - - 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() ) ); + } } }