com.xenonsoft.bridgetown.soa.impl
Class AbstractServiceAssembler

java.lang.Object
  extended bycom.xenonsoft.bridgetown.soa.impl.AbstractServiceAssembler
All Implemented Interfaces:
IDisposable, IServiceAssembler, IServiceObjectFactory, IStartable, java.io.Serializable
Direct Known Subclasses:
AOPAbstractServiceAssembler, ServiceAssemblerImpl

public abstract class AbstractServiceAssembler
extends java.lang.Object
implements IServiceAssembler, java.io.Serializable

Abstract service assembly class

Version:
$Id: AbstractServiceAssembler.java,v 1.10 2005/03/17 02:37:22 peter_pilgrim Exp $
Author:
Peter Pilgrim, Aug 3, 2004 12:19:11 PM
See Also:
Serialized Form

Field Summary
protected  AssemblyConfig assembly
          The root of the assembly configuration
protected  IBeanPropertyValueResolver beanPropertyValueResolver
          the property value resolver
protected  java.lang.ClassLoader classLoader
          The class loader for this assembly factory
protected  IContextCacheContainer instanceCache
          A special container for storing object instance in a context caches
protected  IProxyBeanBuilder proxyBeanBuilder
          the proxy bean builder
 
Constructor Summary
AbstractServiceAssembler()
          Default no-arguments constructor sets the class loader to the current thread context class loader.
 
Method Summary
protected  void checkFactory()
          Implements a basic check for the factory for subclassers
protected  void configureServiceBeanProperties(java.lang.Object serviceBean, ServiceConfig serviceConfig)
          Given a service bean and a service configuration, set the properties of the bean from the loaded configuration.
protected  void configureServiceBeanReferences(java.lang.Object serviceBean, ServiceConfig serviceConfig)
          Given a service bean and a service configuration, set the references of the bean from the loaded configuration.
 boolean containsContext(java.lang.String contextName)
          Implements / overrides containsContext
 boolean containsService(java.lang.String contextName, java.lang.String serviceName)
          Implements / overrides containsContext
protected  void createBeanBuilder()
          Creates the bean builder for the application assembler.
protected  java.lang.Object createRetrieveServiceBean(ServiceConfig serviceConfig, java.lang.Class interfaceClass)
          Refactored method to create either a prototype service bean or retrieve the a singleton service bean from the cache.
protected  java.lang.Object createServiceBean(ServiceConfig serviceConfig)
          Creates the service bean from the supplied service configuration
protected  java.lang.Object createServiceBean(ServiceConfig serviceConfig, java.lang.Class interfaceClass)
          Create the service bean from the supplied service configuration
protected  java.lang.Object createServiceBean(java.lang.String contextName, java.lang.Class interfaceClass)
          Returns the service implementation for a registered interface class name
 void dispose()
          Dispose the services registered with the assembly
protected  void fixupServiceBeanReferences(ServiceConfig serviceConfig)
          Given a service configuration, for all properties verify any associated references.
 AssemblyConfig getAssemblyConfig()
          Returns the assembly configuration
 IBeanPropertyValueResolver getBeanPropertyValueResolver()
          Gets the beanPropertyValueResolver
 java.lang.Class[] getClassListFromNameList(java.lang.String[] classNames, java.lang.String message)
          Given a primitive array of fully qualified class (and/or interface) names, create the corresponding Class array from the current class loader.
 java.lang.ClassLoader getClassLoader()
          Implements / overrides getClassLoader
 ContextConfig getContextConfig(java.lang.String contextName)
          A convenience method to retrieve the context configuration by name.
 java.lang.String[] getContextNameList()
          Implements / overrides getContextNameList
 IProxyBeanBuilder getProxyBeanBuilder()
          Gets the proxy bean builder
 ServiceConfig getServiceConfig(java.lang.String contextName, java.lang.String serviceId)
          A convenience method to retrieve the service configuration by identifier and context name.
 java.lang.String[] getServiceNameList(java.lang.String contextName)
          Implements / overrides getServiceNameList
 ServicesConfig getServicesConfig(java.lang.String contextName)
          A convenience method to retrieve the services configurations by context name.
protected  void invokeServiceBeanMethod(java.lang.Object serviceBean, ServiceConfig serviceConfig, MethodConfig methodConfig)
          Invoke the supplied service bean's specific method in order to perform Method Dependency Injection Internally this method uses the ConvertUtils and MethodUtils from Commons BeanUtils.
protected  void invokeServiceBeanMethods(java.lang.Object serviceBean, ServiceConfig serviceConfig)
          Invoke the all the methods registered with the supplied service bean in order to perform Method Dependency Injection Internally this method uses the ConvertUtils and MethodUtils from Commons BeanUtils.
 void load(IConfigLoader configLoader)
          Loads the configuration for this service assembly
 void merge(IConfigLoader configLoader, boolean override)
          Merge the supplied reference service assembly into the current existing configuration.
