View Javadoc

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   * MBeanServerInterceptor intercept manageable service request and regist
14   * service instance to a MBeanServer and ServiceContainer.
15   * 
16   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
17   * @version $Revision: 1.6 $ $Date: 2004/10/18 14:40:32 $
18   * @version Revision: 1.0
19   */
20  
21  public class MBeanServerInterceptor implements ServiceInterceptor {
22  
23      private ManageableServiceContainer manageableServiceContainer = ManageableServiceContainer
24              .getInstance();
25  
26      /***
27       * Interceptor invoke.
28       * 
29       * @see org.huihoo.jfox.soaf.container.ServiceInterceptor#invoke(org.huihoo.jfox.soaf.container.ServiceEntry)
30       */
31      public void invoke(ServiceEntry serviceEntry, ClassLoader classLoader)
32              throws Throwable {
33  
34          if (isManageable(serviceEntry)) {
35              Class service = classLoader.loadClass(serviceEntry
36                      .getImplementation());
37              Object object = service.newInstance();           
38  
39              synchronized (manageableServiceContainer) {
40                  manageableServiceContainer.registManagebleService(object,
41                          serviceEntry);
42              }
43          }
44      }
45  
46      /***
47       * Is manageability currently enabled?
48       * 
49       * @param serviceEntry
50       * @return boolean
51       */
52      private boolean isManageable(ServiceEntry serviceEntry) {
53          if (serviceEntry.getManageable().equalsIgnoreCase("true")) {
54              return true;
55          } else {
56              return false;
57          }
58      }
59  
60  }