01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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: */
16: package edu.iu.uis.eden.messaging.serviceproxies;
17:
18: import java.io.Serializable;
19: import java.lang.reflect.Proxy;
20: import java.util.List;
21:
22: import org.kuali.rice.RiceConstants;
23: import org.kuali.rice.core.Core;
24: import org.kuali.rice.resourceloader.ContextClassLoaderProxy;
25: import org.kuali.rice.util.ClassLoaderUtils;
26:
27: import edu.iu.uis.eden.messaging.AsynchronousCallback;
28: import edu.iu.uis.eden.messaging.MessageServiceInvoker;
29: import edu.iu.uis.eden.messaging.PersistedMessage;
30: import edu.iu.uis.eden.messaging.RemotedServiceHolder;
31:
32: /**
33: * Used to Call a service synchronously but through the messaging code within workflow. Used to when switching generally
34: * asynchronously called services to synchronously called services. Generally for testing purposes.
35: *
36: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
37: *
38: */
39: public class SynchronousServiceCallProxy extends
40: AsynchronousServiceCallProxy {
41:
42: private SynchronousServiceCallProxy(
43: List<RemotedServiceHolder> serviceDefs,
44: AsynchronousCallback callback, Serializable context,
45: String value1, String value2) {
46: super (serviceDefs, callback, context, value1, value2);
47: }
48:
49: public static Object createInstance(
50: List<RemotedServiceHolder> serviceDefs,
51: AsynchronousCallback callback, Serializable context,
52: String value1, String value2) {
53: if (serviceDefs == null || serviceDefs.isEmpty()) {
54: throw new RuntimeException(
55: "Cannot create service proxy, no service(s) passed in.");
56: }
57: return Proxy.newProxyInstance(ClassLoaderUtils
58: .getDefaultClassLoader(), ContextClassLoaderProxy
59: .getInterfacesToProxyIncludeSpring(serviceDefs.get(0)
60: .getService()),
61: new SynchronousServiceCallProxy(serviceDefs, callback,
62: context, value1, value2));
63: }
64:
65: @Override
66: protected void executeMessage(PersistedMessage message) {
67: if (!new Boolean(Core.getCurrentContextConfig().getProperty(
68: RiceConstants.MESSAGING_OFF))) {
69: new MessageServiceInvoker(message).run();
70: }
71: }
72: }
|