net.sf.jeters.componentInterface
Class ComponentManager

java.lang.Object
  extended by net.sf.jeters.componentInterface.ComponentManager

public class ComponentManager
extends java.lang.Object

class that manages components. It will make sure configurations and translations are applied to components when being initialized. For other classes, it provides get and set methods to access components and to change which components are currently in use. Note that neither set nor get methods clone the components, modifying them (e.g. by setting configurations) will affect the active component.

Author:
Tobias Knerr

Constructor Summary
ComponentManager(java.io.File componentDirectory, net.sf.jeters.configuration.io.ConfigurationReader[] configurationReaders, TranslationReader translationReader)
          constructor creating a component manager using a given directory as component source
 
Method Summary
 void createMissingComponentConfigurations()
          creates missing configuration data.
 void createMissingComponentConfigurations(java.lang.Class componentClass, Configuration defaultConfig)
          creates missing configuration data for a single component class, has a parameter for the default configuration, thus it is not necessary for this method to create an instance of the componentClass.
 java.util.List<java.lang.Class> getAvailableComponentClasses(java.lang.Class... classes)
          returns the available components classes, can be limited to those components that are instances of given classes/interfaces.
 java.lang.Class getComponentClassForName(java.lang.String name)
          returns the component class for the given name
 InputComponent getInputComponent()
          returns the current input component
 java.lang.String getLocalizedComponentName(java.lang.Class componentClass)
          returns the localized component name for a component; this name is determined from its ressource bundle for the current locale (if it exists)
 java.util.List<java.lang.String> getNamesOfAvailableComponentClasses(java.lang.Class... classes)
          returns the full names of the available components classes, can be limited to those components that are instances of given classes/interfaces.
 OutputComponent getOutputComponent()
          returns the current output component
 java.util.List<ReplacerComponent> getReplacerComponents()
          returns a list of the current replacer components; modifying of the list will not affect the component manager, modifying the components, however, will modify the originals.
 UIComponent getUIComponent()
          returns the current input component
 void setInputComponent(java.lang.Class componentClass)
          creates a new input component from the given class and sets it as active input component
 void setOutputComponent(java.lang.Class componentClass)
          creates a new output component from the given class and sets it as active output component
 void setReplacerComponent(java.util.Collection<java.lang.Class> componentClasses)
          creates new replacer components from the given classes and sets it as active replacer components
 void setTranslation(Component component)
          loads and sets the translation for a translatable component using the current translatationReader.
 void setUIComponent(java.lang.Class componentClass)
          creates a new UI component from the given class and sets it as active UI component
 void writeCurrentConfigurations()
          stores the current configurations of all active components; to be used before exiting program
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentManager

public ComponentManager(java.io.File componentDirectory,
                        net.sf.jeters.configuration.io.ConfigurationReader[] configurationReaders,
                        TranslationReader translationReader)
constructor creating a component manager using a given directory as component source

Parameters:
componentDirectory - directory containing components (classes/jars)
configurationReaders - objects reading and writing configurations for components, with decreasing priority (conflicting values => first one is kept)
translationReader - reader providing language-specific Strings for components implementing Translatable
Method Detail

getUIComponent

public UIComponent getUIComponent()
returns the current input component

Returns:
current input component

getInputComponent

public InputComponent getInputComponent()
returns the current input component

Returns:
current input component

getOutputComponent

public OutputComponent getOutputComponent()
returns the current output component

Returns:
current input component

getReplacerComponents

public java.util.List<ReplacerComponent> getReplacerComponents()
returns a list of the current replacer components; modifying of the list will not affect the component manager, modifying the components, however, will modify the originals.

Returns:
list of current replacer components; guaranteed to be non-null (can, however, be empty)

setUIComponent

public void setUIComponent(java.lang.Class componentClass)
creates a new UI component from the given class and sets it as active UI component

Parameters:
componentClass - class that will be instantiated to create the component; must implement UIComponent, not null, a call to newInstance must not cause an InstantiationException or IllegalAccessException

setInputComponent

public void setInputComponent(java.lang.Class componentClass)
creates a new input component from the given class and sets it as active input component

Parameters:
componentClass - class that will be instantiated to create the component; must implement InputComponent, not null, a call to newInstance must not cause an InstantiationException or IllegalAccessException

setOutputComponent

public void setOutputComponent(java.lang.Class componentClass)
creates a new output component from the given class and sets it as active output component

Parameters:
componentClass - class that will be instantiated to create the component; must implement OutputComponent, not null, a call to newInstance must not cause an InstantiationException or IllegalAccessException

setReplacerComponent

public void setReplacerComponent(java.util.Collection<java.lang.Class> componentClasses)
creates new replacer components from the given classes and sets it as active replacer components

Parameters:
componentClasses - collection of classes that will be instantiated to create the components; every class must implement ReplacerComponent, neither the list nor its element may be null, a call to newInstance for a class must not cause an InstantiationException or IllegalAccessException

createMissingComponentConfigurations

public void createMissingComponentConfigurations()
creates missing configuration data. For each ComponentReader that has a writing ability (i.e. also implements ComponentWriter), this method will check whether it has configuration information about all components (not only checks files, but single options as well). For those it lacks config info, it will have default data written.


createMissingComponentConfigurations

public void createMissingComponentConfigurations(java.lang.Class componentClass,
                                                 Configuration defaultConfig)
creates missing configuration data for a single component class, has a parameter for the default configuration, thus it is not necessary for this method to create an instance of the componentClass. For general behavior, see parameterless version.

Parameters:
componentClass - class to check completeness of config for, != null
defaultConfig - default configuration used as template for missing entries, != null

getAvailableComponentClasses

public java.util.List<java.lang.Class> getAvailableComponentClasses(java.lang.Class... classes)
returns the available components classes, can be limited to those components that are instances of given classes/interfaces. Examples: If you want to get only UI components, call:
getAvailableComponentClasses(UIComponent.class)
For all configurable input components, use:
getAvailableComponentClasses(Configurable.class, InputComponent.class)
If you simply want all components, you should call
getAvailableComponents()

Parameters:
classes - classes/interfaces the component classes must be subtypes of (a vararg parameter)
Returns:
list of all avaliable component classes that are subtypes of the classes given as parameter

getNamesOfAvailableComponentClasses

public java.util.List<java.lang.String> getNamesOfAvailableComponentClasses(java.lang.Class... classes)
returns the full names of the available components classes, can be limited to those components that are instances of given classes/interfaces. For details and examples, see getAvailableComponentClasses(Class[])

Parameters:
classes - classes/interfaces the component classes must be subtypes of (a vararg parameter)
Returns:
list of the names of all avaliable component classes that are subtypes of the classes given as parameter

getComponentClassForName

public java.lang.Class getComponentClassForName(java.lang.String name)
returns the component class for the given name

Parameters:
name - the full name of the component class
Returns:
a class implementing the Component interface or null if no component class with the given name exists

writeCurrentConfigurations

public void writeCurrentConfigurations()
stores the current configurations of all active components; to be used before exiting program


setTranslation

public void setTranslation(Component component)
loads and sets the translation for a translatable component using the current translatationReader.

Parameters:
component - component whose translation is to be set, not null; may be a component that is not translatable (=> no action)

getLocalizedComponentName

public java.lang.String getLocalizedComponentName(java.lang.Class componentClass)
returns the localized component name for a component; this name is determined from its ressource bundle for the current locale (if it exists)

Parameters:
componentClass - component class to get localized name for, != null
Returns:
localizied name or null (if no localized name exists)