com.threerings.antidote.field
Class BaseFieldWrapper<F extends ReferenceField>

java.lang.Object
  extended by com.threerings.antidote.field.BaseFieldWrapper<F>
All Implemented Interfaces:
Field, FieldWrapper<F>, Mutable, RequiresValidation
Direct Known Subclasses:
OptionalField, RequiredField

abstract class BaseFieldWrapper<F extends ReferenceField>
extends Object
implements FieldWrapper<F>

A base class for common FieldWrapper functionality. Package private. Use one of the subclasses.

See Also:
RequiredField, OptionalField

Constructor Summary
BaseFieldWrapper(Class<? extends Field> clazz, Field parent)
          Construct a FieldWrapper which expects the wrapped Field to be set later using setField(F).
BaseFieldWrapper(F wrapped, Field parent)
          Construct a FieldWrapper by providing the already constructed Field to be wrapped and the parent Field which holds the wrapped Field.
BaseFieldWrapper(String abstractName, Field parent)
          Construct a FieldWrapper which expects the wrapped Field to be set later using setField(F).
 
Method Summary
protected  void appendViolation(Violation violation)
          Add a violation to the list of violations returned when this Field is validated.
protected  void appendViolationList(List<Violation> violations)
          Add a list of violations to the list of violations returned when this Field is validated.
 F getField()
          Returns the Field held by this FieldWrapper.
 String getFieldName()
          Returns the unique name of this Field.
 Location getLocation()
          Provide the location of the wrapped Field if it is set, otherwise use the parent Field location, which will be a good estimate.
 Field getParent()
          Return the parent Field of the wrapped Field.
 boolean isNotSet()
          Returns true if the Mutable data contained in this object is not set, e.g.
 boolean isSet()
          Returns true if the Mutable data contained in this object is set, e.g.
 void setField(F wrapped)
          Set the wrapped Field.
 List<Violation> validate()
          Validates the object, returning a list of Violation classes for any validation violations.
protected abstract  void validateWrappedField()
          Provide subclasses a chance to perform additional validation, including validation of the wrapped field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseFieldWrapper

public BaseFieldWrapper(F wrapped,
                        Field parent)
Construct a FieldWrapper by providing the already constructed Field to be wrapped and the parent Field which holds the wrapped Field.

Parameters:
wrapped - The Field to be wrapped.
parent - The wrapped Field parent.
Throws:
IllegalArgumentException - If either wrapped or parent is null.

BaseFieldWrapper

public BaseFieldWrapper(Class<? extends Field> clazz,
                        Field parent)
Construct a FieldWrapper which expects the wrapped Field to be set later using setField(F). The Class of the wrapped Field is provided so that the name of the Field can be determined. The parent Field which holds the wrapped Field is also provided.

Parameters:
parent - The wrapped Field parent.
Throws:
IllegalArgumentException - If parent is null.

BaseFieldWrapper

public BaseFieldWrapper(String abstractName,
                        Field parent)
Construct a FieldWrapper which expects the wrapped Field to be set later using setField(F). This constructor should be used for abstract Field classes where the name of the field cannot be known until a concrete class is constructed via the Ant setter or added method. The name of the abstract Field class is provided to be used for the field name until the wrapped field is set. The parent Field which holds the wrapped Field is also provided.

Parameters:
abstractName - The name of the abstract Field to be wrapped.
parent - The wrapped Field parent.
Throws:
IllegalArgumentException - If parent or abstractName is null.
Method Detail

setField

public void setField(F wrapped)
Description copied from interface: FieldWrapper
Set the wrapped Field. Provided so that the wrapped Field may be set whenever an Ant setter method is called, which may be after this FieldWrapper was constructed. It is a violation to set the wrapped Field more than once and the FieldWrapper will fail in RequiresValidation.validate().

Specified by:
setField in interface FieldWrapper<F extends ReferenceField>

getField

public F getField()
Description copied from interface: FieldWrapper
Returns the Field held by this FieldWrapper. If the held Field is set that object will be returned. If the Field is set and is a Reference to another Field, the referenced Field will be returned. Finally, if the Field is not set, RequiresValidationException will be thrown. Use Mutable.isSet() or Mutable.isNotSet() to determine the status of the held Field before calling this method.

Specified by:
getField in interface FieldWrapper<F extends ReferenceField>

getParent

public Field getParent()
Description copied from interface: FieldWrapper
Return the parent Field of the wrapped Field.

Specified by:
getParent in interface FieldWrapper<F extends ReferenceField>

getFieldName

public String getFieldName()
Description copied from interface: Field
Returns the unique name of this Field.

Specified by:
getFieldName in interface Field

getLocation

public Location getLocation()
Provide the location of the wrapped Field if it is set, otherwise use the parent Field location, which will be a good estimate.

Specified by:
getLocation in interface Field

isSet

public boolean isSet()
Description copied from interface: Mutable
Returns true if the Mutable data contained in this object is set, e.g. not null. False otherwise.

Specified by:
isSet in interface Mutable

isNotSet

public boolean isNotSet()
Description copied from interface: Mutable
Returns true if the Mutable data contained in this object is not set, e.g. null. False otherwise.

Specified by:
isNotSet in interface Mutable

validate

public final List<Violation> validate()
Description copied from interface: RequiresValidation
Validates the object, returning a list of Violation classes for any validation violations.

Specified by:
validate in interface RequiresValidation

appendViolation

protected void appendViolation(Violation violation)
Add a violation to the list of violations returned when this Field is validated.


appendViolationList

protected void appendViolationList(List<Violation> violations)
Add a list of violations to the list of violations returned when this Field is validated.


validateWrappedField

protected abstract void validateWrappedField()
Provide subclasses a chance to perform additional validation, including validation of the wrapped field.



Copyright © 2007-2008 Three Rings Design, Inc. All Rights Reserved. Released under a BSD license.