net.sf.mmm.util.pojo.base
Class SimplePojoFactory

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.pojo.base.SimplePojoFactory
All Implemented Interfaces:
PojoFactory
Direct Known Subclasses:
DefaultPojoFactory

public class SimplePojoFactory
extends AbstractLoggableComponent
implements PojoFactory

This is the simplest implementation of the PojoFactory interface.
It uses Class.newInstance() to create new instances.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Constructor Summary
SimplePojoFactory()
           
 
Method Summary
<POJO> POJO
newInstance(Class<POJO> pojoType)
          This method creates a new instance of the given pojoType.
protected
<POJO> POJO
newInstanceForClass(Class<POJO> pojoType)
          Implementation of newInstance(Class) for regular class.
protected
<POJO> POJO
newInstanceForInterface(Class<POJO> pojoInterface)
          This method is invoked from newInstance(Class) if the given Class is an interface.
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
doInitialize, getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimplePojoFactory

public SimplePojoFactory()
Method Detail

newInstance

public <POJO> POJO newInstance(Class<POJO> pojoType)
                 throws InstantiationFailedException
This method creates a new instance of the given pojoType.
The simplest implementation may just delegate to Class.newInstance(). However implementations can solve arbitrary problems such as if the given pojoType has no non-arg constructor, or it is an interface or abstract class.

Specified by:
newInstance in interface PojoFactory
Type Parameters:
POJO - is the generic type of the Pojo to create.
Parameters:
pojoType - is the Class reflecting the Pojo to create.
Returns:
the new instance of the given pojoType.
Throws:
InstantiationFailedException - if the instantiation failed.

newInstanceForClass

protected <POJO> POJO newInstanceForClass(Class<POJO> pojoType)
                            throws InstantiationFailedException
Implementation of newInstance(Class) for regular class.

Type Parameters:
POJO - is the generic type of the Pojo to create.
Parameters:
pojoType - is the Class reflecting the Pojo to create.
Returns:
the new instance of the given pojoType.
Throws:
InstantiationFailedException - if the instantiation failed.

newInstanceForInterface

protected <POJO> POJO newInstanceForInterface(Class<POJO> pojoInterface)
                                throws InstantiationFailedException
This method is invoked from newInstance(Class) if the given Class is an interface.

Type Parameters:
POJO - is the generic type of the Pojo to create.
Parameters:
pojoInterface - is the interface reflecting the Pojo to create.
Returns:
the new instance of the given pojoType or null if no implementation could be found.
Throws:
InstantiationFailedException - if the instantiation failed.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.