KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > registries > ServicesRegistry


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution S�rl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * Contributor(s):
36  * 19-DEC-2000, Xo3 SA, Eric Vassalli
37  * 23-JUL-2001, Xo3 SA, Stephane Boury
38  * 15-AUG-2003, Jahia Solutions Sarl: Fulco Houkes
39  *
40  * ----- END LICENSE BLOCK -----
41  */

42
43
44 package org.jahia.registries;
45
46 import java.util.HashMap JavaDoc;
47 import java.util.Properties JavaDoc;
48 import java.util.Vector JavaDoc;
49
50 import org.jahia.exceptions.JahiaException;
51 import org.jahia.exceptions.JahiaInitializationException;
52 import org.jahia.resourcebundle.ResourceBundleService;
53 import org.jahia.services.JahiaService;
54 import org.jahia.services.importexport.ImportExportService;
55 import org.jahia.services.sso.CasService;
56 import org.jahia.services.fileextraction.JahiaFileExtractionService;
57 import org.jahia.services.acl.JahiaACLManagerService;
58 import org.jahia.services.applications.JahiaApplicationContextService;
59 import org.jahia.services.applications.JahiaApplicationsDispatchingService;
60 import org.jahia.services.applications.JahiaApplicationsManagerService;
61 import org.jahia.services.applications.JahiaApplicationsPersistanceService;
62 import org.jahia.services.audit.JahiaAuditLogManagerService;
63 import org.jahia.services.cache.CacheFactory;
64 import org.jahia.services.containers.JahiaContainersService;
65 import org.jahia.services.database.JahiaIncrementorsDBService;
66 import org.jahia.services.deamons.filewatcher.JahiaFileWatcherService;
67 import org.jahia.services.events.JahiaEventGeneratorService;
68 import org.jahia.services.fetchers.JahiaFetcherService;
69 import org.jahia.services.fields.JahiaFieldService;
70 import org.jahia.services.filemanager.JahiaFilemanagerService;
71 import org.jahia.services.files.JahiaFileTransferService;
72 import org.jahia.services.files.JahiaTextFileService;
73 import org.jahia.services.homepages.JahiaHomepagesService;
74 import org.jahia.services.htmleditors.HtmlEditorsService;
75 import org.jahia.services.htmlparser.HtmlParserService;
76 import org.jahia.services.lock.LockService;
77 import org.jahia.services.mail.MailService;
78 import org.jahia.services.pages.JahiaPageService;
79 import org.jahia.services.pages.JahiaPageTemplateService;
80 import org.jahia.services.search.JahiaSearchService;
81 import org.jahia.services.shares.AppsShareService;
82 import org.jahia.services.sitemap.JahiaSiteMapService;
83 import org.jahia.services.sites.JahiaSitesService;
84 import org.jahia.services.templates_deployer.JahiaTemplatesDeployerService;
85 import org.jahia.services.usermanager.JahiaGroupManagerService;
86 import org.jahia.services.usermanager.JahiaSiteGroupManagerService;
87 import org.jahia.services.usermanager.JahiaSiteUserManagerService;
88 import org.jahia.services.usermanager.JahiaUserManagerService;
89 import org.jahia.services.version.JahiaVersionService;
90 import org.jahia.services.webapps_deployer.JahiaWebAppsDeployerService;
91 import org.jahia.settings.SettingsBean;
92 import org.jahia.services.categories.CategoryService;
93 import org.jahia.mbeans.JahiaMBeanServer;
94 import org.jahia.services.urlrewriting.URLRewritingService;
95 import java.util.Iterator JavaDoc;
96 import org.jahia.services.scheduler.SchedulerService;
97
98
99 /**
100  * The ServicesRegistry class that give a unique access point to Jahia Services.
101  * Services are instanciated and put in an Hashtable.<br>
102  * Services are loaded from properties file.<br>
103  *
104  * @author Eric Vassalli
105  * @author Khue Nguyen
106  * @author Fulco Houkes
107  */

