echoxul.view
Class ViewLocator

java.lang.Object
  extended byechoxul.view.ViewLocator
Direct Known Subclasses:
BaseViewLocator

public abstract class ViewLocator
extends java.lang.Object

This is the abstract base class for accessing/resolving View instances by symbolic names. It is accessed through a singleton-like mechanism where the instance is retrieved from the EchoInstance attributes collection with the name ViewCache.ATTRIBUTE_NAME.

Note that this scheme means that a new ViewCache will be instantiated for every user. View instances were intended to be used by all sessions in a server and recreating them for every user is wasteful of resources. To get around this, the developer must explicitly initialize the EchoInstance singleton to a ViewCache that is shared across the entire application.

If a ViewCache has not been explicitly set, the first call to the getInstance(EchoInstance) method will result in a limited ViewCache being created which is only capable of loading resources from the class path (ie. via Class.getResource()). More complicated schems that use web or file system resources need to be explicitly set during server startup.

Author:
Terry Laurenzo

Field Summary
static java.lang.String ATTRIBUTE_NAME
          The name of the attribute in EchoInstance where the singleton is stored.
 
Constructor Summary
ViewLocator()
           
 
Method Summary
static ViewLocator getInstance(nextapp.echo.EchoInstance echoInstance)
          Return the singleton instance, creating a default one if necessary
abstract  View lookupView(java.lang.Class clazz)
          Similar to lookupView(String) except that it converts the given class into a path and looks up the view with that path.
abstract  View lookupView(java.lang.String path)
          Looks up a (potentially cached) view from the list of ViewResolvers registered with this instance.
static void setInstance(nextapp.echo.EchoInstance echoInstance, ViewLocator viewCache)
          Call at application startup to initialize an EchoInstance with a singleton ViewCache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_NAME

public static final java.lang.String ATTRIBUTE_NAME
The name of the attribute in EchoInstance where the singleton is stored.

See Also:
Constant Field Values
Constructor Detail

ViewLocator

public ViewLocator()
Method Detail

getInstance

public static ViewLocator getInstance(nextapp.echo.EchoInstance echoInstance)
Return the singleton instance, creating a default one if necessary

Parameters:
echoInstance -
Returns:

setInstance

public static void setInstance(nextapp.echo.EchoInstance echoInstance,
                               ViewLocator viewCache)
Call at application startup to initialize an EchoInstance with a singleton ViewCache.

Parameters:
echoInstance -
viewCache -

lookupView

public abstract View lookupView(java.lang.String path)
                         throws ViewNotFoundException
Looks up a (potentially cached) view from the list of ViewResolvers registered with this instance. The only syntax which is always supported is the one for looking up Java classpath resources. See ViewComponent for details.

TODO: Fully document this method

Parameters:
path - The resolver specific path string
Returns:
The View requested
Throws:
ViewNotFoundException - if the view cannot be found

lookupView

public abstract View lookupView(java.lang.Class clazz)
                         throws ViewNotFoundException
Similar to lookupView(String) except that it converts the given class into a path and looks up the view with that path.

Parameters:
clazz - The class to lookup.
Returns:
The ViewRequested
Throws:
ViewNotFoundException - if the view cannot be found


Copyright © 2004 Terry Laurenzo. All Rights Reserved.