1
2
3
4
5
6 package de.keepondreaming.xml;
7
8 import java.lang.reflect.Proxy;
9
10 /***
11 * This strategy is based upon dynamic proxies. Created objects will
12 * be dynamic proxies and member access is handled via calls to
13 * the methods offered by the added interface {@link de.keepondreaming.xml.ClassProxyAccess}
14 *
15 * $Author: wintermond $
16 * $Date: 2005/07/10 18:40:58 $
17 * $Log: ProxyObjectStrategy.java,v $
18 * Revision 1.3 2005/07/10 18:40:58 wintermond
19 * javadoc
20 *
21 * Revision 1.2 2005/07/09 10:01:34 wintermond
22 * javadoc
23 *
24 */
25 public class ProxyObjectStrategy implements ObjectStrategy
26 {
27 /***
28 * Default constructor
29 */
30 public ProxyObjectStrategy()
31 {
32 super();
33 }
34
35
36
37
38
39 public Object createInstance(Class clazz)
40 {
41 Object result = null;
42 if(clazz.isInterface())
43 {
44 result = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader()
45 , new Class[]{clazz, ClassProxyAccess.class}
46 , new ClassProxy());
47 }
48 else
49 {
50 throw new IllegalArgumentException();
51 }
52 return result;
53 }
54
55
56
57
58 public void setAttribute(Object target, String attribute, Object value)
59 {
60 ClassProxyAccess setter = (ClassProxyAccess) target;
61 setter.setAttribute(attribute, value);
62 }
63
64
65
66
67
68 public void init()
69 {
70
71 }
72
73
74
75
76
77 public Class resolveInterface(Object object)
78 {
79 Class result = null;
80 if(object instanceof ClassProxyAccess)
81 {
82 result = object.getClass().getInterfaces()[0];
83 }
84 return result;
85 }
86
87
88 public String getMethodName(Class clazz, String attribute, boolean set)
89 {
90 return null;
91 }
92
93
94
95 }