org.nuiton.jaxx.action
Class ActionFactoryFromProvider<A extends MyAbstractAction>

java.lang.Object
  extended by org.nuiton.jaxx.action.ActionFactoryFromProvider<A>
Type Parameters:
A - the type of action
All Implemented Interfaces:
ActionFactory<A>

public class ActionFactoryFromProvider<A extends MyAbstractAction>
extends java.lang.Object
implements ActionFactory<A>

A simple implementation of ActionFactory using some ActionProvider to seek actions.

An entry is in that form : action.actionName=fqn where

actionName is the key of action used in factory, and fqn is the fully qualified name of the implemented action class.

A special clase is to have for a given entry a key like this : action.:fqn'=fqn, in that case, le fqn' is a classe of type ActionNameProvider which gives us at runtime the names of each entry to put in cache for the givne action fqn.

Author:
chemit

Field Summary
protected  ActionConfigConfigurationResolver actionConfigInitializer
           
protected  java.lang.Class<A> baseImpl
          class of encapsuling action
protected  java.util.List<AbstractActionConfigurationResolver> configurationResolvers
           
protected static org.apache.commons.logging.Log log
           
protected  SelectActionConfigConfigurationResolver selectActionConfigInitializer
           
protected  ToggleActionConfigConfigurationResolver toggleActionConfigInitializer
           
 
Constructor Summary
protected ActionFactoryFromProvider(java.lang.Class<A> baseImpl)
           
 
Method Summary
 java.util.Set<java.util.Map.Entry<java.lang.String,A>> cacheEntrySet()
           
protected  void checkRegistredAction(java.lang.String actionKey)
           
 void dispose()
          dispose all actions in cache using MyAbstractAction.disposeUI() on each action, then ActionFactory.resetCache()
protected  void finalize()
           
protected  void finalizeNewAction(javax.swing.AbstractButton component, MyAbstractAction action, ActionConfigurationResolver<?,?> configurationResolver)
           
protected  void finalizeNewAction(javax.swing.JComboBox component, MyAbstractAction action, ActionConfigurationResolver<?,?> configurationResolver)
           
 void fireAction(java.lang.String actionKey, java.lang.Object source)
          Fire an action given his key and his source, no widget are involved here
 void fireAction(java.lang.String actionKey, java.lang.Object source, javax.swing.JComponent component)
          Fire an action given his key, his source and tthe widget responsible of action
 void fireAction0(java.lang.String actionKey, java.lang.Object source, A action)
          Fire an action given his action's key, his source and the real action.
