public final class DefaultFactory extends Object implements Factory
DefaultFactory is a default implementation of the Factory Interface.
The DefaultFactory registers all setter methods that take a single producable paramter with a class template
| Modifier and Type | Field and Description |
|---|---|
protected Class[] |
parameterPriority
Priority to resolve method name clashes
|
| Constructor and Description |
|---|
DefaultFactory(Class template)
Creates a new Factory for the given
Class template. |
| Modifier and Type | Method and Description |
|---|---|
Method |
getSetter(Class template)
Returns a Setter Method that accepts the given class as a parameter
|
Method |
getSetter(String name)
Returns a setter method by name
|
Collection |
getSetters() |
Class |
getTemplate() |
Method |
guessSetter(String name)
Returns a setter method by a Attribute name.
|
Object |
newInstance()
Create a new component instance
|
Object |
newInstance(Object parameter)
Creates a new Object which class is
getTemplate(). |
Object |
newInstance(Object[] parameter)
Creates a new Object which class is
getTemplate() and the constructor
parameter are parameter. |
protected int |
priority(Class type)
Returns a priority ID of the given type based on a priority arrray
|
protected void |
registerSetters()
Registers all available setter methods meeting these rules:
Method name needs to start with set
Method signature specifies exactly one parameter
if methods have the same name then super class methods are ignored
if methods have the same name and are implemented in the same class,
then only the method which parameter type has the highest priority is registered
|
void |
removeSetter(Method method)
Remove the given method form the collection of supported setters.
|
protected Class[] parameterPriority
public DefaultFactory(Class template)
Class template.template - Class
Note:
Only setMethods that take a single parameter are considered.
Moreover, to be regsitered, a Converter needs to be available in the ConverterLibrary that can create
instances of the paramter type.
protected int priority(Class type)
type - Classint parameter type priorityprotected void registerSetters()
public Object newInstance() throws Exception
newInstance in interface FactoryObject a new instance of a template classExceptionpublic Object newInstance(Object parameter) throws Exception
getTemplate().
A default costructior is only used if no constructor is available,
accepting the provided parameternewInstance in interface Factoryparameter - Object, parameter used during construction or initialization.Object a new instance of a template classExceptionpublic Object newInstance(Object[] parameter) throws InstantiationException, IllegalAccessException, InvocationTargetException
getTemplate() and the constructor
parameter are parameter.newInstance in interface Factoryparameter - Object[] the parameter array to be passed into the constructorObject - the created object, an instance of the template classInstantiationException - if the creation of the object failedIllegalAccessException - if the constructor is either private or protected.InvocationTargetException - if the constructor invoked throws an exception
idea suggested by Frank Meissner public Class getTemplate()
getTemplate in interface FactoryClass the backing class templatepublic Collection getSetters()
getSetters in interface FactoryCollection containing all available setter methodspublic Method getSetter(Class template)
getSetter in interface Factorytemplate - ClassMethod - setter that accepts the given class as a parameterFactory.getSetter(java.lang.Class)public Method getSetter(String name)
getSetter in interface Factoryname - String name of the setter methodMethod - setter method which can be invoked on an object of the template classguessSetter(java.lang.String),
Typical Use:
Method method = factory.getSetter("set" + Parser.capitalize(attr.getName()));
public Method guessSetter(String name)
getSetter method, here the attibute
name can be used directly and case doesn't matter.guessSetter in interface Factoryname - String name of the setter methodMethod - setter method which can invoked on an object of the template classTypical Use:
Method method = factory.getSetter( attr.getName() );
public void removeSetter(Method method)
method - MethodCopyright © 2002 - 2013 - Wolf Paulus - wolfpaulus.com. All rights reserved.