108 public class ServicesRegistry {
109
110     private static org.apache.log4j.Logger logger =
111             org.apache.log4j.Logger.getLogger (ServicesRegistry.class);
112
113
114     /** It's a Singleton **/
115     private static ServicesRegistry theObject = null;
116
117     /** The single point access to services refered by their names *
118      * @associates JahiaService*/

119     private HashMap JavaDoc registry;
120
121     /** Setting used to initialize services **/
122     private SettingsBean jSettings;
123
124     // Jahia Files Services
125
private final String JavaDoc FILE_TRANSFER_SERVICE = "JahiaFileTransferService";
126     private final String JavaDoc TEXT_FILE_SERVICE = "JahiaTextFileService";
127
128     /** Jahia Page Services Name **/
129     private final String JavaDoc JAHIA_PAGE_SERVICE = "JahiaPageService";
130
131     /** Jahia Page Template Service name */
132     private final String JavaDoc JAHIA_PAGE_TEMPLATE_SERVICE = "JahiaPageTemplateService";
133
134     /** Jahia Fields Service Name **/
135     private final String JavaDoc JAHIA_FIELD_SERVICE = "JahiaFieldService";
136
137     /** Jahia Application Dispatching Service Name **/
138     private final String JavaDoc JAHIA_APPLICATIONS_DISPATCHING_SERVICE = "JahiaApplicationsDispatchingService";
139
140     /** Jahia Application Persistance Storage Service **/
141     private final String JavaDoc JAHIA_APPLICATIONS_PERSISTANCE_SERVICE = "JahiaApplicationsPersistanceService";
142
143     private final String JavaDoc JAHIA_INCREMENTORS_DB_SERVICE = "JahiaIncrementorsDBService";
144
145     // Jahia Containers Services
146
private final String JavaDoc JAHIA_CONTAINERS_SERVICE = "JahiaContainersService";
147
148     // Jahia User Manager Service
149
private final String JavaDoc JAHIA_USER_MANAGER_SERVICE = "JahiaUserManagerService";
150     private final String JavaDoc JAHIA_GROUP_MANAGER_SERVICE = "JahiaGroupManagerService";
151     private final String JavaDoc JAHIA_SITE_USER_MANAGER_SERVICE = "JahiaSiteUserManagerService";
152     private final String JavaDoc JAHIA_SITE_GROUP_MANAGER_SERVICE = "JahiaSiteGroupManagerService";
153
154     // Jahia ACL Manager Service
155
private final String JavaDoc JAHIA_ACL_MANAGER_SERVICE = "JahiaACLManagerService";
156
157     // Jahia SearchService
158
private final String JavaDoc JAHIA_SEARCH_SERVICE = "JahiaSearchService";
159
160     // Jahia File Manager Service
161
private final String JavaDoc jahia_filemgr_SERVICE = "JahiaFilemanagerService";
162
163     // Jahia Fetcher Service
164
private final String JavaDoc JAHIA_FETCHER_SERVICE = "JahiaFetcherService";
165
166     // Jahia Templates Deployer Service
167
private final String JavaDoc JAHIA_TEMPLATES_DEPLOYER_SERVICE = "JahiaTemplatesDeployerService";
168
169     // Jahia WebApps Deployer Service
170
private final String JavaDoc JAHIA_WEBAPPS_DEPLOYER_SERVICE = "JahiaWebAppsDeployerService";
171
172     // Jahia FileWatcher Service
173
private final String JavaDoc JAHIA_FILE_WATCHER_SERVICE = "JahiaFileWatcherService";
174
175     // Jahia Event Service
176
private final String JavaDoc JAHIA_EVENT_SERVICE = "JahiaEventService";
177
178     // Jahia Application Manager Service
179
private final String JavaDoc JAHIA_APPLICATIONS_MANAGER_SERVICE = "JahiaApplicationsManagerService";
180
181     // Jahia Application Context Manager Service
182
private final String JavaDoc JAHIA_APPLICATION_CONTEXT_SERVICE = "JahiaApplicationContextService";
183
184     // Jahia Audit Log Manager Service
185
private final String JavaDoc JAHIA_AUDIT_LOG_MANAGER_SERVICE = "JahiaAuditLogManagerService";
186
187     // Jahia Multi Sites Manager Service
188
private final String JavaDoc JAHIA_SITES_SERVICE = "JahiaSitesService";
189
190     // Jahia Applications Share Service
191
private final String JavaDoc JAHIA_APPS_SHARE_SERVICE = "AppsShareService";
192
193     // Jahia Homepages Service
194
private final String JavaDoc JAHIA_HOMEPAGES_SERVICE = "JahiaHomepagesService";
195
196     // Jahia Versioning Service
197
private final String JavaDoc JAHIA_VERSION_SERVICE = "JahiaVersionService";
198
199     // Jahia Html Editors Service
200
private final String JavaDoc JAHIA_HTMLEDITORS_SERVICE = "JahiaHtmlEditorsService";
201
202     // Jahia ResourceBundles Service
203
private final String JavaDoc JAHIA_RESOURCEBUNDLE_SERVICE = "JahiaResourceBundleService";
204
205     // Jahia Cache factory for every cache except the HTML one
206
private final String JavaDoc JAHIA_CACHE_SERVICE = "JahiaCacheService";
207
208     //Jahia site map helper
209
private final String JavaDoc JAHIA_SITE_MAP_SERVICE = "JahiaSiteMapService";
210
211     private final String JavaDoc MAIL_SERVICE = "MailService";
212
213     private final String JavaDoc LOCK_SERVICE = "LockService";
214
215     private final String JavaDoc CATEGORY_SERVICE = "CategoryService";
216
217     private final String JavaDoc HTML_PARSER_SERVICE = "HtmlParserService";
218
219     private final String JavaDoc URL_REWRITING_SERVICE = "URLRewritingService";
220
221     private final String JavaDoc SCHEDULER_SERVICE = "SchedulerService";
222
223     private final String JavaDoc FILEEXTRACTION_SERVICE = "FileExtractionService";
224
225     private final String JavaDoc IMPORTEXPORT_SERVICE = "ImportExportService";
226
227     // BEGIN [added by Pascal Aubry for CAS authentication]
228
private final String JavaDoc CAS_SERVICE = "CasService";
229     // END [added by Pascal Aubry for CAS authentication]
230

231     /** Return the unique instance of this class.
232      *
233      * @return the unique instance of this class
234      */

235     public static synchronized ServicesRegistry getInstance () {
236         if (theObject == null) {
237             theObject = new ServicesRegistry ();
238         }
239         return theObject;
240     }
241
242
243     /** Initialize the Services registry.
244      *
245      * @param jSettings the Jahia settings
246      *
247      * @throws JahiaException
248      * when a service could not be loaded and instanciated.
249      */

250     public void init (SettingsBean jSettings)
251             throws JahiaException
252     {
253         registry = new HashMap JavaDoc(40);
254         this.jSettings = jSettings;
255         Properties JavaDoc fileProperties = this.jSettings.getPropertiesFile ();
256         Vector JavaDoc classNames = new Vector JavaDoc ();
257
258         ////////////////////////////////////////////////////////////////////////////////////////
259
// FIXME -Fulco- : These class names should be extracted automaticaly from the
260
// jahia.properties file. Much better -> use an XML file to store Jahia
261
// properties.
262
// (29 June 2003), this comment is still valid! ;o)
263
////////////////////////////////////////////////////////////////////////////////////////
264

265
266         ////////////////////////////////////////////////////////////////////////////////////////
267
// NOTE -Fulco- : THE CACHE SERVICE AND THE ACL MANAGER MUST BE THE FIRST ONE TO BE
268
// INITIALIZED!!
269
////////////////////////////////////////////////////////////////////////////////////////
270
classNames.add (JAHIA_CACHE_SERVICE);
271         classNames.add (SCHEDULER_SERVICE);
272         classNames.add (JAHIA_ACL_MANAGER_SERVICE);
273
274         classNames.add (JAHIA_INCREMENTORS_DB_SERVICE);
275         classNames.add (FILE_TRANSFER_SERVICE);
276         classNames.add (TEXT_FILE_SERVICE);
277
278         classNames.add (JAHIA_PAGE_TEMPLATE_SERVICE);
279         classNames.add (JAHIA_PAGE_SERVICE);
280
281         classNames.add (JAHIA_FIELD_SERVICE);
282         classNames.add (JAHIA_APPLICATIONS_DISPATCHING_SERVICE);
283         classNames.add (JAHIA_APPLICATIONS_PERSISTANCE_SERVICE);
284         classNames.add (JAHIA_APPLICATIONS_MANAGER_SERVICE);
285         classNames.add (JAHIA_APPLICATION_CONTEXT_SERVICE);
286         classNames.add (JAHIA_CONTAINERS_SERVICE);
287         classNames.add (jahia_filemgr_SERVICE);
288         classNames.add (JAHIA_FETCHER_SERVICE);
289         classNames.add (JAHIA_GROUP_MANAGER_SERVICE);
290         classNames.add (JAHIA_USER_MANAGER_SERVICE);
291         classNames.add (JAHIA_SITE_USER_MANAGER_SERVICE);
292         classNames.add (JAHIA_TEMPLATES_DEPLOYER_SERVICE);
293         classNames.add (JAHIA_WEBAPPS_DEPLOYER_SERVICE);
294         classNames.add (JAHIA_FILE_WATCHER_SERVICE);
295         classNames.add (JAHIA_EVENT_SERVICE);
296         classNames.add (JAHIA_AUDIT_LOG_MANAGER_SERVICE);
297         classNames.add (JAHIA_SITES_SERVICE);
298         classNames.add (JAHIA_SITE_GROUP_MANAGER_SERVICE);
299         classNames.add (JAHIA_APPS_SHARE_SERVICE);
300         classNames.add (JAHIA_HOMEPAGES_SERVICE);
301         classNames.add (JAHIA_VERSION_SERVICE);
302         classNames.add (JAHIA_SITE_MAP_SERVICE);
303         classNames.add (JAHIA_SEARCH_SERVICE);
304         classNames.add (JAHIA_HTMLEDITORS_SERVICE);
305         classNames.add (JAHIA_RESOURCEBUNDLE_SERVICE);
306         classNames.add (MAIL_SERVICE);
307         classNames.add (LOCK_SERVICE);
308         classNames.add (CATEGORY_SERVICE);
309         classNames.add (HTML_PARSER_SERVICE);
310         classNames.add (URL_REWRITING_SERVICE);
311         classNames.add (FILEEXTRACTION_SERVICE);
312         classNames.add (IMPORTEXPORT_SERVICE);
313         // BEGIN [added by Pascal Aubry for CAS authentication]
314
classNames.add (CAS_SERVICE);
315         // END [added by Pascal Aubry for CAS authentication]
316

317         // ... add new services here
318

319         int i;
320         String JavaDoc propClassName, className;
321         for (i = 0; i < classNames.size (); i++) {
322             className = (String JavaDoc)classNames.get (i);
323             propClassName = fileProperties.getProperty (className);
324             if (propClassName != null) {
325                 if ("".equals (propClassName)) {
326                     logger.debug ("Server [" + className + "] deactivated.");
327                 } else {
328                     propClassName.trim ();
329
330                     loadService (className, propClassName);
331                     logger.debug ("Loaded Service [" + className + "] " +
332                             "class [" + propClassName + "]");
333                 }
334             } else {
335                 logger.debug ("Service [" + className +
336                         "] could not be found in the property file ->" +
337                         " STOP JAHIA !");
338
339                 throw new JahiaException ("Services Registry Initialization",
340                         "Could not load the service [" + className + "]",
341                         JahiaException.SERVICE_ERROR,
342                         JahiaException.KISSYOURASSGOODBYE_SEVERITY);
343             }
344         }
345     }
346
347     /**
348      * Shutdowns all the services. In no specific order !
349      */

350     public void shutdown () {
351         Iterator JavaDoc serviceIter = registry.values().iterator();
352         while (serviceIter.hasNext()) {
353             JahiaService curJahiaService = (JahiaService) serviceIter.next();
354             try {
355                 curJahiaService.shutdown();
356             } catch (JahiaException je) {
357                 logger.error("Error while shutting down service " +
358                              curJahiaService.getServiceName(), je);
359             }
360         }
361         registry.clear();
362     }
363
364     // @author NK 21.12.2000
365
/** Retrieve the service instance associated to the service name <code>serviceName</code>.
366      *
367      * @param serviceName the service name
368      * @return the service instance
369      */

370     public JahiaService getService (String JavaDoc serviceName) {
371         return (JahiaService)registry.get (serviceName);
372     } // end getService
373

374
375     // @author NK 21.12.2000
376
/**
377      * method getJahiaFileTransFerService
378      */

379     public JahiaFileTransferService getJahiaFileTransferService () {
380         return (JahiaFileTransferService)registry.get (FILE_TRANSFER_SERVICE);
381     }
382
383
384     // @author NK 21.12.2000
385
/**
386      * method getJahiaFileTransFerService
387      */

388     public JahiaTextFileService getJahiaTextFileService () {
389         return (JahiaTextFileService)registry.get (TEXT_FILE_SERVICE);
390     }
391
392
393     // @author NK 21.12.2000
394
/**
395      * method getJahiaPageService
396      */

397     public JahiaPageService getJahiaPageService () {
398         return (JahiaPageService)registry.get (JAHIA_PAGE_SERVICE);
399     }
400
401
402     // @author NK 21.12.2000
403
/**
404      * method getJahiaPageTemplateService
405      */

406     public JahiaPageTemplateService getJahiaPageTemplateService () {
407         return (JahiaPageTemplateService)registry.
408                 get (JAHIA_PAGE_TEMPLATE_SERVICE);
409     }
410
411
412     // @author NK 21.12.2000
413
/**
414      * method getJahiaFieldService
415      */

416     public JahiaFieldService getJahiaFieldService () {
417         return (JahiaFieldService)registry.get (JAHIA_FIELD_SERVICE);
418     }
419
420
421     // @author NK 21.12.2000
422
/**
423      * method getJahiaApplicationsDispatchingService
424      */

425     public JahiaApplicationsDispatchingService getJahiaApplicationsDispatchingService () {
426         return (JahiaApplicationsDispatchingService)registry.
427                 get (JAHIA_APPLICATIONS_DISPATCHING_SERVICE);
428     }
429
430
431     // @author NK 21.12.2000
432
/**
433      * method getJahiaApplicationsPersistanceService
434      */

435     public JahiaApplicationsPersistanceService getJahiaApplicationsPersistanceService () {
436         return (JahiaApplicationsPersistanceService)registry.
437                 get (JAHIA_APPLICATIONS_PERSISTANCE_SERVICE);
438     }
439
440
441     // @author NK 21.12.2000
442
/**
443      * method getJahiaIncrementorsDBService
444      */

445     public JahiaIncrementorsDBService getJahiaIncrementorsDBService () {
446         return (JahiaIncrementorsDBService)registry.
447                 get (JAHIA_INCREMENTORS_DB_SERVICE);
448     }
449
450
451     /**
452      * Return a reference on the DB User Manager service
453      */

454     public JahiaUserManagerService getJahiaUserManagerService () {
455         return (JahiaUserManagerService)registry.
456                 get (JAHIA_USER_MANAGER_SERVICE);
457     }
458
459
460     /**
461      * Return a reference on the DB User Manager service
462      */

463     public JahiaGroupManagerService getJahiaGroupManagerService () {
464         return (JahiaGroupManagerService)registry.
465                 get (JAHIA_GROUP_MANAGER_SERVICE);
466     }
467
468
469     /**
470      *
471      */

472     public JahiaACLManagerService getJahiaACLManagerService () {
473         return (JahiaACLManagerService)registry.
474                 get (JAHIA_ACL_MANAGER_SERVICE);
475     }
476
477
478     /**
479      *
480      */

481     public JahiaContainersService getJahiaContainersService () {
482         return (JahiaContainersService)registry.
483                 get (JAHIA_CONTAINERS_SERVICE);
484     }
485
486
487     /**
488      * DJ 03.01.2001
489      */

490     public JahiaSearchService getJahiaSearchService () {
491         return (JahiaSearchService)registry.get (JAHIA_SEARCH_SERVICE);
492     }
493
494
495     /**
496      * NK 04.01.2001
497      */

498     public JahiaFilemanagerService getJahiaFilemanagerService () {
499         return (JahiaFilemanagerService)registry.
500                 get (jahia_filemgr_SERVICE);
501     }
502
503
504     /**
505      * EV 11.01.2001
506      */

507     public JahiaFetcherService getJahiaFetcherService () {
508         return (JahiaFetcherService)registry.get (JAHIA_FETCHER_SERVICE);
509     }
510
511
512     /**
513      * NK 20.01.2001
514      */

515     public JahiaTemplatesDeployerService getJahiaTemplatesDeployerService () {
516         return (JahiaTemplatesDeployerService)registry.
517                 get (JAHIA_TEMPLATES_DEPLOYER_SERVICE);
518     }
519
520
521     /**
522      * NK 24.01.2001
523      */

524     public JahiaWebAppsDeployerService getJahiaWebAppsDeployerService () {
525         return (JahiaWebAppsDeployerService)registry.
526                 get (JAHIA_WEBAPPS_DEPLOYER_SERVICE);
527     }
528
529
530     /**
531      * NK 12.01.2001
532      */

533     public JahiaFileWatcherService getJahiaFileWatcherService () {
534         return (JahiaFileWatcherService)registry.
535                 get (JAHIA_FILE_WATCHER_SERVICE);
536     }
537
538
539     /**
540      * EV 12.01.2001
541      */

542     public JahiaEventGeneratorService getJahiaEventService () {
543         return (JahiaEventGeneratorService)registry.
544                 get (JAHIA_EVENT_SERVICE);
545     }
546
547
548     /**
549      * NK 13.02.2001
550      */

551     public JahiaApplicationsManagerService getJahiaApplicationsManagerService () {
552         return (JahiaApplicationsManagerService)registry.
553                 get (JAHIA_APPLICATIONS_MANAGER_SERVICE);
554     }
555
556     /**
557      * NK 18.06.2002
558      */

559     public JahiaApplicationContextService getJahiaApplicationContextService () {
560         return (JahiaApplicationContextService)registry.
561                 get (JAHIA_APPLICATION_CONTEXT_SERVICE);
562     }
563
564     /**
565      * MJ 20.02.2001
566      */

567     public JahiaAuditLogManagerService getJahiaAuditLogManagerService () {
568         return (JahiaAuditLogManagerService)registry.
569                 get (JAHIA_AUDIT_LOG_MANAGER_SERVICE);
570     }
571
572
573     /**
574      * NK 12.03.2001
575      */

576     public JahiaSitesService getJahiaSitesService () {
577         return (JahiaSitesService)registry.get (JAHIA_SITES_SERVICE);
578     }
579
580
581     /**
582      * Return a reference on the DB Site User Manager service
583      */

584     public JahiaSiteUserManagerService getJahiaSiteUserManagerService () {
585         return (JahiaSiteUserManagerService)registry.
586                 get (JAHIA_SITE_USER_MANAGER_SERVICE);
587     }
588
589
590     /**
591      * Return a reference on the DB Site Group Manager service
592      */

593     public JahiaSiteGroupManagerService getJahiaSiteGroupManagerService () {
594         return (JahiaSiteGroupManagerService)registry.
595                 get (JAHIA_SITE_GROUP_MANAGER_SERVICE);
596     }
597
598     /**
599      * Return a reference on the apps share service
600      */

601     public AppsShareService getAppsShareService () {
602         return (AppsShareService)registry.
603                 get (JAHIA_APPS_SHARE_SERVICE);
604     }
605
606     /**
607      * Return a reference to the homepages service
608      */

609     public JahiaHomepagesService getJahiaHomepagesService () {
610         return (JahiaHomepagesService)registry.get (JAHIA_HOMEPAGES_SERVICE);
611     }
612
613     /**
614      * Return a reference to the version service
615      */

616     public JahiaVersionService getJahiaVersionService () {
617         return (JahiaVersionService)registry.get (JAHIA_VERSION_SERVICE);
618     }
619
620     /**
621      * Return a reference to the Jahia Cache Factory service
622      */

623     public CacheFactory getJahiaCacheServiceBis () {
624         return (CacheFactory)registry.get (JAHIA_CACHE_SERVICE);
625     }
626
627     public JahiaSiteMapService getJahiaSiteMapService () {
628         return (JahiaSiteMapService)registry.get (JAHIA_SITE_MAP_SERVICE);
629     }
630
631     public HtmlEditorsService getHtmlEditorsService () {
632         return (HtmlEditorsService)registry.get (JAHIA_HTMLEDITORS_SERVICE);
633     }
634
635     public ResourceBundleService getResourceBundleService () {
636         return (ResourceBundleService)registry.get (this.JAHIA_RESOURCEBUNDLE_SERVICE);
637     }
638
639     public MailService getMailService () {
640         return (MailService)registry.get (this.MAIL_SERVICE);
641     }
642
643     public LockService getLockService () {
644         return (LockService)registry.get (this.LOCK_SERVICE);
645     }
646
647     public CategoryService getCategoryService() {
648         return (CategoryService) registry.get(this.CATEGORY_SERVICE);
649     }
650
651     public HtmlParserService getHtmlParserService() {
652         return (HtmlParserService) registry.get(this.HTML_PARSER_SERVICE);
653     }
654
655     public URLRewritingService getURLRewritingService() {
656         return (URLRewritingService) registry.get(this.URL_REWRITING_SERVICE);
657     }
658
659     public SchedulerService getSchedulerService() {
660         return (SchedulerService) registry.get(this.SCHEDULER_SERVICE);
661     }
662
663     public JahiaFileExtractionService getFileExtractionService() {
664         return (JahiaFileExtractionService) registry.get(this.FILEEXTRACTION_SERVICE);
665     }
666
667     public ImportExportService getImportExportService() {
668         return (ImportExportService) getService(this.IMPORTEXPORT_SERVICE);
669     }
670     
671     // BEGIN [added by Pascal Aubry for CAS authentication]
672
/**
673      * Return a reference to the CAS service.
674      */

675     public CasService getCasService() {
676         return (CasService) registry.get(this.CAS_SERVICE);
677     }
678     // END [added by Pascal Aubry for CAS authentication]
679

680    /** Default constructor, creates a new <code>ServiceRegistry</code> instance.
681     */

682     private ServicesRegistry () {
683         logger.debug("Initializing services registry");
684         registry = new HashMap JavaDoc(40);
685     }
686
687     // @author NK 21.12.2000
688
/**
689      * method loadService
690      */

691     private void loadService (String JavaDoc serviceName, String JavaDoc className)
692             throws JahiaException {
693         try {
694             //logger.debug( "Registry", "ServicesRegistry loads services : serviceName=" + serviceName + ", classe name=" + className );
695

696             // Try to get a service by the getInstance method first
697
JahiaService service = getServiceInstance (className);
698
699             if (service != null) {
700                 registry.put (serviceName, service);
701             } else {
702                 logger.warn("getInstance() method failed for service " + serviceName + ", trying to create using default constructor...");
703                 registry.put (serviceName, Class.forName (className).newInstance ());
704             }
705
706             // Try to initialize the service
707
JahiaService instanceObj = (JahiaService)registry.get (serviceName);
708             instanceObj.setServiceName (serviceName);
709             // logger.debug( "Registry", "Try to init instance of " + serviceName );
710
instanceObj.init (this.jSettings);
711
712             JahiaMBeanServer.getInstance().registerManagedInstance(instanceObj, serviceName, serviceName);
713
714         } catch (ClassNotFoundException JavaDoc cnfe) {
715
716             String JavaDoc errorMsg = "ClassNotFoundException, Error in initializing Service : " + serviceName + ", class=" + className + "\n" + cnfe.toString ();
717             logger.error (errorMsg + " -> BAILING OUT", cnfe);
718             throw new JahiaException ("ClassNotFoundException",
719                     errorMsg, JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY, cnfe);
720
721         } catch (InstantiationException JavaDoc cie) {
722
723             String JavaDoc errorMsg = "InstantiationException, Error in initializing Service : " + serviceName + ", class=" + className + "\n" + cie.toString ();
724             logger.error (errorMsg + " -> BAILING OUT", cie);
725             throw new JahiaException ("InstanciationException",
726                     errorMsg, JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY, cie);
727
728         } catch (IllegalAccessException JavaDoc iae) {
729
730             String JavaDoc errorMsg = "IllegalAccessException,Error in initializing Service : " + serviceName + ", class=" + className + "\n" + iae.toString ();
731             logger.error (errorMsg + " -> BAILING OUT", iae);
732             throw new JahiaException ("IllegalAccessException",
733                     errorMsg, JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY, iae);
734
735         } catch (JahiaInitializationException jie) {
736
737             String JavaDoc errorMsg = "JahiaInitializationException,Error in initializing Service : " + serviceName + ", class=" + className + "\n" + jie.toString ();
738             if (jie.getRootCause () != null) {
739                 logger.error ("Root cause:", jie);
740             }
741             logger.error (errorMsg + " -> BAILING OUT", jie);
742             throw new JahiaException ("JahiaInitializationException",
743                     jie.getJahiaErrorMsg (), JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY, jie);
744         }
745
746         logger.debug("Registering services ended. Current registry size=" + registry.size());
747     }
748
749
750     //* @author NK 21.12.2000
751
/**
752      * Try to instanciate a service by the calling the method getInstance()
753      * For Singleton Service
754      *
755      * @return null if fail
756      */

757     private JahiaService getServiceInstance (String JavaDoc className)
758             throws ClassNotFoundException JavaDoc
759     {
760         JahiaService service = null;
761
762         logger.debug("Attempting to instantiate service class [" + className + "]");
763
764         try {
765
766             Class JavaDoc self = Class.forName (className);
767             java.lang.reflect.Method JavaDoc aMethod =
768                     self.getMethod ("getInstance", null);
769
770             if (aMethod != null) {
771                 try {
772                     service = (JahiaService)aMethod.invoke (self, null);
773
774                 } catch (java.lang.reflect.InvocationTargetException JavaDoc ite) {
775                     logger.error ("Error while invoking singleton constructor for class ["+
776                             className +"]:", ite.getTargetException ());
777                 }
778             }
779
780         } catch (NoSuchMethodException JavaDoc nme) {
781             logger.error (" Class " + className +
782                     " method getInstance NoSuchMethodException ", nme);
783
784         } catch (IllegalAccessException JavaDoc iae) {
785             logger.error (" Class " + className +
786                     " method getInstance IllegalAccessException ", iae);
787
788         } catch (ClassCastException JavaDoc ex) {
789             logger.error ("Class "+ className +" could not be casted into JahiaService");
790         }
791         return service;
792     }
793
794     public HashMap JavaDoc getRegistry() {
795         return registry;
796     }
797
798 }
799
Popular Tags