com.sourceforge.jpatterns.patterns.factory
Class JPFactoryImpl

java.lang.Object
  extended by com.sourceforge.jpatterns.patterns.PatternBase
      extended by com.sourceforge.jpatterns.patterns.factory.JPFactoryImpl
All Implemented Interfaces:
IJPFactory, IJPattern, com.zmicer.utils.model.ICheckable, Serializable

public class JPFactoryImpl
extends PatternBase
implements IJPFactory

The default implementation of the IJPFactory interface.

todo [zmicer]: increase the coverage later - almost all the cases are checked still we need to finish covering all the protected methods. todo [zmicer]: adjust logAndThrow method - actually we are able to detrmine where to thrown Consumer of Framework config exception. $Author:: zmicer $
$Rev:: 67 $
* $Date:: 2007-08-28 21:37:07 #$

See Also:
Serialized Form

Field Summary
static org.apache.log4j.Logger LOG
          Logger instance.
 
Fields inherited from class com.sourceforge.jpatterns.patterns.PatternBase
m_castorSection, m_configBean
 
Constructor Summary
JPFactoryImpl()
           
 
Method Summary
 boolean check()
           
 boolean checkCastorConfig(com.sourceforge.jpatterns.schema.CastorSectionType castorSectionType)
          Make the check this type of the castor config fits the pattern
 Object getImplementation(Class interfaceClass, String scope)
          Get implementation of the interface defined by the given class and the scope we need to obtain.
 Object getImplementation(Class interfaceClass, String implType, String scope)
          Get implementation of the interface defined by the given class and the scope we need to obtain.
 Object getImplementation(String interfaceClassBaseName, String scope)
          Get implementation of the interface defined by the given class (class of the interface).
 Object getImplementation(String interfaceClassBaseName, String implType, String scope)
          Get implementation of the interface defined by the given class (class of the interface).
 String getImplementationFullName(Class interfaceClass, String scope)
          Get the full name of the implementation of the interface defined by the given class and the scope we need to obtain.
 String getImplementationFullName(String interfaceClassBaseName, String scope)
          Get the full name of the implementation of the interface defined by the given class (class of the interface).
 Map<String,Object> getImplementations(Class interfaceClass, String scope)
          Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
 Map<String,Object> getImplementations(String interfaceClassBaseName, String scope)
          Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
 Map<String,String> getImplementationsFullNames(Class interfaceClass, String scope)
          Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
 Map<String,String> getImplementationsFullNames(String interfaceClassBaseName, String scope)
          Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
protected  Map<String,String> getImplementationsNamesByItem(com.sourceforge.jpatterns.schema.Item item)
          Instantiate the Object using the provided item
 Object getOperator(Class productBaseClass, Class operatorBaseClass, Object productObj, String scope)
          The the operator for the provided object and scope.
 Map<Object,Object> getOperators(Class productBaseClass, Class operatorBaseClass, List<Object> productObjs, String scope)
          Get the mappings between the operators (which would be created at this methods) and the List of the products objects provided here.
protected  com.sourceforge.jpatterns.schema.Param getParam(com.sourceforge.jpatterns.schema.Item item, String key)
          Get Param castor object by the key.
protected  Object instantiateObjectByItem(com.sourceforge.jpatterns.schema.Item item, Class claz)
          Instantiate the Object using the provided item.
protected  Object instantiateObjectByItemAndType(com.sourceforge.jpatterns.schema.Item item, String type, Class claz)
          Instantiate the Object using the provided item and the type we need
protected  Map<String,Object> validateImplementationsMap(Class clazz, Map<String,Object> map)
          Check that all the implementations of the map - are the types of the provided class.
 
Methods inherited from class com.sourceforge.jpatterns.patterns.PatternBase
getActualScope, init, logAndThrow, retrieveItem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sourceforge.jpatterns.patterns.IJPattern
init
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG
Logger instance.

Constructor Detail

JPFactoryImpl

public JPFactoryImpl()
Method Detail

checkCastorConfig

public boolean checkCastorConfig(com.sourceforge.jpatterns.schema.CastorSectionType castorSectionType)
Description copied from interface: IJPattern
Make the check this type of the castor config fits the pattern

Specified by:
checkCastorConfig in interface IJPattern
Specified by:
checkCastorConfig in class PatternBase
Parameters:
castorSectionType - the castor config object which is the root configuration storage for all the patterns (according to the XSD scheme)
Returns:
true if this fits to the pattern implementation nature, and false otherwise
See Also:
IJPattern.checkCastorConfig(com.sourceforge.jpatterns.schema.CastorSectionType)

getImplementation

public Object getImplementation(Class interfaceClass,
                                String scope)
Description copied from interface: IJPFactory
Get implementation of the interface defined by the given class and the scope we need to obtain.
Be noticed the validation if the implementation specified at the JPatterns config file is casted to the interface provided.

