Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.modeshape.common.component
Class ComponentLibrary<ComponentType,ConfigType extends ComponentConfig>

    java.lang.Object
      org.modeshape.common.component.ComponentLibrary<ComponentType,ConfigType>

Type Parameters:
  `ComponentType` - the type of component being managed, which may be a subclass of `Component`
  `ConfigType` - the configuration type describing the components

Direct Known Subclasses:
  SequencerLibrary

    @ThreadSafe
    public class ComponentLibrary<ComponentType,ConfigType extends ComponentConfig>

extends Object

Maintains the list of component instances for the system. This class does not actively update the component configurations, but is designed to properly maintain the instances when those configurations are changed by other callers. If the components are subclasses of `Component`, then they will be `configured` with the appropriate configuration.

Therefore, this library does guarantee that the `instances` at the time they are `obtained` are always reflected by the configurations.

Field Summary
`static ClassLoaderFactory` | `DEFAULT` Class loader factory instance that always returns the `current thread's context class loader` (if not null) or component library's class loader.

Constructor Summary
`ComponentLibrary()` Create a new library of components.
`ComponentLibrary(boolean addBeforeExistingConfigs)` Create a new library of components.

Method Summary
`boolean` | `add(ConfigType config)` Add the configuration for a component, or update any existing one that represents the `same configuration`
`protected void` | `configure(ComponentType newInstance, ConfigType configuration)`
`protected ComponentType` | `doCreateInstance(Class<?> componentClass)` Method that instantiates the supplied class.
`protected int` | `findIndexOfMatchingConfiguration(ConfigType config)` Find the index for the matching `configuration` and `component`.
`protected int` | `findIndexOfMatchingConfiguration(String name)` Find the index for the matching `configuration` and `component`.
`ClassLoaderFactory` | `getClassLoaderFactory()` Get the class loader factory that should be used to load the component classes.
`ComponentType` | `getInstance(String name)` Get the instance given by the configuration with the supplied name.
`List<ComponentType>` | `getInstances()` Return the list of components.
`List<ConfigType>` | `getSequenceConfigs()` Get the configurations for all Sequencers
`protected ComponentType` | `newInstance(ConfigType config)` Instantiate, configure and return a new component described by the supplied configuration.
`boolean` | `refreshInstances()` Refresh the instances by attempting to re-instantiate each registered configuration.
`boolean` | `remove(ConfigType config)` Remove the configuration for a component.
`boolean` | `removeAll()`
`boolean` | `removeAllAndAdd(ConfigType config)`
`void` | `setClassLoaderFactory(ClassLoaderFactory classLoaderFactory)` Set the Maven Repository that should be used to load the component classes.
`boolean` | `update(ConfigType config)` Update the configuration for a component, or add it if there is no `matching configuration` .

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT

    public static final ClassLoaderFactory DEFAULT

  Class loader factory instance that always returns the `current thread's context class loader` (if not null) or component library's class loader.

Constructor Detail

### ComponentLibrary

    public ComponentLibrary()

  Create a new library of components.

### ComponentLibrary

    public ComponentLibrary(boolean addBeforeExistingConfigs)

  Create a new library of components.

  Parameters:
    `addBeforeExistingConfigs` - `true` if configurations should be `added` before previously added configurations.

Method Detail

### getClassLoaderFactory

    public ClassLoaderFactory getClassLoaderFactory()

  Get the class loader factory that should be used to load the component classes. Unless changed, the library uses the `default` class loader factory, which uses the `current thread's context class loader` if not null or the class loader that loaded the library class.

  Returns:
    the class loader factory; never null
  See Also:
    `setClassLoaderFactory(ClassLoaderFactory)`

### getSequenceConfigs

    public List<ConfigType> getSequenceConfigs()

  Get the configurations for all Sequencers

  Returns:
    the class loader factory; never null
  See Also:
    `setClassLoaderFactory(ClassLoaderFactory)`

### setClassLoaderFactory

    public void setClassLoaderFactory(ClassLoaderFactory classLoaderFactory)

  Set the Maven Repository that should be used to load the component classes. Unless changed, the library uses the `default` class loader factory, which uses the `current thread's context class loader` if not null or the class loader that loaded the library class.

  Parameters:
    `classLoaderFactory` - the class loader factory reference, or null if the `default class loader factory` should be used
  See Also:
    `getClassLoaderFactory()`

### add

    public boolean add(ConfigType config)

  Add the configuration for a component, or update any existing one that represents the `same configuration`

  Parameters:
    `config` - the new configuration
  Returns:
    true if the component was added, or false if there already was an existing and `unchanged` component configuration
  Throws:
    `IllegalArgumentException` - if `config` is null
  See Also:
    `update(ComponentConfig)`, `remove(ComponentConfig)`

### getInstance

    public ComponentType getInstance(String name)

  Get the instance given by the configuration with the supplied name.

  Parameters:
    `name` - the configuration name
  Returns:
    the instance, or null if the configuration doesn't exist

### update

    public boolean update(ConfigType config)

  Update the configuration for a component, or add it if there is no `matching configuration` .

  Parameters:
    `config` - the updated (or new) configuration
  Returns:
    true if the component was updated, or false if there already was an existing and `unchanged` component configuration
  Throws:
    `IllegalArgumentException` - if `config` is null
  See Also:
    `add(ComponentConfig)`, `remove(ComponentConfig)`

### remove

    public boolean remove(ConfigType config)

  Remove the configuration for a component.

  Parameters:
    `config` - the configuration to be removed
  Returns:
    true if the component was remove, or false if there was no existing configuration
  Throws:
    `IllegalArgumentException` - if `config` is null
  See Also:
    `add(ComponentConfig)`, `update(ComponentConfig)`

### removeAll

    public boolean removeAll()

### removeAllAndAdd

    public boolean removeAllAndAdd(ConfigType config)

### refreshInstances

    public boolean refreshInstances()

  Refresh the instances by attempting to re-instantiate each registered configuration.

  Returns:
    true if at least one instance was instantiated, or false if none were

### getInstances

    public List<ComponentType> getInstances()

  Return the list of components.

  Returns:
    the unmodifiable list of components; never null

### newInstance

    protected ComponentType newInstance(ConfigType config)

  Instantiate, configure and return a new component described by the supplied configuration. This method does not manage the returned instance.

  Parameters:
    `config` - the configuration describing the component
  Returns:
    the new component, or null if the component could not be successfully configured
  Throws:
    `IllegalArgumentException` - if the component could not be configured properly

### configure

    protected void configure(ComponentType newInstance,
                             ConfigType configuration)
                      throws Exception

  Throws:
    `Exception`

### doCreateInstance

    protected ComponentType doCreateInstance(Class<?> componentClass)
                                      throws InstantiationException,
                                             IllegalAccessException

  Method that instantiates the supplied class. This method can be overridden by subclasses that may need to wrap or adapt the instance to be a ComponentType.

  Parameters:
    `componentClass` -
  Returns:
    the new ComponentType instance
  Throws:
    `InstantiationException`
    `IllegalAccessException`

### findIndexOfMatchingConfiguration

    protected int findIndexOfMatchingConfiguration(ConfigType config)

  Find the index for the matching `configuration` and `component`.

  Parameters:
    `config` - the configuration; may not be null
  Returns:
    the index, or -1 if not found

### findIndexOfMatchingConfiguration

    protected int findIndexOfMatchingConfiguration(String name)

  Find the index for the matching `configuration` and `component`.

  Parameters:
    `name` - the configuration name; may not be null
  Returns:
    the index, or -1 if not found

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.