Package org.coliper.ibean
Interface IBeanFactory
-
- All Known Implementing Classes:
ProxyIBeanFactory
public interface IBeanFactoryCreates IBean instances for given bean interfaces.
For example:
IBeanFactory factory = ...; SomeBeanType bean = factory.create(SomeBeanType.class);IBeanFactorys are the heart and the core of the IBean framework. They are responsible for creating instances for provided IBean compliant interfaces with their desired behavior. IBean interfaces consist of setter and getter methods and super-interfaces.
Following code shows an example of a bean interface:
public interface Person { void setFirstname(String s); String getFirstname(); void setDateOfBirth(Date d); Date getDateOfBirth(); }
AnIBeanFactoryof course cannot create a bean instance from every kind of interface. An interface that can be handled by a factory needs to follow these criteria:- Every method declared in the interface must either be
- a getter or setter method,
- a default method (interface method with a given default implementation) or
- a method belonging to an extension interface.
- Always a tuple of a setter and a getter method virtually defines an interface field. (firstname and dateOfBirth would be the fields of the example above.) That means for each setter a getter must exist as well and vice versa.
- An
IBeanFactoryalways looks on the complete list of methods including those from super interfaces. The factory does not care in which hierarchy level a method is declared. That means for example that you can declare getter and setter methods in different parent or sub interfaces as long as they are complete in the final interface that is provided to thecreate(Class)method. - Default methods are ignored by the
IBeanFactory. You must therefore not have default implementations for getter or setter methods. - Whether an interface method is a getter or setter method and whether a method pair builds
up a valid setter-getter combination is defined by the so called
bean style. All built in bean styles for example require a consistent type to be used
in both methods to unambiguously define the field type. If a setter for example has
a primitive
booleanparameter, the getter should return the same type, not evenBooleanwould be accepted instead. SeeBeanStylefor more information. - A method can also belong to a so called extension interface. Extension interfaces
are a group of interfaces that are well known by the
IBeanFactory. These interfaces are declared as super interfaces of the bean interface and add certain functionality to the beans. TheIBeanFactorysimply ignores all methods from these extension super interfaces. Seeorg.coliper.ibean.extensionpackage for more details about extension interfaces.
InvalidIBeanTypeExceptionwill be thrown.See IBean tutorial for a more holistic view on IBean.
At the moment there is only one
IBeanFactoryimplementation which isProxyIBeanFactory.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Tcreate(Class<T> beanType)Creates a new instance of a given bean type.
-
-
-
Method Detail
-
create
<T> T create(Class<T> beanType) throws InvalidIBeanTypeException
Creates a new instance of a given bean type.- Type Parameters:
T- generic typeTis the bean class provided with parameterbeanType- Parameters:
beanType- a IBean that matches general IBean rules and that complies to the specific requirements for this factory like bean styles or supported extension interfaces- Returns:
- an instance of the bean type, never
null. The returned beans will usually have default values set for all field values, likenullfor objects or zero for number primitives. - Throws:
InvalidIBeanTypeException- if the givenbeanTypeis not a valid IBean interface for this factory
-
-