org.scopemvc.core
Class PropertyManager

java.lang.Object
  |
  +--org.scopemvc.core.ModelManager
        |
        +--org.scopemvc.core.PropertyManager
Direct Known Subclasses:
BeansPropertyManager

public abstract class PropertyManager
extends ModelManager

PropertyManager is a ModelManager that provides access to the properties of model objects. An implementation for JavaBean model objects is provided in org.scopemvc.model.beans.BeansPropertyManager.

Version:
$Revision: 1.8 $ $Date: 2002/09/11 19:12:29 $
Author:
Steve Meyfroidt

Constructor Summary
PropertyManager()
           
 
Method Summary
abstract  java.lang.Object get(java.lang.Object inModel, Selector inSelector)
           Return the value of the property identified by the passed Selector.
static PropertyManager getInstance(java.lang.Class inModelClass)
          Create an PropertyManager for the model class
static PropertyManager getInstance(java.lang.Object inModel)
          Create an PropertyManager for the model
abstract  java.lang.Class getPropertyClass(java.lang.Object inModel, Selector inSelector)
          Return the Class of a property.
abstract  Selector getSelectorFor(java.lang.Object inModel, java.lang.Object inProperty)
          Return a Selector that would get() a property equals() to the passed Object.
abstract  java.util.Iterator getSelectorIterator(java.lang.Object inModel)
           Return an Iterator that iterates over Selectors for all properties of the passed model object.
abstract  boolean hasProperty(java.lang.Object inModel, Selector inSelector)
          Does the passed model object contain the property identified by the passed Selector?
abstract  boolean isReadOnly(java.lang.Object inModel, Selector inSelector)
           Is a property read-only? If the passed Selector is null then is the model object as a whole read-only?
abstract  void set(java.lang.Object inModel, Selector inSelector, java.lang.Object inValue)
           Set the value of the property identified by a Selector in the passed model object to a new value.
 
Methods inherited from class org.scopemvc.core.ModelManager
getModelClass, make
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyManager

public PropertyManager()
Method Detail

getInstance

public static PropertyManager getInstance(java.lang.Class inModelClass)
Create an PropertyManager for the model class

Parameters:
inModelClass - The model class
Returns:
The PropertyManager instance

getInstance

public static PropertyManager getInstance(java.lang.Object inModel)
Create an PropertyManager for the model

Parameters:
inModel - The model
Returns:
The PropertyManager instance

get

public abstract java.lang.Object get(java.lang.Object inModel,
                                     Selector inSelector)
                              throws java.lang.Exception

Return the value of the property identified by the passed Selector. If the passed Selector is null, return the model object itself.

Parameters:
inModel - model to get property from
inSelector - identify the property to be returned or null for the model object itself.
Returns:
value of selected property
Throws:
java.lang.Exception - If the value of the property could not be retrieved

isReadOnly

public abstract boolean isReadOnly(java.lang.Object inModel,
                                   Selector inSelector)
                            throws java.lang.Exception

Is a property read-only? If the passed Selector is null then is the model object as a whole read-only?

Enforcement of the access state must be implemented by the model itself.

Parameters:
inModel - model object to test the property on.
inSelector - The property to test or null to test the whole model object.
Returns:
whether the property is read-only or not.
Throws:
java.lang.Exception - If the read-only state of the property could not be tested

getPropertyClass

public abstract java.lang.Class getPropertyClass(java.lang.Object inModel,
                                                 Selector inSelector)
                                          throws java.lang.Exception
Return the Class of a property.

Parameters:
inModel - model to test the property for.
inSelector - property to test.
Returns:
Class of property. Never null.
Throws:
java.lang.Exception - If the class of the property could not be retrieved

getSelectorIterator

public abstract java.util.Iterator getSelectorIterator(java.lang.Object inModel)

Return an Iterator that iterates over Selectors for all properties of the passed model object.

Parameters:
inModel - model to make an Iterator for.
Returns:
Iterator that iterates over Selectors for all properties of the passed model object.

getSelectorFor

public abstract Selector getSelectorFor(java.lang.Object inModel,
                                        java.lang.Object inProperty)
Return a Selector that would get() a property equals() to the passed Object. Guaranteed to work only for non-primitive properties.

Parameters:
inProperty - the property Object to find.
inModel - the model to get the property from.
Returns:
a Selector that would return an Object equals() to the passed property, or null if not found.

set

public abstract void set(java.lang.Object inModel,
                         Selector inSelector,
                         java.lang.Object inValue)
                  throws java.lang.Exception

Set the value of the property identified by a Selector in the passed model object to a new value.

The implementation should not set the value if the new value has the same Object reference as the original. It could also avoid setting the value if the new value is equivalent to the old value, and the value is of an immutable Class (like Integer, String). Otherwise the property must be set to the new value, even if it equals() the old value.

Usually, a ModelChangeEvent for ModelChangeTypes.VALUE_CHANGED should be broadcast by the model when the property is set so that interested listeners know that the model's state has changed.

If the property is a sub-model object then the parent model should be registered as a ModelChangeListener to be able to propagate events properly. This propagation is partially implemented in BasicModel but it relies on child Models being listened to by their parent. (Note: deregister from the old Model then register with the new one). See the sample code for examples using BasicModel.listenNewSubmodel(org.scopemvc.core.Selector) and BasicModel.unlistenOldSubmodel(org.scopemvc.core.Selector).

Parameters:
inModel - model to set the property on.
inSelector - identify the property to be set. Can't be null.
inValue - the value to set the property to.
Throws:
java.lang.Exception - if the value could not be set in the model

hasProperty

public abstract boolean hasProperty(java.lang.Object inModel,
                                    Selector inSelector)
Does the passed model object contain the property identified by the passed Selector?

Parameters:
inModel - model to test the property for.
inSelector - property to test.
Returns:
true if the property exists on the passed model.


Copyright © 2000-2002 The Scope Team. All Rights Reserved.