Class DefaultDispatcher

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
org.eclnt.jsfserver.managedbean.DefaultDispatcher
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>, IDispatcher
Direct Known Subclasses:
WorkpageDispatcher

public abstract class DefaultDispatcher extends HashMap<String,Object> implements Serializable, IDispatcher
Dispatcher that manages managed beans inside a hash map - so that for each managed bean class exactly one object instance is kept. The following beans are managed:

(1) Beans, that are resided in the package in which your inheriting class is placed. The access expression for these classes is their class name (without package!).

(2) Beans, that are registered in the xml registration file. This file has the name "dispatcherinfo.xml" and must be placed in the same directory as the class that inherits from this DefaultDispatcher class.

(3) Beans, that are explicitly registered by calling the method registerBean.
See Also:
  • Constructor Details

    • DefaultDispatcher

      public DefaultDispatcher()
  • Method Details

    • getDialogSessionInstance

      public static IDispatcher getDialogSessionInstance()
      Returns the root dispatcher instance within the current dialog session. There is one dispatcher within each dialog session.

      This method must only be called within some http session context!
    • getDialogSessionInstance

      public static IDispatcher getDialogSessionInstance(ISessionAbstraction dialogSession)
    • getRootExpression

      protected String getRootExpression()
      Override if NOT using "#{d}" as root dispatcher..
    • addDispatcherExtension

      public static void addDispatcherExtension(IDispatcherExtension dispatcherExtension)
    • removeDispatcherExtension

      public static void removeDispatcherExtension(IDispatcherExtension dispatcherExtension)
    • getStaticDispatcherInfo

      public static DefaultDispatcher.DispatcherInfo getStaticDispatcherInfo()
    • createSubDispatcherIndex

      public int createSubDispatcherIndex()
      Specified by:
      createSubDispatcherIndex in interface IDispatcher
    • setOwner

      public void setOwner(IDispatcher owner)
      Specified by:
      setOwner in interface IDispatcher
    • getDispatchedBean

      public Object getDispatchedBean(String dispatchedBeanName)
      Description copied from interface: IDispatcher
      Find managed bean for name. If the bean already exists then the beans is returned. If it does not exist yet then a new instance will be created.
      Specified by:
      getDispatchedBean in interface IDispatcher
      Parameters:
      dispatchedBeanName - Name of the beans - this is the name that is used for binding the bean within the user interface, as well. E.g. if the bean's binding is "#{d.AbcdeUI. ...} then you may access the bean by passing "AbcdeUI".
    • removeDispatchedBean

      public void removeDispatchedBean(String dispatchedBeanName)
      Description copied from interface: IDispatcher
      Removes dispatched bean from dispatcher.
      Specified by:
      removeDispatchedBean in interface IDispatcher
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map<String,Object>
      Overrides:
      get in class HashMap<String,Object>
    • readObject

      protected Object readObject(String key) throws Exception
      This is the method that is called internally in order to read a dispatched object - which is not in the hashtable of dispatched objects yet. Extensions of DefaultDispatche may override this method and add own ways how to resolve dispatched beans.

      Inside the method first the class is resolved using the method resolveClass(String). Then a "best fitting" constructor is searched and an object is created.
      Throws:
      Exception
    • createObjectInstance

      protected Object createObjectInstance(Class resultClass) throws Exception
      After resolving the class for a given name, an object needs to be created for the class. This is done by this method.
      In this implementation first a constructor with a preferred argument (typically the IDispatcher or the IWorkpageDispatcher instance) is checked. If this does not exsit, then a constructor without parameters is called.
      Throws:
      Exception
    • prepareObject

      protected void prepareObject(Object object)
      After the creation of the object (default: readObject(String) this method is called. Here you can add own preparation logic.
    • createProcessPreview

      protected IProcessPreview createProcessPreview()
    • outputLogInfoWhenNoClassWasResolved

      protected void outputLogInfoWhenNoClassWasResolved(String key)
      The default method readObject(String) tries to resolve a class for a key that is passed. If does not find one it throws an error and outputs corresponding log information. The output of log information is done in this method. You may override this method in case you override the readObject-method - sometimes you want to implement your readObject-method in a way that you first want to test if the default object resolution is successful, and only in case of an error perform your own resolution. In this case you do not want the default mechanism to produce huge error log messages.
    • resolveClass

      public Class resolveClass(String key)
      Resolves the class for a binding key. This method may be overridden by implementations of DefaultDispatcher. Returns null if the class cannot be resolved.

      The resolution is done in two ways within this default implementation: (a) the class is resolved in the same package as the dispatcher, (b) the class is resolved using the "dispatcherinfo.xml" file, that needs to be located in the same package as the dispatcher implementation.

      In case of overriding this method you must FIRST resolve the class with your own resolution strategy before calling this implementation.
    • checkIfDispatchedBeanIsLoaded

      public boolean checkIfDispatchedBeanIsLoaded(Class dispatchedBeanClass)
      Specified by:
      checkIfDispatchedBeanIsLoaded in interface IDispatcher
    • checkIfDispatchedBeanIsLoaded

      public boolean checkIfDispatchedBeanIsLoaded(String dispatchedBeanName)
      Specified by:
      checkIfDispatchedBeanIsLoaded in interface IDispatcher
    • getDispatchedBean

      public Object getDispatchedBean(Class dispatchedBeanClass)
      Description copied from interface: IDispatcher
      Find managed bean for class. If the bean already exists then the bean is returned. If it does not exist yet then a new instance will be created.
      Specified by:
      getDispatchedBean in interface IDispatcher
    • removeDispatchedBean

      public void removeDispatchedBean(Class dispatchedBeanClass)
      Description copied from interface: IDispatcher
      Removes dispatched bean from dispatcher.
      Specified by:
      removeDispatchedBean in interface IDispatcher
    • createSubDispatcherInstance

      public IDispatcher createSubDispatcherInstance()
      Creates a sub dispatcher instance: the class of the instance is the current class of this instance.
      Specified by:
      createSubDispatcherInstance in interface IDispatcher
    • createSubDispatcherInstance

      public IDispatcher createSubDispatcherInstance(Class subDispatcherClass)
      Creates a sub dispatcher instance of the class that is passed as argument. The class must provide a constructor without parameters.

      If overriding this class: after creating the instance you need to call the method resgisterSubDispatcherInstance() with passing the newly created dispatcher instance as parameter.
    • registerSubDispatcherInstance

      protected void registerSubDispatcherInstance(IDispatcher subDispatcher)
    • getExpressionBase

      public String getExpressionBase()
      Description copied from interface: IDispatcher
      Each dispatcher is the entry point to its managed beans. Dispatchers themselves may be nested. This method returns the expression of this dispatcher instance.
      Specified by:
      getExpressionBase in interface IDispatcher
    • destroy

      public void destroy()
      Description copied from interface: IDispatcher
      Destroys the dispatcher and its contained objects.
      Specified by:
      destroy in interface IDispatcher
    • unregisterSubDispatcherInstance

      public void unregisterSubDispatcherInstance(IDispatcher subDispatcher)
      Specified by:
      unregisterSubDispatcherInstance in interface IDispatcher
    • updateExpression

      public String updateExpression(String expression)
      Description copied from interface: IDispatcher
      Within the bean processing you may create components in a dynamic way, e.g. using the feature "componentbinding". When assigning expression to component you need to pay attention that the binding fits to the dispatcher environment in which your bean resides.
      This method builds an expression that is relative to the current dispatcher.
      Specified by:
      updateExpression in interface IDispatcher
      Parameters:
      expression - The normal expression, e.g. "#{d.Car}".
      Returns:
      The relative expression, e.g. "#{d.d_1.Car}".
    • getContentReplace

      public String getContentReplace()
      Description copied from interface: IDispatcher
      Returns the content replace statement that is passed to included pages. Returns a value like "#{d.:#{d.d_1.".
      Specified by:
      getContentReplace in interface IDispatcher
    • getOwner

      public IDispatcher getOwner()
      Description copied from interface: IDispatcher
      Passes back the dispatcher above. Null is returned if the current instance is the top dispatcher
      Specified by:
      getOwner in interface IDispatcher
    • getTopOwner

      public IDispatcher getTopOwner()
      Description copied from interface: IDispatcher
      Passes back the top owner of the dispatcher hierarchy. If the current dispatcher is the top owner itself, then the current dispatcher is returned.
      Specified by:
      getTopOwner in interface IDispatcher
    • getMyExpression

      public String getMyExpression(Object o)
      Description copied from interface: IDispatcher
      Returns the expression for the object that is managed inside the dispatcher.
      Specified by:
      getMyExpression in interface IDispatcher
      Returns:
      Expression of object: "#{d.xyz}"
    • getMyExpression

      public String getMyExpression(Class cl)
      Description copied from interface: IDispatcher
      Returns the expression for the object that is managed inside the dispatcher.
      Specified by:
      getMyExpression in interface IDispatcher
      Returns:
      Expression of object: "#{d.xyz}"
    • createModalPopup

      public ModalPopup createModalPopup()
      Create a modal popup instance within the context of this dispatcher. The contentdrilldown that you normally have to do when creating a popup is done automatically.
      Specified by:
      createModalPopup in interface IDispatcher
    • createModelessPopup

      public ModelessPopup createModelessPopup()
      Create a modeless popup instance within the context of this dispatcher. The contentdrilldown that you normally have to do when creating a popup is done automatically.
      Specified by:
      createModelessPopup in interface IDispatcher
    • toString

      public String toString()
      Overrides:
      toString in class AbstractMap<String,Object>
    • getChildDispatchers

      public List<IDispatcher> getChildDispatchers()
      A dispatcher may be hierarchized.
      Specified by:
      getChildDispatchers in interface IDispatcher
    • isDestroyed

      public boolean isDestroyed()
    • initDispatcher

      protected void initDispatcher()
    • initRegisteredPackages

      protected List<String> initRegisteredPackages(List<String> packageNames)
      This method is called one time during first initialization of the dispatcher. The dispatcher has a certain list of packages that it uses for searching for dispatched beans. This list on the one hand includes the dispatcher package itself but also includes additional packages defined in disptacherinfo.xml. You may update this list of packages by overriding this method.

      In the default implementation the packageNames that are passed as parameter are directly passed back. There is no further activity.
      Parameters:
      packageNames - List of used packages.
      Returns:
      Updated list of packages to be used.
    • initRegisteredBeanInfos

      This method is called one time during first initialization of the dispatcher. The dispatcher tries to find/create an object for a name. For this reason it allows to specify explicit name=>class definitions, which are typically defined in diespatcherinfo.xml. In this method you receive the list of already defined infos and can update the list.

      In the default implementation the infos are directly returned. There is no further activity.
      Parameters:
      infos - List of dispatched bean infos.
      Returns:
      Updated list of dispatched bean infos to be used.
    • getPreferredConstructorArguentClass

      protected Class getPreferredConstructorArguentClass()
      Preferred constructor argument for creation of managed beans. To be overridden by subclasses.