com.levigo.util.swing.action
Class BasicCommandFactory

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

public class BasicCommandFactory
extends Object
implements NamedCommandFactory

BasicCommandFactory provides base functionality for command factories.

Author:
Carolin Köhler
See Also:
CommandFactory, DefaultCommandFactory

Field Summary
protected  Properties commandLookupProperties
          Set of provided command properties.
protected static List<String> EMPTY_STRING_LIST
           
protected  String factoryName
          Name of this command factory, usually its properties file name.
 
Constructor Summary
protected BasicCommandFactory()
          Constructor
protected BasicCommandFactory(InputStream propertyInputStream, String factoryName)
          Constructor, reads a property list (key and element pairs) from the given input stream and fills up the contained commandLookupProperties.
protected BasicCommandFactory(String propertiesFileName)
          Constructor, invokes the loading of the property file name resource and fills up the contained commandLookupProperties.
 
Method Summary
 void clearLookupProperties()
          Clears the lookup properties.
protected  Command createCommand(String key)
           
 Command getCommand(String key)
          Default constructor using the settings of the commands.properties file.
protected  String getCommandClassname(String key)
          Returns the command class name for given key, provided by embedded commandLookupProperties, or an empty string if no command entry was found.
 String getFactoryName()
          Returns the name of this factory, usually its properties file name.
 String getLookupProperty(String key)
          Allows an application to request lookup properties programmatically.
protected  void loadProperties(InputStream is)
          Reads a property list (key and element pairs) from the input stream and fills the embedded commandLookupProperties.
protected  void loadProperties(String propertiesFileName)
          Reads a property list (key and element pairs) from the input file name and fills the embedded commandLookupProperties.
 void putLookupProperty(String key, String value)
          Deprecated. use setLookupProperty(String, String) instead
 void removeLookupProperty(String key)
          Removes the value for given key.
protected  void setFactoryName(String factoryName)
          Changes the name of this factory.
 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

EMPTY_STRING_LIST

protected static final List<String> EMPTY_STRING_LIST

commandLookupProperties

protected Properties commandLookupProperties
Set of provided command properties. Will be used to generate and configure provided commands.


factoryName

protected String factoryName
Name of this command factory, usually its properties file name. In plugin context, this name could be any descriptive text.

Constructor Detail

BasicCommandFactory

protected BasicCommandFactory(String propertiesFileName)
                       throws Exception
Constructor, invokes the loading of the property file name resource and fills up the contained commandLookupProperties.

Parameters:
propertiesFileName - for which should be factory created
Throws:
Exception
See Also:
Properties

BasicCommandFactory

protected BasicCommandFactory()
Constructor


BasicCommandFactory

protected BasicCommandFactory(InputStream propertyInputStream,
                              String factoryName)
                       throws Exception
Constructor, reads a property list (key and element pairs) from the given input stream and fills up the contained commandLookupProperties.

Parameters:
propertyInputStream - the inputstream to read the command properties
factoryName - name of this factory
Throws:
Exception
See Also:
Properties
Method Detail

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(String)

createCommand

protected Command createCommand(String key)

getCommandClassname

protected String getCommandClassname(String key)
Returns the command class name for given key, provided by embedded commandLookupProperties, or an empty string if no command entry was found.

Parameters:
key -
Returns:
associated command class name

loadProperties

protected void loadProperties(String propertiesFileName)
                       throws IOException
Reads a property list (key and element pairs) from the input file name and fills the embedded commandLookupProperties.

Parameters:
propertiesFileName - from which should be the informations read
Throws:
IOException

loadProperties

protected void loadProperties(InputStream is)
                       throws IOException
Reads a property list (key and element pairs) from the input stream and fills the embedded commandLookupProperties.

Throws:
IOException

getFactoryName

public String getFactoryName()
Returns the name of this factory, usually its properties file name. In plugin context, this name could be any descriptive text.

Specified by:
getFactoryName in interface NamedCommandFactory
Returns:
name

setFactoryName

protected void setFactoryName(String factoryName)
Changes the name of this factory. The name is usually its properties file name. In plugin context, this name could be any descriptive text.

Parameters:
factoryName - the new factory name

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.

removeLookupProperty

public void removeLookupProperty(String key)
Removes the value for given key.

Parameters:
key -

clearLookupProperties

public void clearLookupProperties()
Clears the lookup properties.


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.


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