You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/10/09 16:29:33 UTC
svn commit: r583181 - in /directory/shared/branches/bigbang/ldap/src:
main/java/org/apache/directory/shared/ldap/common/
test/java/org/apache/directory/shared/ldap/common/
Author: elecharny
Date: Tue Oct 9 07:29:32 2007
New Revision: 583181
URL: http://svn.apache.org/viewvc?rev=583181&view=rev
Log:
° Added the Modification classes (Server, add, replace, remove)
° ServerAttribute constructors now don't throw exception, but use assert instead
° the ServerAttribute( Attribute ) constructor has been changed to accept only ServerAttribute objects. The conversion BasicAttribute -> ServeAttribute will be done in AttributeUtils.
° Fixed the tests to catch AssertionError instead of NamingException
Added:
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AddModification.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RemoveModification.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RenameModification.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerModification.java
Modified:
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeTest.java
Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AddModification.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AddModification.java?rev=583181&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AddModification.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AddModification.java Tue Oct 9 07:29:32 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.common;
+
+/**
+ *
+ * The AddModification class is used to store an Add Modification
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AddModification extends ServerModification
+{
+ /**
+ *
+ * Creates a new instance of AddModification.
+ *
+ */
+ public AddModification()
+ {
+ super();
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return "Add Modification" + super.toString();
+ }
+}
Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RemoveModification.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RemoveModification.java?rev=583181&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RemoveModification.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RemoveModification.java Tue Oct 9 07:29:32 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.common;
+
+/**
+ *
+ * The RemoveModification class is used to store a Remove Modification
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class RemoveModification extends ServerModification
+{
+ /**
+ *
+ * Creates a new instance of RemoveModification.
+ *
+ */
+ public RemoveModification()
+ {
+ super();
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return "Remove Modification" + super.toString();
+ }
+}
\ No newline at end of file
Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RenameModification.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RenameModification.java?rev=583181&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RenameModification.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/RenameModification.java Tue Oct 9 07:29:32 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.common;
+
+/**
+ *
+ * The RenameModification class is used to store a Rename Modification
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class RenameModification extends ServerModification
+{
+ /**
+ *
+ * Creates a new instance of RenameModification.
+ *
+ */
+ public RenameModification()
+ {
+ super();
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return "Rename Modification" + super.toString();
+ }
+}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java?rev=583181&r1=583180&r2=583181&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java Tue Oct 9 07:29:32 2007
@@ -25,17 +25,12 @@
import java.util.Iterator;
import java.util.List;
-import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.BasicAttribute;
import org.apache.directory.shared.asn1.primitives.OID;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.StringTools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -46,8 +41,6 @@
*/
public class ServerAttributeImpl implements ServerAttribute, Serializable, Cloneable
{
- private static final Logger LOG = LoggerFactory.getLogger( ServerAttributeImpl.class );
-
/** For serialization */
private static final long serialVersionUID = 2L;
@@ -76,16 +69,12 @@
* Creates a ServerAttribute with an id
*
* @param id the id or name of this attribute.
- * @throws NamingException if the id is null
*/
- public ServerAttributeImpl( String id ) throws NamingException
+ public ServerAttributeImpl( String id )
{
- if ( StringTools.isEmpty( id ) )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
-
+ // Use assert instead of throwing an exception
+ assert( !StringTools.isEmpty( id ) );
+
upId = id;
value = null;
values = null;
@@ -98,15 +87,11 @@
* Creates a ServerAttribute with an oid
*
* @param oid the oid of this attribute.
- * @throws NamingException if the oid is null
*/
- public ServerAttributeImpl( OID oid ) throws NamingException
+ public ServerAttributeImpl( OID oid )
{
- if ( oid == null )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
+ // Use assert instead of throwing an exception
+ assert( oid != null );
upId = oid.toString();
value = null;
@@ -121,16 +106,12 @@
*
* @param id the id or name of this attribute.
* @param val the attribute's value
- * @throws NamingException if the id is invalid
*/
- public ServerAttributeImpl( String id, Value<?> val ) throws NamingException
+ public ServerAttributeImpl( String id, Value<?> val )
{
- if ( StringTools.isEmpty( id ) )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
-
+ // Use assert instead of throwing an exception
+ assert( !StringTools.isEmpty( id ) );
+
upId = id;
value = val;
values = null;
@@ -144,15 +125,11 @@
*
* @param oid the oid of this attribute.
* @param val the attribute's value
- * @throws NamingException if the oid is invalid
*/
- public ServerAttributeImpl( OID oid, Value<?> val ) throws NamingException
+ public ServerAttributeImpl( OID oid, Value<?> val )
{
- if ( oid == null )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
+ // Use assert instead of throwing an exception
+ assert( oid != null );
upId = oid.toString();
value = val;
@@ -167,16 +144,12 @@
*
* @param id the id or name of this attribute.
* @param val a value for the attribute
- * @throws NamingException if the id string is invalid
*/
- public ServerAttributeImpl( String id, byte[] val ) throws NamingException
+ public ServerAttributeImpl( String id, byte[] val )
{
- if ( StringTools.isEmpty( id ) )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
-
+ // Use assert instead of throwing an exception
+ assert( !StringTools.isEmpty( id ) );
+
upId = id;
values = null;
value = new BinaryValue( val );
@@ -190,15 +163,11 @@
*
* @param oid the oid of this attribute.
* @param val a value for the attribute
- * @throws NamingException if the oid is invalid
*/
- public ServerAttributeImpl( OID oid, byte[] val ) throws NamingException
+ public ServerAttributeImpl( OID oid, byte[] val )
{
- if ( oid == null )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
+ // Use assert instead of throwing an exception
+ assert( oid != null );
upId = oid.toString();
values = null;
@@ -213,16 +182,12 @@
*
* @param id the id or name of this attribute.
* @param val a value for the attribute
- * @throws NamingException if the id string is invalid
*/
- public ServerAttributeImpl( String id, String val ) throws NamingException
+ public ServerAttributeImpl( String id, String val )
{
- if ( StringTools.isEmpty( id ) )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
-
+ // Use assert instead of throwing an exception
+ assert( !StringTools.isEmpty( id ) );
+
upId = id;
values = null;
value = new StringValue( val );
@@ -236,15 +201,11 @@
*
* @param oid the oid of this attribute.
* @param val a value for the attribute
- * @throws NamingException if there's no OID provided
*/
- public ServerAttributeImpl( OID oid, String val ) throws NamingException
+ public ServerAttributeImpl( OID oid, String val )
{
- if ( oid == null )
- {
- LOG.error( "Attributes with an empty ID or OID are not allowed" );
- throw new NamingException( "Attributes with an empty ID or OID are not allowed" );
- }
+ // Use assert instead of throwing an exception
+ assert( oid != null );
upId = oid.toString();
values = null;
@@ -258,42 +219,48 @@
* Create a copy of an Attribute, be it an ServerAttributeImpl
* instance of a BasicAttribute instance
*
- * @param attribute the Attribute instace to copy
- * @throws NamingException if the attribute is not an instance of BasicAttribute
- * or ServerAttributeImpl or is null
+ * @param attribute the Attribute instance to copy
*/
- public ServerAttributeImpl( Attribute attribute ) throws NamingException
+ public ServerAttributeImpl( ServerAttribute attribute )
{
- if ( attribute == null )
- {
- LOG.error( "Null attribute is not allowed" );
- throw new NamingException( "Null attribute is not allowed" );
- }
- else if ( attribute instanceof ServerAttributeImpl )
- {
- ServerAttributeImpl copy = (ServerAttributeImpl)attribute;
-
- upId = copy.upId;
- oid = copy.oid;
-
- switch ( copy.size() )
- {
- case 0:
- values = null;
- value = null;
- size = 0;
- break;
-
- case 1:
+ // Use assert instead of throwing an exception
+ assert( attribute != null );
+
+ ServerAttribute copy = attribute.clone();
+
+ upId = ((ServerAttributeImpl)copy).getID();
+ oid = ((ServerAttributeImpl)copy).getOid();
+
+ switch ( copy.size() )
+ {
+ case 0:
+ values = null;
+ value = null;
+ size = 0;
+ break;
+
+ case 1:
+ try
+ {
value = getClonedValue( copy.get() );
- values = null;
- size = 1;
- break;
-
- default :
- value = null;
- values = new ArrayList<Value<?>>( copy.size() );
-
+ }
+ catch ( NamingException ne )
+ {
+ // It should not happen, but in this case,
+ // let's create an empty Value
+ value = new StringValue( (String)null );
+ }
+
+ values = null;
+ size = 1;
+ break;
+
+ default :
+ value = null;
+ values = new ArrayList<Value<?>>( copy.size() );
+
+ try
+ {
Iterator<Value<?>> vals = copy.getAll();
while ( vals.hasNext() )
@@ -301,82 +268,20 @@
Value<?> val = vals.next();
values.add( val );
}
-
- size = copy.size();
-
- break;
- }
-
- oid = null;
+ }
+ catch ( NamingException ne )
+ {
+ // It should not happen, but in this case,
+ // let's create an empty Value
+ values.add( new StringValue( (String)null ) );
+ }
+
+ size = copy.size();
+
+ break;
}
- else if ( attribute instanceof BasicAttribute )
- {
- upId = attribute.getID();
- oid = null;
-
- switch ( attribute.size() )
- {
- case 0 :
- value = null;
- values = null;
- size = 0;
- break;
-
- case 1 :
- Object val = attribute.get();
-
- if ( val instanceof String )
- {
- value = new StringValue( (String)val );
- }
- else if ( val instanceof byte[] )
- {
- value = new BinaryValue( (byte[])val );
- }
- else
- {
- LOG.error( "The value's type is not String or byte[]" );
- throw new NamingException( "The value's type is not String or byte[]" );
- }
- values = null;
- size = 1;
-
- break;
-
- default :
- NamingEnumeration<?> vals = attribute.getAll();
-
- while ( vals.hasMoreElements() )
- {
- val = vals.nextElement();
-
- if ( val instanceof String )
- {
- value = new StringValue( (String)val );
- }
- else if ( val instanceof byte[] )
- {
- value = new BinaryValue( (byte[])val );
- }
- else
- {
- LOG.error( "The value's type is not String or byte[]" );
- throw new NamingException( "The value's type is not String or byte[]" );
- }
- }
-
- values = null;
- size = attribute.size();
-
- break;
- }
- }
- else
- {
- LOG.error( "Attribute must be an instance of BasicAttribute or AttributeImpl" );
- throw new NamingException( "Attribute must be an instance of BasicAttribute or AttributeImpl" );
- }
+ oid = null;
}
Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerModification.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerModification.java?rev=583181&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerModification.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerModification.java Tue Oct 9 07:29:32 2007
@@ -0,0 +1,157 @@
+/*
+ * 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.common;
+
+/**
+ *
+ * The ServerModification class is used to store attribute modifications as
+ * they are sent by the modifyRequest.
+ *
+ * There are three kind of modifications :
+ * - Add
+ * - Replace
+ * - Remove
+ *
+ * One should not instanciate this class directly.
+ *
+ * Each of these modifications will be implemented as a subclass
+ * of this one.
+ *
+ * For operationnal attributes which are modified by the server, we use
+ * a flag which is set to <code>true</code>.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerModification
+{
+ /** A flag set for an attribute modified by the server */
+ private boolean serverModified;
+
+ /** The modified attribute */
+ private ServerAttribute attribute;
+
+ /**
+ * Creates a new instance of ServerModification.
+ */
+ protected ServerModification()
+ {
+ serverModified = false;
+ }
+
+
+ /**
+ * Creates a new instance of ServerModification.
+ *
+ * @param attribute The modified attribute
+ */
+ protected ServerModification( ServerAttribute attribute )
+ {
+ this.attribute = attribute;
+ serverModified = false;
+ }
+
+
+ /**
+ * Creates a new instance of ServerModification.
+ *
+ * @param attribute The modified attribute
+ */
+ protected ServerModification( String attributeId, Value<?> value )
+ {
+ this.attribute = new ServerAttributeImpl( attributeId, value );
+ serverModified = false;
+ }
+
+
+ /**
+ * Creates a new instance of ServerModification.
+ *
+ * @param attribute The modified attribute
+ * @param serverModified The attribute is modified by the server
+ */
+ protected ServerModification( ServerAttribute attribute, boolean serverModified )
+ {
+ this.attribute = attribute;
+ this.serverModified = serverModified;
+ }
+
+
+ /**
+ * Get the modified attribute
+ *
+ * @return The modified attribute
+ */
+ public ServerAttribute getAttribute()
+ {
+ return attribute;
+ }
+
+
+ /**
+ *
+ * Set the modified attribute
+ *
+ * @param attribute The modified attribute
+ */
+ public void setAttribute( ServerAttribute attribute )
+ {
+ this.attribute = attribute;
+ }
+
+
+ /**
+ *
+ * Tels if the attribute has been modified by the server
+ *
+ * @return
+ */
+ public boolean isServerModified()
+ {
+ return serverModified;
+ }
+
+
+ /**
+ * Set the flag for a server modified attribute
+ */
+ public void setServerModified()
+ {
+ serverModified = true;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ if ( serverModified )
+ {
+ sb.append( "[S]" );
+ }
+
+ sb.append( " : " ).append( attribute );
+
+ return sb.toString();
+ }
+}
Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeTest.java?rev=583181&r1=583180&r2=583181&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeTest.java Tue Oct 9 07:29:32 2007
@@ -58,49 +58,49 @@
{
new ServerAttributeImpl( (OID)null );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (OID)null, "test" );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (OID)null, StringTools.EMPTY_BYTES );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (OID)null, new StringValue() );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (String)null );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (String)null, "test" );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (String)null, StringTools.EMPTY_BYTES );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
try
{
new ServerAttributeImpl( (String)null, new StringValue() );
fail();
- } catch ( NamingException ne ) {}
+ } catch ( AssertionError ae ) {}
}
/**