Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.scopemvc.controller.basic
Class BasicController  view BasicController download BasicController.java

java.lang.Object
  extended byorg.scopemvc.controller.basic.BasicController
All Implemented Interfaces:
org.scopemvc.core.Controller

public abstract class BasicController
extends java.lang.Object
implements org.scopemvc.core.Controller

Full implementation of Controller that adds:

To implement a subclass of BasicController:

Version:
$Revision: 1.9 $ $Date: 2002/01/26 09:46:20 $

Field Summary
static java.lang.String CHANGE_MODEL_CONTROL_ID
          An internal Control calls changeModel().
private  java.util.LinkedList children
           
static java.lang.String EXIT_CONTROL_ID
           A convenience Control that can be used when a Controller wants to exit.
static java.lang.String HIDE_VIEW_CONTROL_ID
          ID of common Control that is handled by BasicController to hide the current view.
private static org.apache.commons.logging.Log LOG
           
private  java.lang.Object model
           
private  BasicController parent
           
private  org.scopemvc.core.View view
           
 
Constructor Summary
BasicController()
           Construct subclasses by either using a passed model object and View, or creating new ones.
 
Method Summary
 void addChild(BasicController inChild)
           
protected  void bindModelToView(org.scopemvc.core.View inView, java.lang.Object inModel)
           
private  void changeModel(java.lang.Object inParameter)
          Respond to CHANGE_MODEL_CONTROL_ID to keep the controller's model in sync with the currently shown model if it is changed as a submodel of a model managed by a parent controller.
protected  void doHandleControl(org.scopemvc.core.Control inControl)
           Override this to recognise Controls that this Controller can handle.
 java.util.List getChildren()
          This supports ScopeServlet.
 java.lang.Object getModel()
           
 org.scopemvc.core.Controller getParent()
           
 org.scopemvc.core.Controller getTopParent()
          Convenience method.
 org.scopemvc.core.View getView()
           
 void handleControl(org.scopemvc.core.Control inControl)
          Application writers see doHandleControl(org.scopemvc.core.Control) 55 .
protected  void handleControlException(org.scopemvc.core.ControlException inException)
          Called by handleControl(org.scopemvc.core.Control) 55 when a Control throws a ControlException.
protected  void hideView()
           
protected  void hideView(org.scopemvc.core.View inView)
           
protected  void passControlToParent(org.scopemvc.core.Control inControl)
          Feed a Control to the parent Controller up the chain of command.
 void removeChild(BasicController inChild)
           
 void setModel(java.lang.Object inModel)
          Sets the model object that this Controller links to its View.
 void setModelAndView(java.lang.Object inModel, org.scopemvc.core.View inView)
          Change to both a new model object and new View, binding the two together properly.
protected  void setParent(BasicController inParent)
          Hook this Controller into the chain of responsiblity as a child of the passed Controller.
 void setView(org.scopemvc.core.View inView)
          Sets the View that this Controller links to its model object.
protected  void showError(java.lang.String inErrorTitle, java.lang.String inErrorMessage)
          Convenience to show an error using the current ViewContext.
protected  void showView()
           
protected  void showView(org.scopemvc.core.View inView)
           
 void shutdown()
          Can be called by a parent to shutdown and remove this from the chain of responsibility.
 void startup()
          Call this after creating the Controller to make it perform its initial action.
 
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

HIDE_VIEW_CONTROL_ID

public static final java.lang.String HIDE_VIEW_CONTROL_ID
ID of common Control that is handled by BasicController to hide the current view.

See Also:
Constant Field Values

CHANGE_MODEL_CONTROL_ID

public static final java.lang.String CHANGE_MODEL_CONTROL_ID
An internal Control calls changeModel(). This is an internal Control to keep Controller's model in sync with the currently shown model in its View. This occurs when a parent controller modifies its model when that contains the submodel managed by a child controller. This is fully implemented by the concrete impl of SwingView. ServletView doesn't need it.

See Also:
Constant Field Values

EXIT_CONTROL_ID

public static final java.lang.String EXIT_CONTROL_ID

A convenience Control that can be used when a Controller wants to exit. For an application Controller this means exitting the application, but for a sub-controller it probably means just an exit from that local area of functionality. This impl causes this Control to propogate up the chain of responsibility so that if unhandled the application will exit.

