FileDocCategorySizeDatePackage
DataProxyHandler.javaAPI DocHibernate 3.2.51456Tue Dec 06 14:23:38 GMT 2005org.hibernate.test.dynamicentity

DataProxyHandler

public final class DataProxyHandler extends Object implements InvocationHandler
A simple {@link InvocationHandler} to act as the handler for our generated {@link java.lang.reflect.Proxy}-based entity instances.

This is a trivial impl which simply keeps the property values into a Map.

author
Steve Ebersole

Fields Summary
private String
entityName
private HashMap
data
Constructors Summary
public DataProxyHandler(String entityName, Serializable id)


	     
		this.entityName = entityName;
		data.put( "Id", id );
	
Methods Summary
public java.util.HashMapgetData()

		return data;
	
public java.lang.StringgetEntityName()

		return entityName;
	
public java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

		String methodName = method.getName();
		if ( methodName.startsWith( "set" ) ) {
			String propertyName = methodName.substring( 3 );
			data.put( propertyName, args[0] );
		}
		else if ( methodName.startsWith( "get" ) ) {
			String propertyName = methodName.substring( 3 );
			return data.get( propertyName );
		}
		else if ( "toString".equals( methodName ) ) {
			return entityName + "#" + data.get( "Id" );
		}
		else if ( "hashCode".equals( methodName ) ) {
			return new Integer( this.hashCode() );
		}
		return null;