protected  java.lang.Object recursiveCreateServiceBean(ServiceConfig serviceConfig, java.lang.Class[] interfaceClassList)
          Creates the service bean from the supplied service configuration.
protected  java.lang.Object resolveValueReferences(int depth, ValueReferenceConfig valueRef, ServiceConfig serviceConfig, java.lang.String nodeText)
          Resolve references for a value reference.
 void setBeanPropertyValueResolver(IBeanPropertyValueResolver beanPropertyValueResolver)
          Sets the beanPropertyValueResolver
 void setClassLoader(java.lang.ClassLoader classLoader)
          Implements / overrides setClassLoader
 void setProxyBeanBuilder(IProxyBeanBuilder proxyBeanBuilder)
          Sets the proxy bean builder
 void start()
          Start the services registered with the assembly Here is the default wiring injection algorithm Phase 1 - Create the beans Phase 2 - Fix up the references to dependencies For all contexts (Property dependency injection) Phase 3 - Wire the references to dependencies For all contexts Phase 4 - Call the startable interface for each service, if it applies Phase 5 - Call the methods associated for each service, if it applies (Method dependency injection)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.xenonsoft.bridgetown.soa.IServiceObjectFactory
getName, getName, getService
 

Field Detail

assembly

protected AssemblyConfig assembly
The root of the assembly configuration


instanceCache

protected IContextCacheContainer instanceCache
A special container for storing object instance in a context caches


classLoader

protected transient java.lang.ClassLoader classLoader
The class loader for this assembly factory


proxyBeanBuilder

protected IProxyBeanBuilder proxyBeanBuilder
the proxy bean builder


beanPropertyValueResolver

protected IBeanPropertyValueResolver beanPropertyValueResolver
the property value resolver

Constructor Detail

AbstractServiceAssembler

public AbstractServiceAssembler()
Default no-arguments constructor sets the class loader to the current thread context class loader. If the thread context has no class loader, use the class loader that loaded this class.

Method Detail

createBeanBuilder

protected void createBeanBuilder()
Creates the bean builder for the application assembler. This method is designed to be called just once from the default constructor. Subclassers can override this method to create specialised bean builder instance for their purposes.


getClassLoader

public java.lang.ClassLoader getClassLoader()
Implements / overrides getClassLoader

Specified by:
getClassLoader in interface IServiceAssembler
Returns:
See Also:
IServiceAssembler.getClassLoader()

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Implements / overrides setClassLoader

Specified by:
setClassLoader in interface IServiceAssembler
Parameters:
classLoader -
See Also:
IServiceAssembler.setClassLoader(java.lang.ClassLoader)

getProxyBeanBuilder

public IProxyBeanBuilder getProxyBeanBuilder()
Gets the proxy bean builder

Returns:
Returns the proxyBeanBuilder.

setProxyBeanBuilder

public void setProxyBeanBuilder(IProxyBeanBuilder proxyBeanBuilder)
Sets the proxy bean builder

Parameters:
proxyBeanBuilder - the new value for proxyBeanBuilder

getBeanPropertyValueResolver

public IBeanPropertyValueResolver getBeanPropertyValueResolver()
Gets the beanPropertyValueResolver

Specified by:
getBeanPropertyValueResolver in interface IServiceAssembler
Returns:
Returns the beanPropertyValueResolver.

setBeanPropertyValueResolver

public void setBeanPropertyValueResolver(IBeanPropertyValueResolver beanPropertyValueResolver)
Sets the beanPropertyValueResolver

Specified by:
setBeanPropertyValueResolver in interface IServiceAssembler
Parameters:
beanPropertyValueResolver - The beanPropertyValueResolver to set.

load

public void load(IConfigLoader configLoader)
Loads the configuration for this service assembly

Specified by:
load in interface IServiceAssembler
Parameters:
configLoader - the configuration loader
Throws:
AssemblyConfigException - if the factory cannot read the assembly configuration
AssemblyFactoryException - if the factory cannot create the service assembly
See Also:
merge(IConfigLoader, boolean)

merge

public void merge(IConfigLoader configLoader,
                  boolean override)
Merge the supplied reference service assembly into the current existing configuration.

Here are the cases for a merge algorithm

  1. There is no current assembly service configuration. The behaviour is exactly the same as load( IConfigLoader )
  2. The reference context does NOT exist in the current service assembly. If the caller indicated s/he wants to override then therefore simply add the reference context to the current assembly.
  3. A service bean in the reference assembly does not exist in current assembly, so add the reference service to the current assembly.
  4. If the service bean in the reference assembly does does exist in the current assembly, and the caller has indicated s/he wants to the reference to override, then replace the current service definition with the reference definition.

