Clover coverage report - JFox Service-Oriented Application Framework - 1.0-M2 Coverage timestamp: 星期四 十一月 25 2004 17:14:11 PST FRAMES NO FRAMES |
file stats: | LOC: | 111 |  | Methods: | 5
| NCLOC: | 49 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
ManageableServiceContainer.java | 66.7% | 68.8% | 80% | 70.4% |

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 |  |
     import javax.management.MBeanServer;
13 |  |
     import javax.management.MBeanServerFactory;
14 |  |
     import javax.management.MalformedObjectNameException;
15 |  |
     import javax.management.ObjectName;
16 |  |
17 |  |
     import org.apache.commons.lang.StringUtils;
18 |  |
19 |  |
     /**
20 |  |
      * <p>
21 |  |
      * The manageable service container is a wrapper container on the top of
22 |  |
      * ServiceContainer and MBeanServer. It's a manageable Inversion of Control
23 |  |
      * (IoC) container which service can be managed by JMX.
24 |  |
      * </p>
25 |  |
      *
26 |  |
      * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
27 |  |
      * @version $Revision: 1.4 $ $Date: 2004/10/28 11:08:53 $
28 |  |
      * @version Revision: 1.0
29 |  |
      */
30 |  |
31 |  |
     public class ManageableServiceContainer {
32 |  |
33 |  |
         private static ManageableServiceContainer manageableServiceContainer;
34 |  |
35 |  |
         private ServiceContainer serviceContainer = ServiceContainer.getInstance();
36 |  |
37 |  |
         private final MBeanServer mBeanServer = MBeanServerFactory
38 |  |
                 .createMBeanServer("jfoxsoafmx");
39 |  |
40 | 6 |
         public static ManageableServiceContainer getInstance() {
41 | 6 |
             if (manageableServiceContainer == null) {
42 | 2 |
                 manageableServiceContainer = new ManageableServiceContainer();
43 |  |
             }
44 | 6 |
             return manageableServiceContainer;
45 |  |
         }
46 |  |
47 |  |
         /**
48 |  |
          * Regist managable service.
49 |  |
          *
50 |  |
          * @param serviceInstance
51 |  |
          * @param serviceEntry
52 |  |
          * @throws Throwable
53 |  |
          */
54 | 1 |
         public void registManagebleService(Object serviceInstance,
55 |  |
                 ServiceEntry serviceEntry) throws Throwable {
56 | 1 |
             if (StringUtils.isEmpty(serviceEntry.getId())) {
57 | 1 |
                 mBeanServer
58 |  |
                         .registerMBean(serviceInstance, objectName(serviceEntry));
59 | 1 |
                 serviceContainer.registerServiceInstance(serviceInstance);
60 |  |
             } else {
61 | 0 |
                 registManagebleService(serviceEntry.getId(), serviceInstance,
62 |  |
                         serviceEntry);
63 |  |
             }
64 |  |
         }
65 |  |
66 |  |
         /**
67 |  |
          * Regist manageable service with service id.
68 |  |
          *
69 |  |
          * @param serviceKey
70 |  |
          * @param serviceInstance
71 |  |
          * @param serviceEntry
72 |  |
          * @throws Throwable
73 |  |
          */
74 | 0 |
         private void registManagebleService(Object serviceKey,
75 |  |
                 Object serviceInstance, ServiceEntry serviceEntry) throws Throwable {
76 | 0 |
             mBeanServer.registerMBean(serviceInstance, objectName(serviceEntry));
77 | 0 |
             serviceContainer.registerServiceInstance(serviceKey, serviceInstance);
78 |  |
         }
79 |  |
80 |  |
         /**
81 |  |
          * Get an MBeanServer instance.
82 |  |
          *
83 |  |
          * @return MBeanServer
84 |  |
          */
85 | 1 |
         public MBeanServer getMBeanServer() {
86 | 1 |
             return this.mBeanServer;
87 |  |
         }
88 |  |
89 |  |
         /**
90 |  |
          * Convert object string to ObjectName.
91 |  |
          *
92 |  |
          * @param serviceEntry
93 |  |
          * @return
94 |  |
          * @throws MalformedObjectNameException
95 |  |
          */
96 | 2 |
         public ObjectName objectName(ServiceEntry serviceEntry)
97 |  |
                 throws MalformedObjectNameException {
98 | 2 |
             String objectStr = "";
99 | 2 |
             if (!StringUtils.isEmpty(serviceEntry.getId())) {
100 |  |
101 | 0 |
                 objectStr = mBeanServer.getDefaultDomain() + ":type="
102 |  |
                         + serviceEntry.getId();
103 | 0 |
                 return new ObjectName(objectStr);
104 |  |
             } else {
105 | 2 |
                 objectStr = mBeanServer.getDefaultDomain() + ":type="
106 |  |
                         + serviceEntry.getImplementation();
107 | 2 |
                 return new ObjectName(objectStr);
108 |  |
             }
109 |  |
         }
110 |  |
111 |  |
     }