KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > service > ServiceDescriptorRegistry


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.service;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.alfresco.service.ServiceDescriptor;
26 import org.alfresco.service.ServiceRegistry;
27 import org.alfresco.service.cmr.action.ActionService;
28 import org.alfresco.service.cmr.coci.CheckOutCheckInService;
29 import org.alfresco.service.cmr.dictionary.DictionaryService;
30 import org.alfresco.service.cmr.lock.LockService;
31 import org.alfresco.service.cmr.model.FileFolderService;
32 import org.alfresco.service.cmr.repository.ContentService;
33 import org.alfresco.service.cmr.repository.CopyService;
34 import org.alfresco.service.cmr.repository.MimetypeService;
35 import org.alfresco.service.cmr.repository.NodeService;
36 import org.alfresco.service.cmr.repository.TemplateService;
37 import org.alfresco.service.cmr.rule.RuleService;
38 import org.alfresco.service.cmr.search.CategoryService;
39 import org.alfresco.service.cmr.search.SearchService;
40 import org.alfresco.service.cmr.security.AuthenticationService;
41 import org.alfresco.service.cmr.security.AuthorityService;
42 import org.alfresco.service.cmr.security.PermissionService;
43 import org.alfresco.service.cmr.version.VersionService;
44 import org.alfresco.service.cmr.view.ExporterService;
45 import org.alfresco.service.cmr.view.ImporterService;
46 import org.alfresco.service.descriptor.DescriptorService;
47 import org.alfresco.service.namespace.NamespaceService;
48 import org.alfresco.service.namespace.QName;
49 import org.alfresco.service.transaction.TransactionService;
50 import org.springframework.beans.BeansException;
51 import org.springframework.beans.factory.BeanFactory;
52 import org.springframework.beans.factory.BeanFactoryAware;
53 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
54 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
55
56
57 /**
58  * Implementation of a Service Registry based on the definition of
59  * Services contained within a Spring Bean Factory.
60  *
61  * @author David Caruana
62  */

