View Javadoc

1   /*
2    * Copyright 2005 by Mark Vollmann Hamburg, Germany. All rights reserved.
3    * 
4    * Created on 08.07.2005
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      /* (non-Javadoc)
37       * @see de.keepondreaming.xml.ObjectStrategy#createInstance(java.lang.Class)
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      /* (non-Javadoc)
56       * @see de.keepondreaming.xml.ObjectStrategy#setAttribute(java.lang.Object, java.lang.String, java.lang.Object)
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  	/* (non-Javadoc)
66  	 * @see de.keepondreaming.xml.ObjectStrategy#init()
67  	 */
68  	public void init()
69  	{
70  		// nothing to do
71  	}
72  
73  
74  	/* (non-Javadoc)
75  	 * @see de.keepondreaming.xml.ObjectStrategy#resolveInterface(java.lang.Object)
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  }