01: /*
02: * XML 2 Java Binding (X2JB) - the excellent Java tool.
03: * Copyright 2007, by Richard Opalka.
04: *
05: * This is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as
07: * published by the Free Software Foundation; either version 2.1 of
08: * the License, or (at your option) any later version.
09: *
10: * This software is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this software; if not see the FSF site:
17: * http://www.fsf.org/ and search for the LGPL License document there.
18: */
19: package org.x2jb.bind;
20:
21: import java.lang.reflect.InvocationHandler;
22: import java.lang.reflect.Method;
23: import java.lang.reflect.Proxy;
24: import java.util.Map;
25:
26: /**
27: * Return values wrapper
28: *
29: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
30: * @version 1.0
31: */
32: final class ProxyImpl implements InvocationHandler {
33:
34: // mapping - keys are method names, values are processed return values
35: private final Map returnValues;
36:
37: /**
38: * Constructor
39: */
40: private ProxyImpl(Map returnValues) {
41: super ();
42: this .returnValues = returnValues;
43: }
44:
45: /**
46: * Factory method
47: */
48: static Object newInstance(Class iface, Map returnValues) {
49: return Proxy.newProxyInstance(iface.getClassLoader(),
50: new Class[] { iface }, new ProxyImpl(returnValues));
51: }
52:
53: /**
54: * Method invocation returns value associated with the method name
55: */
56: public Object invoke(Object proxy, Method method, Object[] args)
57: throws Throwable {
58: return this.returnValues.get(method.getName());
59: }
60:
61: }
|