org.scopemvc.model.beans
Class BeansPropertyManager

java.lang.Object
  |
  +--org.scopemvc.core.ModelManager
        |
        +--org.scopemvc.core.PropertyManager
              |
              +--org.scopemvc.model.beans.BeansPropertyManager

public class BeansPropertyManager
extends PropertyManager

BeansPropertyManager is a PropertyManager that handles the properties of JavaBean model objects.

Version:
$Revision: 1.10 $ $Date: 2002/09/12 10:51:03 $
Author:
Steve Meyfroidt

Constructor Summary
BeansPropertyManager()
           
 
Method Summary
 java.lang.Object get(java.lang.Object inModel, Selector inSelector)
           Return the value of the property identified by the passed Selector.
 java.lang.Class getPropertyClass(java.lang.Object inModel, Selector inSelector)
          Return the Class of a property.
 Selector getSelectorFor(java.lang.Object inModel, java.lang.Object inProperty)
           Tries to find a Selector that would get() a property equals() to the passed Object.
 java.util.Iterator getSelectorIterator(java.lang.Object inModel)
           Return an Iterator that iterates over Selectors for all properties of the passed model object.
 boolean hasProperty(java.lang.Object inModel, Selector inSelector)
           Set the value of the property identified by a Selector in the passed model object to a new value.
 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?
 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.PropertyManager
getInstance, getInstance
 
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

BeansPropertyManager

public BeansPropertyManager()
Method Detail

get

public 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.

Specified by:
get in class PropertyManager
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 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 by using the DynamicReadOnly interface.

Specified by:
isReadOnly in class PropertyManager
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
See Also:
DynamicReadOnly

getPropertyClass

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

Specified by:
getPropertyClass in class PropertyManager
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 java.util.Iterator getSelectorIterator(java.lang.Object inModel)

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

Specified by:
getSelectorIterator in class PropertyManager
Parameters:
inModel - model to make an Iterator for.
Returns:
Iterator that iterates over Selectors for all properties of the passed model object.

getSelectorFor

public Selector getSelectorFor(java.lang.Object inModel,
                               java.lang.Object inProperty)

Tries to find a Selector that would get() a property equals() to the passed Object. If the model is a java.util.List, call indexOf() to search contents first. For Object[] search through contents. Else get an Iterator over all properties and iterate over to find a match.

Note: doesn't search through JavaBeans indexed properties for a match.

Specified by:
getSelectorFor in class PropertyManager
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 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 ModelChangeEvent#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).

Specified by:
set in class PropertyManager
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 boolean hasProperty(java.lang.Object inModel,
                           Selector inSelector)

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 ModelChangeEvent#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).

Specified by:
hasProperty in class PropertyManager
Parameters:
inModel - model to set the property on.
inSelector - identify the property to be set. Can't be null.
Returns:
TODO: Describe the Return Value
Throws:
java.lang.Exception - if the value could not be set in the model


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