edu.internet2.middleware.ldappc.synchronize
Class AttributeModifier

java.lang.Object
  extended by edu.internet2.middleware.ldappc.synchronize.AttributeModifier
Direct Known Subclasses:
DnAttributeModifier

public class AttributeModifier
extends Object

This is a synchronizer helper class for modifying LDAP attribute values. It is to be used in the following manner.

  1. Initialize it with the current values stored in the attribute to be modified. If the current attribute is empty, call init(Attribute) passing null . Otherwise call init(Attribute) passing an Attribute holding the current set of values.
  2. For each value the attribute is to hold, call store(String) passing the value. The AttributeModifier determines whether or not the value is an existing value that must remain or is a new value to be added to the attribute.
  3. After storing all of the values to be included in the attribute, call getModifications() to generate an array of ModificationItems that can be used to update the directory. Applying these modifications will result in the attribute holding the desired set of values.
Note that if no values are stored, the modifications generated by AttributeModifier will result in the attribute holding no values. This may not be acceptable for example if the attribute is a MUST attribute. To ensure the generated modifications will always result in the attribute holding a value, the AttributeModifier supports a no value. If the no value is set to a non-null String and no values are stored, the generated modifications will result in attribute holding just the no value.

The following assumptions apply when using an AttributeModifier.


Nested Class Summary
 class AttributeModifier.Values
          Implements optional case ignoring set by backing it with a Map, mapping the possibly lowercased values to the actual values.
 
Constructor Summary
AttributeModifier(String attributeName)
          Constructs an AttributeModifier for the attribute name.
AttributeModifier(String attributeName, boolean caseSensitive)
          Constructs an AttributeModifier for the attribute name with the case sensitivity for string comparisions set as given.
AttributeModifier(String attributeName, String noValue)
          Constructs an AttributeModifier for the attribute name with the given "no value" value.
AttributeModifier(String attributeName, String noValue, boolean caseSensitive)
          Constructs an AttributeModifier for the attribute name with the given "no value" value and case sensitivity.
 
Method Summary
 void clear()
          Clears all of the existing values to be added or deleted.
 Attribute getAdditions()
          Returns an attribute with the values to be added.
 AttributeModifier.Values getAdds()
           
 String getAttributeName()
          Gets the attribute name.
 AttributeModifier.Values getDeletes()
           
 List<org.openspml.v2.msg.spml.Modification> getDSMLModification()
           
 ModificationItem[] getModifications()
          Returns an array of modification items necessary to update attribute based on the state of this object.
 String getNoValue()
          Gets the "no value" value.
 List<org.openspml.v2.msg.spml.Modification> getReferenceModification()
           
 AttributeModifier.Values getRetainedValues()
           
 void init()
          Initializes this with an empty value set.
 void init(Attribute attribute)
          Initializes this with the values from the given attribute.
 void init(Collection<String> collection)
          Initializes this with the values from the given collection.
 void initDSML(org.openspml.v2.profiles.dsml.DSMLValue... dsmlValues)
           
 void initReference(Collection<org.openspml.v2.msg.spmlref.Reference> references)
           
 boolean isCaseSensitive()
          Indicates whether or not the AttributeModifier is case sensitive when comparing attribute value strings.
protected  String makeComparisonString(String value)
          If caseSensitive is true, return value, otherwise return lowercased value.
 void retainAll()
          This method retains all of the current values.
 void setAttributeName(String attributeName)
          Sets the attribute name.
 void setNoValue(String noValue)
          Set the "no value" value.
 void store(Collection<org.openspml.v2.msg.spmlref.Reference> references)
           
 void store(org.openspml.v2.profiles.dsml.DSMLValue[] dsmlValues)
           
 void store(String attrValue)
          Stores the attribute value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeModifier

public AttributeModifier(String attributeName)
Constructs an AttributeModifier for the attribute name. This AttributeModifier is case insensitive and assumes the attribute is not required as the "no value" is not defined.

Parameters:
attributeName - Name of the attribute

AttributeModifier

public AttributeModifier(String attributeName,
                         String noValue)
Constructs an AttributeModifier for the attribute name with the given "no value" value. This AttributeModifier is case insensitive.

Parameters:
attributeName - Name of the attribute
noValue - "no value" value (null if the attribute is not required).

AttributeModifier

public AttributeModifier(String attributeName,
                         boolean caseSensitive)
Constructs an AttributeModifier for the attribute name with the case sensitivity for string comparisions set as given. it is assumed that the attribute is not required as the "no value" is not defined.

