01: package net.sourceforge.jaxor.util;
02:
03: import java.io.Serializable;
04: import java.lang.reflect.InvocationHandler;
05: import java.lang.reflect.Method;
06: import java.lang.reflect.Proxy;
07:
08: /*
09: * User: Mike
10: * Date: Oct 18, 2002
11: * Time: 7:58:04 PM
12: */
13:
14: public class NullProxy implements InvocationHandler, Serializable {
15:
16: public static Object create(Class interfaceClass) {
17: return create(new Class[] { interfaceClass });
18: }
19:
20: public static Object create(Class[] interfaceClass) {
21: return Proxy.newProxyInstance(interfaceClass[0]
22: .getClassLoader(), interfaceClass, new NullProxy());
23: }
24:
25: public Object invoke(Object proxy, Method method, Object[] args) {
26: return getDefaultInstance(method.getReturnType());
27: }
28:
29: public static Object getDefaultInstance(Class param) {
30: if (param == int.class)
31: return new Integer(0);
32: if (param == boolean.class)
33: return Boolean.FALSE;
34: if (param == byte.class)
35: return new Byte("0");
36: if (param == short.class)
37: return new Short("0");
38: if (param == long.class)
39: return new Long("0");
40: if (param == float.class)
41: return new Float("0");
42: if (param == double.class)
43: return new Double("0");
44: return null;
45: }
46: }
|