Specified by:
getImplementation in interface IJPFactory
Parameters:
interfaceClass - the class representing the interface Can not be null (otherwise IllegalArgumentException would appear).
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementation(java.lang.Class,java.lang.String)

getImplementation

public Object getImplementation(String interfaceClassBaseName,
                                String scope)
Description copied from interface: IJPFactory
Get implementation of the interface defined by the given class (class of the interface).
Validation if the implementation is casted to the interface defining by interfaceClassBaseName is not done here as this String could be just any key string

Specified by:
getImplementation in interface IJPFactory
Parameters:
interfaceClassBaseName - the base name of the interface (e.g. IJPFactory), also it could be just String key (just logical case for which we need to obtain smth.)
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementation(java.lang.Class,java.lang.String)

getImplementationFullName

public String getImplementationFullName(Class interfaceClass,
                                        String scope)
Description copied from interface: IJPFactory
Get the full name of the implementation of the interface defined by the given class and the scope we need to obtain.

Specified by:
getImplementationFullName in interface IJPFactory
Parameters:
interfaceClass - the class representing the interface Can not be null (otherwise IllegalArgumentException would appear).
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementationFullName(Class,String)

getImplementationFullName

public String getImplementationFullName(String interfaceClassBaseName,
                                        String scope)
Description copied from interface: IJPFactory
Get the full name of the implementation of the interface defined by the given class (class of the interface).

Specified by:
getImplementationFullName in interface IJPFactory
Parameters:
interfaceClassBaseName - the base name of the interface (e.g. IJPFactory)
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementationFullName(String,String)

getImplementation

public Object getImplementation(Class interfaceClass,
                                String implType,
                                String scope)
Description copied from interface: IJPFactory
Get implementation of the interface defined by the given class and the scope we need to obtain.
note [zmicer]: be noticed that validation if the given interface is the super type of the implementation is performed in this method

Specified by:
getImplementation in interface IJPFactory
Parameters:
interfaceClass - the class representing the interface Can not be null (otherwise IllegalArgumentException would appear).
implType - the type of implementation
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementation(java.lang.Class,java.lang.String,java.lang.String)

getImplementation

public Object getImplementation(String interfaceClassBaseName,
                                String implType,
                                String scope)
Description copied from interface: IJPFactory
Get implementation of the interface defined by the given class (class of the interface).
note [zmicer]: be noticed that validation if the given interface is the super type of the implementation is not performed in this method

Specified by:
getImplementation in interface IJPFactory
Parameters:
interfaceClassBaseName - the base name of the interface (e.g. IJPFactory)
implType - the type of implementation
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementation(java.lang.String,java.lang.String,java.lang.String)

getImplementations

public Map<String,Object> getImplementations(Class interfaceClass,
                                             String scope)
Description copied from interface: IJPFactory
Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
The format is as follows: #key: logical type we need #value: the Object - the concrete implementation of the interface provided corresponding to the logical type

Specified by:
getImplementations in interface IJPFactory
Parameters:
interfaceClass - the class representing the interface Can not be null (otherwise IllegalArgumentException would appear).
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementations(Class,String)

getImplementations

public Map<String,Object> getImplementations(String interfaceClassBaseName,
                                             String scope)
Description copied from interface: IJPFactory
Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
The format is as follows: #key: logical type we need #value: the Object - the concrete implementation of the interface provided corresponding to the logical type

Specified by:
getImplementations in interface IJPFactory
Parameters:
interfaceClassBaseName - the base name of the interface (e.g. IJPFactory)
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementations(String,String)

getImplementationsFullNames

public Map<String,String> getImplementationsFullNames(Class interfaceClass,
                                                      String scope)
Description copied from interface: IJPFactory
Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
The format is as follows: #key: logical type we need #value: the full name of the concrete implementation of the interface provided corresponding to the logical type

Specified by:
getImplementationsFullNames in interface IJPFactory
Parameters:
interfaceClass - the class representing the interface Can not be null (otherwise IllegalArgumentException would appear).
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementationsFullNames(Class,String)

getImplementationsFullNames

public Map<String,String> getImplementationsFullNames(String interfaceClassBaseName,
                                                      String scope)
Description copied from interface: IJPFactory
Get the Map of implementations of the interface defined by the given class and the scope we need to obtain.
The format is as follows: #key: logical type we need #value: the full name of the concrete implementation of the interface provided corresponding to the logical type

Specified by:
getImplementationsFullNames in interface IJPFactory
Parameters:
interfaceClassBaseName - the base name of the interface (e.g. IJPFactory)
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the Object = the real implementation of the class.
See Also:
IJPFactory.getImplementationsFullNames(String,String)

getOperator

public Object getOperator(Class productBaseClass,
                          Class operatorBaseClass,
                          Object productObj,
                          String scope)
Description copied from interface: IJPFactory
The the operator for the provided object and scope. This method would determine the base interface of the product (we would consider the implementation class implements the appropriate interface at once).
The key we would find to obtained the appropriate castor config item would be: %base name of productBaseClass% + "_" + %base name of operatorBaseClass%

