com.guiseframework.model
Class AbstractValueModel<V>

java.lang.Object
  extended by com.globalmentor.beans.BoundPropertyObject
      extended by com.guiseframework.model.AbstractModel
          extended by com.guiseframework.model.AbstractValueModel<V>
Type Parameters:
V - The type of value contained in the model.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, Model, Valued<V>, ValueModel<V>
Direct Known Subclasses:
DefaultListSelectModel, DefaultValueModel

public abstract class AbstractValueModel<V>
extends AbstractModel
implements ValueModel<V>

An abstract implementation of a model representing a value. A derived class need only implement the value access methods.

Author:
Garret Wilson

Field Summary
 
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
 
Fields inherited from interface com.guiseframework.model.ValueModel
VALIDATOR_PROPERTY, VALUE_PROPERTY
 
Fields inherited from interface com.guiseframework.model.Model
PLAIN_TEXT_CONTENT_TYPE, XHTML_CONTENT_TYPE, XHTML_FRAGMENT_CONTENT_TYPE
 
Constructor Summary
AbstractValueModel(java.lang.Class<V> valueClass)
          Constructs a value model indicating the type of value it can hold.
 
Method Summary
static
<VV> java.beans.PropertyVetoException
createPropertyVetoException(java.lang.Object source, ValidationException validationException, java.lang.String propertyName, VV oldValue, VV newValue)
          Creates a property veto exception that represents a validation exception.
 Validator<V> getValidator()
           
 java.lang.Class<V> getValueClass()
           
 boolean isValidValue()
          Determines whether the value of this model is valid.
 void setValidator(Validator<V> newValidator)
          Sets the validator.
 void validateValue()
          Validates the value of this model, throwing an exception if the model is not valid.
 
Methods inherited from class com.guiseframework.model.AbstractModel
getEventListenerManager, getPlainText
 
Methods inherited from class com.globalmentor.beans.BoundPropertyObject
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.guiseframework.model.ValueModel
clearValue, getDefaultValue, getValue, resetValue, setValue
 
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface com.globalmentor.beans.PropertyConstrainable
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
 

Constructor Detail

AbstractValueModel

public AbstractValueModel(java.lang.Class<V> valueClass)
Constructs a value model indicating the type of value it can hold.

Parameters:
valueClass - The class indicating the type of value held in the model.
Throws:
java.lang.NullPointerException - if the given value class is null.
Method Detail

getValidator

public Validator<V> getValidator()
Specified by:
getValidator in interface ValueModel<V>
Returns:
The validator for this model, or null if no validator is installed.

setValidator

public void setValidator(Validator<V> newValidator)
Sets the validator. This is a bound property.

Specified by:
setValidator in interface ValueModel<V>
Parameters:
newValidator - The validator for this model, or null if no validator should be used.
See Also:
ValueModel.VALIDATOR_PROPERTY

getValueClass

public java.lang.Class<V> getValueClass()
Specified by:
getValueClass in interface ValueModel<V>
Returns:
The class representing the type of value this model can hold.

isValidValue

public boolean isValidValue()
Determines whether the value of this model is valid. This version delegates to the validator, if one is installed.

Specified by:
isValidValue in interface ValueModel<V>
Returns:
Whether the value of this model is valid.
See Also:
getValidator(), ValueModel.getValue()

validateValue

public void validateValue()
                   throws ValidationException
Validates the value of this model, throwing an exception if the model is not valid. This version validates the current value if there is a validator installed.

Specified by:
validateValue in interface ValueModel<V>
Throws:
ValidationException - if the value of this model is not valid.

createPropertyVetoException

public static <VV> java.beans.PropertyVetoException createPropertyVetoException(java.lang.Object source,
                                                                                ValidationException validationException,
                                                                                java.lang.String propertyName,
                                                                                VV oldValue,
                                                                                VV newValue)
Creates a property veto exception that represents a validation exception. The validation exception will be accessible via Throwable.getCause(). This is useful for converting a validation exception into a property veto exception in ValueModel.setValue(Object) if an installed validator deems a value invalid.

Type Parameters:
VV - The type of property the change of which was vetoed because of invalidity.
Parameters:
source - The source of the property change event.
validationException - The validation exception that is the cause of the property veto.
propertyName - The name of the property the change of which was vetoed.
oldValue - The old value of the property.
newValue - The new value of the property.
Returns:
A property veto exception representing the validation error.


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.