01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.messaging.bam;
18:
19: import java.lang.reflect.Method;
20: import java.lang.reflect.Proxy;
21:
22: import org.kuali.bus.services.KSBServiceLocator;
23: import org.kuali.rice.proxy.BaseTargetedInvocationHandler;
24: import org.kuali.rice.resourceloader.ContextClassLoaderProxy;
25: import org.kuali.rice.util.ClassLoaderUtils;
26: import org.kuali.rice.util.ExceptionUtils;
27:
28: import edu.iu.uis.eden.messaging.ServiceInfo;
29:
30: /**
31: * A client-side proxy for that records an entry in the BAM for invocations
32: * on the proxied service.
33: *
34: * @see BAMService
35: *
36: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
37: */
38: public class BAMClientProxy extends BaseTargetedInvocationHandler {
39:
40: private ServiceInfo serviceInfo;
41:
42: private BAMClientProxy(Object target, ServiceInfo serviceInfo) {
43: super (target);
44: this .serviceInfo = serviceInfo;
45: }
46:
47: public static Object wrap(Object target, ServiceInfo serviceInfo) {
48: return Proxy.newProxyInstance(ClassLoaderUtils
49: .getDefaultClassLoader(), ContextClassLoaderProxy
50: .getInterfacesToProxyIncludeSpring(target),
51: new BAMClientProxy(target, serviceInfo));
52: }
53:
54: protected Object invokeInternal(Object proxyObject, Method method,
55: Object[] arguments) throws Throwable {
56: BAMTargetEntry bamTargetEntry = KSBServiceLocator
57: .getBAMService().recordClientInvocation(
58: this .serviceInfo, getTarget(), method,
59: arguments);
60: try {
61: return method.invoke(getTarget(), arguments);
62: } catch (Throwable throwable) {
63: throwable = ExceptionUtils.unwrapActualCause(throwable);
64: KSBServiceLocator.getBAMService()
65: .recordClientInvocationError(throwable,
66: bamTargetEntry);
67: throw throwable;
68: }
69: }
70: }
|