Specified by:
getOperator in interface IJPFactory
Parameters:
productBaseClass - the interface or base class of the product for which we are finding the implementation of the operator. Still the actual class of the product provided would be used too. Can not be null (otherwise IllegalArgumentException would appear).
operatorBaseClass - the interface of the base class of the operator we would need to obtain the appropriate configuration item. Be noticed this base class defines the scope we need to consider to obtain the necessary operator Can not be null (otherwise IllegalArgumentException would appear).
productObj - the product for which we need the implementation. This product should of the productBaseClass class Can not be null (otherwise IllegalArgumentException would appear).
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the instance of the operator to be used for the given product.
See Also:
IJPFactory.getOperator(Class,Class,Object, String)

getOperators

public Map<Object,Object> getOperators(Class productBaseClass,
                                       Class operatorBaseClass,
                                       List<Object> productObjs,
                                       String scope)
Description copied from interface: IJPFactory
Get the mappings between the operators (which would be created at this methods) and the List of the products objects provided here. Also the classes for the products and operators are provided as the base path to the necessary Jpatterns configuration. note [zmicer]: In the case there are some different products instances with identical class only one operator would be created.

Specified by:
getOperators in interface IJPFactory
Parameters:
productBaseClass - the interface or base class of the product for which we are finding the implementation of the operator. Still the actual class of the product provided would be used too. Can not be null (otherwise IllegalArgumentException would appear).
operatorBaseClass - the interface of the base class of the operator we would need to obtain the appropriate configuration item. Be noticed this base class defines the scope we need to consider to obtain the necessary operator Can not be null (otherwise IllegalArgumentException would appear).
productObjs - the List of the products for which we need to obtain the appropriate operators. These products should of the productBaseClass class. Can not be null (otherwise IllegalArgumentException would appear).
scope - the scope where do we need to find the implementation. In the case this is null - the default value for scope would be used (would be taken from factory object)
Returns:
the mapping between the products objects (all of them were provided as the members of the productObjs list) and the appropriate operators.
See Also:
IJPFactory.getOperators(Class,Class,java.util.List, String)

check

public boolean check()
Specified by:
check in interface com.zmicer.utils.model.ICheckable
Overrides:
check in class PatternBase
See Also:
ICheckable.check()

getParam

protected com.sourceforge.jpatterns.schema.Param getParam(com.sourceforge.jpatterns.schema.Item item,
                                                          String key)
Get Param castor object by the key.

Parameters:
item - the castor Item. Can not be null (otherwise IllegalArgumentException would appear).
key - The String key object for which we need to obtain the param.
Returns:
the Param Object

instantiateObjectByItem

protected Object instantiateObjectByItem(com.sourceforge.jpatterns.schema.Item item,
                                         Class claz)
                                  throws JPConfigException
Instantiate the Object using the provided item. The provided class object (if it is not null) is used for validating the correct implementation is specified.

Parameters:
item - the Item from value attribute of which we would instantiate the object
claz - the Class instance to check that implementation correlates with the interface for which we obtain this. Could be null.
Returns:
the instantiated Object.
Throws:
JPConfigException - in the case we can not instantiate the object using the value of the provided item

instantiateObjectByItemAndType

protected Object instantiateObjectByItemAndType(com.sourceforge.jpatterns.schema.Item item,
                                                String type,
                                                Class claz)
                                         throws JPConfigException
Instantiate the Object using the provided item and the type we need

Parameters:
item - the Item from value attribute of which we would instantiate the object Can not be null (otherwise IllegalArgumentException would appear).
type - the type for which we need instantiate the object Can not be null (otherwise IllegalArgumentException would appear).
claz - this is necessary to perform the validation that the correct implementation is defined at the configuration file.
Returns:
the instantiated Object.
Throws:
JPConfigException - in the case we can not instantiate the object using the value of the provided item

getImplementationsNamesByItem

protected Map<String,String> getImplementationsNamesByItem(com.sourceforge.jpatterns.schema.Item item)
                                                    throws JPConfigException
Instantiate the Object using the provided item

Parameters:
item - the Item from value attribute of which we would instantiate the object
Returns:
the Map where #key is a types of implementation, and the #value is a full name of the implementation. In the case the castor item do not contains the mapping the empty map is returned.
Throws:
JPConfigException - in the case we can not instantiate the object using the value of the provided item

validateImplementationsMap

protected Map<String,Object> validateImplementationsMap(Class clazz,
                                                        Map<String,Object> map)
Check that all the implementations of the map - are the types of the provided class.

Parameters:
clazz - The class against which we would check the map, Can not be null (otherwise IllegalArgumentException would appear).
map - containing the implementation we need to check
Returns:
the map with the implementation without any changes - just pass through method making the check


Copyright © 2007 jzmicer.team. All Rights Reserved.