Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| SWIXML 1.5 (#144)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.swixml
Class DefaultFactory

    java.lang.Object
      org.swixml.DefaultFactory

All Implemented Interfaces:
  Factory

public final class DefaultFactory
extends Object
implements Factory

The `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

Version:
  $Revision: 1.1 $
Author:
  Wolf Paulus

Field Summary
`protected Class[]` | `parameterPriority` Priority to resolve method name clashes

Fields inherited from interface org.swixml.Factory
`ADDER_ID, SETTER_ID`

Constructor Summary
`DefaultFactory(Class template)` Creates a new Factory for the given `Class` template.

Method Summary
`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.

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

Field Detail

### parameterPriority

    protected Class[] parameterPriority

  Priority to resolve method name clashes

Constructor Detail

### DefaultFactory

    public DefaultFactory(Class template)

  Creates a new Factory for the given `Class` template.

Parameters:
  `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.

Method Detail

### priority

    protected int priority(Class type)

  Returns a priority ID of the given type based on a priority arrray

  Parameters:
    `type` - `Class`
  Returns:
    `int` parameter type priority

### registerSetters

    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

### newInstance

    public Object newInstance()
                       throws Exception

  Create a new component instance

  Specified by:
    `newInstance` in interface `Factory`
  Returns:
    instance `Object` a new instance of a template class
  Throws:
    `Exception`

### newInstance

    public Object newInstance(Object parameter)
                       throws Exception

  Creates a new Object which class is `getTemplate()`. A default costructior is only used if no constructor is available, accepting the provided parameter

  Specified by:
    `newInstance` in interface `Factory`
  Parameters:
    `parameter` - `Object`, parameter used during construction or initialization.
  Returns:
    instance `Object` a new instance of a template class
  Throws:
    `Exception`

### newInstance

    public Object newInstance(Object[] parameter)
                       throws InstantiationException,
                              IllegalAccessException,
                              InvocationTargetException

  Creates a new Object which class is `getTemplate()` and the constructor parameter are `parameter`.

  Specified by:
    `newInstance` in interface `Factory`
  Parameters:
    `parameter` - `Object[]` the parameter array to be passed into the constructor
  Returns:
    `Object - the created object, an instance of the template class`
  Throws:
    `InstantiationException` - if the creation of the object failed
    `IllegalAccessException` - if the constructor is either private or protected.
    `InvocationTargetException` - if the constructor invoked throws an exception idea suggested by Frank Meissner

### getTemplate

    public Class getTemplate()

  Specified by:
    `getTemplate` in interface `Factory`
  Returns:
    class - `Class` the backing class template

### getSetters

    public Collection getSetters()

  Specified by:
    `getSetters` in interface `Factory`
  Returns:
    `Collection` containing all available setter methods

### getSetter

    public Method getSetter(Class template)

  Returns a Setter Method that accepts the given class as a parameter

  Specified by:
    `getSetter` in interface `Factory`
  Parameters:
    `template` - `Class`
  Returns:
    `Method` - setter that accepts the given class as a parameter
  See Also:
    `Factory.getSetter(java.lang.Class)`

### getSetter

    public Method getSetter(String name)

  Returns a setter method by name

  Specified by:
    `getSetter` in interface `Factory`
  Parameters:
    `name` - `String` name of the setter method
  Returns:
    `Method` - setter method which can be invoked on an object of the template class
  See Also:
    `guessSetter(java.lang.String)`, `

        Typical Use:
         Method method = factory.getSetter("set" + Parser.capitalize(attr.getName()));

    `

### guessSetter

    public Method guessSetter(String name)

  Returns a setter method by a Attribute name. Differently to the `getSetter` method, here the attibute name can be used directly and case doesn't matter.

  Specified by:
    `guessSetter` in interface `Factory`
  Parameters:
    `name` - `String` name of the setter method
  Returns:
    `Method` - setter method which can invoked on an object of the template class
  See Also:
    `

        Typical Use:
              Method method = factory.getSetter( attr.getName() );

    `

### removeSetter

    public void removeSetter(Method method)

  Remove the given method form the collection of supported setters.

  Parameters:
    `method` - `Method`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| SWIXML 1.5 (#144)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002 - 2005 - Wolf Paulus - CarlsbadCubes.com . All rights reserved.