org.formaria.registry
Class RegisteredComponentFactory

java.lang.Object
  extended by org.formaria.registry.RegisteredComponentFactory
All Implemented Interfaces:
ComponentConstructor
Direct Known Subclasses:
EditorRegisteredComponentFactory

public class RegisteredComponentFactory
extends java.lang.Object
implements ComponentConstructor

A component factory that builds components based upon some XML configuration files. This factory is designed to work with the Aria which includes a graphical utility for selection and configuration of components. The XML configuration file may also be manipulated outside of the editor.

The factory works by reading a file specifying where a component can be loaded from and the methods within that component that can be used to get and set properties. The getter and setter methods do not need to follow the bean specification and can include various arguments and they can also use different naming schemes.

Copyright (c) Formaria Ltd., 2008

$Revision: 1.21 $

License: see License.txt


Field Summary
protected static int changeCounter
          A counter for changes to the registry.
protected static java.util.Hashtable configFiles
          The config files used to build the set of component adapters
protected  Project currentProject
           
protected  int localChangeCounter
          Used for tracking changes to the registry spec.
protected  java.util.Hashtable propertiesRegister
          The register of component adapters for each component type
protected  java.lang.String urlBase
          Location/spec of the jar file from which the resource are loaded.
 
Constructor Summary
RegisteredComponentFactory(Project project)
          Create the new component factory
 
Method Summary
 ComponentAdapter addComponentAdapter(java.lang.String owner, java.lang.String componentName, java.lang.String iconName, java.lang.String clazz, java.lang.String ui)
          Create a new component adapter
static void addConfigFile(java.lang.String key, java.lang.Object resource, boolean overwrite)
          Add a configuration file.
 java.lang.Object addElement(ComponentFactory cf, java.lang.String type, java.lang.String name, java.lang.String content, java.util.Hashtable attribs)
          A generic factory method for adding non component elements.
 ComponentAdapter addReflectionAdapter(java.lang.String owner, java.lang.String componentName, java.lang.String iconName, java.lang.String clazz, java.lang.String ui)
          Create a new reflection component adapter, that is an adapter that uses reflection to find a suitable getter or setter.
 void checkRegistration()
          Check that all the registered components are loaded
 java.lang.Object constructComponent(ComponentFactory cf, java.lang.String type, java.lang.String content)
          A generic factory for adding Components.
protected  void doRead(java.lang.String key, java.lang.Object configFile)
          Read the component registry.
protected  void doRead(java.lang.String key, java.lang.String configFile)
          Read the component registry.
protected  void doRead(java.lang.String key, java.net.URL configFileURL)
          Read the component registry.
 ComponentAdapter getComponentAdapter(java.lang.String type)
          Get the adapter for a particular component type.
protected  void read()
          Read the component registry.
 void read(java.lang.String key, java.io.Reader reader)
          Read the component registry.
protected  void read(java.lang.String key, java.lang.String configFile)
          Read the component registry.
 void setPackageName(java.lang.String defPackage)
          Set the package name for the factory's widgets.
 void update()
          Notify the component factories that some of their settings may have changed
static void updateConfig()
          Signal that the configuration has been updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertiesRegister

protected java.util.Hashtable propertiesRegister
The register of component adapters for each component type


configFiles

protected static java.util.Hashtable configFiles
The config files used to build the set of component adapters


changeCounter

protected static int changeCounter
A counter for changes to the registry. Used to indicate if the registry needs to be rebuilt


localChangeCounter

protected int localChangeCounter
Used for tracking changes to the registry spec.


urlBase

protected java.lang.String urlBase
Location/spec of the jar file from which the resource are loaded. A temporary object


currentProject

protected Project currentProject
Constructor Detail

RegisteredComponentFactory

public RegisteredComponentFactory(Project project)
Create the new component factory

Parameters:
project - the owner project
Method Detail

addConfigFile

public static void addConfigFile(java.lang.String key,
                                 java.lang.Object resource,
                                 boolean overwrite)
Add a configuration file. If the files have already been loaded then the new file will be loaded

Parameters:
key - the name by which the configuration file is referenced
resource - the name/path of the configuration file or the URL for the file
overwrite - true to overwrite and existing entry matching the specified key

updateConfig

public static void updateConfig()
Signal that the configuration has been updated.


