org.opends.server.admin
Class PropertyDefinition<T>

java.lang.Object
  extended by org.opends.server.admin.PropertyDefinition<T>
Type Parameters:
T - The data-type of values of the property.
All Implemented Interfaces:
java.lang.Comparable<PropertyDefinition<?>>, java.util.Comparator<T>
Direct Known Subclasses:
ACIPropertyDefinition, AggregationPropertyDefinition, AttributeTypePropertyDefinition, BooleanPropertyDefinition, ClassPropertyDefinition, DNPropertyDefinition, DurationPropertyDefinition, EnumPropertyDefinition, IntegerPropertyDefinition, IPAddressMaskPropertyDefinition, IPAddressPropertyDefinition, SizePropertyDefinition, StringPropertyDefinition

public abstract class PropertyDefinition<T>
extends java.lang.Object
implements java.util.Comparator<T>, java.lang.Comparable<PropertyDefinition<?>>

An interface for querying generic property definition features.

Property definitions are analogous to ConfigAttributes in the current model and will play a similar role. Eventually these will replace them.

Implementations must take care to implement the various comparison methods.


Nested Class Summary
protected static class PropertyDefinition.AbstractBuilder<T,D extends PropertyDefinition<T>>
          An interface for incrementally constructing property definitions.
 
Constructor Summary
protected PropertyDefinition(AbstractManagedObjectDefinition<?,?> d, java.lang.Class<T> theClass, java.lang.String propertyName, java.util.EnumSet<PropertyOption> options, AdministratorAction adminAction, DefaultBehaviorProvider<T> defaultBehavior)
          Create a property definition.
 
Method Summary
abstract
<R,P> R
accept(PropertyDefinitionVisitor<R,P> v, P p)
          Apply a visitor to this property definition.
abstract
<R,P> R
accept(PropertyValueVisitor<R,P> v, T value, P p)
          Apply a visitor to a property value associated with this property definition.
 T castValue(java.lang.Object object)
          Cast the provided value to the type associated with this property definition.
 int compare(T o1, T o2)
          Compares two property values for order.
 int compareTo(PropertyDefinition<?> o)
          Compares this property definition with the specified property definition for order.
abstract  T decodeValue(java.lang.String value)
          Parse and validate a string representation of a property value.
 java.lang.String encodeValue(T value)
          Encode the provided property value into its string representation.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this property definition.
 AdministratorAction getAdministratorAction()
          Get the administrator action associated with this property definition.
 DefaultBehaviorProvider<T> getDefaultBehaviorProvider()
          Get the default behavior provider associated with this property definition.
 Message getDescription()
          Gets the optional description of this property definition in the default locale.
 Message getDescription(java.util.Locale locale)
          Gets the optional description of this property definition in the specified locale.
 AbstractManagedObjectDefinition<?,?> getManagedObjectDefinition()
          Gets the managed object definition associated with this property definition.
 java.lang.String getName()
          Get the name of the property.
 Message getSynopsis()
          Gets the synopsis of this property definition in the default locale.
 Message getSynopsis(java.util.Locale locale)
          Gets the synopsis of this property definition in the specified locale.
 int hashCode()
          Returns a hash code value for this property definition.
 boolean hasOption(PropertyOption option)
          Check if the specified option is set for this property definition.
protected  void initialize()
          Performs any run-time initialization required by this property definition.
 java.lang.String normalizeValue(T value)
          Get a normalized string representation of a property value.
 java.lang.String toString()
          Returns a string representation of this property definition.
 void toString(java.lang.StringBuilder builder)
          Append a string representation of the property definition to the provided string builder.
abstract  void validateValue(T value)
          Determine if the provided property value is valid according to this property definition.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertyDefinition

protected PropertyDefinition(AbstractManagedObjectDefinition<?,?> d,
                             java.lang.Class<T> theClass,
                             java.lang.String propertyName,
                             java.util.EnumSet<PropertyOption> options,
                             AdministratorAction adminAction,
                             DefaultBehaviorProvider<T> defaultBehavior)
Create a property definition.

Parameters:
d - The managed object definition associated with this property definition.
theClass - The property value class.
propertyName - The property name.
options - Options applicable to this definition.
adminAction - The administrator action.
defaultBehavior - The default behavior provider.
Method Detail

accept

public abstract <R,P> R accept(PropertyDefinitionVisitor<R,P> v,
                               P p)
Apply a visitor to this property definition.

Type Parameters:
R - The return type of the visitor's methods.
P - The type of the additional parameters to the visitor's methods.
Parameters:
v - The property definition visitor.
p - Optional additional visitor parameter.
Returns:
Returns a result as specified by the visitor.

accept

public abstract <R,P> R accept(PropertyValueVisitor<R,P> v,
                               T value,
                               P p)
Apply a visitor to a property value associated with this property definition.

Type Parameters:
R - The return type of the visitor's methods.
P - The type of the additional parameters to the visitor's methods.
Parameters:
v - The property value visitor.
value - The property value.
p - Optional additional visitor parameter.
Returns:
Returns a result as specified by the visitor.

castValue

public final T castValue(java.lang.Object object)
                  throws java.lang.ClassCastException
Cast the provided value to the type associated with this property definition.

This method only casts the object to the required type; it does not validate the value once it has been cast. Subsequent validation should be performed using the method validateValue(Object).

This method guarantees the following expression is always true:

  PropertyDefinition d;
  x == d.cast(x);
 

Parameters:
object - The property value to be cast (can be null).
Returns:
Returns the property value cast to the correct type.
Throws:
java.lang.ClassCastException - If the provided property value did not have the correct type.

compare

public int compare(T o1,
                   T o2)
