1 /***
2 * JFoxSOAF, Service-Oriented Application Framework
3 *
4 * Copyright (C) www.huihoo.org
5 *
6 * Distributable under GNU LGPL For more information, please visit:
7 * http://www.huihoo.org/jfox/jfoxsoaf
8 */
9
10 package org.huihoo.jfox.soaf.container;
11
12 /***
13 * ServiceContainerInterceptor intercept service request and regist service
14 * instance to a ServiceContainer.
15 *
16 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
17 * @version $Revision: 1.4 $ $Date: 2004/10/18 10:13:07 $
18 * @version Revision: 1.0
19 */
20
21 public class ServiceContainerInterceptor implements ServiceInterceptor {
22
23 private ServiceContainer serviceContainer = ServiceContainer.getInstance();
24
25 /***
26 * Interceptor invoke.
27 *
28 * @see org.huihoo.jfox.soaf.container.ServiceInterceptor#invoke(org.huihoo.jfox.soaf.container.ServiceEntry)
29 */
30 public void invoke(ServiceEntry serviceEntry, ClassLoader classLoader)
31 throws Throwable {
32 ClassLoader cl = classLoader;
33 if (!isManageable(serviceEntry)) {
34 Class service = cl.loadClass(serviceEntry.getImplementation());
35 synchronized (serviceContainer) {
36 if (isIDEmpty(serviceEntry)) {
37 serviceContainer.registerServiceImplementation(serviceEntry
38 .getImplementation(), service);
39 } else {
40 serviceContainer.registerServiceImplementation(serviceEntry
41 .getId(), service);
42 }
43 }
44 }
45 }
46
47 /***
48 * Is manageability currently enabled?
49 *
50 * @param serviceEntry
51 * @return boolean
52 */
53 private boolean isManageable(ServiceEntry serviceEntry) {
54 if (serviceEntry.getManageable().equalsIgnoreCase("true")) {
55 return true;
56 } else {
57 return false;
58 }
59 }
60
61 /***
62 * Is service id empty?
63 *
64 * @param serviceEntry
65 * @return boolean
66 */
67 private boolean isIDEmpty(ServiceEntry serviceEntry) {
68 if (serviceEntry.getId() == null || serviceEntry.getId() == "") {
69 return true;
70 } else {
71 return false;
72 }
73 }
74 }