Specified by:
merge in interface IServiceAssembler
Parameters:
configLoader - the configuration loader
override - true if the configuration context should override the existing configuration
Throws:
AssemblyConfigException - if the factory cannot read the assembly configuration
AssemblyFactoryException - if the factory cannot create the service assembly
See Also:
load(IConfigLoader)

start

public void start()
Start the services registered with the assembly

Here is the default wiring injection algorithm

  1. Phase 1 - Create the beans
  2. Phase 2 - Fix up the references to dependencies For all contexts (Property dependency injection)
  3. Phase 3 - Wire the references to dependencies For all contexts
  4. Phase 4 - Call the startable interface for each service, if it applies
  5. Phase 5 - Call the methods associated for each service, if it applies (Method dependency injection)

Specified by:
start in interface IStartable

dispose

public void dispose()
Dispose the services registered with the assembly

Specified by:
dispose in interface IDisposable

createRetrieveServiceBean

protected java.lang.Object createRetrieveServiceBean(ServiceConfig serviceConfig,
                                                     java.lang.Class interfaceClass)
Refactored method to create either a prototype service bean or retrieve the a singleton service bean from the cache.

Parameters:
serviceConfig - the service configuration
interfaceClass - the interface class (optional)
Returns:
the requested service bean
See Also:
IServiceObjectFactory.getName(String contextName, String beanName, Class interfaceClass ), contextName, Class interfaceClass )

createServiceBean

protected java.lang.Object createServiceBean(java.lang.String contextName,
                                             java.lang.Class interfaceClass)
Returns the service implementation for a registered interface class name

Parameters:
contextName - the context name
interfaceClass - the interface class name
Returns:
the actual registered implementation of the interface.
Throws:
AssemblyFactoryException - - if the service cannot be instantiated, if it reports an error, or cannot be syntactically created with violating class encapsulation, or simply has not been defined at all.

createServiceBean

protected java.lang.Object createServiceBean(ServiceConfig serviceConfig)
Creates the service bean from the supplied service configuration

Parameters:
serviceConfig - the configuration
Returns:
the service bean
Throws:
AssemblyFactoryException - - if the service cannot be instantiated
See Also:
createServiceBean( ServiceConfig serviceConfig, Class interfaceClass )

createServiceBean

protected java.lang.Object createServiceBean(ServiceConfig serviceConfig,
                                             java.lang.Class interfaceClass)
Create the service bean from the supplied service configuration

Parameters:
serviceConfig - the configuration
interfaceClass - the optional interface class that the service must implement
Returns:
the service bean
Throws:
AssemblyFactoryException - - if the service cannot be instantiated

recursiveCreateServiceBean

protected java.lang.Object recursiveCreateServiceBean(ServiceConfig serviceConfig,
                                                      java.lang.Class[] interfaceClassList)
Creates the service bean from the supplied service configuration. This method also optionally checks if the service bean class implements a list of interface classes. If the service bean class cannot be loaded then an exception is raised. If the service bean class does not either one or more of the interface classes, then the method raises an exception. If the array of interfaces classes is null no checking is done.

Parameters:
serviceConfig - the configuration
interfaceClassList - the optional array list of interface classes that the service must implement
Returns:
the service bean
Throws:
AssemblyFactoryException - - if the service cannot be instantiated

getClassListFromNameList

public java.lang.Class[] getClassListFromNameList(java.lang.String[] classNames,
                                                  java.lang.String message)
Given a primitive array of fully qualified class (and/or interface) names, create the corresponding Class array from the current class loader. In other words for an array class names load the classes (and/or interfaces) and return that array.

Parameters:
classNames - the array of class names
message - additionally message to add if a ClassNotFoundException occurs
Returns:
Class array or if the input class name array is null or empty then return null

configureServiceBeanProperties

protected void configureServiceBeanProperties(java.lang.Object serviceBean,
                                              ServiceConfig serviceConfig)
Given a service bean and a service configuration, set the properties of the bean from the loaded configuration.

Parameters:
serviceBean - the bean
serviceConfig - the configuration
Throws:
AssemblyFactoryException - - if the properties of the service cannot be configured correctly

fixupServiceBeanReferences

protected void fixupServiceBeanReferences(ServiceConfig serviceConfig)
Given a service configuration, for all properties verify any associated references.

Throws:
AssemblyFactoryException - - if the references of the service cannot be configured correctly

resolveValueReferences

protected java.lang.Object resolveValueReferences(int depth,
                                                  ValueReferenceConfig valueRef,
                                                  ServiceConfig serviceConfig,
                                                  java.lang.String nodeText)
