Marshalling API version 1.0.0.Beta2

org.jboss.marshalling.reflect
Class ReflectiveCreator

java.lang.Object
  extended by org.jboss.marshalling.reflect.ReflectiveCreator
All Implemented Interfaces:
Creator
Direct Known Subclasses:
SunReflectiveCreator

public class ReflectiveCreator
extends Object
implements Creator

A creator that simply uses reflection to locate and invoke a zero-argument constructor.


Constructor Summary
ReflectiveCreator()
           
 
Method Summary
<T> T
create(Class<T> clazz)
          Create an object instance.
protected
<T> Constructor<T>
getCachedConstructor(Class<T> clazz)
          Get a cached constructor for the class.
protected
<T> Constructor<T>
getNewConstructor(Class<T> clazz)
          Get the constructor to use for a class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectiveCreator

public ReflectiveCreator()
Method Detail

getNewConstructor

protected <T> Constructor<T> getNewConstructor(Class<T> clazz)
Get the constructor to use for a class. Returns null if no suitable constructor is available.

Parameters:
clazz - the class to get a constructor for
Returns:
the constructor, or null if none is available

getCachedConstructor

protected <T> Constructor<T> getCachedConstructor(Class<T> clazz)
                                       throws InstantiationException
Get a cached constructor for the class. If no such constructor is found in the cache, the getNewConstructor() method is invoked to get it. If no constructor is available then an InstantiationException is thrown.

Parameters:
clazz - the class to look up
Returns:
the cached constructor
Throws:
InstantiationException - if no suitable constructor is available

create

public <T> T create(Class<T> clazz)
         throws InstantiationException,
                IllegalAccessException
Create an object instance.

Specified by:
create in interface Creator
Parameters:
clazz - the type of object to create
Returns:
the object instance
Throws:
InstantiationException - if the object could not be instantiated
IllegalAccessException - if there was an access violation

Marshalling API version 1.0.0.Beta2

Copyright © 2008 JBoss, a division of Red Hat, Inc.