1 42 43 44 package org.jahia.registries; 45 46 import java.util.HashMap ; 47 import java.util.Properties ; 48 import java.util.Vector ; 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 ; 96 import org.jahia.services.scheduler.SchedulerService; 97 98 99 108 public class ServicesRegistry { 109 110 private static org.apache.log4j.Logger logger = 111 org.apache.log4j.Logger.getLogger (ServicesRegistry.class); 112 113 114 115 private static ServicesRegistry theObject = null; 116 117 119 private HashMap registry; 120 121 122 private SettingsBean jSettings; 123 124 private final String FILE_TRANSFER_SERVICE = "JahiaFileTransferService"; 126 private final String TEXT_FILE_SERVICE = "JahiaTextFileService"; 127 128 129 private final String JAHIA_PAGE_SERVICE = "JahiaPageService"; 130 131 132 private final String JAHIA_PAGE_TEMPLATE_SERVICE = "JahiaPageTemplateService"; 133 134 135 private final String JAHIA_FIELD_SERVICE = "JahiaFieldService"; 136 137 138 private final String JAHIA_APPLICATIONS_DISPATCHING_SERVICE = "JahiaApplicationsDispatchingService"; 139 140 141 private final String JAHIA_APPLICATIONS_PERSISTANCE_SERVICE = "JahiaApplicationsPersistanceService"; 142 143 private final String JAHIA_INCREMENTORS_DB_SERVICE = "JahiaIncrementorsDBService"; 144 145 private final String JAHIA_CONTAINERS_SERVICE = "JahiaContainersService"; 147 148 private final String JAHIA_USER_MANAGER_SERVICE = "JahiaUserManagerService"; 150 private final String JAHIA_GROUP_MANAGER_SERVICE = "JahiaGroupManagerService"; 151 private final String JAHIA_SITE_USER_MANAGER_SERVICE = "JahiaSiteUserManagerService"; 152 private final String JAHIA_SITE_GROUP_MANAGER_SERVICE = "JahiaSiteGroupManagerService"; 153 154 private final String JAHIA_ACL_MANAGER_SERVICE = "JahiaACLManagerService"; 156 157 private final String JAHIA_SEARCH_SERVICE = "JahiaSearchService"; 159 160 private final String jahia_filemgr_SERVICE = "JahiaFilemanagerService"; 162 163 private final String JAHIA_FETCHER_SERVICE = "JahiaFetcherService"; 165 166 private final String JAHIA_TEMPLATES_DEPLOYER_SERVICE = "JahiaTemplatesDeployerService"; 168 169 private final String JAHIA_WEBAPPS_DEPLOYER_SERVICE = "JahiaWebAppsDeployerService"; 171 172 private final String JAHIA_FILE_WATCHER_SERVICE = "JahiaFileWatcherService"; 174 175 private final String JAHIA_EVENT_SERVICE = "JahiaEventService"; 177 178 private final String JAHIA_APPLICATIONS_MANAGER_SERVICE = "JahiaApplicationsManagerService"; 180 181 private final String JAHIA_APPLICATION_CONTEXT_SERVICE = "JahiaApplicationContextService"; 183 184 private final String JAHIA_AUDIT_LOG_MANAGER_SERVICE = "JahiaAuditLogManagerService"; 186 187 private final String JAHIA_SITES_SERVICE = "JahiaSitesService"; 189 190 private final String JAHIA_APPS_SHARE_SERVICE = "AppsShareService"; 192 193 private final String JAHIA_HOMEPAGES_SERVICE = "JahiaHomepagesService"; 195 196 private final String JAHIA_VERSION_SERVICE = "JahiaVersionService"; 198 199 private final String JAHIA_HTMLEDITORS_SERVICE = "JahiaHtmlEditorsService"; 201 202 private final String JAHIA_RESOURCEBUNDLE_SERVICE = "JahiaResourceBundleService"; 204 205 private final String JAHIA_CACHE_SERVICE = "JahiaCacheService"; 207 208 private final String JAHIA_SITE_MAP_SERVICE = "JahiaSiteMapService"; 210 211 private final String MAIL_SERVICE = "MailService"; 212 213 private final String LOCK_SERVICE = "LockService"; 214 215 private final String CATEGORY_SERVICE = "CategoryService"; 216 217 private final String HTML_PARSER_SERVICE = "HtmlParserService"; 218 219 private final String URL_REWRITING_SERVICE = "URLRewritingService"; 220 221 private final String SCHEDULER_SERVICE = "SchedulerService"; 222 223 private final String FILEEXTRACTION_SERVICE = "FileExtractionService"; 224 225 private final String IMPORTEXPORT_SERVICE = "ImportExportService"; 226 227 private final String CAS_SERVICE = "CasService"; 229 231 235 public static synchronized ServicesRegistry getInstance () { 236 if (theObject == null) { 237 theObject = new ServicesRegistry (); 238 } 239 return theObject; 240 } 241 242 243 250 public void init (SettingsBean jSettings) 251 throws JahiaException 252 { 253 registry = new HashMap (40); 254 this.jSettings = jSettings; 255 Properties fileProperties = this.jSettings.getPropertiesFile (); 256 Vector classNames = new Vector (); 257 258 265 266 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 classNames.add (CAS_SERVICE); 315 317 319 int i; 320 String propClassName, className; 321 for (i = 0; i < classNames.size (); i++) { 322 className = (String )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 350 public void shutdown () { 351 Iterator 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 370 public JahiaService getService (String serviceName) { 371 return (JahiaService)registry.get (serviceName); 372 } 374 375 379 public JahiaFileTransferService getJahiaFileTransferService () { 380 return (JahiaFileTransferService)registry.get (FILE_TRANSFER_SERVICE); 381 } 382 383 384 388 public JahiaTextFileService getJahiaTextFileService () { 389 return (JahiaTextFileService)registry.get (TEXT_FILE_SERVICE); 390 } 391 392 393 397 public JahiaPageService getJahiaPageService () { 398 return (JahiaPageService)registry.get (JAHIA_PAGE_SERVICE); 399 } 400 401 402 406 public JahiaPageTemplateService getJahiaPageTemplateService () { 407 return (JahiaPageTemplateService)registry. 408 get (JAHIA_PAGE_TEMPLATE_SERVICE); 409 } 410 411 412 416 public JahiaFieldService getJahiaFieldService () { 417 return (JahiaFieldService)registry.get (JAHIA_FIELD_SERVICE); 418 } 419 420 421 425 public JahiaApplicationsDispatchingService getJahiaApplicationsDispatchingService () { 426 return (JahiaApplicationsDispatchingService)registry. 427 get (JAHIA_APPLICATIONS_DISPATCHING_SERVICE); 428 } 429 430 431 435 public JahiaApplicationsPersistanceService getJahiaApplicationsPersistanceService () { 436 return (JahiaApplicationsPersistanceService)registry. 437 get (JAHIA_APPLICATIONS_PERSISTANCE_SERVICE); 438 } 439 440 441 445 public JahiaIncrementorsDBService getJahiaIncrementorsDBService () { 446 return (JahiaIncrementorsDBService)registry. 447 get (JAHIA_INCREMENTORS_DB_SERVICE); 448 } 449 450 451 454 public JahiaUserManagerService getJahiaUserManagerService () { 455 return (JahiaUserManagerService)registry. 456 get (JAHIA_USER_MANAGER_SERVICE); 457 } 458 459 460 463 public JahiaGroupManagerService getJahiaGroupManagerService () { 464 return (JahiaGroupManagerService)registry. 465 get (JAHIA_GROUP_MANAGER_SERVICE); 466 } 467 468 469 472 public JahiaACLManagerService getJahiaACLManagerService () { 473 return (JahiaACLManagerService)registry. 474 get (JAHIA_ACL_MANAGER_SERVICE); 475 } 476 477 478 481 public JahiaContainersService getJahiaContainersService () { 482 return (JahiaContainersService)registry. 483 get (JAHIA_CONTAINERS_SERVICE); 484 } 485 486 487 490 public JahiaSearchService getJahiaSearchService () { 491 return (JahiaSearchService)registry.get (JAHIA_SEARCH_SERVICE); 492 } 493 494 495 498 public JahiaFilemanagerService getJahiaFilemanagerService () { 499 return (JahiaFilemanagerService)registry. 500 get (jahia_filemgr_SERVICE); 501 } 502 503 504 507 public JahiaFetcherService getJahiaFetcherService () { 508 return (JahiaFetcherService)registry.get (JAHIA_FETCHER_SERVICE); 509 } 510 511 512 515 public JahiaTemplatesDeployerService getJahiaTemplatesDeployerService () { 516 return (JahiaTemplatesDeployerService)registry. 517 get (JAHIA_TEMPLATES_DEPLOYER_SERVICE); 518 } 519 520 521 524 public JahiaWebAppsDeployerService getJahiaWebAppsDeployerService () { 525 return (JahiaWebAppsDeployerService)registry. 526 get (JAHIA_WEBAPPS_DEPLOYER_SERVICE); 527 } 528 529 530 533 public JahiaFileWatcherService getJahiaFileWatcherService () { 534 return (JahiaFileWatcherService)registry. 535 get (JAHIA_FILE_WATCHER_SERVICE); 536 } 537 538 539 542 public JahiaEventGeneratorService getJahiaEventService () { 543 return (JahiaEventGeneratorService)registry. 544 get (JAHIA_EVENT_SERVICE); 545 } 546 547 548 551 public JahiaApplicationsManagerService getJahiaApplicationsManagerService () { 552 return (JahiaApplicationsManagerService)registry. 553 get (JAHIA_APPLICATIONS_MANAGER_SERVICE); 554 } 555 556 559 public JahiaApplicationContextService getJahiaApplicationContextService () { 560 return (JahiaApplicationContextService)registry. 561 get (JAHIA_APPLICATION_CONTEXT_SERVICE); 562 } 563 564 567 public JahiaAuditLogManagerService getJahiaAuditLogManagerService () { 568 return (JahiaAuditLogManagerService)registry. 569 get (JAHIA_AUDIT_LOG_MANAGER_SERVICE); 570 } 571 572 573 576 public JahiaSitesService getJahiaSitesService () { 577 return (JahiaSitesService)registry.get (JAHIA_SITES_SERVICE); 578 } 579 580 581 584 public JahiaSiteUserManagerService getJahiaSiteUserManagerService () { 585 return (JahiaSiteUserManagerService)registry. 586 get (JAHIA_SITE_USER_MANAGER_SERVICE); 587 } 588 589 590 593 public JahiaSiteGroupManagerService getJahiaSiteGroupManagerService () { 594 return (JahiaSiteGroupManagerService)registry. 595 get (JAHIA_SITE_GROUP_MANAGER_SERVICE); 596 } 597 598 601 public AppsShareService getAppsShareService () { 602 return (AppsShareService)registry. 603 get (JAHIA_APPS_SHARE_SERVICE); 604 } 605 606 609 public JahiaHomepagesService getJahiaHomepagesService () { 610 return (JahiaHomepagesService)registry.get (JAHIA_HOMEPAGES_SERVICE); 611 } 612 613 616 public JahiaVersionService getJahiaVersionService () { 617 return (JahiaVersionService)registry.get (JAHIA_VERSION_SERVICE); 618 } 619 620 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 675 public CasService getCasService() { 676 return (CasService) registry.get(this.CAS_SERVICE); 677 } 678 680 682 private ServicesRegistry () { 683 logger.debug("Initializing services registry"); 684 registry = new HashMap (40); 685 } 686 687 691 private void loadService (String serviceName, String className) 692 throws JahiaException { 693 try { 694 696 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 JahiaService instanceObj = (JahiaService)registry.get (serviceName); 708 instanceObj.setServiceName (serviceName); 709 instanceObj.init (this.jSettings); 711 712 JahiaMBeanServer.getInstance().registerManagedInstance(instanceObj, serviceName, serviceName); 713 714 } catch (ClassNotFoundException cnfe) { 715 716 String 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 cie) { 722 723 String 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 iae) { 729 730 String 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 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 757 private JahiaService getServiceInstance (String className) 758 throws ClassNotFoundException 759 { 760 JahiaService service = null; 761 762 logger.debug("Attempting to instantiate service class [" + className + "]"); 763 764 try { 765 766 Class self = Class.forName (className); 767 java.lang.reflect.Method 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 ite) { 775 logger.error ("Error while invoking singleton constructor for class ["+ 776 className +"]:", ite.getTargetException ()); 777 } 778 } 779 780 } catch (NoSuchMethodException nme) { 781 logger.error (" Class " + className + 782 " method getInstance NoSuchMethodException ", nme); 783 784 } catch (IllegalAccessException iae) { 785 logger.error (" Class " + className + 786 " method getInstance IllegalAccessException ", iae); 787 788 } catch (ClassCastException ex) { 789 logger.error ("Class "+ className +" could not be casted into JahiaService"); 790 } 791 return service; 792 } 793 794 public HashMap getRegistry() { 795 return registry; 796 } 797 798 } 799 | Popular Tags |