FileDocCategorySizeDatePackage
MyEntityInstantiator.javaAPI DocHibernate 3.2.52166Tue Dec 06 14:23:38 GMT 2005org.hibernate.test.dynamicentity.tuplizer

MyEntityInstantiator

public class MyEntityInstantiator extends Object implements org.hibernate.tuple.Instantiator
author
Steve Ebersole

Fields Summary
private final String
entityName
Constructors Summary
public MyEntityInstantiator(String entityName)

		this.entityName = entityName;
	
Methods Summary
public java.lang.Objectinstantiate(java.io.Serializable id)

		if ( Person.class.getName().equals( entityName ) ) {
			return ProxyHelper.newPersonProxy( id );
		}
		if ( Customer.class.getName().equals( entityName ) ) {
			return ProxyHelper.newCustomerProxy( id );
		}
		else if ( Company.class.getName().equals( entityName ) ) {
			return ProxyHelper.newCompanyProxy( id );
		}
		else if ( Address.class.getName().equals( entityName ) ) {
			return ProxyHelper.newAddressProxy( id );
		}
		else {
			throw new IllegalArgumentException( "unknown entity for instantiation [" + entityName + "]" );
		}
	
public java.lang.Objectinstantiate()

		return instantiate( null );
	
public booleanisInstance(java.lang.Object object)

		String resolvedEntityName = null;
		if ( Proxy.isProxyClass( object.getClass() ) ) {
			InvocationHandler handler = Proxy.getInvocationHandler( object );
			if ( DataProxyHandler.class.isAssignableFrom( handler.getClass() ) ) {
				DataProxyHandler myHandler = ( DataProxyHandler ) handler;
				resolvedEntityName = myHandler.getEntityName();
			}
		}
		try {
			return ReflectHelper.classForName( entityName ).isInstance( object );
		}
		catch( Throwable t ) {
			throw new HibernateException( "could not get handle to entity-name as interface : " + t );
		}

//		return entityName.equals( resolvedEntityName );