org.sape.carbon.core.component.factory
Class DefaultComponentFactory

java.lang.Object
  |
  +--org.sape.carbon.core.component.factory.DefaultComponentFactory
All Implemented Interfaces:
ComponentFactory

public class DefaultComponentFactory
extends Object
implements ComponentFactory

This implementation of ComponentFactory constructs the component by assembling the component's functional implementation with various ComponentAssistants defined by the factory's configuration. This implementation uses a DynamicProxy as the glue to hold these pieces together.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.46 $($Author: dvoet $ / $Date: 2003/10/27 19:53:00 $)
Author:
Douglas Voet, January 2002

Nested Class Summary
protected static class DefaultComponentFactory.MethodWrapper
          This class provides a wrapper for tracking methods on the component facade, purely through their signature (name and parameters, but not declaring class).
 
Field Summary
private  org.apache.commons.logging.Log log
          The handle to Apache-commons logger.
 
Constructor Summary
DefaultComponentFactory()
           
 
Method Summary
private  Component assembleComponent(ComponentConfiguration componentConfiguration)
          This method does the actual work of constructing a component.
private  Decorator buildDecorator(DecoratorConfiguration decoratorConfiguration, FunctionalInterface functionalImplementation, ComponentConfiguration componentConfiguration, ComponentProxyInvocationHandler proxyInvocationHandler)
          Factory method for component assistants.
private  FunctionalInterface buildFunctionalImplementation(ComponentConfiguration componentConfiguration)
          Factory method for the components functional implementation.
private  ComponentProxyInvocationHandler buildProxyInvocationHandler(ComponentTemplateConfiguration componentTemplateConfiguration)
          Factory method for the component proxy invocation handler.
private  void checkAllMethodNames(Set interfaces, String componentName)
           Checks if duplicate methods are defined in interfaces.
private  ComponentConfiguration getComponentConfig(String logicalComponentName)
          Gets the configuration of the component specified by the name.
private  ComponentTemplateConfiguration getComponentTemplateConfiguration(ComponentConfiguration componentConfiguration)
          Gets the ComponentTemplateConfiguration for this component.
 Component getInstance(String logicalComponentName)
          Builds the component specified by the name parameter.
private  void initializeComponent(Component component)
          Calls lifecycle methods to initialize the component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
The handle to Apache-commons logger.

Constructor Detail

DefaultComponentFactory

public DefaultComponentFactory()
Method Detail

getInstance

public Component getInstance(String logicalComponentName)

Builds the component specified by the name parameter.

Specified by:
getInstance in interface ComponentFactory
Parameters:
logicalComponentName - the component to build
Returns:
the Component referred to by the name parameter in the LifecycleStateEnum.STOPPED state

getComponentConfig

private ComponentConfiguration getComponentConfig(String logicalComponentName)

Gets the configuration of the component specified by the name.

Parameters:
logicalComponentName - the path to the requested logical component
Returns:
the component's configuration

assembleComponent

private Component assembleComponent(ComponentConfiguration componentConfiguration)

This method does the actual work of constructing a component. It performs the following steps:

  1. instantiates the component's functional implementation
  2. builds all component assistants
  3. instantiates the invocation handler for the component
  4. constructs the component proxy
The component will be in the LifecycleStateEnum.CREATED state when this method is complete.

Parameters:
componentConfiguration - the configuration object for the component being created
Returns:
the component in the LifecycleStateEnum.CREATED state

initializeComponent

private void initializeComponent(Component component)

Calls lifecycle methods to initialize the component. Component should be in LifecycleStateEnum.STOPPED state when complete.

Parameters:
component - the component to be initialized

buildFunctionalImplementation

private FunctionalInterface buildFunctionalImplementation(ComponentConfiguration componentConfiguration)

Factory method for the components functional implementation.

Parameters:
componentConfiguration - the configuration object for the component being created
Returns:
an instance of the component's functional implementation class

buildProxyInvocationHandler

private ComponentProxyInvocationHandler buildProxyInvocationHandler(ComponentTemplateConfiguration componentTemplateConfiguration)

Factory method for the component proxy invocation handler.

Parameters:
componentTemplateConfiguration - the component template configuration that defines the construction of the requested component
Returns:
ComponentProxyInvocationHandler that is the invocation handler for the requested component

buildDecorator

private Decorator buildDecorator(DecoratorConfiguration decoratorConfiguration,
                                 FunctionalInterface functionalImplementation,
                                 ComponentConfiguration componentConfiguration,
                                 ComponentProxyInvocationHandler proxyInvocationHandler)

Factory method for component assistants.

Parameters:
proxyInvocationHandler - the invocation handler of the component being built
decoratorConfiguration - the configuration object containing the name and DecoratorFactory class object for the decortator
functionalImplementation - the component's functional implementation object
componentConfiguration - the component's configuration
Returns:
the interceptor specifed in decoratorConfiguration

getComponentTemplateConfiguration

private ComponentTemplateConfiguration getComponentTemplateConfiguration(ComponentConfiguration componentConfiguration)

Gets the ComponentTemplateConfiguration for this component.

This implementation is hardcoded to always look in one spot in Config ("/core/component/componentTemplate") for the template.

Parameters:
componentConfiguration - this parameter is not used in this implementation. If ComponentConfiguration is modified to have a getComponentTemplateConfiguration method, this method can be modified to use the componet specific component template.
Returns:
ComponentTemplateConfiguration for the component

checkAllMethodNames

private void checkAllMethodNames(Set interfaces,
                                 String componentName)

Checks if duplicate methods are defined in interfaces. If they are then this method logs a warning in the log file about the duplicate

Parameters:
interfaces - various interfaces being implemented
componentName - name of the component


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.