constructComponent

public java.lang.Object constructComponent(ComponentFactory cf,
                                           java.lang.String type,
                                           java.lang.String content)
A generic factory for adding Components. The component is constructed, positioned and added to the parent panel if one exists. The component is named with a counter value to uniquely identify the control. When a ScrollPane is addd it becomes the parent.

Specified by:
constructComponent in interface ComponentConstructor
Parameters:
cf - the calling component factory
type - a name identifying the type of component to be created
content - the component text/content
Returns:
the new component

addElement

public java.lang.Object addElement(ComponentFactory cf,
                                   java.lang.String type,
                                   java.lang.String name,
                                   java.lang.String content,
                                   java.util.Hashtable attribs)
A generic factory method for adding non component elements. The method can be useful in conjunction with the 'repeat' and 'include' keywords where a component may not have a one to one relationship with the XML element.

Specified by:
addElement in interface ComponentConstructor
Parameters:
cf - the calling component factory
type - the object type
name - a name identifying the element to be created
content - the component text/content
attribs - the element attributes if any
Returns:
the new component

update

public void update()
Notify the component factories that some of their settings may have changed

Specified by:
update in interface ComponentConstructor

setPackageName

public void setPackageName(java.lang.String defPackage)
Set the package name for the factory's widgets. This factory ignores the default package name as the classes/componentes being instantiated can come from different packages and their package must be fully specified.

Specified by:
setPackageName in interface ComponentConstructor
Parameters:
defPackage - the default package name

getComponentAdapter

public ComponentAdapter getComponentAdapter(java.lang.String type)
Get the adapter for a particular component type. The adapter can be used to get and set properties of the component.

Specified by:
getComponentAdapter in interface ComponentConstructor
Parameters:
type - the name by which the component is specified and referenced
Returns:
the adapter

read

protected void read()
Read the component registry. The format is described in the components.xsd schema.


read

protected void read(java.lang.String key,
                    java.lang.String configFile)
Read the component registry. The format is described in the components.xsd schema. The config file is also registered.

Parameters:
configFile - the name of the configuration file
key - the name by which the configuration file is referenced

doRead

protected void doRead(java.lang.String key,
                      java.lang.Object configFile)
Read the component registry. The format is described in the components.xsd schema.

Parameters:
configFile - the name of the configuration file
key - the name by which the configuration file is referenced

doRead

protected void doRead(java.lang.String key,
                      java.lang.String configFile)
Read the component registry. The format is described in the components.xsd schema.

Parameters:
configFile - the name of the configuration file
key - the name by which the configuration file is referenced

doRead

protected void doRead(java.lang.String key,
                      java.net.URL configFileURL)
Read the component registry. The format is described in the components.xsd schema.

Parameters:
configFileURL - the URL of the configuration file
key - the name by which the configuration file is referenced

read

public void read(java.lang.String key,
                 java.io.Reader reader)
Read the component registry. The format is described in the components.xsd schema.

Parameters:
key - the name by which the configuration file is referenced
reader - the reader from which to read the file

addComponentAdapter

public ComponentAdapter addComponentAdapter(java.lang.String owner,
                                            java.lang.String componentName,
                                            java.lang.String iconName,
                                            java.lang.String clazz,
                                            java.lang.String ui)
                                     throws java.lang.ClassNotFoundException
Create a new component adapter

Parameters:
owner - the name ofthe owning module
componentName - the component name
iconName - the icon file
clazz - the class file name
ui - the name of the ui
Returns:
the new component adapter
Throws:
java.lang.ClassNotFoundException - problems finding the class

addReflectionAdapter

public ComponentAdapter addReflectionAdapter(java.lang.String owner,
                                             java.lang.String componentName,
                                             java.lang.String iconName,
                                             java.lang.String clazz,
                                             java.lang.String ui)
                                      throws java.lang.ClassNotFoundException
Create a new reflection component adapter, that is an adapter that uses reflection to find a suitable getter or setter.

Parameters:
owner - the name ofthe owning module
componentName - the component name
iconName - the icon file
clazz - the class file name
ui - the name of the ui
Returns:
the new component adapter
Throws:
java.lang.ClassNotFoundException - problems finding the class

checkRegistration

public void checkRegistration()
Check that all the registered components are loaded