Resolve references for a value reference. Given a value reference configuration object attempt to resolve it into a correct bean reference. The resolution algorithm is recursive. The method reads the service configuration and walks the references links until it find non-reference value. If the algorithm is successfully it will return a bean reference, otherwise it will raise an exception.

Parameters:
depth - the depth count
valueRef - the value reference that may have a value or a reference
serviceConfig - the service configuration
nodeText - the relevant information about the configuration point
Throws:
AssemblyFactoryException - - if the references of the service cannot be configured correctly
MaximumWireExceededException - - if the maximum recursive limit

configureServiceBeanReferences

protected void configureServiceBeanReferences(java.lang.Object serviceBean,
                                              ServiceConfig serviceConfig)
Given a service bean and a service configuration, set the references of the bean from the loaded configuration.

Parameters:
serviceBean - the bean
serviceConfig - the service configuration
Throws:
AssemblyFactoryException - - if the references of the service cannot be configured correctly

invokeServiceBeanMethods

protected void invokeServiceBeanMethods(java.lang.Object serviceBean,
                                        ServiceConfig serviceConfig)
Invoke the all the methods registered with the supplied service bean in order to perform Method Dependency Injection

Internally this method uses the ConvertUtils and MethodUtils from Commons BeanUtils.

Parameters:
serviceBean - the bean
serviceConfig - the configuration
Throws:
AssemblyFactoryException - - if the references of the service cannot be configured correctly
See Also:
invokeServiceBeanMethod(Object, ServiceConfig, MethodConfig)

invokeServiceBeanMethod

protected void invokeServiceBeanMethod(java.lang.Object serviceBean,
                                       ServiceConfig serviceConfig,
                                       MethodConfig methodConfig)
Invoke the supplied service bean's specific method in order to perform Method Dependency Injection

Internally this method uses the ConvertUtils and MethodUtils from Commons BeanUtils.

Parameters:
serviceBean - the bean
serviceConfig - the service configuration
methodConfig - the method configuration
Throws:
AssemblyFactoryException - - if the references of the service cannot be configured correctly

getAssemblyConfig

public AssemblyConfig getAssemblyConfig()
Returns the assembly configuration

Specified by:
getAssemblyConfig in interface IServiceAssembler
Returns:
the assembly configuration
See Also:
IServiceAssembler.getAssemblyConfig()

checkFactory

protected void checkFactory()
Implements a basic check for the factory for subclassers

Throws:
AssemblyFactoryException - if the factory is in an illegal state.

containsService

public boolean containsService(java.lang.String contextName,
                               java.lang.String serviceName)
Implements / overrides containsContext

Specified by:
containsService in interface IServiceObjectFactory
Parameters:
contextName -
serviceName -
Returns:
See Also:
com.xenonsoft.bridgetown.soa.IServiceAssembler#containsContext(java.lang.String, java.lang.String)

containsContext

public boolean containsContext(java.lang.String contextName)
Implements / overrides containsContext

Specified by:
containsContext in interface IServiceObjectFactory
Parameters:
contextName -
Returns:
See Also:
IServiceObjectFactory.containsContext(java.lang.String)

getContextNameList

public java.lang.String[] getContextNameList()
Implements / overrides getContextNameList

Specified by:
getContextNameList in interface IServiceObjectFactory
Returns:
See Also:
IServiceObjectFactory.getContextNameList()

getServiceNameList

public java.lang.String[] getServiceNameList(java.lang.String contextName)
Implements / overrides getServiceNameList

Specified by:
getServiceNameList in interface IServiceObjectFactory
Parameters:
contextName -
Returns:
See Also:
IServiceObjectFactory.getServiceNameList(java.lang.String)

getContextConfig

public ContextConfig getContextConfig(java.lang.String contextName)
A convenience method to retrieve the context configuration by name.

Parameters:
contextName - the context configuration
Returns:
the context configuration or null if the named context configuration can be found

getServiceConfig

public ServiceConfig getServiceConfig(java.lang.String contextName,
                                      java.lang.String serviceId)
A convenience method to retrieve the service configuration by identifier and context name.

Parameters:
contextName - the context configuration
serviceId - the service bean identifier
Returns:
the context configuration or null if the named service context element does not exist in the services context.
Throws:
UnknownContextException - if the context does not exist with the assembly.

getServicesConfig

public ServicesConfig getServicesConfig(java.lang.String contextName)
A convenience method to retrieve the services configurations by context name.

Parameters:
contextName - the context configuration
Returns:
the services context configuration
Throws:
UnknownContextException - if the context does not exist with the assembly.


Copyright © 2005 XeNoNSoFT.com. All Rights Reserved.