~raginggoblin/infolog/infolog

« back to all changes in this revision

Viewing changes to InfologServer/lib/hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/dynamicentity/DataProxyHandler.java

  • Committer: Raging Goblin
  • Date: 2013-11-16 16:51:32 UTC
  • Revision ID: raging_goblin-20131116165132-weujnptzc88uy4ah
Mavenized the project, now using shared project InfologSync

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.hibernate.test.dynamicentity;
2
 
 
3
 
import java.lang.reflect.InvocationHandler;
4
 
import java.lang.reflect.Method;
5
 
import java.util.HashMap;
6
 
import java.io.Serializable;
7
 
 
8
 
/**
9
 
 * A simple {@link InvocationHandler} to act as the handler for our generated
10
 
 * {@link java.lang.reflect.Proxy}-based entity instances.
11
 
 * <p/>
12
 
 * This is a trivial impl which simply keeps the property values into
13
 
 * a Map.
14
 
 *
15
 
 * @author <a href="mailto:steve@hibernate.org">Steve Ebersole </a>
16
 
 */
17
 
public final class DataProxyHandler implements InvocationHandler {
18
 
        private String entityName;
19
 
        private HashMap data = new HashMap();
20
 
 
21
 
        public DataProxyHandler(String entityName, Serializable id) {
22
 
                this.entityName = entityName;
23
 
                data.put( "Id", id );
24
 
        }
25
 
 
26
 
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
27
 
                String methodName = method.getName();
28
 
                if ( methodName.startsWith( "set" ) ) {
29
 
                        String propertyName = methodName.substring( 3 );
30
 
                        data.put( propertyName, args[0] );
31
 
                }
32
 
                else if ( methodName.startsWith( "get" ) ) {
33
 
                        String propertyName = methodName.substring( 3 );
34
 
                        return data.get( propertyName );
35
 
                }
36
 
                else if ( "toString".equals( methodName ) ) {
37
 
                        return entityName + "#" + data.get( "Id" );
38
 
                }
39
 
                else if ( "hashCode".equals( methodName ) ) {
40
 
                        return new Integer( this.hashCode() );
41
 
                }
42
 
                return null;
43
 
        }
44
 
 
45
 
        public String getEntityName() {
46
 
                return entityName;
47
 
        }
48
 
 
49
 
        public HashMap getData() {
50
 
                return data;
51
 
        }
52
 
}