com.levigo.util.swing.action
Class DefaultCommandFactory

java.lang.Object
  extended by com.levigo.util.swing.action.DefaultCommandFactory
All Implemented Interfaces:
CommandFactory, NamedCommandFactory

public class DefaultCommandFactory
extends Object
implements NamedCommandFactory

The default implementation of the CommandFactory interface.

The factory read the class information for the command from the property file. Commands are Singletons and held in a cache by keys.

Version:
$Data$ $Revision$
Author:
l.boureanu@levigo.de, Carolin Köhler
See Also:
CommandFactory

Field Summary
protected  String factoryName
          Name of this command factory, usually its properties file name.
protected  List<BasicCommandFactory> linkedCommandFactories
           
 
Method Summary
static void addCommandCreationListener(CommandCreationListener listener)
          Adds a command creation listener to receive informations or failure messages of command creation process.
 void addLinkedCommandFactory(BasicCommandFactory commandFactory)
          Adds a command factory as linked factory to this factory.
 Command getCommand(String key)
          Default constructor using the settings of the commands.properties file.
static CommandCreationListener[] getCommandCreationListeners()
          Returns an array of currently registered creation listeners
 String getFactoryName()
          Returns the name of this factory, usually its properties resource name.
static DefaultCommandFactory getInstance(String propertiesFileName)
          Create instance for the factory.
 NamedCommandFactory[] getLinkedCommandFactories()
          Returns an array of linked command factories
 String getLinkedFactoryDescription()
          Returns a description of linked factories.
 String getLookupProperty(String key)
          Allows an application to request lookup properties programmatically.
 void insertLinkedCommandFactory(int index, BasicCommandFactory commandFactory)
          Inserts a command factory at index position of linked factories.
 void putLookupProperty(String key, String value)
          Deprecated. use setLookupProperty(String, String) instead
static void removeCommandCreationListener(CommandCreationListener listener)
          Removes a command creation listener.
 void removeLinkedCommandFactory(BasicCommandFactory commandFactory)
          Removes a command factory of linked factories.
 void reset()
          Clears and resets this factory instance.
 void setLookupProperty(String key, String value)
          Allows an application to overwrite or set lookup properties programmatically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factoryName

protected String factoryName
Name of this command factory, usually its properties file name.


linkedCommandFactories

protected List<BasicCommandFactory> linkedCommandFactories
Method Detail

addCommandCreationListener

public static void addCommandCreationListener(CommandCreationListener listener)
Adds a command creation listener to receive informations or failure messages of command creation process.

Parameters:
listener - the listener instance to add

removeCommandCreationListener

public static void removeCommandCreationListener(CommandCreationListener listener)
Removes a command creation listener.

Parameters:
listener - the listener instance to remove

getCommandCreationListeners

public static CommandCreationListener[] getCommandCreationListeners()
Returns an array of currently registered creation listeners

Returns:
CommandCreationListener[] registered listeners

getInstance

public static DefaultCommandFactory getInstance(String propertiesFileName)
Create instance for the factory. It can exist more types of the CommandFactorybut just one instance.

The default properties File doesn't have to be used. It can be used the custom property File. If the custom property file is null then will be the default property file used.

Parameters:
propertiesFileName - custom properties file name
Returns:
instance of the CommandFactory.

getCommand

public Command getCommand(String key)
Description copied from interface: CommandFactory
Default constructor using the settings of the commands.properties file. The factory reads all the class definition from this file.

Algorithm of the command creating:

first: lookup, if the command is already in the cache
second: create command, if not already in the cache otherwise next point.
third: return the created command.

Specified by:
getCommand in interface CommandFactory
Parameters:
key - of the command (ID)
Returns:
created Command
See Also:
CommandFactory.getCommand(java.lang.String)

getFactoryName

public String getFactoryName()
Description copied from interface: NamedCommandFactory
Returns the name of this factory, usually its properties resource name.

Specified by:
getFactoryName in interface NamedCommandFactory
Returns:
name
See Also:
NamedCommandFactory.getFactoryName()

getLinkedFactoryDescription

public String getLinkedFactoryDescription()
Returns a description of linked factories.


putLookupProperty

@Deprecated
public void putLookupProperty(String key,
                                         String value)
Deprecated. use setLookupProperty(String, String) instead

Allows an application to overwrite or set lookup properties programmatically. This is useful if some of the properties are not yet known in advance from its properties resource.

Parameters:
key -
value - The value of the given key, null if the key is not mapped to any value.
Throws:
NullPointerException - if the key or value is null.

setLookupProperty

public void setLookupProperty(String key,
                              String value)
Allows an application to overwrite or set lookup properties programmatically. This is useful if some of the properties are not yet known in advance from its properties resource.

Parameters:
key -
value - The value of the given key, null if the key is not mapped to any value.
Throws:
NullPointerException - if the key or value is null.

reset

public void reset()
Clears and resets this factory instance. This is useful if the property sources should be reload.


getLookupProperty

public String getLookupProperty(String key)
Allows an application to request lookup properties programmatically.

Parameters:
key - A key to look up
Returns:
value The value of the given key, null if the key is not mapped to any value.
Throws:
NullPointerException - if the key is null.

getLinkedCommandFactories

public NamedCommandFactory[] getLinkedCommandFactories()
Returns an array of linked command factories

Returns:
NamedCommandFactory[] linked command factories.

addLinkedCommandFactory

public void addLinkedCommandFactory(BasicCommandFactory commandFactory)
Adds a command factory as linked factory to this factory.

Parameters:
commandFactory - factory to add

removeLinkedCommandFactory

public void removeLinkedCommandFactory(BasicCommandFactory commandFactory)
Removes a command factory of linked factories.

Parameters:
commandFactory - factory to remove

insertLinkedCommandFactory

public void insertLinkedCommandFactory(int index,
                                       BasicCommandFactory commandFactory)
Inserts a command factory at index position of linked factories.

Parameters:
index - index of factory
commandFactory - factory to insert


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.