Clover coverage report - JFox Service-Oriented Application Framework - 1.0
Coverage timestamp: 星期一 八月 21 2006 22:56:01 CST
file stats: LOC: 122   Methods: 5
NCLOC: 46   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% 69.2% 80% 70.8%
coverage coverage
 1   
 /**
 2   
  * @(#)ManageableServiceContainer.java
 3   
  * 
 4   
  * JFoxSOAF, Service-Oriented Application Framework
 5   
  * 
 6   
  * Copyright(c) JFoxSOAF Team
 7   
  * 
 8   
  * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
 9   
  * you may not use this file except in compliance with the License. 
 10   
  * You may obtain a copy of the License at  
 11   
  * 
 12   
  * http://www.gnu.org/copyleft/lesser.html
 13   
  * 
 14   
  * Unless required by applicable law or agreed to in writing, software
 15   
  * distributed under the License is distributed on an "AS IS" BASIS, 
 16   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 17   
  * See the License for the specific language governing permissions and 
 18   
  * limitations under the License. 
 19   
  * 
 20   
  * For more information, please visit:
 21   
  * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
 22   
  * http://www.huihoo.org/jfox/jfoxsoaf
 23   
  */
 24   
 
 25   
 package org.huihoo.jfox.soaf.container;
 26   
 
 27   
 import javax.management.MBeanServer;
 28   
 import javax.management.MBeanServerFactory;
 29   
 import javax.management.MalformedObjectNameException;
 30   
 import javax.management.ObjectName;
 31   
 
 32   
 import org.apache.commons.lang.StringUtils;
 33   
 
 34   
 /**
 35   
  * <p>
 36   
  * The manageable service container is a wrapper container on the top of
 37   
  * ServiceContainer and MBeanServer. It's a manageable Inversion of Control
 38   
  * (IoC) container which service can be managed by JMX.
 39   
  * </p>
 40   
  * 
 41   
  * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
 42   
  * @version $Revision: 1.8 $ $Date: 2005/01/17 13:29:59 $
 43   
  * @version Revision: 1.0
 44   
  */
 45   
 
 46   
 public class ManageableServiceContainer {
 47   
 
 48   
     private static ManageableServiceContainer manageableServiceContainer;
 49   
 
 50   
     private ServiceContainer serviceContainer = ServiceContainer.getInstance();
 51   
 
 52   
     private final MBeanServer mBeanServer = MBeanServerFactory
 53   
             .createMBeanServer("jfoxsoafmx");
 54   
 
 55  23
     public static ManageableServiceContainer getInstance() {
 56  23
         if (manageableServiceContainer == null) {
 57  12
             manageableServiceContainer = new ManageableServiceContainer();
 58   
         }
 59  23
         return manageableServiceContainer;
 60   
     }
 61   
 
 62   
     /**
 63   
      * Regist managable service.
 64   
      * 
 65   
      * @param serviceInstance
 66   
      * @param serviceEntry
 67   
      * @throws Throwable
 68   
      */
 69  1
     public void registManagebleService(Object serviceInstance,
 70   
             ServiceEntry serviceEntry) throws Throwable {
 71  1
         if (StringUtils.isEmpty(serviceEntry.getId())) {
 72  1
             mBeanServer
 73   
                     .registerMBean(serviceInstance, objectName(serviceEntry));
 74  1
             serviceContainer.registerServiceInstance(serviceInstance);
 75   
         } else {
 76  0
             registManagebleService(serviceEntry.getId(), serviceInstance,
 77   
                     serviceEntry);
 78   
         }
 79   
     }
 80   
 
 81   
     /**
 82   
      * Regist manageable service with service id.
 83   
      * 
 84   
      * @param serviceKey
 85   
      * @param serviceInstance
 86   
      * @param serviceEntry
 87   
      * @throws Throwable
 88   
      */
 89  0
     private void registManagebleService(Object serviceKey,
 90   
             Object serviceInstance, ServiceEntry serviceEntry) throws Throwable {
 91  0
         mBeanServer.registerMBean(serviceInstance, objectName(serviceEntry));
 92  0
         serviceContainer.registerServiceInstance(serviceKey, serviceInstance);
 93   
     }
 94   
 
 95   
     /**
 96   
      * Get an MBeanServer instance.
 97   
      * 
 98   
      * @return MBeanServer
 99   
      */
 100  1
     public MBeanServer getMBeanServer() {
 101  1
         return this.mBeanServer;
 102   
     }
 103   
 
 104   
     /**
 105   
      * Convert object string to ObjectName.
 106   
      * 
 107   
      * @param serviceEntry
 108   
      * @return
 109   
      * @throws MalformedObjectNameException
 110   
      */
 111  2
     public ObjectName objectName(ServiceEntry serviceEntry)
 112   
             throws MalformedObjectNameException {
 113  2
         if (!StringUtils.isEmpty(serviceEntry.getId())) {
 114  0
             return new ObjectName(mBeanServer.getDefaultDomain() + ":type="
 115   
                     + serviceEntry.getId());
 116   
         } else {
 117  2
             return new ObjectName(mBeanServer.getDefaultDomain() + ":type="
 118   
                     + serviceEntry.getImplementation());
 119   
         }
 120   
     }
 121   
 
 122   
 }