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 2012/01/24 18:44:32 UTC
svn commit: r1235374 [4/27] - in /directory/shared/trunk:
ldap/model/src/main/java/org/apache/directory/shared/ldap/model/constants/
ldap/model/src/main/java/org/apache/directory/shared/ldap/model/csn/
ldap/model/src/main/java/org/apache/directory/shar...
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java Tue Jan 24 17:44:03 2012
@@ -52,10 +52,10 @@ public class DefaultAttribute implements
/** The associated AttributeType */
private AttributeType attributeType;
-
+
/** The set of contained values */
private Set<Value<?>> values = new LinkedHashSet<Value<?>>();
-
+
/** The User provided ID */
private String upId;
@@ -65,17 +65,18 @@ public class DefaultAttribute implements
/** Tells if the attribute is Human Readable or not. When not set,
* this flag is null. */
private Boolean isHR;
-
+
/** The computed hashcode. We don't want to compute it each time the hashcode() method is called */
private volatile int h;
-
+
+
//-------------------------------------------------------------------------
// Helper methods
//-------------------------------------------------------------------------
private Value<String> createStringValue( AttributeType attributeType, String value )
{
Value<String> stringValue = null;
-
+
if ( attributeType != null )
{
try
@@ -91,15 +92,16 @@ public class DefaultAttribute implements
{
stringValue = new StringValue( value );
}
-
+
return stringValue;
}
- private Value<byte[]> createBinaryValue( AttributeType attributeType, byte[] value ) throws LdapInvalidAttributeValueException
+ private Value<byte[]> createBinaryValue( AttributeType attributeType, byte[] value )
+ throws LdapInvalidAttributeValueException
{
Value<byte[]> binaryValue = null;
-
+
if ( attributeType != null )
{
binaryValue = new BinaryValue( attributeType, value );
@@ -108,12 +110,11 @@ public class DefaultAttribute implements
{
binaryValue = new BinaryValue( value );
}
-
+
return binaryValue;
}
-
//-------------------------------------------------------------------------
// Constructors
//-------------------------------------------------------------------------
@@ -123,7 +124,7 @@ public class DefaultAttribute implements
* Create a new instance of a Attribute, without ID nor value.
* Used by the serializer
*/
- /* No protection*/ DefaultAttribute()
+ /* No protection*/DefaultAttribute()
{
}
@@ -132,14 +133,15 @@ public class DefaultAttribute implements
* Create a new instance of a schema aware Attribute, without ID nor value.
* Used by the serializer
*/
- /* No protection*/ DefaultAttribute( AttributeType attributeType, String upId, String normId, boolean isHR, int hashCode, Value<?>... values)
+ /* No protection*/DefaultAttribute( AttributeType attributeType, String upId, String normId, boolean isHR,
+ int hashCode, Value<?>... values )
{
this.attributeType = attributeType;
this.upId = upId;
this.id = normId;
this.isHR = isHR;
this.h = hashCode;
-
+
if ( values != null )
{
for ( Value<?> value : values )
@@ -189,7 +191,7 @@ public class DefaultAttribute implements
*/
public DefaultAttribute( String upId, AttributeType attributeType )
{
- if ( attributeType == null )
+ if ( attributeType == null )
{
String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
LOG.error( message );
@@ -197,14 +199,14 @@ public class DefaultAttribute implements
}
try
- {
+ {
apply( attributeType );
}
catch ( LdapInvalidAttributeValueException liave )
{
// Do nothing, it can't happen, there is no value
}
-
+
setUpId( upId, attributeType );
}
@@ -225,13 +227,13 @@ public class DefaultAttribute implements
// The value can be null, this is a valid value.
if ( vals[0] == null )
{
- add( new StringValue( (String)null ) );
+ add( new StringValue( ( String ) null ) );
}
else
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
- if ( ( val instanceof StringValue) || ( !val.isHumanReadable() ) )
+ if ( ( val instanceof StringValue ) || ( !val.isHumanReadable() ) )
{
add( val );
}
@@ -243,7 +245,7 @@ public class DefaultAttribute implements
}
}
}
-
+
setUpId( upId );
}
@@ -271,7 +273,8 @@ public class DefaultAttribute implements
* @throws LdapInvalidAttributeValueException If any of the
* added values is not valid
*/
- public DefaultAttribute( String upId, AttributeType attributeType, String... vals ) throws LdapInvalidAttributeValueException
+ public DefaultAttribute( String upId, AttributeType attributeType, String... vals )
+ throws LdapInvalidAttributeValueException
{
if ( attributeType == null )
{
@@ -281,12 +284,12 @@ public class DefaultAttribute implements
}
apply( attributeType );
-
+
if ( ( vals != null ) && ( vals.length > 0 ) )
{
add( vals );
}
-
+
setUpId( upId, attributeType );
}
@@ -305,7 +308,8 @@ public class DefaultAttribute implements
* @throws LdapInvalidAttributeValueException If any of the
* added values is not valid
*/
- public DefaultAttribute( String upId, AttributeType attributeType, Value<?>... vals ) throws LdapInvalidAttributeValueException
+ public DefaultAttribute( String upId, AttributeType attributeType, Value<?>... vals )
+ throws LdapInvalidAttributeValueException
{
if ( attributeType == null )
{
@@ -313,7 +317,7 @@ public class DefaultAttribute implements
LOG.error( message );
throw new IllegalArgumentException( message );
}
-
+
apply( attributeType );
setUpId( upId, attributeType );
add( vals );
@@ -352,7 +356,7 @@ public class DefaultAttribute implements
{
// Do nothing, it can't happen
}
-
+
setUpId( upId );
}
@@ -366,14 +370,14 @@ public class DefaultAttribute implements
public DefaultAttribute( String upId, byte[]... vals )
{
try
- {
+ {
add( vals );
}
catch ( LdapInvalidAttributeValueException liave )
{
// Do nothing, this can't happen
}
-
+
setUpId( upId );
}
@@ -402,7 +406,8 @@ public class DefaultAttribute implements
* @throws LdapInvalidAttributeValueException If any of the
* added values is not valid
*/
- public DefaultAttribute( String upId, AttributeType attributeType, byte[]... vals ) throws LdapInvalidAttributeValueException
+ public DefaultAttribute( String upId, AttributeType attributeType, byte[]... vals )
+ throws LdapInvalidAttributeValueException
{
if ( attributeType == null )
{
@@ -413,8 +418,8 @@ public class DefaultAttribute implements
add( vals );
setUpId( upId, attributeType );
}
-
-
+
+
/**
* Creates a new instance of schema aware Attribute, by copying another attribute.
* If the initial Attribute is not schema aware, the copy will be if the attributeType
@@ -435,7 +440,7 @@ public class DefaultAttribute implements
isHR = attribute.isHumanReadable();
// Copy all the values
- for ( Value<?> value:attribute )
+ for ( Value<?> value : attribute )
{
add( value.clone() );
}
@@ -447,16 +452,16 @@ public class DefaultAttribute implements
}
else
{
-
+
isHR = attributeType.getSyntax().isHumanReadable();
// Copy all the values
- for ( Value<?> clientValue:attribute )
+ for ( Value<?> clientValue : attribute )
{
- Value<?> serverValue = null;
+ Value<?> serverValue = null;
// We have to convert the value first
- if ( clientValue instanceof StringValue)
+ if ( clientValue instanceof StringValue )
{
if ( isHR )
{
@@ -465,7 +470,7 @@ public class DefaultAttribute implements
else
{
// We have to convert the value to a binary value first
- serverValue = new BinaryValue( attributeType,
+ serverValue = new BinaryValue( attributeType,
clientValue.getBytes() );
}
}
@@ -488,14 +493,14 @@ public class DefaultAttribute implements
}
}
-
+
/**
* {@inheritDoc}
*/
public byte[] getBytes() throws LdapInvalidAttributeValueException
{
Value<?> value = get();
-
+
if ( !isHR && ( value != null ) )
{
return value.getBytes();
@@ -513,12 +518,12 @@ public class DefaultAttribute implements
public String getString() throws LdapInvalidAttributeValueException
{
Value<?> value = get();
-
+
if ( isHR && ( value != null ) )
{
return value.getString();
}
-
+
String message = I18n.err( I18n.ERR_04131 );
LOG.error( message );
throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message );
@@ -551,7 +556,7 @@ public class DefaultAttribute implements
setUpId( upId, attributeType );
}
-
+
/**
* Check that the upId is either a name or the OID of a given AT
*/
@@ -560,12 +565,12 @@ public class DefaultAttribute implements
// First, get rid of the options, if any
int optPos = id.indexOf( ';' );
String idNoOption = id;
-
+
if ( optPos != -1 )
{
idNoOption = id.substring( 0, optPos );
}
-
+
// Check that we find the ID in the AT names
for ( String name : attributeType.getNames() )
{
@@ -574,11 +579,11 @@ public class DefaultAttribute implements
return true;
}
}
-
+
// Not found in names, check the OID
- return Oid.isOid(id) && attributeType.getOid().equals(id);
+ return Oid.isOid( id ) && attributeType.getOid().equals( id );
}
-
+
/**
* {@inheritDoc}
@@ -591,28 +596,28 @@ public class DefaultAttribute implements
{
throw new IllegalArgumentException( "Cannot set a null ID with a null AttributeType" );
}
-
+
String newId = Strings.toLowerCase( trimmed );
-
+
if ( attributeType == null )
{
if ( this.attributeType == null )
{
this.upId = upId;
this.id = newId;
-
+
// Compute the hashCode
rehash();
return;
- }
+ }
else
{
if ( areCompatible( newId, this.attributeType ) )
{
this.upId = upId;
this.id = this.attributeType.getOid();
-
+
// Compute the hashCode
rehash();
@@ -624,13 +629,13 @@ public class DefaultAttribute implements
}
}
}
-
+
if ( Strings.isEmpty( newId ) )
{
this.attributeType = attributeType;
this.upId = attributeType.getName();
this.id = attributeType.getOid();
-
+
// Compute the hashCode
rehash();
@@ -642,14 +647,15 @@ public class DefaultAttribute implements
this.upId = upId;
this.id = attributeType.getOid();
this.attributeType = attributeType;
-
+
// Compute the hashCode
rehash();
return;
}
- throw new IllegalArgumentException( "ID '" + id + "' and AttributeType '" + attributeType.getName() + "' are not compatible " );
+ throw new IllegalArgumentException( "ID '" + id + "' and AttributeType '" + attributeType.getName()
+ + "' are not compatible " );
}
@@ -658,36 +664,35 @@ public class DefaultAttribute implements
*/
public boolean isHumanReadable()
{
- return isHR != null ? isHR : false;
+ return isHR != null ? isHR : false;
}
-
+
/**
* {@inheritDoc}
*/
public boolean isValid( AttributeType attributeType ) throws LdapInvalidAttributeValueException
{
LdapSyntax syntax = attributeType.getSyntax();
-
+
if ( syntax == null )
{
return false;
}
-
+
SyntaxChecker syntaxChecker = syntax.getSyntaxChecker();
-
+
if ( syntaxChecker == null )
{
return false;
}
-
-
+
// Check that we can have no value for this attributeType
if ( values.size() == 0 )
{
return syntaxChecker.isValidSyntax( null );
}
-
+
// Check that we can't have more than one value if the AT is single-value
if ( attributeType.isSingleValued() )
{
@@ -720,27 +725,27 @@ public class DefaultAttribute implements
/**
* {@inheritDoc}
*/
- @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_LOAD_OF_KNOWN_NULL_VALUE",
- justification="Validity of null depends on the checker")
+ @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_LOAD_OF_KNOWN_NULL_VALUE",
+ justification = "Validity of null depends on the checker")
public int add( Value<?>... vals )
{
int nbAdded = 0;
BinaryValue nullBinaryValue = null;
StringValue nullStringValue = null;
boolean nullValueAdded = false;
-
+
if ( attributeType != null )
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
if ( attributeType.getSyntax().isHumanReadable() )
{
if ( ( val == null ) || val.isNull() )
{
try
- {
- Value<String> nullSV = new StringValue( attributeType, (String)null );
-
+ {
+ Value<String> nullSV = new StringValue( attributeType, ( String ) null );
+
if ( values.add( nullSV ) )
{
nbAdded++;
@@ -751,17 +756,17 @@ public class DefaultAttribute implements
continue;
}
}
- else if ( val instanceof StringValue)
+ else if ( val instanceof StringValue )
{
- StringValue stringValue = (StringValue)val;
-
+ StringValue stringValue = ( StringValue ) val;
+
try
- {
+ {
if ( stringValue.getAttributeType() == null )
{
stringValue.apply( attributeType );
}
-
+
if ( values.add( val ) )
{
nbAdded++;
@@ -786,8 +791,8 @@ public class DefaultAttribute implements
{
try
{
- Value<byte[]> nullSV = new BinaryValue( attributeType, (byte[])null );
-
+ Value<byte[]> nullSV = new BinaryValue( attributeType, ( byte[] ) null );
+
if ( values.add( nullSV ) )
{
nbAdded++;
@@ -808,15 +813,15 @@ public class DefaultAttribute implements
{
if ( val instanceof BinaryValue )
{
- BinaryValue binaryValue = (BinaryValue)val;
-
+ BinaryValue binaryValue = ( BinaryValue ) val;
+
try
{
if ( binaryValue.getAttributeType() == null )
{
- binaryValue = new BinaryValue( attributeType, val.getBytes() );
+ binaryValue = new BinaryValue( attributeType, val.getBytes() );
}
-
+
if ( values.add( binaryValue ) )
{
nbAdded++;
@@ -838,7 +843,7 @@ public class DefaultAttribute implements
}
else
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
if ( val == null )
{
@@ -851,9 +856,9 @@ public class DefaultAttribute implements
// know later if we add some new value.
// We have to do that because we are using a Set,
// and we can't remove the first element of the Set.
- nullBinaryValue = new BinaryValue( (byte[])null );
- nullStringValue = new StringValue( (String)null );
-
+ nullBinaryValue = new BinaryValue( ( byte[] ) null );
+ nullStringValue = new StringValue( ( String ) null );
+
values.add( nullBinaryValue );
values.add( nullStringValue );
nullValueAdded = true;
@@ -862,21 +867,21 @@ public class DefaultAttribute implements
else if ( !isHR )
{
// The attribute type is binary.
- nullBinaryValue = new BinaryValue( (byte[])null );
-
+ nullBinaryValue = new BinaryValue( ( byte[] ) null );
+
// Don't add a value if it already exists.
if ( !values.contains( nullBinaryValue ) )
{
values.add( nullBinaryValue );
nbAdded++;
}
-
+
}
else
{
// The attribute is HR
- nullStringValue = new StringValue( (String)null );
-
+ nullStringValue = new StringValue( ( String ) null );
+
// Don't add a value if it already exists.
if ( !values.contains( nullStringValue ) )
{
@@ -887,7 +892,7 @@ public class DefaultAttribute implements
else
{
// Let's check the value type.
- if ( val instanceof StringValue)
+ if ( val instanceof StringValue )
{
// We have a String value
if ( isHR == null )
@@ -902,7 +907,7 @@ public class DefaultAttribute implements
// The attributeType is binary, convert the
// value to a BinaryValue
BinaryValue bv = new BinaryValue( val.getBytes() );
-
+
if ( !contains( bv ) )
{
values.add( bv );
@@ -943,7 +948,7 @@ public class DefaultAttribute implements
// The attribute Type is HR, convert the
// value to a StringValue
StringValue sv = new StringValue( val.getString() );
-
+
if ( !contains( sv ) )
{
values.add( sv );
@@ -960,7 +965,7 @@ public class DefaultAttribute implements
// and to remove the other
if ( nullValueAdded )
{
- if ( isHR )
+ if ( isHR )
{
// Remove the Binary value
values.remove( nullBinaryValue );
@@ -982,7 +987,7 @@ public class DefaultAttribute implements
public int add( String... vals ) throws LdapInvalidAttributeValueException
{
int nbAdded = 0;
-
+
// First, if the isHR flag is not set, we assume that the
// attribute is HR, because we are asked to add some strings.
if ( isHR == null )
@@ -995,17 +1000,17 @@ public class DefaultAttribute implements
{
if ( isHR )
{
- for ( String val:vals )
+ for ( String val : vals )
{
Value<String> value = createStringValue( attributeType, val );
-
+
if ( value == null )
{
// The value can't be normalized : we don't add it.
LOG.error( I18n.err( I18n.ERR_04449, val ) );
continue;
}
-
+
// Call the add(Value) method, if not already present
if ( add( value ) == 1 )
{
@@ -1020,24 +1025,24 @@ public class DefaultAttribute implements
else
{
// The attribute is binary. Transform the String to byte[]
- for ( String val:vals )
+ for ( String val : vals )
{
byte[] valBytes = null;
-
+
if ( val != null )
{
- valBytes = Strings.getBytesUtf8(val);
+ valBytes = Strings.getBytesUtf8( val );
}
-
+
Value<byte[]> value = createBinaryValue( attributeType, valBytes );
-
+
if ( value == null )
{
// The value can't be normalized or is invalid : we don't add it.
LOG.error( I18n.err( I18n.ERR_04449, val ) );
continue;
}
-
+
// Now call the add(Value) method
if ( add( value ) == 1 )
{
@@ -1053,20 +1058,20 @@ public class DefaultAttribute implements
LOG.error( I18n.err( I18n.ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED, attributeType.getName() ) );
return 0;
}
-
+
if ( isHR )
{
- for ( String val:vals )
+ for ( String val : vals )
{
Value<String> value = createStringValue( attributeType, val );
-
+
if ( value == null )
{
// The value can't be normalized : we don't add it.
LOG.error( I18n.err( I18n.ERR_04449, val ) );
continue;
}
-
+
// Call the add(Value) method, if not already present
if ( add( value ) == 1 )
{
@@ -1081,24 +1086,24 @@ public class DefaultAttribute implements
else
{
// The attribute is binary. Transform the String to byte[]
- for ( String val:vals )
+ for ( String val : vals )
{
byte[] valBytes = null;
-
+
if ( val != null )
{
- valBytes = Strings.getBytesUtf8(val);
+ valBytes = Strings.getBytesUtf8( val );
}
-
+
Value<byte[]> value = createBinaryValue( attributeType, valBytes );
-
+
if ( value == null )
{
// The value can't be normalized or is invalid : we don't add it.
LOG.error( I18n.err( I18n.ERR_04449, val ) );
continue;
}
-
+
// Now call the add(Value) method
if ( add( value ) == 1 )
{
@@ -1107,31 +1112,31 @@ public class DefaultAttribute implements
}
}
}
-
+
return nbAdded;
- }
-
-
+ }
+
+
/**
* {@inheritDoc}
*/
public int add( byte[]... vals ) throws LdapInvalidAttributeValueException
{
int nbAdded = 0;
-
+
// First, if the isHR flag is not set, we assume that the
// attribute is not HR, because we are asked to add some byte[].
if ( isHR == null )
{
isHR = false;
}
-
+
if ( !isHR )
{
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
Value<byte[]> value = null;
-
+
if ( attributeType == null )
{
value = new BinaryValue( val );
@@ -1140,14 +1145,14 @@ public class DefaultAttribute implements
{
value = createBinaryValue( attributeType, val );
}
-
+
if ( add( value ) != 0 )
{
nbAdded++;
}
else
{
- LOG.error( I18n.err( I18n.ERR_04486_VALUE_ALREADY_EXISTS, Strings.dumpBytes(val), upId ) );
+ LOG.error( I18n.err( I18n.ERR_04486_VALUE_ALREADY_EXISTS, Strings.dumpBytes( val ), upId ) );
}
}
}
@@ -1157,11 +1162,11 @@ public class DefaultAttribute implements
LOG.info( I18n.err( I18n.ERR_04451 ) );
return 0;
}
-
+
return nbAdded;
- }
-
-
+ }
+
+
/**
* {@inheritDoc}
*/
@@ -1189,9 +1194,9 @@ public class DefaultAttribute implements
// Iterate through all the values, convert the Binary values
// to String values, and quit id any of the values is not
// contained in the object
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
- if ( val instanceof StringValue)
+ if ( val instanceof StringValue )
{
if ( !values.contains( val ) )
{
@@ -1201,9 +1206,9 @@ public class DefaultAttribute implements
else
{
byte[] binaryVal = val.getBytes();
-
+
// We have to convert the binary value to a String
- if ( ! values.contains( new StringValue( Strings.utf8ToString(binaryVal) ) ) )
+ if ( !values.contains( new StringValue( Strings.utf8ToString( binaryVal ) ) ) )
{
return false;
}
@@ -1215,14 +1220,14 @@ public class DefaultAttribute implements
// Iterate through all the values, convert the String values
// to binary values, and quit id any of the values is not
// contained in the object
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
if ( val.isHumanReadable() )
{
String stringVal = val.getString();
-
+
// We have to convert the binary value to a String
- if ( ! values.contains( new BinaryValue( Strings.getBytesUtf8(stringVal) ) ) )
+ if ( !values.contains( new BinaryValue( Strings.getBytesUtf8( stringVal ) ) ) )
{
return false;
}
@@ -1244,12 +1249,12 @@ public class DefaultAttribute implements
// depending on the isHR flag value.
if ( isHR )
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
- if ( val instanceof StringValue)
+ if ( val instanceof StringValue )
{
- StringValue stringValue = (StringValue)val;
-
+ StringValue stringValue = ( StringValue ) val;
+
try
{
if ( stringValue.getAttributeType() == null )
@@ -1261,7 +1266,7 @@ public class DefaultAttribute implements
{
return false;
}
-
+
if ( !values.contains( val ) )
{
return false;
@@ -1276,7 +1281,7 @@ public class DefaultAttribute implements
}
else
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
if ( val instanceof BinaryValue )
{
@@ -1293,7 +1298,7 @@ public class DefaultAttribute implements
}
}
}
-
+
return true;
}
@@ -1313,7 +1318,7 @@ public class DefaultAttribute implements
{
if ( isHR )
{
- for ( String val:vals )
+ for ( String val : vals )
{
try
{
@@ -1334,10 +1339,10 @@ public class DefaultAttribute implements
// the values before checking for them in the values
// Iterate through all the values, and quit if we
// don't find one in the values
- for ( String val:vals )
+ for ( String val : vals )
{
- byte[] binaryVal = Strings.getBytesUtf8(val);
-
+ byte[] binaryVal = Strings.getBytesUtf8( val );
+
if ( !contains( new BinaryValue( binaryVal ) ) )
{
return false;
@@ -1351,12 +1356,12 @@ public class DefaultAttribute implements
{
// Iterate through all the values, and quit if we
// don't find one in the values
- for ( String val:vals )
+ for ( String val : vals )
{
try
{
StringValue value = new StringValue( attributeType, val );
-
+
if ( !values.contains( value ) )
{
return false;
@@ -1367,7 +1372,7 @@ public class DefaultAttribute implements
return false;
}
}
-
+
return true;
}
else
@@ -1375,11 +1380,11 @@ public class DefaultAttribute implements
return false;
}
}
-
+
return true;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -1397,7 +1402,7 @@ public class DefaultAttribute implements
{
// Iterate through all the values, and quit if we
// don't find one in the values
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
if ( !contains( new BinaryValue( val ) ) )
{
@@ -1411,10 +1416,10 @@ public class DefaultAttribute implements
// the values before checking for them in the values
// Iterate through all the values, and quit if we
// don't find one in the values
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
- String stringVal = Strings.utf8ToString(val);
-
+ String stringVal = Strings.utf8ToString( val );
+
if ( !contains( new StringValue( stringVal ) ) )
{
return false;
@@ -1428,12 +1433,12 @@ public class DefaultAttribute implements
{
// Iterate through all the values, and quit if we
// don't find one in the values
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
try
- {
+ {
BinaryValue value = new BinaryValue( attributeType, val );
-
+
if ( !values.contains( value ) )
{
return false;
@@ -1444,7 +1449,7 @@ public class DefaultAttribute implements
return false;
}
}
-
+
return true;
}
else
@@ -1452,11 +1457,11 @@ public class DefaultAttribute implements
return false;
}
}
-
+
return true;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -1466,7 +1471,7 @@ public class DefaultAttribute implements
{
return null;
}
-
+
return values.iterator().next();
}
@@ -1485,21 +1490,21 @@ public class DefaultAttribute implements
*/
public boolean remove( Value<?>... vals )
{
- if ( ( isHR == null ) || ( values.size() == 0 ) )
+ if ( ( isHR == null ) || ( values.size() == 0 ) )
{
// Trying to remove a value from an empty list will fail
return false;
}
-
+
boolean removed = true;
-
+
if ( attributeType == null )
{
if ( isHR )
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
- if ( val instanceof StringValue)
+ if ( val instanceof StringValue )
{
removed &= values.remove( val );
}
@@ -1507,13 +1512,13 @@ public class DefaultAttribute implements
{
// Convert the binary value to a string value
byte[] binaryVal = val.getBytes();
- removed &= values.remove( new StringValue( Strings.utf8ToString(binaryVal) ) );
+ removed &= values.remove( new StringValue( Strings.utf8ToString( binaryVal ) ) );
}
}
}
else
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
removed &= values.remove( val );
}
@@ -1526,19 +1531,19 @@ public class DefaultAttribute implements
// As the attribute may be HR or not, we have two separated treatments
if ( isHR )
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
- if ( val instanceof StringValue)
+ if ( val instanceof StringValue )
{
- StringValue stringValue = (StringValue)val;
-
+ StringValue stringValue = ( StringValue ) val;
+
try
{
if ( stringValue.getAttributeType() == null )
{
stringValue.apply( attributeType );
}
-
+
removed &= values.remove( stringValue );
}
catch ( LdapInvalidAttributeValueException liave )
@@ -1554,19 +1559,19 @@ public class DefaultAttribute implements
}
else
{
- for ( Value<?> val:vals )
+ for ( Value<?> val : vals )
{
if ( val instanceof BinaryValue )
{
try
{
- BinaryValue binaryValue = (BinaryValue)val;
-
+ BinaryValue binaryValue = ( BinaryValue ) val;
+
if ( binaryValue.getAttributeType() == null )
{
binaryValue.apply( attributeType );
}
-
+
removed &= values.remove( binaryValue );
}
catch ( LdapInvalidAttributeValueException liave )
@@ -1581,7 +1586,7 @@ public class DefaultAttribute implements
}
}
}
-
+
return removed;
}
@@ -1591,20 +1596,20 @@ public class DefaultAttribute implements
*/
public boolean remove( byte[]... vals )
{
- if ( ( isHR == null ) || ( values.size() == 0 ) )
+ if ( ( isHR == null ) || ( values.size() == 0 ) )
{
// Trying to remove a value from an empty list will fail
return false;
}
-
+
boolean removed = true;
-
+
if ( attributeType == null )
{
if ( !isHR )
{
// The attribute type is not HR, we can directly process the values
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
BinaryValue value = new BinaryValue( val );
removed &= values.remove( value );
@@ -1614,20 +1619,20 @@ public class DefaultAttribute implements
{
// The attribute type is String, we have to convert the values
// to String before removing them
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
- StringValue value = new StringValue( Strings.utf8ToString(val) );
+ StringValue value = new StringValue( Strings.utf8ToString( val ) );
removed &= values.remove( value );
}
}
}
else
{
- if ( !isHR )
+ if ( !isHR )
{
try
{
- for ( byte[] val:vals )
+ for ( byte[] val : vals )
{
BinaryValue value = new BinaryValue( attributeType, val );
removed &= values.remove( value );
@@ -1643,7 +1648,7 @@ public class DefaultAttribute implements
removed = false;
}
}
-
+
return removed;
}
@@ -1653,20 +1658,20 @@ public class DefaultAttribute implements
*/
public boolean remove( String... vals )
{
- if ( ( isHR == null ) || ( values.size() == 0 ) )
+ if ( ( isHR == null ) || ( values.size() == 0 ) )
{
// Trying to remove a value from an empty list will fail
return false;
}
-
+
boolean removed = true;
-
+
if ( attributeType == null )
{
if ( isHR )
{
// The attribute type is HR, we can directly process the values
- for ( String val:vals )
+ for ( String val : vals )
{
StringValue value = new StringValue( val );
removed &= values.remove( value );
@@ -1676,9 +1681,9 @@ public class DefaultAttribute implements
{
// The attribute type is binary, we have to convert the values
// to byte[] before removing them
- for ( String val:vals )
+ for ( String val : vals )
{
- BinaryValue value = new BinaryValue( Strings.getBytesUtf8(val) );
+ BinaryValue value = new BinaryValue( Strings.getBytesUtf8( val ) );
removed &= values.remove( value );
}
}
@@ -1687,7 +1692,7 @@ public class DefaultAttribute implements
{
if ( isHR )
{
- for ( String val:vals )
+ for ( String val : vals )
{
try
{
@@ -1705,7 +1710,7 @@ public class DefaultAttribute implements
removed = false;
}
}
-
+
return removed;
}
@@ -1719,8 +1724,8 @@ public class DefaultAttribute implements
{
return values.iterator();
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -1728,8 +1733,8 @@ public class DefaultAttribute implements
{
return attributeType;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -1742,7 +1747,7 @@ public class DefaultAttribute implements
this.attributeType = attributeType;
this.id = attributeType.getOid();
-
+
if ( Strings.isEmpty( this.upId ) )
{
this.upId = attributeType.getName();
@@ -1754,7 +1759,7 @@ public class DefaultAttribute implements
this.upId = attributeType.getName();
}
}
-
+
if ( values != null )
{
Set<Value<?>> newValues = new LinkedHashSet<Value<?>>( values.size() );
@@ -1764,25 +1769,25 @@ public class DefaultAttribute implements
value.apply( attributeType );
newValues.add( value );
}
-
+
values = newValues;
}
-
+
isHR = attributeType.getSyntax().isHumanReadable();
-
+
// Compute the hashCode
rehash();
}
-
-
+
+
/**
* {@inheritDoc}
*/
public boolean isInstanceOf( AttributeType attributeType ) throws LdapInvalidAttributeValueException
{
- return ( attributeType != null ) &&
- ( this.attributeType.equals( attributeType ) ||
- this.attributeType.isDescendantOf( attributeType ) );
+ return ( attributeType != null ) &&
+ ( this.attributeType.equals( attributeType ) ||
+ this.attributeType.isDescendantOf( attributeType ) );
}
@@ -1795,24 +1800,24 @@ public class DefaultAttribute implements
private void rehash()
{
h = 37;
-
+
if ( isHR != null )
{
- h = h*17 + isHR.hashCode();
+ h = h * 17 + isHR.hashCode();
}
-
+
if ( id != null )
{
- h = h*17 + id.hashCode();
+ h = h * 17 + id.hashCode();
}
-
+
if ( attributeType != null )
{
- h = h*17 + attributeType.hashCode();
+ h = h * 17 + attributeType.hashCode();
}
}
-
+
/**
* The hashCode is based on the id, the isHR flag and
* on the internal values.
@@ -1826,11 +1831,11 @@ public class DefaultAttribute implements
{
rehash();
}
-
+
return h;
}
-
-
+
+
/**
* @see Object#equals(Object)
*/
@@ -1840,14 +1845,14 @@ public class DefaultAttribute implements
{
return true;
}
-
- if ( ! (obj instanceof Attribute ) )
+
+ if ( !( obj instanceof Attribute ) )
{
return false;
}
-
- Attribute other = (Attribute)obj;
-
+
+ Attribute other = ( Attribute ) obj;
+
if ( id == null )
{
if ( other.getId() != null )
@@ -1876,34 +1881,34 @@ public class DefaultAttribute implements
}
}
}
-
- if ( isHumanReadable() != other.isHumanReadable() )
+
+ if ( isHumanReadable() != other.isHumanReadable() )
{
return false;
}
-
+
if ( values.size() != other.size() )
{
return false;
}
-
- for ( Value<?> val:values )
+
+ for ( Value<?> val : values )
{
- if ( ! other.contains( val ) )
+ if ( !other.contains( val ) )
{
return false;
}
}
-
+
if ( attributeType == null )
{
return other.getAttributeType() == null;
}
-
+
return attributeType.equals( other.getAttributeType() );
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -1911,16 +1916,16 @@ public class DefaultAttribute implements
{
try
{
- DefaultAttribute attribute = (DefaultAttribute)super.clone();
+ DefaultAttribute attribute = ( DefaultAttribute ) super.clone();
attribute.setUpId( upId );
-
+
attribute.values = new LinkedHashSet<Value<?>>( values.size() );
-
- for ( Value<?> value:values )
+
+ for ( Value<?> value : values )
{
attribute.values.add( value.clone() );
}
-
+
return attribute;
}
catch ( CloneNotSupportedException cnse )
@@ -1928,21 +1933,21 @@ public class DefaultAttribute implements
return null;
}
}
-
-
+
+
/**
* @see Object#toString()
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
-
+
if ( ( values != null ) && ( values.size() != 0 ) )
{
- for ( Value<?> value:values )
+ for ( Value<?> value : values )
{
sb.append( " " ).append( upId ).append( ": " );
-
+
if ( value.isNull() )
{
sb.append( "''" );
@@ -1951,7 +1956,7 @@ public class DefaultAttribute implements
{
sb.append( value );
}
-
+
sb.append( '\n' );
}
}
@@ -1959,7 +1964,7 @@ public class DefaultAttribute implements
{
sb.append( " " ).append( upId ).append( ": (null)\n" );
}
-
+
return sb.toString();
}
@@ -1974,7 +1979,7 @@ public class DefaultAttribute implements
{
// Write the UPId (the id will be deduced from the upID)
out.writeUTF( upId );
-
+
// Write the HR flag, if not null
if ( isHR != null )
{
@@ -1985,24 +1990,24 @@ public class DefaultAttribute implements
{
out.writeBoolean( false );
}
-
+
// Write the number of values
out.writeInt( size() );
-
- if ( size() > 0 )
+
+ if ( size() > 0 )
{
// Write each value
- for ( Value<?> value:values )
+ for ( Value<?> value : values )
{
// Write the value
value.writeExternal( out );
}
}
-
+
out.flush();
}
-
+
/**
* {@inheritDoc}
*/
@@ -2010,10 +2015,10 @@ public class DefaultAttribute implements
{
// Read the ID and the UPId
upId = in.readUTF();
-
+
// Compute the id
setUpId( upId );
-
+
// Read the HR flag, if not null
if ( in.readBoolean() )
{
@@ -2028,7 +2033,7 @@ public class DefaultAttribute implements
for ( int i = 0; i < nbValues; i++ )
{
Value<?> value = null;
-
+
if ( isHR )
{
value = new StringValue( attributeType );
@@ -2037,9 +2042,9 @@ public class DefaultAttribute implements
{
value = new BinaryValue( attributeType );
}
-
+
value.readExternal( in );
-
+
values.add( value );
}
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java Tue Jan 24 17:44:03 2012
@@ -91,7 +91,7 @@ public final class DefaultEntry implemen
*/
public DefaultEntry()
{
- this( (SchemaManager)null );
+ this( ( SchemaManager ) null );
}
@@ -250,12 +250,12 @@ public final class DefaultEntry implemen
*/
public DefaultEntry( SchemaManager schemaManager, Dn dn, Object... elements ) throws LdapException
{
- DefaultEntry entry = (DefaultEntry)createEntry( schemaManager, elements );
-
+ DefaultEntry entry = ( DefaultEntry ) createEntry( schemaManager, elements );
+
this.dn = dn;
this.attributes = entry.attributes;
this.schemaManager = schemaManager;
-
+
if ( schemaManager != null )
{
this.dn.apply( schemaManager );
@@ -329,7 +329,8 @@ public final class DefaultEntry implemen
//-------------------------------------------------------------------------
// Helper methods
//-------------------------------------------------------------------------
- private Entry createEntry( SchemaManager schemaManager, Object... elements ) throws LdapInvalidAttributeValueException, LdapLdifException
+ private Entry createEntry( SchemaManager schemaManager, Object... elements )
+ throws LdapInvalidAttributeValueException, LdapLdifException
{
StringBuilder sb = new StringBuilder();
int pos = 0;
@@ -387,10 +388,11 @@ public final class DefaultEntry implemen
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry( schemaManager, sb.toString() );
-
+
return entry;
}
-
+
+
/**
* Get the trimmed and lower cased entry ID
*/
@@ -427,7 +429,7 @@ public final class DefaultEntry implemen
LOG.error( message );
throw new IllegalArgumentException( message );
}
-
+
return upId;
}
else if ( Strings.isEmpty( normUpId ) )
@@ -438,7 +440,7 @@ public final class DefaultEntry implemen
{
id = attributeType.getOid();
}
-
+
return id;
}
else
@@ -465,14 +467,15 @@ public final class DefaultEntry implemen
{
return;
}
-
+
try
{
synchronized ( MUTEX )
{
if ( objectClassAttributeType == null )
{
- objectClassAttributeType = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
+ objectClassAttributeType = schemaManager
+ .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
}
}
}
@@ -528,15 +531,16 @@ public final class DefaultEntry implemen
}
*/
}
-
-
+
+
/**
* Add a new EntryAttribute, with its upId. If the upId is null,
* default to the AttributeType name.
*
* Updates the AttributeMap.
*/
- protected void createAttribute( String upId, AttributeType attributeType, byte[]... values ) throws LdapInvalidAttributeValueException
+ protected void createAttribute( String upId, AttributeType attributeType, byte[]... values )
+ throws LdapInvalidAttributeValueException
{
Attribute attribute = new DefaultAttribute( attributeType, values );
attribute.setUpId( upId, attributeType );
@@ -550,7 +554,8 @@ public final class DefaultEntry implemen
*
* Updates the AttributeMap.
*/
- protected void createAttribute( String upId, AttributeType attributeType, String... values ) throws LdapInvalidAttributeValueException
+ protected void createAttribute( String upId, AttributeType attributeType, String... values )
+ throws LdapInvalidAttributeValueException
{
Attribute attribute = new DefaultAttribute( attributeType, values );
attribute.setUpId( upId, attributeType );
@@ -564,7 +569,8 @@ public final class DefaultEntry implemen
*
* Updates the AttributeMap.
*/
- protected void createAttribute( String upId, AttributeType attributeType, Value<?>... values ) throws LdapInvalidAttributeValueException
+ protected void createAttribute( String upId, AttributeType attributeType, Value<?>... values )
+ throws LdapInvalidAttributeValueException
{
Attribute attribute = new DefaultAttribute( attributeType, values );
attribute.setUpId( upId, attributeType );
@@ -577,7 +583,7 @@ public final class DefaultEntry implemen
*/
protected AttributeType getAttributeType( String upId ) throws LdapException
{
- if ( Strings.isEmpty(Strings.trim(upId)) )
+ if ( Strings.isEmpty( Strings.trim( upId ) ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -853,7 +859,7 @@ public final class DefaultEntry implemen
*/
public void add( String upId, byte[]... values ) throws LdapException
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -895,7 +901,7 @@ public final class DefaultEntry implemen
*/
public void add( String upId, String... values ) throws LdapException
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -937,7 +943,7 @@ public final class DefaultEntry implemen
*/
public void add( String upId, Value<?>... values ) throws LdapException
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -1201,7 +1207,7 @@ public final class DefaultEntry implemen
*/
public boolean contains( String upId, byte[]... values )
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
return false;
}
@@ -1236,7 +1242,7 @@ public final class DefaultEntry implemen
*/
public boolean contains( String upId, String... values )
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
return false;
}
@@ -1271,7 +1277,7 @@ public final class DefaultEntry implemen
*/
public boolean contains( String upId, Value<?>... values )
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
return false;
}
@@ -1368,7 +1374,7 @@ public final class DefaultEntry implemen
*/
public Attribute put( String upId, byte[]... values )
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -1407,7 +1413,7 @@ public final class DefaultEntry implemen
*/
public Attribute put( String upId, String... values )
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -1446,7 +1452,7 @@ public final class DefaultEntry implemen
*/
public Attribute put( String upId, Value<?>... values )
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.error( message );
@@ -1620,7 +1626,7 @@ public final class DefaultEntry implemen
}
else
{
- if ( !Strings.isEmpty(upId) )
+ if ( !Strings.isEmpty( upId ) )
{
AttributeType tempAT = getAttributeType( upId );
@@ -1670,7 +1676,7 @@ public final class DefaultEntry implemen
}
else
{
- if ( !Strings.isEmpty(upId) )
+ if ( !Strings.isEmpty( upId ) )
{
AttributeType tempAT = getAttributeType( upId );
@@ -1713,7 +1719,7 @@ public final class DefaultEntry implemen
}
else
{
- if ( !Strings.isEmpty(upId) )
+ if ( !Strings.isEmpty( upId ) )
{
AttributeType tempAT = getAttributeType( upId );
@@ -2048,7 +2054,7 @@ public final class DefaultEntry implemen
*/
public boolean remove( String upId, byte[]... values ) throws LdapException
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.info( message );
@@ -2128,7 +2134,7 @@ public final class DefaultEntry implemen
*/
public boolean remove( String upId, String... values ) throws LdapException
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.info( message );
@@ -2207,7 +2213,7 @@ public final class DefaultEntry implemen
*/
public boolean remove( String upId, Value<?>... values ) throws LdapException
{
- if ( Strings.isEmpty(upId) )
+ if ( Strings.isEmpty( upId ) )
{
String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
LOG.info( message );
@@ -2384,7 +2390,6 @@ public final class DefaultEntry implemen
// Read the Dn
dn = new Dn( schemaManager );
dn.readExternal( in );
-
// Read the number of attributes
int nbAttributes = in.readInt();
@@ -2447,7 +2452,7 @@ public final class DefaultEntry implemen
{
return false;
}
-
+
for ( String objectClass : objectClasses )
{
if ( schemaManager != null )
@@ -2465,7 +2470,7 @@ public final class DefaultEntry implemen
}
}
}
-
+
return true;
}
@@ -2479,23 +2484,23 @@ public final class DefaultEntry implemen
{
return false;
}
-
- for ( Attribute objectClass:objectClasses )
+
+ for ( Attribute objectClass : objectClasses )
{
// We have to check that we are checking the ObjectClass attributeType
if ( !objectClass.getAttributeType().equals( objectClassAttributeType ) )
{
return false;
}
-
+
Attribute attribute = attributes.get( objectClassAttributeType.getOid() );
-
+
if ( attribute == null )
{
// The entry does not have an ObjectClass attribute
return false;
}
-
+
for ( Value<?> value : objectClass )
{
// Loop on all the values, and check if they are present
@@ -2509,7 +2514,7 @@ public final class DefaultEntry implemen
return true;
}
-
+
/**
* {@inheritDoc}
*/
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java Tue Jan 24 17:44:03 2012
@@ -19,6 +19,7 @@
*/
package org.apache.directory.shared.ldap.model.entry;
+
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@@ -31,6 +32,7 @@ import org.apache.directory.shared.ldap.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
* An internal implementation for a ModificationItem. The name has been
* chosen so that it does not conflict with @see ModificationItem
@@ -41,17 +43,17 @@ public class DefaultModification impleme
{
/** The modification operation */
private ModificationOperation operation;
-
+
/** The attribute which contains the modification */
private Attribute attribute;
-
+
/** The AtributeType */
private AttributeType attributeType;
-
+
/** logger for reporting errors that might not be handled properly upstream */
protected static final Logger LOG = LoggerFactory.getLogger( Modification.class );
-
+
/**
* Creates a new instance of DefaultModification.
*/
@@ -59,7 +61,7 @@ public class DefaultModification impleme
{
}
-
+
/**
* Creates a new instance of DefaultModification.
*
@@ -135,7 +137,7 @@ public class DefaultModification impleme
* @param attributeType The associated attributeType
* @param values the associated values
*/
- public DefaultModification( ModificationOperation operation, AttributeType attributeType, String... values )
+ public DefaultModification( ModificationOperation operation, AttributeType attributeType, String... values )
throws LdapInvalidAttributeValueException
{
this.operation = operation;
@@ -151,7 +153,7 @@ public class DefaultModification impleme
* @param values the associated values
*/
public DefaultModification( ModificationOperation operation, AttributeType attributeType, byte[]... values )
- throws LdapInvalidAttributeValueException
+ throws LdapInvalidAttributeValueException
{
this.operation = operation;
this.attribute = new DefaultAttribute( attributeType, values );
@@ -166,7 +168,7 @@ public class DefaultModification impleme
* @param values the associated values
*/
public DefaultModification( ModificationOperation operation, AttributeType attributeType, Value<?>... values )
- throws LdapInvalidAttributeValueException
+ throws LdapInvalidAttributeValueException
{
this.operation = operation;
this.attribute = new DefaultAttribute( attributeType, values );
@@ -180,7 +182,7 @@ public class DefaultModification impleme
* @param attributeType The associated attributeType
*/
public DefaultModification( ModificationOperation operation, AttributeType attributeType )
- throws LdapInvalidAttributeValueException
+ throws LdapInvalidAttributeValueException
{
this.operation = operation;
this.attribute = new DefaultAttribute( attributeType );
@@ -196,18 +198,18 @@ public class DefaultModification impleme
public DefaultModification( SchemaManager schemaManager, Modification modification )
{
operation = modification.getOperation();
-
+
Attribute modAttribute = modification.getAttribute();
-
+
try
{
AttributeType at = modAttribute.getAttributeType();
-
+
if ( at == null )
{
at = schemaManager.lookupAttributeTypeRegistry( modAttribute.getId() );
}
-
+
attribute = new DefaultAttribute( at, modAttribute );
}
catch ( LdapException ne )
@@ -216,8 +218,8 @@ public class DefaultModification impleme
LOG.error( I18n.err( I18n.ERR_04472, modAttribute.getId() ) );
}
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -225,8 +227,8 @@ public class DefaultModification impleme
{
return operation;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -235,7 +237,7 @@ public class DefaultModification impleme
this.operation = ModificationOperation.getOperation( operation );
}
-
+
/**
* {@inheritDoc}
*/
@@ -243,8 +245,8 @@ public class DefaultModification impleme
{
this.operation = operation;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -252,8 +254,8 @@ public class DefaultModification impleme
{
return attribute;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -261,15 +263,15 @@ public class DefaultModification impleme
{
this.attribute = attribute;
}
-
-
+
+
/**
* {@inheritDoc}
*/
public void apply( AttributeType attributeType ) throws LdapInvalidAttributeValueException
{
this.attributeType = attributeType;
-
+
if ( attribute != null )
{
attribute.apply( attributeType );
@@ -284,8 +286,8 @@ public class DefaultModification impleme
{
return attributeType;
}
-
-
+
+
/**
* @see Object#equals(Object)
* @return <code>true</code> if both values are equal
@@ -297,14 +299,14 @@ public class DefaultModification impleme
{
return true;
}
-
- if ( ! (that instanceof Modification ) )
+
+ if ( !( that instanceof Modification ) )
{
return false;
}
-
- Modification otherModification = (Modification)that;
-
+
+ Modification otherModification = ( Modification ) that;
+
// Check the operation
if ( operation != otherModification.getOperation() )
{
@@ -316,11 +318,11 @@ public class DefaultModification impleme
{
return otherModification.getAttribute() == null;
}
-
+
return attribute.equals( otherModification.getAttribute() );
}
-
-
+
+
/**
* Compute the modification @see Object#hashCode
* @return the instance's hash code
@@ -328,13 +330,13 @@ public class DefaultModification impleme
public int hashCode()
{
int h = 37;
-
- h += h*17 + operation.getValue();
- h += h*17 + attribute.hashCode();
-
+
+ h += h * 17 + operation.getValue();
+ h += h * 17 + attribute.hashCode();
+
return h;
}
-
+
/**
* @see java.io.Externalizable#readExternal(ObjectInput)
@@ -346,15 +348,15 @@ public class DefaultModification impleme
// The EntryAttribute if we have some
boolean hasAttribute = in.readBoolean();
-
+
if ( hasAttribute )
{
attribute = new DefaultAttribute();
attribute.readExternal( in );
}
}
-
-
+
+
/**
* @see java.io.Externalizable#writeExternal(ObjectOutput)
*/
@@ -362,7 +364,7 @@ public class DefaultModification impleme
{
// The operation
out.writeInt( operation.getValue() );
-
+
// The EntryAttribute if not null
if ( attribute != null )
{
@@ -373,11 +375,11 @@ public class DefaultModification impleme
{
out.writeBoolean( false );
}
-
+
out.flush();
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -385,8 +387,8 @@ public class DefaultModification impleme
{
try
{
- DefaultModification clone = (DefaultModification)super.clone();
-
+ DefaultModification clone = ( DefaultModification ) super.clone();
+
clone.attribute = this.attribute.clone();
return clone;
}
@@ -395,21 +397,21 @@ public class DefaultModification impleme
return null;
}
}
-
-
+
+
/**
* @see Object#toString()
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
-
+
sb.append( "Modification: " ).
append( operation ).
append( "\n" ).
append( ", attribute : " ).
append( attribute );
-
+
return sb.toString();
}
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java Tue Jan 24 17:44:03 2012
@@ -86,7 +86,7 @@ public interface Entry extends Cloneable
*/
boolean hasObjectClass( Attribute... objectClasses );
-
+
/**
* <p>
* Returns the attribute with the specified alias. The return value
@@ -102,7 +102,7 @@ public interface Entry extends Cloneable
*/
Attribute get( String alias );
-
+
/**
* Returns the attribute associated with an AttributeType
*
@@ -118,16 +118,16 @@ public interface Entry extends Cloneable
* @return The combined set of all the attributes.
*/
Collection<Attribute> getAttributes();
-
-
+
+
/**
* Set this entry's Dn.
*
* @param dn The Dn associated with this entry
*/
void setDn( Dn dn );
-
-
+
+
/**
* Set this entry's Dn.
*
@@ -174,7 +174,7 @@ public interface Entry extends Cloneable
*/
void add( AttributeType attributeType, byte[]... values ) throws LdapException;
-
+
/**
* <p>
* Add an attribute (represented by its AttributeType and some String values) into an
@@ -195,7 +195,7 @@ public interface Entry extends Cloneable
*/
void add( AttributeType attributeType, String... values ) throws LdapException;
-
+
/**
* <p>
* Add an attribute (represented by its AttributeType and some values) into an
@@ -216,7 +216,7 @@ public interface Entry extends Cloneable
*/
void add( AttributeType attributeType, Value<?>... values ) throws LdapException;
-
+
/**
* <p>
* Add an attribute (represented by its AttributeType and some binary values) into an
@@ -238,7 +238,7 @@ public interface Entry extends Cloneable
*/
void add( String upId, AttributeType attributeType, byte[]... values ) throws LdapException;
-
+
/**
* <p>
* Add an attribute (represented by its AttributeType and some String values) into an
@@ -260,7 +260,7 @@ public interface Entry extends Cloneable
*/
void add( String upId, AttributeType attributeType, String... values ) throws LdapException;
-
+
/**
* <p>
* Add an attribute (represented by its AttributeType and some values) into an
@@ -547,7 +547,7 @@ public interface Entry extends Cloneable
*/
boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException;
-
+
/**
* <p>
* Removes the specified String values from an attribute.
@@ -571,7 +571,7 @@ public interface Entry extends Cloneable
*/
boolean remove( AttributeType attributeType, String... values ) throws LdapException;
-
+
/**
* <p>
* Removes the specified values from an attribute.
@@ -595,7 +595,7 @@ public interface Entry extends Cloneable
*/
boolean remove( AttributeType attributeType, Value<?>... values ) throws LdapException;
-
+
/**
* Removes the specified attributes. The removed attributes are
* returned by this method. If there were no attribute the return value
@@ -605,7 +605,7 @@ public interface Entry extends Cloneable
* @return the removed attribute, if exists; otherwise <code>null</code>
*/
List<Attribute> remove( Attribute... attributes ) throws LdapException;
-
+
/**
* <p>
@@ -760,7 +760,7 @@ public interface Entry extends Cloneable
*/
boolean containsAttribute( AttributeType attributeType );
-
+
/**
* <p>
* Checks if an entry contains a list of attributes.
@@ -818,15 +818,15 @@ public interface Entry extends Cloneable
*/
boolean containsAttribute( String... attributes );
-
+
/**
* Returns the number of attributes.
*
* @return the number of attributes
*/
int size();
-
-
+
+
/**
* Tells if the Entry is schema aware
* @return true if the Entry is schema aware
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java Tue Jan 24 17:44:03 2012
@@ -50,6 +50,7 @@ public class ImmutableEntry implements E
/** The wrapped Entry for this entry */
private Entry entry;
+
//-------------------------------------------------------------------------
// Constructors
//-------------------------------------------------------------------------
@@ -131,7 +132,7 @@ public class ImmutableEntry implements E
* {@inheritDoc}
*/
public void add( Attribute... attributes ) throws LdapException
- {
+ {
new Exception().printStackTrace();
throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
}
@@ -715,8 +716,8 @@ public class ImmutableEntry implements E
{
return entry.isSchemaAware();
}
-
-
+
+
/**
* @see Object#equals(Object)
*/
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Modification.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Modification.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Modification.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Modification.java Tue Jan 24 17:44:03 2012
@@ -19,11 +19,13 @@
*/
package org.apache.directory.shared.ldap.model.entry;
+
import java.io.Externalizable;
import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
import org.apache.directory.shared.ldap.model.schema.AttributeType;
+
/**
* An internal interface for a ModificationItem. The name has been
* chosen so that it does not conflict with @see ModificationItem
@@ -66,8 +68,8 @@ public interface Modification extends Cl
* @param attribute The modified attribute
*/
void setAttribute( Attribute attribute );
-
-
+
+
/**
* The clone operation
*
@@ -75,7 +77,7 @@ public interface Modification extends Cl
*/
Modification clone();
-
+
/**
* Apply the AttributeType to the Modification
*
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationOperation.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationOperation.java?rev=1235374&r1=1235373&r2=1235374&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationOperation.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationOperation.java Tue Jan 24 17:44:03 2012
@@ -19,6 +19,7 @@
*/
package org.apache.directory.shared.ldap.model.entry;
+
/**
* An enum storing the different modification operation which can be used
* in a Modification. There is a one to one mapping with the DirContext.ADD_ATTRIBUTE,
@@ -28,14 +29,14 @@ package org.apache.directory.shared.ldap
*/
public enum ModificationOperation
{
- ADD_ATTRIBUTE( 0 ),
- REMOVE_ATTRIBUTE( 1 ),
- REPLACE_ATTRIBUTE( 2 );
+ ADD_ATTRIBUTE(0),
+ REMOVE_ATTRIBUTE(1),
+ REPLACE_ATTRIBUTE(2);
/** Internal value */
private int value;
-
-
+
+
/**
* Creates a new instance of ModificationOperation.
*/
@@ -43,8 +44,8 @@ public enum ModificationOperation
{
this.value = value;
}
-
-
+
+
/**
* @return The integer value associated with the element. This value
* is equivalent to the one found in DirContext.
@@ -53,8 +54,8 @@ public enum ModificationOperation
{
return value;
}
-
-
+
+
/**
* Get the ModificationOperation from an int value
*
@@ -80,7 +81,8 @@ public enum ModificationOperation
return null;
}
}
-
+
+
/**
* @see Object#toString()
*/
@@ -88,16 +90,16 @@ public enum ModificationOperation
{
switch ( this )
{
- case ADD_ATTRIBUTE :
+ case ADD_ATTRIBUTE:
return "add";
-
- case REPLACE_ATTRIBUTE :
+
+ case REPLACE_ATTRIBUTE:
return "replace";
-
- case REMOVE_ATTRIBUTE :
+
+ case REMOVE_ATTRIBUTE:
return "remove";
-
- default :
+
+ default:
return "";
}
}