63 public class ServiceDescriptorRegistry
64     implements BeanFactoryAware, BeanFactoryPostProcessor, ServiceRegistry
65 {
66     // Bean Factory within which the registry lives
67
private BeanFactory beanFactory = null;
68
69     // Service Descriptor map
70
private Map JavaDoc<QName, BeanServiceDescriptor> descriptors = new HashMap JavaDoc<QName, BeanServiceDescriptor>();
71
72     
73     /* (non-Javadoc)
74      * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
75      */

76     public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
77     {
78         Map JavaDoc beans = beanFactory.getBeansOfType(ServiceDescriptorMetaData.class);
79         Iterator JavaDoc iter = beans.entrySet().iterator();
80         while (iter.hasNext())
81         {
82             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iter.next();
83             ServiceDescriptorMetaData metaData = (ServiceDescriptorMetaData)entry.getValue();
84             QName serviceName = QName.createQName(metaData.getNamespace(), (String JavaDoc)entry.getKey());
85             StoreRedirector redirector = (entry.getValue() instanceof StoreRedirector) ? (StoreRedirector)entry.getValue() : null;
86             BeanServiceDescriptor serviceDescriptor = new BeanServiceDescriptor(serviceName, metaData, redirector);
87             descriptors.put(serviceDescriptor.getQualifiedName(), serviceDescriptor);
88         }
89     }
90
91     /* (non-Javadoc)
92      * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
93      */

94     public void setBeanFactory(BeanFactory beanFactory) throws BeansException
95     {
96         this.beanFactory = beanFactory;
97     }
98         
99     /* (non-Javadoc)
100      * @see org.alfresco.repo.service.ServiceRegistry#getServices()
101      */

102     public Collection JavaDoc<QName> getServices()
103     {
104         return Collections.unmodifiableSet(descriptors.keySet());
105     }
106
107     /* (non-Javadoc)
108      * @see org.alfresco.repo.service.ServiceRegistry#isServiceProvided(org.alfresco.repo.ref.QName)
109      */

110     public boolean isServiceProvided(QName service)
111     {
112         return descriptors.containsKey(service);
113     }
114
115     /* (non-Javadoc)
116      * @see org.alfresco.repo.service.ServiceRegistry#getServiceDescriptor(org.alfresco.repo.ref.QName)
117      */

118     public ServiceDescriptor getServiceDescriptor(QName service)
119     {
120         return descriptors.get(service);
121     }
122
123     /* (non-Javadoc)
124      * @see org.alfresco.repo.service.ServiceRegistry#getService(org.alfresco.repo.ref.QName)
125      */

126     public Object JavaDoc getService(QName service)
127     {
128         return beanFactory.getBean(service.getLocalName());
129     }
130
131     /* (non-Javadoc)
132      * @see org.alfresco.service.ServiceRegistry#getDescriptorService()
133      */

134     public DescriptorService getDescriptorService()
135     {
136         return (DescriptorService)getService(DESCRIPTOR_SERVICE);
137     }
138     
139     /* (non-Javadoc)
140      * @see org.alfresco.repo.service.ServiceRegistry#getNodeService()
141      */

142     public NodeService getNodeService()
143     {
144         return (NodeService)getService(NODE_SERVICE);
145     }
146
147     /* (non-Javadoc)
148      * @see org.alfresco.repo.service.ServiceRegistry#getNodeService()
149      */

150     public AuthenticationService getAuthenticationService()
151     {
152         return (AuthenticationService)getService(AUTHENTICATION_SERVICE);
153     }
154
155     /* (non-Javadoc)
156      * @see org.alfresco.repo.service.ServiceRegistry#getContentService()
157      */

158     public ContentService getContentService()
159     {
160         return (ContentService)getService(CONTENT_SERVICE);
161     }
162
163     /* (non-Javadoc)
164      * @see org.alfresco.service.ServiceRegistry#getMimetypeService()
165      */

166     public MimetypeService getMimetypeService()
167     {
168         return (MimetypeService)getService(MIMETYPE_SERVICE);
169     }
170
171     /* (non-Javadoc)
172      * @see org.alfresco.repo.service.ServiceRegistry#getVersionService()
173      */

174     public VersionService getVersionService()
175     {
176         return (VersionService)getService(VERSION_SERVICE);
177     }
178
179     /* (non-Javadoc)
180      * @see org.alfresco.repo.service.ServiceRegistry#getLockService()
181      */

182     public LockService getLockService()
183     {
184         return (LockService)getService(LOCK_SERVICE);
185     }
186
187     /* (non-Javadoc)
188      * @see org.alfresco.repo.service.ServiceRegistry#getDictionaryService()
189      */

190     public DictionaryService getDictionaryService()
191     {
192         return (DictionaryService)getService(DICTIONARY_SERVICE);
193     }
194
195     /* (non-Javadoc)
196      * @see org.alfresco.service.ServiceRegistry#getSearchService()
197      */

198     public SearchService getSearchService()
199     {
200         return (SearchService)getService(SEARCH_SERVICE);
201     }
202     
203     /* (non-Javadoc)
204      * @see org.alfresco.service.ServiceRegistry#getTransactionService()
205      */

206     public TransactionService getTransactionService()
207     {
208         return (TransactionService)getService(TRANSACTION_SERVICE);
209     }
210
211     /* (non-Javadoc)
212      * @see org.alfresco.service.ServiceRegistry#getCopyService()
213      */

214     public CopyService getCopyService()
215     {
216         return (CopyService)getService(COPY_SERVICE);
217     }
218
219     /* (non-Javadoc)
220      * @see org.alfresco.service.ServiceRegistry#getCheckOutCheckInService()
221      */

222     public CheckOutCheckInService getCheckOutCheckInService()
223     {
224         return (CheckOutCheckInService)getService(COCI_SERVICE);
225     }
226     
227     /* (non-Javadoc)
228      * @see org.alfresco.service.ServiceRegistry#getCategoryService()
229      */

230     public CategoryService getCategoryService()
231     {
232         return (CategoryService)getService(CATEGORY_SERVICE);
233     }
234
235     /* (non-Javadoc)
236      * @see org.alfresco.service.ServiceRegistry#getNamespaceService()
237      */

238     public NamespaceService getNamespaceService()
239     {
240         return (NamespaceService)getService(NAMESPACE_SERVICE);
241     }
242     
243     /* (non-Javadoc)
244      * @see org.alfresco.service.ServiceRegistry#getImporterService()
245      */

246     public ImporterService getImporterService()
247     {
248         return (ImporterService)getService(IMPORTER_SERVICE);
249     }
250
251     /* (non-Javadoc)
252      * @see org.alfresco.service.ServiceRegistry#getExporterService()
253      */

254     public ExporterService getExporterService()
255     {
256         return (ExporterService)getService(EXPORTER_SERVICE);
257     }
258     
259     /* (non-Javadoc)
260      * @see org.alfresco.service.ServiceRegistry#getRuleService()
261      */

262     public RuleService getRuleService()
263     {
264         return (RuleService)getService(RULE_SERVICE);
265     }
266     
267     /*
268      * (non-Javadoc)
269      * @see org.alfresco.service.ServiceRegistry#getActionService()
270      */

271     public ActionService getActionService()
272     {
273         return (ActionService)getService(ACTION_SERVICE);
274     }
275
276     /* (non-Javadoc)
277      * @see org.alfresco.service.ServiceRegistry#getPermissionService()
278      */

279     public PermissionService getPermissionService()
280     {
281         return (PermissionService)getService(PERMISSIONS_SERVICE);
282     }
283     
284     /* (non-Javadoc)
285      * @see org.alfresco.service.ServiceRegistry#getAuthorityService()
286      */

287     public AuthorityService getAuthorityService()
288     {
289         return (AuthorityService)getService(AUTHORITY_SERVICE);
290     }
291
292     /* (non-Javadoc)
293      * @see org.alfresco.service.ServiceRegistry#getTemplateService()
294      */

295     public TemplateService getTemplateService()
296     {
297         return (TemplateService)getService(TEMPLATE_SERVICE);
298     }
299
300     /* (non-Javadoc)
301      * @see org.alfresco.service.ServiceRegistry#getTemplateService()
302      */

303     public FileFolderService getFileFolderService()
304     {
305         return (FileFolderService) getService(FILE_FOLDER_SERVICE);
306     }
307 }
308
Popular Tags