FileDocCategorySizeDatePackage
PojoInstantiator.javaAPI DocHibernate 3.2.53494Fri Feb 03 15:15:20 GMT 2006org.hibernate.tuple

PojoInstantiator

public class PojoInstantiator extends Object implements Serializable, Instantiator
Defines a POJO-based instantiator for use from the tuplizers.

Fields Summary
private static final Log
log
private transient Constructor
constructor
private final Class
mappedClass
private final transient ReflectionOptimizer.InstantiationOptimizer
optimizer
private final boolean
embeddedIdentifier
private final Class
proxyInterface
Constructors Summary
public PojoInstantiator(org.hibernate.mapping.Component component, ReflectionOptimizer.InstantiationOptimizer optimizer)


	     
		this.mappedClass = component.getComponentClass();
		this.optimizer = optimizer;

		this.proxyInterface = null;
		this.embeddedIdentifier = false;

		try {
			constructor = ReflectHelper.getDefaultConstructor(mappedClass);
		}
		catch ( PropertyNotFoundException pnfe ) {
			log.info(
			        "no default (no-argument) constructor for class: " +
					mappedClass.getName() +
					" (class must be instantiated by Interceptor)"
			);
			constructor = null;
		}
	
public PojoInstantiator(org.hibernate.mapping.PersistentClass persistentClass, ReflectionOptimizer.InstantiationOptimizer optimizer)

		this.mappedClass = persistentClass.getMappedClass();
		this.proxyInterface = persistentClass.getProxyInterface();
		this.embeddedIdentifier = persistentClass.hasEmbeddedIdentifier();
		this.optimizer = optimizer;

		try {
			constructor = ReflectHelper.getDefaultConstructor( mappedClass );
		}
		catch ( PropertyNotFoundException pnfe ) {
			log.info(
			        "no default (no-argument) constructor for class: " +
					mappedClass.getName() +
					" (class must be instantiated by Interceptor)"
			);
			constructor = null;
		}
	
Methods Summary
public java.lang.Objectinstantiate()

		if ( ReflectHelper.isAbstractClass(mappedClass) ) {
			throw new InstantiationException( "Cannot instantiate abstract class or interface: ", mappedClass );
		}
		else if ( optimizer != null ) {
			return optimizer.newInstance();
		}
		else if ( constructor == null ) {
			throw new InstantiationException( "No default constructor for entity: ", mappedClass );
		}
		else {
			try {
				return constructor.newInstance( null );
			}
			catch ( Exception e ) {
				throw new InstantiationException( "Could not instantiate entity: ", mappedClass, e );
			}
		}
	
public java.lang.Objectinstantiate(java.io.Serializable id)

		final boolean useEmbeddedIdentifierInstanceAsEntity = embeddedIdentifier && 
				id != null && 
				id.getClass().equals(mappedClass);
		return useEmbeddedIdentifierInstanceAsEntity ? id : instantiate();
	
public booleanisInstance(java.lang.Object object)

		return mappedClass.isInstance(object) || 
				( proxyInterface!=null && proxyInterface.isInstance(object) ); //this one needed only for guessEntityMode()
	
private voidreadObject(java.io.ObjectInputStream stream)

		stream.defaultReadObject();
		constructor = ReflectHelper.getDefaultConstructor(mappedClass);