View Javadoc

1   /*
2    * Created on 09.05.2005 from Linke
3    *
4    */
5   package net.sf.crispy.proxy;
6   
7   import java.util.Properties;
8   
9   import net.sf.crispy.InterceptorHandler;
10  import net.sf.crispy.InvocationException;
11  
12  /**
13   * 
14   * Decorate the Proxy. It is a Wrapper. Intercept calls on the newInstance-Methode (for internal use).
15   * 
16   * @author Linke
17   *
18   */
19  public class ProxyDecorator extends Proxy {
20  
21  	private Proxy proxy = null;
22  	private InterceptorHandler interceptorHandler = null;
23  	
24  	public ProxyDecorator(Proxy pvProxy, InterceptorHandler pvInterceptorHandler) {
25  		proxy = pvProxy;
26  		interceptorHandler = pvInterceptorHandler;
27  	}
28  	
29  	/**
30  	 * Intercept the Method and delegate Method to Proxy.
31  	 * @see net.sf.crispy.proxy.Proxy#newInstance(java.lang.Class)
32  	 */
33  	public Object newInstance(Class pvClass) {
34  		interceptorHandler.fireBeforeNewInstance(pvClass);
35  		Object lvProxyObject = null;
36  		try {
37  			lvProxyObject = proxy.newInstance(pvClass);
38  		} catch (Exception e) {
39  			interceptorHandler.fireOnError(e);
40  			throw new InvocationException("Error in ProxyDecorator.newInstance with proxy: " + proxy 
41  					+ " (" + pvClass + ") " + e, e);
42  		}
43  		finally {
44  			interceptorHandler.fireAfterNewInstance(pvClass, lvProxyObject);
45  		}
46  		return lvProxyObject;
47  	}
48  	
49  	/**
50  	 * Get the wrapped (decorated) Proxy.
51  	 * @return the wrapped Proxy
52  	 */
53  	public Proxy getProxy() { return proxy; }
54  
55  	/**
56  	 * Set the wrapped (decorated) Proxy.
57  	 * @param pvProxy The to wrapped Proxy
58  	 */
59  	public void setProxy(Proxy pvProxy) { proxy = pvProxy; }
60  
61  	/**
62  	 * Delegate Method to Proxy.
63  	 * @see net.sf.crispy.proxy.Proxy#getProperties()
64  	 */
65  	public Properties getProperties() { return proxy.getProperties(); }
66  	/**
67  	 * Delegate Method to Proxy.
68  	 * @see net.sf.crispy.proxy.Proxy#setProperties(Properties)
69  	 */	
70  	public void setProperties(Properties pvProperties) { proxy.setProperties(pvProperties); }
71  
72  	/**
73  	 * Delegate Method to Proxy.
74  	 * @see net.sf.crispy.proxy.Proxy#getProxyClass()
75  	 */
76  	public Class getProxyClass() { return proxy.getProxyClass(); }
77  	
78  	/**
79  	 * Delegate Method to Proxy.
80  	 * @see net.sf.crispy.proxy.Proxy#getProxyObject()
81  	 */
82  	public Object getProxyObject() { return proxy.getProxyObject(); }
83  }