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  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  import org.huihoo.jfox.soaf.util.resource.ResourceHelper;
15  
16  import org.apache.commons.lang.StringUtils;
17  import org.apache.commons.lang.BooleanUtils;
18  
19  /***
20   * ServiceContainerInterceptor intercept service request and regist service
21   * instance to a ServiceContainer.
22   * 
23   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
24   * @version $Revision: 1.8 $ $Date: 2004/10/28 11:09:49 $
25   * @version Revision: 1.0
26   */
27  
28  public class ServiceContainerInterceptor implements ServiceInterceptor {
29  
30      private final Log logger = LogFactory.getLog(getClass());
31  
32      private ServiceContainer serviceContainer = ServiceContainer.getInstance();
33  
34      /***
35       * Interceptor invoke.
36       * 
37       * @see org.huihoo.jfox.soaf.container.ServiceInterceptor#invoke(org.huihoo.jfox.soaf.container.ServiceEntry)
38       */
39      public void invoke(ServiceEntry serviceEntry) throws Throwable {
40          if (!BooleanUtils.toBoolean(serviceEntry.getManageable())) {
41              logger.info("Register Service : "
42                      + serviceEntry.getImplementation());
43              Class service = ResourceHelper.classForName(serviceEntry
44                      .getImplementation());
45              synchronized (serviceContainer) {
46                  if (StringUtils.isEmpty(serviceEntry.getId())) {
47                      serviceContainer.registerServiceImplementation(serviceEntry
48                              .getImplementation(), service);
49                  } else {
50                      serviceContainer.registerServiceImplementation(serviceEntry
51                              .getId(), service);
52                  }
53              }
54          }
55      }
56  
57  }