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/12/15 21:38:19 UTC
svn commit: r604510 -
/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/
Author: elecharny
Date: Sat Dec 15 12:38:19 2007
New Revision: 604510
URL: http://svn.apache.org/viewvc?rev=604510&view=rev
Log:
o Updated the ServerAttribute classes, implementing the new methods with varargs.
o Created an abstract class to be used by DefaultServerAttribute and ObjectClassAttribute
o Fixed some issues in the Value classes
o Added some doco
Added:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
- copied, changed from r603878, directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
Removed:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
Modified:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java?rev=604510&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java (added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java Sat Dec 15 12:38:19 2007
@@ -0,0 +1,560 @@
+/*
+ * 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.server.core.entry;
+
+
+import org.apache.directory.shared.ldap.entry.BinaryValue;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.StringValue;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.NamingException;
+import javax.naming.directory.InvalidAttributeValueException;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+
+/**
+ * An abstract class to collect common methods and common members for the
+ * BasicServerAttribute and ObjectClassAttribute classes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractServerAttribute implements ServerAttribute<ServerValue<?>>
+{
+ /** logger for reporting errors that might not be handled properly upstream */
+ private static final Logger LOG = LoggerFactory.getLogger( AbstractServerAttribute.class );
+
+ /** The set of contained values */
+ protected Set<ServerValue<?>> values = new HashSet<ServerValue<?>>();
+
+ /** The associated AttributeType */
+ protected AttributeType attributeType;
+
+ /** The User provided ID */
+ protected String upId;
+
+
+ // -----------------------------------------------------------------------
+ // utility methods
+ // -----------------------------------------------------------------------
+ /**
+ * Utility method to get some logs if an assert fails
+ */
+ protected String logAssert( String message )
+ {
+ LOG.error( message );
+ return message;
+ }
+
+ /**
+ * Check the attributeType member. It should not be null,
+ * and it should contains a syntax.
+ */
+ protected String checkAttributeType( AttributeType attributeType )
+ {
+ try
+ {
+ if ( attributeType == null )
+ {
+ return "The AttributeType parameter should not be null";
+ }
+
+ if ( attributeType.getSyntax() == null )
+ {
+ return "There is no Syntax associated with this attributeType";
+ }
+
+ return null;
+ }
+ catch ( NamingException ne )
+ {
+ return "This AttributeType is incorrect";
+ }
+ }
+
+ /**
+ * Set the user provided ID. If we have none, the upId is assigned
+ * the attributetype's name. If it does not have any name, we will
+ * use the OID.
+ *
+ * @param upId The attribute ID
+ * @param attributeType The associated attributeType
+ */
+ protected void setUpId( String upId, AttributeType attributeType )
+ {
+ if ( upId == null )
+ {
+ String name = attributeType.getName();
+
+ if ( name == null )
+ {
+ this.upId = attributeType.getOid();
+ }
+ else
+ {
+ this.upId = name;
+ }
+ }
+ else
+ {
+ this.upId = upId;
+ }
+ }
+
+
+ // -----------------------------------------------------------------------
+ // API
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the attribute type associated with this ServerAttribute.
+ *
+ * @return the attributeType associated with this entry attribute
+ */
+ public AttributeType getType()
+ {
+ return attributeType;
+ }
+
+
+ /**
+ * Get's the user provided identifier for this entry. This is the value
+ * that will be used as the identifier for the attribute within the
+ * entry. If this is a commonName attribute for example and the user
+ * provides "COMMONname" instead when adding the entry then this is
+ * the format the user will have that entry returned by the directory
+ * server. To do so we store this value as it was given and track it
+ * in the attribute using this property.
+ *
+ * @return the user provided identifier for this attribute
+ */
+ public String getUpId()
+ {
+ return upId;
+ }
+
+
+ /**
+ * Checks to see if this attribute is valid along with the values it contains.
+ *
+ * @return true if the attribute and it's values are valid, false otherwise
+ * @throws NamingException if there is a failure to check syntaxes of values
+ */
+ public boolean isValid() throws NamingException
+ {
+ if ( attributeType.isSingleValue() && values.size() > 1 )
+ {
+ return false;
+ }
+
+ for ( ServerValue<?> value : values )
+ {
+ if ( ! value.isValid() )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value)
+ */
+ public boolean add( ServerValue<?> val ) throws InvalidAttributeValueException, NamingException
+ {
+ if ( attributeType.getSyntax().isHumanReadable() )
+ {
+ if ( !( val instanceof StringValue ) )
+ {
+ String message = "The value must be a String, as its AttributeType is H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+ else
+ {
+ if ( !( val instanceof BinaryValue ) )
+ {
+ String message = "The value must be a byte[], as its AttributeType is not H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+
+ return values.add( val );
+ }
+
+
+ /**
+ * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value...)
+ */
+ public int add( ServerValue<?>... vals ) throws InvalidAttributeValueException, NamingException
+ {
+ int nbAdded = 0;
+
+ for ( ServerValue<?> val:vals )
+ {
+ if ( add( val ) )
+ {
+ nbAdded ++;
+ }
+ }
+
+ return nbAdded;
+ }
+
+
+ /**
+ * @see EntryAttribute#add(String)
+ */
+ public boolean add( String val ) throws InvalidAttributeValueException, NamingException
+ {
+ if ( attributeType.getSyntax().isHumanReadable() )
+ {
+ return add( new ServerStringValue( attributeType, val ) );
+ }
+ else
+ {
+ String message = "The value must be a String, as its AttributeType is H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+
+
+ /**
+ * @see EntryAttribute#add(String...)
+ */
+ public int add( String... vals ) throws InvalidAttributeValueException, NamingException
+ {
+ int nbAdded = 0;
+
+ for ( String val:vals )
+ {
+ if ( add( val ) )
+ {
+ nbAdded ++;
+ }
+ }
+
+ return nbAdded;
+ }
+
+
+ /**
+ * @see EntryAttribute#add(byte[])
+ */
+ public boolean add( byte[] val ) throws InvalidAttributeValueException, NamingException
+ {
+ if ( ! attributeType.getSyntax().isHumanReadable() )
+ {
+ return add( new ServerBinaryValue( attributeType, val ) );
+ }
+ else
+ {
+ String message = "The value must be a byte[], as its AttributeType is not H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+
+
+ /**
+ * @see EntryAttribute#add(byte[]...)
+ */
+ public int add( byte[]... vals ) throws InvalidAttributeValueException, NamingException
+ {
+ int nbAdded = 0;
+
+ for ( byte[] val:vals )
+ {
+ if ( add( val ) )
+ {
+ nbAdded ++;
+ }
+ }
+
+ return nbAdded;
+ }
+
+ /**
+ * Remove all the values from this attribute type, including a
+ * null value.
+ */
+ public void clear()
+ {
+ values.clear();
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value)
+ */
+ public boolean contains( ServerValue<?> val )
+ {
+ return values.contains( val );
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value...)
+ */
+ public boolean contains( ServerValue<?>... vals )
+ {
+ // Iterate through all the values, and quit if we
+ // don't find one in the values
+ for ( ServerValue<?> val:vals )
+ {
+ if ( !values.contains( val ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(String)
+ */
+ public boolean contains( String val )
+ {
+ try
+ {
+ if ( !attributeType.getSyntax().isHumanReadable() )
+ {
+ return false;
+ }
+ }
+ catch ( NamingException ne )
+ {
+ // We have had a pb while getting the syntax...
+ return false;
+ }
+
+ ServerStringValue value = new ServerStringValue( attributeType, val );
+
+ return values.contains( value );
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(String...)
+ */
+ public boolean contains( String... vals )
+ {
+ // Iterate through all the values, and quit if we
+ // don't find one in the values
+ for ( String val:vals )
+ {
+ if ( !contains( val ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(byte[])
+ */
+ public boolean contains( byte[] val )
+ {
+ try
+ {
+ if ( attributeType.getSyntax().isHumanReadable() )
+ {
+ return false;
+ }
+ }
+ catch ( NamingException ne )
+ {
+ // We have had a pb while getting the syntax...
+ return false;
+ }
+
+ ServerBinaryValue sbv = new ServerBinaryValue( attributeType, val );
+ return values.contains( sbv );
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(byte[]...)
+ */
+ public boolean contains( byte[]... vals )
+ {
+ // Iterate through all the values, and quit if we
+ // don't find one in the values
+ for ( byte[] val:vals )
+ {
+ if ( !contains( val ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Get the first value of this attribute. If there is none,
+ * null is returned.
+ *
+ * Note : as we are storing values into a Set, one can't assume
+ * the values to be ordered in any way. This method is meant to
+ * be used if the attribute hold only one value.
+ *
+ * @return The first value for this attribute.
+ */
+ public ServerValue<?> get()
+ {
+ if ( values.isEmpty() )
+ {
+ return null;
+ }
+
+ return values.iterator().next();
+ }
+
+
+ /**
+ * Get all the stored values.
+ *
+ * @return An iterator over the values stored into the attribute
+ */
+ public Iterator<ServerValue<?>> getAll()
+ {
+ return iterator();
+ }
+
+
+ /**
+ * Get the number or values stored in the attribute
+ *
+ * @return the number of stored values. As 'null' can be a valid
+ * value, it is counted as one result, not 0.
+ */
+ public int size()
+ {
+ return values.size();
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value)
+ */
+ public boolean remove( ServerValue<?> val )
+ {
+ return values.remove( val );
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value...)
+ */
+ public boolean remove( ServerValue<?>... vals )
+ {
+ boolean removed = false;
+
+ // Loop through all the values to remove. If one of
+ // them is not present, the method will return false.
+ for ( ServerValue<?> val:vals )
+ {
+ removed &= values.remove( val );
+ }
+
+ return removed;
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(byte[])
+ */
+ public boolean remove( byte[] val )
+ {
+ ServerBinaryValue sbv = new ServerBinaryValue( attributeType, val );
+ return values.remove( sbv );
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(byte[]...)
+ */
+ public boolean remove( byte[]... vals )
+ {
+ boolean removed = true;
+
+ for ( byte[] val:vals )
+ {
+ ServerBinaryValue value = new ServerBinaryValue( attributeType, val );
+ removed &= values.remove( value );
+ }
+
+ return removed;
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(String)
+ */
+ public boolean remove( String val )
+ {
+ ServerStringValue ssv = new ServerStringValue( attributeType, val );
+ return values.remove( ssv );
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(String...)
+ */
+ public boolean remove( String... vals )
+ {
+ boolean removed = true;
+
+ for ( String val:vals )
+ {
+ ServerStringValue value = new ServerStringValue( attributeType, val );
+ removed &= values.remove( value );
+ }
+
+ return removed;
+ }
+
+
+ /**
+ * An iterator on top of the stored values.
+ *
+ * @return an iterator over the stored values.
+ */
+ public Iterator<ServerValue<?>> iterator()
+ {
+ return values.iterator();
+ }
+}
Copied: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java (from r603878, directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java?p2=directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java&p1=directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java&r1=603878&r2=604510&rev=604510&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java Sat Dec 15 12:38:19 2007
@@ -19,10 +19,16 @@
package org.apache.directory.server.core.entry;
+import org.apache.directory.shared.ldap.entry.BinaryValue;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.StringValue;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.naming.NamingException;
-import java.util.HashSet;
+import javax.naming.directory.InvalidAttributeValueException;
+
import java.util.Iterator;
@@ -32,25 +38,32 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class BasicServerAttribute implements ServerAttribute<ServerValue<?>>
+public final class DefaultServerAttribute extends AbstractServerAttribute
{
- private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
- private AttributeType attributeType;
- private String upId;
+ /** logger for reporting errors that might not be handled properly upstream */
+ private static final Logger LOG = LoggerFactory.getLogger( DefaultServerAttribute.class );
// maybe have some additional convenience constructors which take
// an initial value as a string or a byte[]
-
-
- public BasicServerAttribute( AttributeType attributeType )
+ /**
+ * Create a new instance of a EntryAttribute, without ID nor value.
+ */
+ public DefaultServerAttribute( AttributeType attributeType )
{
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
+
this.attributeType = attributeType;
setUpId( null, attributeType );
}
- public BasicServerAttribute( String upId, AttributeType attributeType )
+ /**
+ * Create a new instance of a EntryAttribute, without value.
+ */
+ public DefaultServerAttribute( String upId, AttributeType attributeType )
{
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
+
this.attributeType = attributeType;
setUpId( upId, attributeType );
}
@@ -67,7 +80,7 @@
* @param val an initial value for this attribute
* @throws NamingException if there are problems creating the new attribute
*/
- public BasicServerAttribute( AttributeType attributeType, ServerValue<?> val ) throws NamingException
+ public DefaultServerAttribute( AttributeType attributeType, ServerValue<?> val ) throws NamingException
{
this( null, attributeType, val );
}
@@ -79,128 +92,104 @@
* If the value does not correspond to the same attributeType, then it's
* wrapped value is copied into a new ServerValue which uses the specified
* attributeType.
+ *
+ * Otherwise, the value is stored, but as a reference. It's not a copy.
*
* @param upId
* @param attributeType the attribute type according to the schema
* @param val an initial value for this attribute
* @throws NamingException if there are problems creating the new attribute
*/
- public BasicServerAttribute( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
+ public DefaultServerAttribute( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
{
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
+
this.attributeType = attributeType;
+ // The value can be null, this is a valid value.
if ( val == null )
{
if ( attributeType.getSyntax().isHumanReadable() )
{
- values.add( new ServerStringValue( attributeType ) );
+ add( new ServerStringValue( attributeType ) );
}
else
{
- values.add( new ServerBinaryValue( attributeType ) );
+ add( new ServerBinaryValue( attributeType ) );
}
}
else
{
if ( attributeType.equals( val.getAttributeType() ) )
{
- values.add( val );
+ add( val );
}
else if ( val instanceof ServerStringValue )
{
ServerStringValue serverString = ( ServerStringValue ) val;
- values.add( new ServerStringValue( attributeType, serverString.get() ) );
+ add( new ServerStringValue( attributeType, serverString.get() ) );
}
else if ( val instanceof ServerBinaryValue )
{
ServerBinaryValue serverBinary = ( ServerBinaryValue ) val;
- values.add( new ServerBinaryValue( attributeType, serverBinary.getCopy() ) );
+ add( new ServerBinaryValue( attributeType, serverBinary.getCopy() ) );
}
else
{
- throw new IllegalStateException( "Unknown value type: " + val.getClass().getName() );
+ String message = "Unknown value type: " + val.getClass().getName();
+ LOG.error( message );
+ throw new IllegalStateException( message );
}
-
- values.add( val );
}
setUpId( upId, attributeType );
}
- public BasicServerAttribute( AttributeType attributeType, String val ) throws NamingException
+ /**
+ * Create a new instance of a EntryAttribute, withoiut ID but with a value.
+ */
+ public DefaultServerAttribute( AttributeType attributeType, String val ) throws NamingException
{
this( null, attributeType, val );
}
- public BasicServerAttribute( String upId, AttributeType attributeType, String val ) throws NamingException
+ /**
+ * Create a new instance of a EntryAttribute.
+ */
+ public DefaultServerAttribute( String upId, AttributeType attributeType, String val ) throws NamingException
{
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
+
this.attributeType = attributeType;
- if ( val == null )
- {
- if ( attributeType.getSyntax().isHumanReadable() )
- {
- values.add( new ServerStringValue( attributeType ) );
- }
- else
- {
- values.add( new ServerBinaryValue( attributeType ) );
- }
- }
- else
- {
- values.add( new ServerStringValue( attributeType, val ) );
- }
+ add( val );
setUpId( upId, attributeType );
}
- public BasicServerAttribute( AttributeType attributeType, byte[] val ) throws NamingException
+ /**
+ * Create a new instance of a EntryAttribute, with a byte[] value.
+ */
+ public DefaultServerAttribute( AttributeType attributeType, byte[] val ) throws NamingException
{
this( null, attributeType, val );
}
- public BasicServerAttribute( String upId, AttributeType attributeType, byte[] val ) throws NamingException
+ /**
+ * Create a new instance of a EntryAttribute, with a String value.
+ */
+ public DefaultServerAttribute( String upId, AttributeType attributeType, byte[] val ) throws NamingException
{
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
+
this.attributeType = attributeType;
- if ( val == null )
- {
- if ( attributeType.getSyntax().isHumanReadable() )
- {
- values.add( new ServerStringValue( attributeType ) );
- }
- else
- {
- values.add( new ServerBinaryValue( attributeType ) );
- }
- }
- else
- {
- values.add( new ServerBinaryValue( attributeType, val ) );
- }
+ add( val );
setUpId( upId, attributeType );
}
- private void setUpId( String upId, AttributeType attributeType )
- {
- if ( upId == null )
- {
- String name = attributeType.getName();
- if ( name == null )
- {
- this.upId = attributeType.getOid();
- }
- else
- {
- this.upId = name;
- }
- }
- }
-
-
/**
* Gets the attribute type associated with this ServerAttribute.
*
@@ -254,50 +243,259 @@
}
- public boolean add( ServerValue<?> val )
+ /**
+ * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value)
+ */
+ public boolean add( ServerValue<?> val ) throws InvalidAttributeValueException, NamingException
{
+ if ( attributeType.getSyntax().isHumanReadable() )
+ {
+ if ( !( val instanceof StringValue ) )
+ {
+ String message = "The value must be a String, as its AttributeType is H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+ else
+ {
+ if ( !( val instanceof BinaryValue ) )
+ {
+ String message = "The value must be a byte[], as its AttributeType is not H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+
return values.add( val );
}
- public boolean add( String val )
+ /**
+ * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value...)
+ */
+ public int add( ServerValue<?>... vals ) throws InvalidAttributeValueException, NamingException
{
- return values.add( new ServerStringValue( attributeType, val ) );
+ int nbAdded = 0;
+
+ for ( ServerValue<?> val:vals )
+ {
+ if ( add( val ) )
+ {
+ nbAdded ++;
+ }
+ }
+
+ return nbAdded;
}
- public boolean add( byte[] val )
+ /**
+ * @see EntryAttribute#add(String)
+ */
+ public boolean add( String val ) throws InvalidAttributeValueException, NamingException
{
- return values.add( new ServerBinaryValue( attributeType, val ) );
+ if ( attributeType.getSyntax().isHumanReadable() )
+ {
+ return add( new ServerStringValue( attributeType, val ) );
+ }
+ else
+ {
+ String message = "The value must be a String, as its AttributeType is H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
}
+ /**
+ * @see EntryAttribute#add(String...)
+ */
+ public int add( String... vals ) throws InvalidAttributeValueException, NamingException
+ {
+ int nbAdded = 0;
+
+ for ( String val:vals )
+ {
+ if ( add( val ) )
+ {
+ nbAdded ++;
+ }
+ }
+
+ return nbAdded;
+ }
+
+
+ /**
+ * @see EntryAttribute#add(byte[])
+ */
+ public boolean add( byte[] val ) throws InvalidAttributeValueException, NamingException
+ {
+ if ( ! attributeType.getSyntax().isHumanReadable() )
+ {
+ return add( new ServerBinaryValue( attributeType, val ) );
+ }
+ else
+ {
+ String message = "The value must be a byte[], as its AttributeType is not H/R";
+ LOG.error( message );
+ throw new InvalidAttributeValueException( message );
+ }
+ }
+
+
+ /**
+ * @see EntryAttribute#add(byte[]...)
+ */
+ public int add( byte[]... vals ) throws InvalidAttributeValueException, NamingException
+ {
+ int nbAdded = 0;
+
+ for ( byte[] val:vals )
+ {
+ if ( add( val ) )
+ {
+ nbAdded ++;
+ }
+ }
+
+ return nbAdded;
+ }
+
+ /**
+ * Remove all the values from this attribute type, including a
+ * null value.
+ */
public void clear()
{
values.clear();
}
+ /**
+ * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value)
+ */
public boolean contains( ServerValue<?> val )
{
return values.contains( val );
}
+ /**
+ * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value...)
+ */
+ public boolean contains( ServerValue<?>... vals )
+ {
+ // Iterate through all the values, and quit if we
+ // don't find one in the values
+ for ( ServerValue<?> val:vals )
+ {
+ if ( !values.contains( val ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(String)
+ */
public boolean contains( String val )
{
- ServerStringValue ssv = new ServerStringValue( attributeType, val );
- return values.contains( ssv );
+ try
+ {
+ if ( !attributeType.getSyntax().isHumanReadable() )
+ {
+ return false;
+ }
+ }
+ catch ( NamingException ne )
+ {
+ // We have had a pb while getting the syntax...
+ return false;
+ }
+
+ ServerStringValue value = new ServerStringValue( attributeType, val );
+
+ return values.contains( value );
}
+ /**
+ * @see EntryAttribute#contains(String...)
+ */
+ public boolean contains( String... vals )
+ {
+ // Iterate through all the values, and quit if we
+ // don't find one in the values
+ for ( String val:vals )
+ {
+ if ( !contains( val ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * @see EntryAttribute#contains(byte[])
+ */
public boolean contains( byte[] val )
{
+ try
+ {
+ if ( attributeType.getSyntax().isHumanReadable() )
+ {
+ return false;
+ }
+ }
+ catch ( NamingException ne )
+ {
+ // We have had a pb while getting the syntax...
+ return false;
+ }
+
ServerBinaryValue sbv = new ServerBinaryValue( attributeType, val );
return values.contains( sbv );
}
+ /**
+ * @see EntryAttribute#contains(byte[]...)
+ */
+ public boolean contains( byte[]... vals )
+ {
+ // Iterate through all the values, and quit if we
+ // don't find one in the values
+ for ( byte[] val:vals )
+ {
+ if ( !contains( val ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Get the first value of this attribute. If there is none,
+ * null is returned.
+ *
+ * Note : as we are storing values into a Set, one can't assume
+ * the values to be ordered in any way. This method is meant to
+ * be used if the attribute hold only one value.
+ *
+ * @return The first value for this attribute.
+ */
public ServerValue<?> get()
{
if ( values.isEmpty() )
@@ -309,24 +507,59 @@
}
+ /**
+ * Get all the stored values.
+ *
+ * @return An iterator over the values stored into the attribute
+ */
public Iterator<ServerValue<?>> getAll()
{
return iterator();
}
+ /**
+ * Get the number or values stored in the attribute
+ *
+ * @return the number of stored values. As 'null' can be a valid
+ * value, it is counted as one result, not 0.
+ */
public int size()
{
return values.size();
}
+ /**
+ * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value)
+ */
public boolean remove( ServerValue<?> val )
{
return values.remove( val );
}
+ /**
+ * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value...)
+ */
+ public boolean remove( ServerValue<?>... vals )
+ {
+ boolean removed = false;
+
+ // Loop through all the values to remove. If one of
+ // them is not present, the method will return false.
+ for ( ServerValue<?> val:vals )
+ {
+ removed &= values.remove( val );
+ }
+
+ return removed;
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(byte[])
+ */
public boolean remove( byte[] val )
{
ServerBinaryValue sbv = new ServerBinaryValue( attributeType, val );
@@ -334,6 +567,26 @@
}
+ /**
+ * @see EntryAttribute#remove(byte[]...)
+ */
+ public boolean remove( byte[]... vals )
+ {
+ boolean removed = true;
+
+ for ( byte[] val:vals )
+ {
+ ServerBinaryValue value = new ServerBinaryValue( attributeType, val );
+ removed &= values.remove( value );
+ }
+
+ return removed;
+ }
+
+
+ /**
+ * @see EntryAttribute#remove(String)
+ */
public boolean remove( String val )
{
ServerStringValue ssv = new ServerStringValue( attributeType, val );
@@ -341,6 +594,28 @@
}
+ /**
+ * @see EntryAttribute#remove(String...)
+ */
+ public boolean remove( String... vals )
+ {
+ boolean removed = true;
+
+ for ( String val:vals )
+ {
+ ServerStringValue value = new ServerStringValue( attributeType, val );
+ removed &= values.remove( value );
+ }
+
+ return removed;
+ }
+
+
+ /**
+ * An iterator on top of the stored values.
+ *
+ * @return an iterator over the stored values.
+ */
public Iterator<ServerValue<?>> iterator()
{
return values.iterator();
Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java?rev=604510&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java (added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java Sat Dec 15 12:38:19 2007
@@ -0,0 +1,415 @@
+/*
+ * 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.server.core.entry;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.NotImplementedException;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.NamingException;
+
+
+/**
+ * A default implementation of a ServerEntry which should suite most
+ * use cases.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DefaultServerEntry implements ServerEntry<ServerAttribute<ServerValue<?>>>
+{
+ private static final Logger LOG = LoggerFactory.getLogger( DefaultServerEntry.class );
+
+ private Map<AttributeType, ServerAttribute<ServerValue<?>>> serverAttributeMap = new HashMap<AttributeType, ServerAttribute<ServerValue<?>>>();
+ private ObjectClassAttribute objectClassAttribute;
+ private final transient Registries registries;
+ private transient AttributeType objectClassAT;
+ private LdapDN dn;
+
+
+ public DefaultServerEntry( LdapDN dn, Registries registries ) throws NamingException
+ {
+ this.dn = dn;
+ this.registries = registries;
+
+ objectClassAT = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT );
+ setObjectClassAttribute( new ObjectClassAttribute( registries ) );
+ }
+
+
+ private ServerAttribute<ServerValue<?>> setObjectClassAttribute( ServerAttribute<ServerValue<?>> objectClassAttribute ) throws NamingException
+ {
+ this.objectClassAttribute = (ObjectClassAttribute)objectClassAttribute;
+ return serverAttributeMap.put( objectClassAT, objectClassAttribute );
+ }
+
+
+ private ServerAttribute<ServerValue<?>> removeObjectClassAttribute( ServerAttribute<ServerValue<?>> objectClassAttribute ) throws NamingException
+ {
+ this.objectClassAttribute = (ObjectClassAttribute)objectClassAttribute;
+
+ return serverAttributeMap.remove( objectClassAT );
+ }
+
+
+ public boolean addObjectClass( ObjectClass objectClass, String alias ) throws NamingException
+ {
+ return objectClassAttribute.addObjectClass( objectClass, alias );
+ }
+
+
+ public boolean addObjectClass( ObjectClass objectClass ) throws NamingException
+ {
+ return objectClassAttribute.addObjectClass( objectClass );
+ }
+
+
+ public boolean hasObjectClass( ObjectClass objectClass )
+ {
+ return objectClassAttribute.hasObjectClass( objectClass );
+ }
+
+
+ public Set<ObjectClass> getAbstractObjectClasses()
+ {
+ return objectClassAttribute.getAbstractObjectClasses();
+ }
+
+
+ public ObjectClass getStructuralObjectClass()
+ {
+ return objectClassAttribute.getStructuralObjectClass();
+ }
+
+
+ public Set<ObjectClass> getStructuralObjectClasses()
+ {
+ return objectClassAttribute.getStructuralObjectClasses();
+ }
+
+
+ public Set<ObjectClass> getAuxiliaryObjectClasses()
+ {
+ return objectClassAttribute.getAuxiliaryObjectClasses();
+ }
+
+
+ public Set<ObjectClass> getAllObjectClasses()
+ {
+ return objectClassAttribute.getAllObjectClasses();
+ }
+
+
+ public Set<AttributeType> getMustList()
+ {
+ return objectClassAttribute.getMustList();
+ }
+
+
+ public Set<AttributeType> getMayList()
+ {
+ return objectClassAttribute.getMayList();
+ }
+
+
+ public boolean isValid()
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public boolean isValid( ObjectClass objectClass )
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public ServerAttribute<ServerValue<?>> get( AttributeType attributeType )
+ {
+ return serverAttributeMap.get( attributeType );
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( ServerAttribute<ServerValue<?>> serverAttribute ) throws NamingException
+ {
+ if ( serverAttribute.getType().equals( objectClassAT ) && serverAttribute instanceof ObjectClassAttribute )
+ {
+ return setObjectClassAttribute( ( ObjectClassAttribute ) serverAttribute );
+ }
+
+ if ( serverAttribute.getType().equals( objectClassAT ) )
+ {
+ ObjectClassAttribute objectClassAttribute = new ObjectClassAttribute( registries );
+
+ for ( ServerValue<?> val : serverAttribute )
+ {
+ objectClassAttribute.add( val );
+ }
+
+ return setObjectClassAttribute( objectClassAttribute );
+ }
+
+ return serverAttributeMap.put( serverAttribute.getType(), serverAttribute );
+ }
+
+
+ public List<ServerAttribute<ServerValue<?>>> put( ServerAttribute<ServerValue<?>>... serverAttributes ) throws NamingException
+ {
+ List<ServerAttribute<ServerValue<?>>> duplicatedAttributes = new ArrayList<ServerAttribute<ServerValue<?>>>();
+
+ for ( ServerAttribute<ServerValue<?>> serverAttribute:serverAttributes )
+ {
+ if ( serverAttribute.getType().equals( objectClassAT ) )
+ {
+ if ( serverAttribute instanceof ObjectClassAttribute )
+ {
+ setObjectClassAttribute( ( ObjectClassAttribute ) serverAttribute );
+ }
+ else
+ {
+ ObjectClassAttribute objectClassAttribute = new ObjectClassAttribute( registries );
+
+ for ( ServerValue<?> val : serverAttribute )
+ {
+ objectClassAttribute.add( val );
+ }
+
+ setObjectClassAttribute( objectClassAttribute );
+ }
+ }
+
+ if ( serverAttributeMap.containsKey( serverAttribute.getType() ) )
+ {
+ duplicatedAttributes.add( serverAttribute );
+ }
+ else
+ {
+ serverAttributeMap.put( serverAttribute.getType(), serverAttribute );
+ }
+ }
+
+ return duplicatedAttributes;
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType ) throws NamingException
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( AttributeType attributeType ) throws NamingException
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public ServerAttribute<ServerValue<?>> remove( ServerAttribute<ServerValue<?>> serverAttribute ) throws NamingException
+ {
+ if ( serverAttribute.getType().equals( objectClassAT ) )
+ {
+ return setObjectClassAttribute( new ObjectClassAttribute( registries ) );
+ }
+
+ return serverAttributeMap.remove( serverAttribute.getType() );
+ }
+
+
+ public List<ServerAttribute<ServerValue<?>>> remove( ServerAttribute<ServerValue<?>>... serverAttributes ) throws NamingException
+ {
+ List<ServerAttribute<ServerValue<?>>> removedAttributes = new ArrayList<ServerAttribute<ServerValue<?>>>();
+
+ for ( ServerAttribute<ServerValue<?>> serverAttribute:serverAttributes )
+ {
+ if ( serverAttribute.getType().equals( objectClassAT ) )
+ {
+ removeObjectClassAttribute( new ObjectClassAttribute( registries ) );
+ }
+
+ if ( serverAttributeMap.containsKey( serverAttribute.getType() ) )
+ {
+ serverAttributeMap.remove( serverAttribute.getType() );
+ removedAttributes.add( serverAttribute );
+ }
+ }
+
+ return removedAttributes;
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( AttributeType attributeType, ServerValue<?> val ) throws NamingException
+ {
+ ServerAttribute<ServerValue<?>> existing = serverAttributeMap.get( attributeType );
+
+ if ( existing != null )
+ {
+ return put( existing.getUpId(), attributeType, val );
+ }
+ else
+ {
+ return put( null, attributeType, val );
+ }
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
+ {
+ if ( attributeType.equals( objectClassAT ) )
+ {
+ return setObjectClassAttribute( new ObjectClassAttribute( upId, registries, val ) );
+ }
+
+ return serverAttributeMap.put( attributeType, new DefaultServerAttribute( upId, attributeType, val ) );
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( AttributeType attributeType, String val ) throws NamingException
+ {
+ ServerAttribute<ServerValue<?>> existing = serverAttributeMap.get( attributeType );
+
+ if ( attributeType.equals( objectClassAT ) )
+ {
+ if ( existing != null )
+ {
+ return setObjectClassAttribute( new ObjectClassAttribute( existing.getUpId(), registries, val ) );
+ }
+
+ return setObjectClassAttribute( new ObjectClassAttribute( registries, val ) );
+ }
+
+ if ( existing != null )
+ {
+ return put( existing.getUpId(), attributeType, val );
+ }
+ else
+ {
+ return put( null, attributeType, val );
+ }
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType, String val ) throws NamingException
+ {
+ if ( attributeType.equals( objectClassAT ) )
+ {
+ return setObjectClassAttribute( new ObjectClassAttribute( upId, registries, val ) );
+ }
+
+ return serverAttributeMap.put( attributeType, new DefaultServerAttribute( upId, attributeType, val ) );
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( AttributeType attributeType, byte[] val ) throws NamingException
+ {
+ if ( attributeType.equals( objectClassAT ) )
+ {
+ throw new UnsupportedOperationException( "Only String values supported for objectClass attribute" );
+ }
+
+ ServerAttribute<ServerValue<?>> existing = serverAttributeMap.get( attributeType );
+
+ if ( existing != null )
+ {
+ return put( existing.getUpId(), attributeType, val );
+ }
+ else
+ {
+ return put( null, attributeType, val );
+ }
+ }
+
+
+ public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType, byte[] val ) throws NamingException
+ {
+ if ( attributeType.equals( objectClassAT ) )
+ {
+ throw new UnsupportedOperationException( "Only String values supported for objectClass attribute" );
+ }
+
+ return serverAttributeMap.put( attributeType, new DefaultServerAttribute( upId, attributeType, val ) );
+ }
+
+
+ public ServerAttribute<ServerValue<?>> remove( AttributeType attributeType ) throws NamingException
+ {
+ if ( attributeType.equals( objectClassAT ) )
+ {
+ return setObjectClassAttribute( new ObjectClassAttribute( registries ) );
+ }
+ else
+ {
+ return serverAttributeMap.remove( attributeType );
+ }
+ }
+
+
+ public void clear()
+ {
+ serverAttributeMap.clear();
+
+ try
+ {
+ setObjectClassAttribute( new ObjectClassAttribute( registries ) );
+ }
+ catch ( NamingException e )
+ {
+ String msg = "failed to properly set the objectClass attribute on clear";
+ LOG.error( msg, e );
+ throw new IllegalStateException( msg, e );
+ }
+ }
+
+
+ public LdapDN getDn()
+ {
+ return dn;
+ }
+
+
+ public void setDn( LdapDN dn )
+ {
+ this.dn = dn;
+ }
+
+
+ public Iterator<ServerAttribute<ServerValue<?>>> iterator()
+ {
+ return Collections.unmodifiableMap( serverAttributeMap ).values().iterator();
+ }
+
+
+ public int size()
+ {
+ return serverAttributeMap.size();
+ }
+}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java?rev=604510&r1=604509&r2=604510&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java Sat Dec 15 12:38:19 2007
@@ -27,7 +27,6 @@
import javax.naming.NamingException;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import java.util.Collections;
@@ -38,20 +37,11 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ObjectClassAttribute implements ServerAttribute<ServerValue<?>>
+public class ObjectClassAttribute extends AbstractServerAttribute
{
- /** A logger */
+ /** logger for reporting errors that might not be handled properly upstream */
private static final Logger LOG = LoggerFactory.getLogger( ObjectClassAttribute.class );
- /** An unordered set storing the values */
- private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
-
- /** The associated Attribute Type */
- private AttributeType attributeType;
-
- /** The attribute User Provided ID */
- private String upId;
-
// Sets dealing with objectClass operations
private Set<ObjectClass> allObjectClasses = new HashSet<ObjectClass>();
private Set<ObjectClass> abstractObjectClasses = new HashSet<ObjectClass>();
@@ -63,9 +53,6 @@
- // maybe have some additional convenience constructors which take
- // an initial value as a string or a byte[]
-
/**
* Creates a new ObjectClassAttribute with a null ID
*
@@ -86,8 +73,8 @@
*/
public ObjectClassAttribute( String upId, Registries registries ) throws NamingException
{
- setAttributeTypeAndRegistries( registries );
- setUpId( upId );
+ attributeType = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT_OID );
+ setUpId( upId, attributeType );
}
@@ -113,7 +100,7 @@
*/
public ObjectClassAttribute( String upId, Registries registries, ServerValue<?> val ) throws NamingException
{
- setAttributeTypeAndRegistries( registries );
+ attributeType = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT_OID );
if ( val == null )
{
@@ -121,14 +108,16 @@
}
else if ( ! ( val instanceof ServerStringValue ) )
{
- throw new UnsupportedOperationException( "Only String values supported for objectClass attribute" );
+ String message = "Only String values supported for objectClass attribute";
+ LOG.error( message );
+ throw new UnsupportedOperationException( message );
}
else
{
values.add( val );
}
- setUpId( upId );
+ setUpId( upId, attributeType );
}
@@ -140,7 +129,7 @@
public ObjectClassAttribute( String upId, Registries registries, String val ) throws NamingException
{
- setAttributeTypeAndRegistries( registries );
+ attributeType = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT_OID );
if ( val == null )
{
@@ -151,65 +140,10 @@
values.add( new ServerStringValue( attributeType, val ) );
}
- setUpId( upId );
+ setUpId( upId, attributeType );
}
- /**
- * Initialize the ObjectClass attributeType, using the ObjectClass' OID.
- *
- * TODO This is a strange method : we _know_ that the ObjectClass' attributeType
- * will always be the same, but we can't initialize it to its default value,
- * unless the server is already started, or if we call this method only once,
- * but then we need to synchronize this class, which can be a burden.
- *
- * This is was seems the best anyway...
- *
- * @param registries The registries used to extract the AttributeType
- *
- * @throws NamingException If something went wrong (very unlikely)
- */
- private void setAttributeTypeAndRegistries( Registries registries ) throws NamingException
- {
- synchronized ( attributeType )
- {
- if ( attributeType == null )
- {
- attributeType = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT_OID );
- }
- }
- }
-
-
- /**
- * Set the user provided value for this objectClass.
- *
- * @param upId The user provided ID
- * @param attributeType
- */
- private void setUpId( String upId )
- {
- if ( upId == null )
- {
- String name = attributeType.getName();
-
- if ( name == null )
- {
- this.upId = attributeType.getOid();
- }
- else
- {
- this.upId = name;
- }
- }
- else
- {
- this.upId = upId;
- }
- }
-
-
-
// -----------------------------------------------------------------------
@@ -268,7 +202,9 @@
break;
default:
- throw new IllegalStateException( "Unrecognized objectClass type value: " + oc.getType() );
+ String message = "Unrecognized objectClass type value: " + oc.getType();
+ LOG.error( message );
+ throw new UnsupportedOperationException( message );
}
// now go through all objectClassses to collect the must an may list attributes
@@ -344,145 +280,27 @@
return Collections.unmodifiableSet( mayList );
}
-
- /**
- * Gets the attribute type associated with this ServerAttribute.
- *
- * @return the attributeType associated with this entry attribute
- */
- public AttributeType getType()
- {
- return attributeType;
- }
-
-
- /**
- * Get's the user provided identifier for this entry. This is the value
- * that will be used as the identifier for the attribute within the
- * entry. If this is a commonName attribute for example and the user
- * provides "COMMONname" instead when adding the entry then this is
- * the format the user will have that entry returned by the directory
- * server. To do so we store this value as it was given and track it
- * in the attribute using this property.
- *
- * @return the user provided identifier for this attribute
- */
- public String getUpId()
- {
- return upId;
- }
-
-
- /**
- * Checks to see if this attribute is valid along with the values it contains.
- *
- * @return true if the attribute and it's values are valid, false otherwise
- * @throws NamingException if there is a failure to check syntaxes of values
- */
- public boolean isValid() throws NamingException
- {
- for ( ServerValue<?> value:values )
- {
- if ( ! value.isValid() )
- {
- return false;
- }
- }
-
- return true;
- }
-
-
- /**
- * Add a value to the current objectClass
- */
- public boolean add( ServerValue<?> val )
- {
- return values.add( (ServerValue<?>)val );
- }
-
-
- public boolean add( String val )
- {
- return values.add( new ServerStringValue( attributeType, val ) );
- }
-
-
+
public boolean add( byte[] val )
{
- throw new UnsupportedOperationException( "Binary values are not accepted by ObjectClassAttributes" );
- }
-
-
- public void clear()
- {
- values.clear();
- }
-
-
- public boolean contains( ServerValue<?> val )
- {
- return values.contains( val );
- }
-
-
- public boolean contains( String val )
- {
- ServerStringValue ssv = new ServerStringValue( attributeType, val );
- return values.contains( ssv );
+ String message = "Binary values are not accepted by ObjectClassAttributes";
+ LOG.error( message );
+ throw new UnsupportedOperationException( message );
}
public boolean contains( byte[] val )
{
- throw new UnsupportedOperationException( "There are no binary values in an ObjectClass attribute." );
- }
-
-
- public ServerValue<?> get()
- {
- if ( values.isEmpty() )
- {
- return null;
- }
-
- return values.iterator().next();
- }
-
-
- public Iterator<ServerValue<?>> getAll()
- {
- return iterator();
- }
-
-
- public int size()
- {
- return values.size();
- }
-
-
- public boolean remove( ServerValue<?> val )
- {
- return values.remove( val );
+ String message = "There are no binary values in an ObjectClass attribute.";
+ LOG.error( message );
+ throw new UnsupportedOperationException( message );
}
public boolean remove( byte[] val )
{
- throw new UnsupportedOperationException( "There are no binary values in an ObjectClass attribute." );
- }
-
-
- public boolean remove( String val )
- {
- ServerStringValue ssv = new ServerStringValue( attributeType, val );
- return values.remove( ssv );
- }
-
-
- public Iterator<ServerValue<?>> iterator()
- {
- return values.iterator();
+ String message = "There are no binary values in an ObjectClass attribute.";
+ LOG.error( message );
+ throw new UnsupportedOperationException( message );
}
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=604510&r1=604509&r2=604510&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Sat Dec 15 12:38:19 2007
@@ -63,10 +63,7 @@
*/
public ServerBinaryValue( AttributeType attributeType )
{
- if ( attributeType == null )
- {
- throw new NullPointerException( "attributeType cannot be null" );
- }
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
try
{
@@ -247,7 +244,6 @@
try
{
- //noinspection unchecked
return getComparator().compare( getNormalizedReference(), binaryValue.getNormalizedReference() );
}
catch ( NamingException e )
@@ -280,13 +276,7 @@
return true;
}
- //noinspection RedundantIfStatement
- if ( this.attributeType.isDescentantOf( attributeType ) )
- {
- return true;
- }
-
- return false;
+ return this.attributeType.isDescentantOf( attributeType );
}
@@ -311,7 +301,7 @@
try
{
- return getNormalizedReference().hashCode();
+ return Arrays.hashCode( getNormalizedReference() );
}
catch ( NamingException e )
{
@@ -335,11 +325,6 @@
if ( this == obj )
{
return true;
- }
-
- if ( obj == null )
- {
- return false;
}
if ( ! ( obj instanceof ServerBinaryValue ) )
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=604510&r1=604509&r2=604510&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Sat Dec 15 12:38:19 2007
@@ -45,10 +45,6 @@
/** logger for reporting errors that might not be handled properly upstream */
private static final Logger LOG = LoggerFactory.getLogger( ServerStringValue.class );
- /** used to dynamically lookup the attributeType when/if deserializing */
- @SuppressWarnings ( { "FieldCanBeLocal", "UnusedDeclaration" } )
- private final String oid;
-
/** reference to the attributeType which is not serialized */
private transient AttributeType attributeType;
@@ -66,10 +62,7 @@
*/
public ServerStringValue( AttributeType attributeType )
{
- if ( attributeType == null )
- {
- throw new NullPointerException( "attributeType cannot be null" );
- }
+ assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
try
{
@@ -85,7 +78,6 @@
}
this.attributeType = attributeType;
- this.oid = attributeType.getOid();
}
@@ -251,13 +243,7 @@
return true;
}
- //noinspection RedundantIfStatement
- if ( this.attributeType.isDescentantOf( attributeType ) )
- {
- return true;
- }
-
- return false;
+ return this.attributeType.isDescentantOf( attributeType );
}
@@ -306,11 +292,6 @@
if ( this == obj )
{
return true;
- }
-
- if ( obj == null )
- {
- return false;
}
if ( ! ( obj instanceof ServerStringValue ) )