View Javadoc

1   /***
2    * @(#)ServiceContainer.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 java.util.List;
28  
29  import org.picocontainer.ComponentAdapter;
30  import org.picocontainer.PicoContainer;
31  import org.picocontainer.PicoException;
32  import org.picocontainer.PicoRegistrationException;
33  import org.picocontainer.defaults.ComponentAdapterFactory;
34  import org.picocontainer.defaults.DefaultPicoContainer;
35  
36  /***
37   * <p>
38   * The services container is a extension of DefaultPicoContainer.
39   * </p>
40   * 
41   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
42   * @version $Revision: 1.13 $ $Date: 2006/02/15 08:45:45 $
43   * @version Revision: 1.0
44   */
45  
46  public class ServiceContainer extends DefaultPicoContainer {
47  
48      private static ServiceContainer serviceContainer;
49  
50      public static ServiceContainer getInstance() {
51          if (serviceContainer == null) {
52              serviceContainer = new ServiceContainer();
53          }
54          return serviceContainer;
55      }
56  
57      /***
58       * Creates a new container with a custom ComponentAdapterFactory and a
59       * parent container.
60       * 
61       * @param componentAdapterFactory
62       * @param parent
63       */
64      public ServiceContainer(ComponentAdapterFactory componentAdapterFactory,
65              PicoContainer parent) {
66          super(componentAdapterFactory, parent);
67      }
68  
69      /***
70       * Creates a new container with a parent container.
71       * 
72       * @param parent
73       */
74      public ServiceContainer(PicoContainer parent) {
75          super(parent);
76      }
77  
78      /***
79       * Default Container.
80       * 
81       * @param parent
82       */
83      public ServiceContainer() {
84          super();
85      }
86  
87      /***
88       * @see org.picocontainer.MutablePicoContainer#registerComponentImplementation(java.lang.Object)
89       */
90      public ComponentAdapter registerServiceImplementation(Class serviceImpl)
91              throws PicoRegistrationException {
92          return super.registerComponentImplementation(serviceImpl);
93  
94      }
95  
96      /***
97       * @see org.picocontainer.defaults.DefaultPicoContainer#registerComponentImplementation(java.lang.Object,
98       *      java.lang.Class, java.util.List)
99       */
100     public ComponentAdapter registerServiceImplementation(Object serviceKey,
101             Class serviceImpl, List parameters)
102             throws PicoRegistrationException {
103         return super.registerComponentImplementation(serviceKey, serviceImpl,
104                 parameters);
105     }
106 
107     /***
108      * @see org.picocontainer.MutablePicoContainer#registerComponentImplementation(java.lang.Object,
109      *      java.lang.Class)
110      */
111     public ComponentAdapter registerServiceImplementation(Object serviceKey,
112             Class serviceImpl) throws PicoRegistrationException {
113         return super.registerComponentImplementation(serviceKey, serviceImpl);
114     }
115 
116     /***
117      * @see org.picocontainer.MutablePicoContainer#registerComponentInstance(java.lang.Object,
118      *      java.lang.Object)
119      */
120     public ComponentAdapter registerServiceInstance(Object serviceKey,
121             Object serviceInstance) throws PicoRegistrationException {
122         return super.registerComponentInstance(serviceKey, serviceInstance);
123     }
124 
125     /***
126      * @see org.picocontainer.MutablePicoContainer#registerComponentInstance(java.lang.Object)
127      */
128     public ComponentAdapter registerServiceInstance(Object serviceInstance)
129             throws PicoRegistrationException {
130         return super.registerComponentInstance(serviceInstance);
131     }
132 
133     /***
134      * @see org.picocontainer.PicoContainer#getComponentInstance(java.lang.Object)
135      */
136     public Object getService(Object serviceKey) throws PicoException {
137         return super.getComponentInstance(serviceKey);
138     }
139 
140     /***
141      * @see org.picocontainer.PicoContainer#getComponentInstanceOfType(java.lang.Class)
142      */
143     public Object getServiceOfType(Class serviceType) {
144         return super.getComponentInstanceOfType(serviceType);
145     }
146 
147     /***
148      * Unregister service.
149      * 
150      * @param service
151      * @return ComponentAdapter
152      */
153     public ComponentAdapter unregisterService(Object service) {
154         return super.unregisterComponent(service);
155     }
156 }