Parameters:
attributeName - Name of the attribute
caseSensitive - boolean indicating if attribute value comparisions are case sensitive.

AttributeModifier

public AttributeModifier(String attributeName,
                         String noValue,
                         boolean caseSensitive)
Constructs an AttributeModifier for the attribute name with the given "no value" value and case sensitivity.

Parameters:
attributeName - Name of the attribute
noValue - "no value" value (null if the attribute is not required).
caseSensitive - boolean indicating if attribute value comparisions are case sensitive.
Method Detail

getAttributeName

public String getAttributeName()
Gets the attribute name.

Returns:
Attribute name

setAttributeName

public void setAttributeName(String attributeName)
Sets the attribute name.

Parameters:
attributeName - the attribute name to set

getNoValue

public String getNoValue()
Gets the "no value" value. If not null, this value is stored in the attribute when the modifications identified here would result in the attribute having no values.

Returns:
"no value" value

setNoValue

public void setNoValue(String noValue)
Set the "no value" value. If not null, this value is stored in the attribute when the modifications identified here would result in the attribute having no values.

Parameters:
noValue - "no value" string, or null if the attribute is not required to have values.

isCaseSensitive

public boolean isCaseSensitive()
Indicates whether or not the AttributeModifier is case sensitive when comparing attribute value strings.

Returns:
true if case sensitive, and false otherwise

clear

public void clear()
Clears all of the existing values to be added or deleted.


init

public void init()
Initializes this with an empty value set.


init

public void init(Attribute attribute)
          throws NamingException
Initializes this with the values from the given attribute. This clears any pre-existing values, and populates it with the given list of values.

Parameters:
attribute - Attribute
Throws:
NamingException - thrown if an error occurs accessing the attribute values
InvalidAttributeValueException - thrown if a non-String value is encountered

init

public void init(Collection<String> collection)
Initializes this with the values from the given collection. This clears any pre-existing values, and populates it with the given list of values.

Parameters:
collection - Initial values

initDSML

public void initDSML(org.openspml.v2.profiles.dsml.DSMLValue... dsmlValues)

initReference

public void initReference(Collection<org.openspml.v2.msg.spmlref.Reference> references)
                   throws org.openspml.v2.util.Spml2Exception
Throws:
org.openspml.v2.util.Spml2Exception

store

public void store(String attrValue)
Stores the attribute value. This identifies the value as one that must either remain from the original set or be added to the attribute.

Parameters:
attrValue - Attribute value
Throws:
NamingException - thrown if a naming exception occurs

store

public void store(org.openspml.v2.profiles.dsml.DSMLValue[] dsmlValues)

store

public void store(Collection<org.openspml.v2.msg.spmlref.Reference> references)
           throws org.openspml.v2.util.Spml2Exception
Throws:
org.openspml.v2.util.Spml2Exception

getAdditions

public Attribute getAdditions()
Returns an attribute with the values to be added. This is based on the state of this object. If there are no values being added and the "no value" value is defined, the "no value" is included. This ignores any existing attribute values.

Returns:
Attribute holding values to be added

getModifications

public ModificationItem[] getModifications()
                                    throws NamingException
Returns an array of modification items necessary to update attribute based on the state of this object.

Returns:
A possibly empty array of ModificationItems.
Throws:
NamingException - thrown if a naming error occurs

getDSMLModification

public List<org.openspml.v2.msg.spml.Modification> getDSMLModification()
                                                                throws org.openspml.v2.profiles.dsml.DSMLProfileException
Throws:
org.openspml.v2.profiles.dsml.DSMLProfileException

getReferenceModification

public List<org.openspml.v2.msg.spml.Modification> getReferenceModification()
                                                                     throws org.openspml.v2.util.Spml2Exception
Throws:
org.openspml.v2.util.Spml2Exception

getAdds

public AttributeModifier.Values getAdds()

getDeletes

public AttributeModifier.Values getDeletes()

retainAll

public void retainAll()
This method retains all of the current values.

Throws:
NamingException - thrown if a naming error occurs

makeComparisonString

protected String makeComparisonString(String value)
If caseSensitive is true, return value, otherwise return lowercased value. Note that caseSensitive is a class variable in the enclosing class.

Parameters:
value - string to convert.
Returns:
value, possibly lowercased.

getRetainedValues

public AttributeModifier.Values getRetainedValues()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011 Internet2. All Rights Reserved.