The parameter of this Control is the Controller that issued it (ie the one that's shutting down), or null if just issued by this. The default impl here propogates the Control up, changing the shutdown Controller as it goes up, until it meets the top of the Controller tree at which point ViewContext.exit() 55 is called: for Swing this does System.exit and for Servlets it is ignored. If you use this Control, recognise it at some parent of the Controller that can issue it, and take appropriate action.

See Also:
Constant Field Values

parent

private BasicController parent

children

private java.util.LinkedList children

model

private java.lang.Object model

view

private org.scopemvc.core.View view
Constructor Detail

BasicController

public BasicController()

Construct subclasses by either using a passed model object and View, or creating new ones. Use setModel(java.lang.Object) 55 and setView(org.scopemvc.core.View) 55 or setModelAndView(java.lang.Object, org.scopemvc.core.View) 55 . Never show a View on construction: initialisation should set the application up without actually starting it by showing a View. An initial startup action implemented in startup() can show a View when called after construction.

Throw a ControlException from subclasses if something goes wrong.

Method Detail

getChildren

public final java.util.List getChildren()
This supports ScopeServlet.


addChild

public final void addChild(BasicController inChild)

removeChild

public final void removeChild(BasicController inChild)

setParent

protected final void setParent(BasicController inParent)
Hook this Controller into the chain of responsiblity as a child of the passed Controller. See addChild(org.scopemvc.controller.basic.BasicController) 55


getParent

public final org.scopemvc.core.Controller getParent()
Specified by:
getParent in interface org.scopemvc.core.Controller

bindModelToView

protected void bindModelToView(org.scopemvc.core.View inView,
                               java.lang.Object inModel)

setModel

public final void setModel(java.lang.Object inModel)
Sets the model object that this Controller links to its View. If you need to set both the View and model then use setModelAndView(java.lang.Object, org.scopemvc.core.View) 55 rather than calling setModel and setView separately.

Specified by:
setModel in interface org.scopemvc.core.Controller

getModel

public final java.lang.Object getModel()
Specified by:
getModel in interface org.scopemvc.core.Controller

setView

public final void setView(org.scopemvc.core.View inView)
Sets the View that this Controller links to its model object. Unlinks the old View from the current model object and also hides it, however, doesn't show the new view. If you need to set both the View and model object then slightly more efficient in establishing the binding to use setModelAndView(java.lang.Object, org.scopemvc.core.View) 55 rather than calling setModel() and setView() separately.

Specified by:
setView in interface org.scopemvc.core.Controller

getView

public final org.scopemvc.core.View getView()
Specified by:
getView in interface org.scopemvc.core.Controller

setModelAndView

public final void setModelAndView(java.lang.Object inModel,
                                  org.scopemvc.core.View inView)
Change to both a new model object and new View, binding the two together properly. Also disconnect and discard/hide the previous model/View pair. Slightly more efficient in changing to a new model/view binding than calling setModel and setView separately.


handleControl

public final void handleControl(org.scopemvc.core.Control inControl)
Application writers see doHandleControl(org.scopemvc.core.Control) 55 . This base implementation handles
  • HIDE_VIEW_CONTROL_ID
  • the internal CHANGE_MODEL_CONTROL_ID
  • EXIT_CONTROL_ID after allowing application code to intercept in doHandleControl. If this Controller has a parent, then hideView and pass it up, else call the ViewContext to do the exit according to context. ***** should get children to hideView too

Specified by:
handleControl in interface org.scopemvc.core.Controller

doHandleControl

protected void doHandleControl(org.scopemvc.core.Control inControl)
                        throws org.scopemvc.core.ControlException

Override this to recognise Controls that this Controller can handle. Any unhandled Controls are passed up the chain of responsibility to parent Controllers.

 protected void doHandleControl(Control inControl) throws ControlException {
     if (inControl.matchesID(FOO_CONTROL_ID)) {
         doFoo(inControl.getParameter());
     } else if (inControl.matchesID(BAR_CONTROL_ID)) {
         doBar(inControl.getParameter());
     }
 }
 

If something goes wrong when running some presentation logic, throw a ControlException which results in a call to handleControlException(org.scopemvc.core.ControlException) 55 ).


handleControlException

protected void handleControlException(org.scopemvc.core.ControlException inException)
Called by handleControl(org.scopemvc.core.Control) 55 when a Control throws a ControlException. This impl uses the showError(java.lang.String, java.lang.String) 55 method.


passControlToParent

protected final void passControlToParent(org.scopemvc.core.Control inControl)
Feed a Control to the parent Controller up the chain of command.


getTopParent

public final org.scopemvc.core.Controller getTopParent()
Convenience method.

Specified by:
getTopParent in interface org.scopemvc.core.Controller

changeModel

private void changeModel(java.lang.Object inParameter)
Respond to CHANGE_MODEL_CONTROL_ID to keep the controller's model in sync with the currently shown model if it is changed as a submodel of a model managed by a parent controller.


showView

protected final void showView()

showView

protected final void showView(org.scopemvc.core.View inView)

hideView

protected final void hideView()

hideView

protected final void hideView(org.scopemvc.core.View inView)

showError

protected final void showError(java.lang.String inErrorTitle,
                               java.lang.String inErrorMessage)
Convenience to show an error using the current ViewContext.


startup

public void startup()
Call this after creating the Controller to make it perform its initial action. Default implementation here just calls showView() if a View is set.


shutdown

public void shutdown()
Can be called by a parent to shutdown and remove this from the chain of responsibility. Default impl does this:
  • call shutdown() on every child controller
  • call hideView()
  • setParent(null)