01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.integration.spring.support;
16:
17: import java.io.Serializable;
18: import java.lang.reflect.InvocationHandler;
19: import java.lang.reflect.InvocationTargetException;
20: import java.lang.reflect.Method;
21: import org.araneaframework.Environment;
22: import org.springframework.beans.factory.BeanFactory;
23:
24: public class SpringBeanInvocationHandler implements InvocationHandler,
25: Serializable {
26: private Environment env;
27: private String id;
28:
29: public SpringBeanInvocationHandler(Environment env, String id) {
30: this .env = env;
31: this .id = id;
32: env.requireEntry(BeanFactory.class);
33: }
34:
35: public Object invoke(Object proxy, Method method, Object[] args)
36: throws Throwable {
37: BeanFactory bf = (BeanFactory) env.getEntry(BeanFactory.class);
38:
39: //XXX: This is a bit evil, but otherwise Serialization debug fails
40: //The check is done in the constructor to ensure that generally
41: //BeanFactory is available
42: if (bf == null)
43: return null;
44:
45: Object bean = bf.getBean(id);
46:
47: try {
48: return method.invoke(bean, args);
49: } catch (InvocationTargetException ex) {
50: throw ex.getTargetException();
51: }
52: }
53: }
|