|
|||||||||
| Home >> All >> org >> scopemvc >> model >> [ basic overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.scopemvc.model.basic
Class BasicModel

java.lang.Objectorg.scopemvc.model.basic.BasicModel
- All Implemented Interfaces:
- org.scopemvc.core.ModelChangeEventSource, org.scopemvc.core.ModelChangeListener, org.scopemvc.core.ModelChangeTypes
- public abstract class BasicModel
- extends java.lang.Object
- implements org.scopemvc.core.ModelChangeEventSource, org.scopemvc.core.ModelChangeTypes
- extends java.lang.Object
A simple implementation of ModelChangeEventSource for use as a base class. An alternative (JavaBeans style) is to use ModelChangeEventSupport as a delegate in all models.
To implement a BasicModel:
-
extend
BasicModel, -
Notify interested listeners of changes in Model state at the end of
setmethods by:fireModelChange(...) -
Register as a ModelChangeListener with submodels in the appropriate
set methods to ensure event propogation up the tree of
models. For example:
public final static Selector NAME = Selector.fromString("name"); public final static Selector ADDRESS = Selector.fromString("address"); public void setAddress(AddressModel inAddress) throws ModelException { if (inAddress == address) { return; } unlistenOldSubmodel(ADDRESS); address = inAddress; listenNewSubmodel(ADDRESS); fireModelChange(VALUE_CHANGE, ADDRESS); }This ensures that any change in the Address's state is received by this parent which will then fire its own ModelChangeEvent to its listeners. See ModelChangeEventSource for more discussion. Note the use of the Selector constants: this is for convenience (and performance). - Use Scope's collection models instead of the regular Java collections: Scope collections propogate changes to submodels as above and are compliant ModelChangeEventSources. These collections must be listened to in the same way as other submodel properties. Note that Scope collections are just thin wrappers on native Java collections.
- Version:
- $Revision: 1.6 $ $Date: 2002/01/26 09:46:20 $
| Field Summary | |
private static org.apache.commons.logging.Log |
LOG
|
private org.scopemvc.core.PropertyManager |
manager
|
private ModelChangeEventSupport |
mceSupport
|
| Fields inherited from interface org.scopemvc.core.ModelChangeTypes |
ACCESS_CHANGED, VALUE_ADDED, VALUE_CHANGED, VALUE_REMOVED |
| Constructor Summary | |
BasicModel()
|
|
| Method Summary | |
void |
addModelChangeListener(org.scopemvc.core.ModelChangeListener inListener)
|
void |
fireModelChange(int inChangeType,
org.scopemvc.core.Selector inSelector)
|
protected void |
listenNewSubmodel(org.scopemvc.core.Selector inSelector)
Convenience for BasicModel implementors: call this at the end of setters for submodel properties (ie properties of type ModelChangeEventSource) to register this as a ModelChangeListener to the current submodel for event propogation. |
void |
makeActive(boolean inActive)
Control whether this BasicModel broadcasts ModelChangeEvents. |
void |
modelChanged(org.scopemvc.core.ModelChangeEvent inEvent)
Handle changes to children ModelChangeEventSources by firing a change event from this
(and propogating the original Selector). |
void |
removeModelChangeListener(org.scopemvc.core.ModelChangeListener inListener)
|
protected void |
unlistenOldSubmodel(org.scopemvc.core.Selector inSelector)
Convenience for BasicModel implementors: call this at the start of setters for submodel properties (ie properties of type ModelChangeEventSource) to deregister this as a ModelChangeListener to the current submodel (about to be set to another Model). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
LOG
private static final org.apache.commons.logging.Log LOG
mceSupport
private ModelChangeEventSupport mceSupport
manager
private org.scopemvc.core.PropertyManager manager
| Constructor Detail |
BasicModel
public BasicModel()
| Method Detail |
addModelChangeListener
public final void addModelChangeListener(org.scopemvc.core.ModelChangeListener inListener)
- Specified by:
addModelChangeListenerin interfaceorg.scopemvc.core.ModelChangeEventSource
removeModelChangeListener
public final void removeModelChangeListener(org.scopemvc.core.ModelChangeListener inListener)
- Specified by:
removeModelChangeListenerin interfaceorg.scopemvc.core.ModelChangeEventSource
fireModelChange
public final void fireModelChange(int inChangeType,
org.scopemvc.core.Selector inSelector)
- Specified by:
fireModelChangein interfaceorg.scopemvc.core.ModelChangeEventSource
modelChanged
public void modelChanged(org.scopemvc.core.ModelChangeEvent inEvent)
Handle changes to children ModelChangeEventSources by firing a change event from
this(and propogating the original Selector). If the event's source is no longer a child property of this parent then there is no need to continue propogating the event.- Specified by:
modelChangedin interfaceorg.scopemvc.core.ModelChangeEventSource
unlistenOldSubmodel
protected final void unlistenOldSubmodel(org.scopemvc.core.Selector inSelector)
- Convenience for BasicModel implementors:
call this at the start of setters for submodel properties
(ie properties of type ModelChangeEventSource) to
deregister this as a ModelChangeListener
to the current submodel (about to be set to another Model).
listenNewSubmodel
protected final void listenNewSubmodel(org.scopemvc.core.Selector inSelector)
- Convenience for BasicModel implementors:
call this at the end of setters for submodel properties
(ie properties of type ModelChangeEventSource) to
register this as a ModelChangeListener
to the current submodel for event propogation.
makeActive
public void makeActive(boolean inActive)
Control whether this BasicModel broadcasts ModelChangeEvents. Make sure nested calls are properly matched to fully re-activate a BasicModel that was deactivated.
Subclasses may override this to propogate the activation state to child BasicModel properties if necessary.
|
|||||||||
| Home >> All >> org >> scopemvc >> model >> [ basic overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.scopemvc.model.basic.BasicModel