Compares two property values for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

This default implementation normalizes both values using normalizeValue(Object) and then performs a case-sensitive string comparison.

Specified by:
compare in interface java.util.Comparator<T>
Parameters:
o1 - the first object to be compared.
o2 - the second object to be compared.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareTo

public final int compareTo(PropertyDefinition<?> o)
Compares this property definition with the specified property definition for order. Returns a negative integer, zero, or a positive integer if this property definition is less than, equal to, or greater than the specified property definition.

The ordering must be determined first from the property name and then base on the underlying value type.

Specified by:
compareTo in interface java.lang.Comparable<PropertyDefinition<?>>
Parameters:
o - The reference property definition with which to compare.
Returns:
Returns a negative integer, zero, or a positive integer if this property definition is less than, equal to, or greater than the specified property definition.

decodeValue

public abstract T decodeValue(java.lang.String value)
                       throws IllegalPropertyValueStringException
Parse and validate a string representation of a property value.

Parameters:
value - The property string value (must not be null).
Returns:
Returns the decoded property value.
Throws:
IllegalPropertyValueStringException - If the property value string is invalid.

encodeValue

public java.lang.String encodeValue(T value)
                             throws IllegalPropertyValueException
Encode the provided property value into its string representation.

This default implementation simply returns invokes the Object.toString() method on the provided value.

Parameters:
value - The property value (must not be null).
Returns:
Returns the encoded property string value.
Throws:
IllegalPropertyValueException - If the property value is invalid.

equals

public final boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this property definition. This method must obey the general contract of Object.equals(Object). Additionally, this method can return true only if the specified Object is also a property definition and it has the same name, as returned by getName(), and also is deemed to be "compatible" with this property definition. Compatibility means that the two property definitions share the same underlying value type and provide similar comparator implementations.

Specified by:
equals in interface java.util.Comparator<T>
Overrides:
equals in class java.lang.Object
Parameters:
o - The reference object with which to compare.
Returns:
Returns true only if the specified object is also a property definition and it has the same name and is compatible with this property definition.
See Also:
Object.equals(java.lang.Object), Object.hashCode()

getAdministratorAction

public final AdministratorAction getAdministratorAction()
Get the administrator action associated with this property definition. The administrator action describes any action which the administrator must perform in order for changes to this property to take effect.

Returns:
Returns the administrator action associated with this property definition.

getDefaultBehaviorProvider

public final DefaultBehaviorProvider<T> getDefaultBehaviorProvider()
Get the default behavior provider associated with this property definition.

Returns:
Returns the default behavior provider associated with this property definition.

getDescription

public final Message getDescription()
Gets the optional description of this property definition in the default locale.

Returns:
Returns the description of this property definition in the default locale, or null if there is no description.

getDescription

public final Message getDescription(java.util.Locale locale)
Gets the optional description of this property definition in the specified locale.

Parameters:
locale - The locale.
Returns:
Returns the description of this property definition in the specified locale, or null if there is no description.

getManagedObjectDefinition

public final AbstractManagedObjectDefinition<?,?> getManagedObjectDefinition()
Gets the managed object definition associated with this property definition.

Returns:
Returns the managed object definition associated with this property definition.

getName

public final java.lang.String getName()
Get the name of the property.

Returns:
Returns the name of the property.

getSynopsis

public final Message getSynopsis()
Gets the synopsis of this property definition in the default locale.

Returns:
Returns the synopsis of this property definition in the default locale.

getSynopsis

public final Message getSynopsis(java.util.Locale locale)
Gets the synopsis of this property definition in the specified locale.

Parameters:
locale - The locale.
Returns:
Returns the synopsis of this property definition in the specified locale.

hashCode

public final int hashCode()
Returns a hash code value for this property definition. The hash code should be derived from the property name and the type of values handled by this property definition.

Overrides:
hashCode in class java.lang.Object
Returns:
Returns the hash code value for this property definition.

hasOption

public final boolean hasOption(PropertyOption option)
Check if the specified option is set for this property definition.

Parameters:
option - The option to test.
Returns:
Returns true if the option is set, or false otherwise.

normalizeValue

public java.lang.String normalizeValue(T value)
                                throws IllegalPropertyValueException
Get a normalized string representation of a property value. This can then be used for comparisons and for generating hash-codes.

This method may throw an exception if the provided value is invalid. However, applications should not assume that implementations of this method will always validate a value. This task is the responsibility of validateValue(Object).

This default implementation simply returns the string representation of the provided value. Sub-classes might want to override this method if this behavior is insufficient (for example, a string property definition might strip white-space and convert characters to lower-case).

Parameters:
value - The property value to be normalized.
Returns:
Returns the normalized property value.
Throws:
IllegalPropertyValueException - If the property value is invalid.

toString

public final java.lang.String toString()
Returns a string representation of this property definition.

Overrides:
toString in class java.lang.Object
Returns:
Returns a string representation of this property definition.
See Also:
Object.toString()

toString

public void toString(java.lang.StringBuilder builder)
Append a string representation of the property definition to the provided string builder.

This simple implementation just outputs the propertyName of the property definition. Sub-classes should override this method to provide more complete string representations.

Parameters:
builder - The string builder where the string representation should be appended.

validateValue

public abstract void validateValue(T value)
                            throws IllegalPropertyValueException
Determine if the provided property value is valid according to this property definition.

Parameters:
value - The property value (must not be null).
Throws:
IllegalPropertyValueException - If the property value is invalid.

initialize

protected void initialize()
                   throws java.lang.Exception
Performs any run-time initialization required by this property definition. This may include resolving managed object paths and property names.

Throws:
java.lang.Exception - If this property definition could not be initialized.