Package org.eclnt.jsfserver.managedbean
Class 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.
(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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Interface from tools (layout editor - bean browser) into the application.static class
Interface from tools (layout editor - bean browser) into the application.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addDispatcherExtension
(IDispatcherExtension dispatcherExtension) boolean
checkIfDispatchedBeanIsLoaded
(Class dispatchedBeanClass) boolean
checkIfDispatchedBeanIsLoaded
(String dispatchedBeanName) Create a modal popup instance within the context of this dispatcher.Create a modeless popup instance within the context of this dispatcher.protected Object
createObjectInstance
(Class resultClass) After resolving the class for a given name, an object needs to be created for the class.protected IProcessPreview
int
Creates a sub dispatcher instance: the class of the instance is the current class of this instance.createSubDispatcherInstance
(Class subDispatcherClass) Creates a sub dispatcher instance of the class that is passed as argument.void
destroy()
Destroys the dispatcher and its contained objects.A dispatcher may be hierarchized.Returns the content replace statement that is passed to included pages.static IDispatcher
Returns the root dispatcher instance within the current dialog session.static IDispatcher
getDialogSessionInstance
(ISessionAbstraction dialogSession) getDispatchedBean
(Class dispatchedBeanClass) Find managed bean for class.getDispatchedBean
(String dispatchedBeanName) Find managed bean for name.Each dispatcher is the entry point to its managed beans.getMyExpression
(Class cl) Returns the expression for the object that is managed inside the dispatcher.Returns the expression for the object that is managed inside the dispatcher.getOwner()
Passes back the dispatcher above.protected Class
Preferred constructor argument for creation of managed beans.protected String
Override if NOT using "#{d}" as root dispatcher..Passes back the top owner of the dispatcher hierarchy.protected void
protected List<DefaultDispatcher.DispatchedBeanInfo>
This method is called one time during first initialization of the dispatcher.initRegisteredPackages
(List<String> packageNames) This method is called one time during first initialization of the dispatcher.boolean
protected void
The default methodreadObject(String)
tries to resolve a class for a key that is passed.protected void
prepareObject
(Object object) After the creation of the object (default:readObject(String)
this method is called.protected Object
readObject
(String key) 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.protected void
registerSubDispatcherInstance
(IDispatcher subDispatcher) void
removeDispatchedBean
(Class dispatchedBeanClass) Removes dispatched bean from dispatcher.void
removeDispatchedBean
(String dispatchedBeanName) Removes dispatched bean from dispatcher.static void
removeDispatcherExtension
(IDispatcherExtension dispatcherExtension) resolveClass
(String key) Resolves the class for a binding key.void
setOwner
(IDispatcher owner) toString()
void
unregisterSubDispatcherInstance
(IDispatcher subDispatcher) updateExpression
(String expression) Within the bean processing you may create components in a dynamic way, e.g. using the feature "componentbinding".Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Constructor Details
-
DefaultDispatcher
public DefaultDispatcher()
-
-
Method Details
-
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
-
getRootExpression
Override if NOT using "#{d}" as root dispatcher.. -
addDispatcherExtension
-
removeDispatcherExtension
-
getStaticDispatcherInfo
-
createSubDispatcherIndex
public int createSubDispatcherIndex()- Specified by:
createSubDispatcherIndex
in interfaceIDispatcher
-
setOwner
- Specified by:
setOwner
in interfaceIDispatcher
-
getDispatchedBean
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 interfaceIDispatcher
- 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
Description copied from interface:IDispatcher
Removes dispatched bean from dispatcher.- Specified by:
removeDispatchedBean
in interfaceIDispatcher
-
get
-
readObject
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 methodresolveClass(String)
. Then a "best fitting" constructor is searched and an object is created.- Throws:
Exception
-
createObjectInstance
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 theIDispatcher
or theIWorkpageDispatcher
instance) is checked. If this does not exsit, then a constructor without parameters is called.- Throws:
Exception
-
prepareObject
After the creation of the object (default:readObject(String)
this method is called. Here you can add own preparation logic. -
createProcessPreview
-
outputLogInfoWhenNoClassWasResolved
The default methodreadObject(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
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
- Specified by:
checkIfDispatchedBeanIsLoaded
in interfaceIDispatcher
-
checkIfDispatchedBeanIsLoaded
- Specified by:
checkIfDispatchedBeanIsLoaded
in interfaceIDispatcher
-
getDispatchedBean
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 interfaceIDispatcher
-
removeDispatchedBean
Description copied from interface:IDispatcher
Removes dispatched bean from dispatcher.- Specified by:
removeDispatchedBean
in interfaceIDispatcher
-
createSubDispatcherInstance
Creates a sub dispatcher instance: the class of the instance is the current class of this instance.- Specified by:
createSubDispatcherInstance
in interfaceIDispatcher
-
createSubDispatcherInstance
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
-
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 interfaceIDispatcher
-
destroy
public void destroy()Description copied from interface:IDispatcher
Destroys the dispatcher and its contained objects.- Specified by:
destroy
in interfaceIDispatcher
-
unregisterSubDispatcherInstance
- Specified by:
unregisterSubDispatcherInstance
in interfaceIDispatcher
-
updateExpression
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 interfaceIDispatcher
- Parameters:
expression
- The normal expression, e.g. "#{d.Car}".- Returns:
- The relative expression, e.g. "#{d.d_1.Car}".
-
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 interfaceIDispatcher
-
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 interfaceIDispatcher
-
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 interfaceIDispatcher
-
getMyExpression
Description copied from interface:IDispatcher
Returns the expression for the object that is managed inside the dispatcher.- Specified by:
getMyExpression
in interfaceIDispatcher
- Returns:
- Expression of object: "#{d.xyz}"
-
getMyExpression
Description copied from interface:IDispatcher
Returns the expression for the object that is managed inside the dispatcher.- Specified by:
getMyExpression
in interfaceIDispatcher
- Returns:
- Expression of object: "#{d.xyz}"
-
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 interfaceIDispatcher
-
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 interfaceIDispatcher
-
toString
- Overrides:
toString
in classAbstractMap<String,
Object>
-
getChildDispatchers
A dispatcher may be hierarchized.- Specified by:
getChildDispatchers
in interfaceIDispatcher
-
isDestroyed
public boolean isDestroyed() -
initDispatcher
protected void initDispatcher() -
initRegisteredPackages
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
protected List<DefaultDispatcher.DispatchedBeanInfo> initRegisteredBeanInfos(List<DefaultDispatcher.DispatchedBeanInfo> infos) 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
Preferred constructor argument for creation of managed beans. To be overridden by subclasses.
-