static java.net.URLClassLoader fixClassLoader(java.lang.Class<?> klass)
          Fix the class loader when application is launched from a java -jar The ServiceLoader seems not to find services from jar manifest...
 A getActionFromCache(java.lang.String actionKey)
           
 java.lang.String[] getActionNames()
           
 java.lang.Class<A> getBaseClass()
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Class<? extends MyAbstractAction>>> implsEntrySet()
           
 java.util.Map<java.lang.String,java.lang.Class<? extends MyAbstractAction>> init()
          Method to init the dictionary of knwon action implementations.
 void loadActions(JAXXObject ui)
          For a given ui, load all actions registred in factory.
 A newAction(java.lang.String actionKey)
          Obtain an action instance given his key (should call ActionFactory.newAction(String, JComponent)

This is a convinient method when you want to obtain an action with no attached widget.

 A newAction(java.lang.String actionKey, javax.swing.JComponent component)
          Obtain an action instance given his key and widget
protected  A newActionInstance(java.lang.String actionKey)
           
static
<A extends MyAbstractAction>
ActionFactory<A>
newInstance(java.lang.Class<A> klazz)
           
protected
<I extends AbstractActionConfigurationResolver>
I
registerInitializer(java.lang.Class<I> initizalizer)
           
 void resetCache()
          clear the cache of instanciated actions.
protected  ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log

baseImpl

protected java.lang.Class<A extends MyAbstractAction> baseImpl
class of encapsuling action


actionConfigInitializer

protected final ActionConfigConfigurationResolver actionConfigInitializer

toggleActionConfigInitializer

protected final ToggleActionConfigConfigurationResolver toggleActionConfigInitializer

selectActionConfigInitializer

protected final SelectActionConfigConfigurationResolver selectActionConfigInitializer

configurationResolvers

protected java.util.List<AbstractActionConfigurationResolver> configurationResolvers
Constructor Detail

ActionFactoryFromProvider

protected ActionFactoryFromProvider(java.lang.Class<A> baseImpl)
Method Detail

newInstance

public static <A extends MyAbstractAction> ActionFactory<A> newInstance(java.lang.Class<A> klazz)

getBaseClass

public java.lang.Class<A> getBaseClass()
Specified by:
getBaseClass in interface ActionFactory<A extends MyAbstractAction>
Returns:
the class of the base action of the factory.

resetCache

public void resetCache()
Description copied from interface: ActionFactory
clear the cache of instanciated actions.

Specified by:
resetCache in interface ActionFactory<A extends MyAbstractAction>

loadActions

public void loadActions(JAXXObject ui)
Description copied from interface: ActionFactory
For a given ui, load all actions registred in factory.

The id of the widget in ui is directly mapped to a action key.

Specified by:
loadActions in interface ActionFactory<A extends MyAbstractAction>
Parameters:
ui - the ui to treate

newAction

public A newAction(java.lang.String actionKey,
                   javax.swing.JComponent component)
Description copied from interface: ActionFactory
Obtain an action instance given his key and widget

Specified by:
newAction in interface ActionFactory<A extends MyAbstractAction>
Parameters:
actionKey - le nom de l'action tel que définie dans le fichier de mapping (sans le prefix action.)
component - le button où rattacher l'action
Returns:
une nouvelle instance de l'action associée à sa clef.

newAction

public A newAction(java.lang.String actionKey)
Description copied from interface: ActionFactory
Obtain an action instance given his key (should call ActionFactory.newAction(String, JComponent)

This is a convinient method when you want to obtain an action with no attached widget.

Specified by:
newAction in interface ActionFactory<A extends MyAbstractAction>
Parameters:
actionKey - the key of action
Returns:
the instanciated action (could come from cache if already instanciated ActionFactory.getActionFromCache(String)

getActionNames

public java.lang.String[] getActionNames()
Specified by:
getActionNames in interface ActionFactory<A extends MyAbstractAction>
Returns:
the array of names of all actions known by the factory

implsEntrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Class<? extends MyAbstractAction>>> implsEntrySet()
Specified by:
implsEntrySet in interface ActionFactory<A extends MyAbstractAction>
Returns:
the set of all the action's classes known by the factory.

cacheEntrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,A>> cacheEntrySet()
Specified by:
cacheEntrySet in interface ActionFactory<A extends MyAbstractAction>
Returns:
the set of all actions cached in factory indexed by their name

fireAction

public void fireAction(java.lang.String actionKey,
                       java.lang.Object source,
                       javax.swing.JComponent component)
Description copied from interface: ActionFactory
Fire an action given his key, his source and tthe widget responsible of action

Specified by:
fireAction in interface ActionFactory<A extends MyAbstractAction>
Parameters:
actionKey - the action's key
source - the object source of action
component - the component doing the action

fireAction

public void fireAction(java.lang.String actionKey,
                       java.lang.Object source)
Description copied from interface: ActionFactory
Fire an action given his key and his source, no widget are involved here

Specified by:
fireAction in interface ActionFactory<A extends MyAbstractAction>
Parameters:
actionKey - the action's key
source - the object source of action

getActionFromCache

public A getActionFromCache(java.lang.String actionKey)
Specified by:
getActionFromCache in interface ActionFactory<A extends MyAbstractAction>
Parameters:
actionKey - la clef de l'action
Returns:
l'action deja stockee dans le cache d'action, ou null si non trouvée.

dispose

public void dispose()
Description copied from interface: ActionFactory
dispose all actions in cache using MyAbstractAction.disposeUI() on each action, then ActionFactory.resetCache()

Specified by:
dispose in interface ActionFactory<A extends MyAbstractAction>

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

finalizeNewAction

protected void finalizeNewAction(javax.swing.AbstractButton component,
                                 MyAbstractAction action,
                                 ActionConfigurationResolver<?,?> configurationResolver)
Parameters:
component - le button où rattacher l'action
action - action
configurationResolver - initializer

finalizeNewAction

protected void finalizeNewAction(javax.swing.JComboBox component,
                                 MyAbstractAction action,
                                 ActionConfigurationResolver<?,?> configurationResolver)
Parameters:
component - le select box où rattacher l'action
action - action
configurationResolver - initializer

resolveActionConfiguration

protected ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action)

registerInitializer

protected <I extends AbstractActionConfigurationResolver> I registerInitializer(java.lang.Class<I> initizalizer)

fireAction0

public void fireAction0(java.lang.String actionKey,
                        java.lang.Object source,
                        A action)
Description copied from interface: ActionFactory
Fire an action given his action's key, his source and the real action.

This is a convinient method when you need to modified action before fire it.

Specified by:
fireAction0 in interface ActionFactory<A extends MyAbstractAction>
Parameters:
actionKey - action's key
source - source of action
action - real action

checkRegistredAction

protected void checkRegistredAction(java.lang.String actionKey)

newActionInstance

protected A newActionInstance(java.lang.String actionKey)
                                                throws java.lang.InstantiationException,
                                                       java.lang.IllegalAccessException,
                                                       java.lang.reflect.InvocationTargetException,
                                                       java.lang.NoSuchMethodException
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

init

public java.util.Map<java.lang.String,java.lang.Class<? extends MyAbstractAction>> init()
Description copied from interface: ActionFactory
Method to init the dictionary of knwon action implementations.

Specified by:
init in interface ActionFactory<A extends MyAbstractAction>
Returns:
the dictionary of known action implementations

fixClassLoader

public static java.net.URLClassLoader fixClassLoader(java.lang.Class<?> klass)
Fix the class loader when application is launched from a java -jar The ServiceLoader seems not to find services from jar manifest...

Our solution is to get all jar from the jar manifest and create a URLClassLoader, this is not perfect but works.

TODO Put this nice code in a ServiceLoaderUtil in lutinutil...

Parameters:
klass - class to use to obtain classloader
Returns:
the fixed classloader


Copyright © 2008-2010 CodeLutin. All Rights Reserved.