1 13 20 package org.jahia.registries; 21 22 import java.util.Hashtable ; 23 import java.util.Vector ; 24 25 import org.jahia.engines.JahiaEngine; 26 import org.jahia.engines.core.Core_Engine; 27 28 29 public class EnginesRegistry { 30 31 private static EnginesRegistry instance = null; 32 private Hashtable theRegistry; 33 34 35 private static final org.apache.log4j.Logger logger = 36 org.apache.log4j.Logger.getLogger (EnginesRegistry.class); 37 38 39 42 private EnginesRegistry () { 43 } 44 45 46 49 public static synchronized EnginesRegistry getInstance () { 50 if (instance == null) { 51 instance = new EnginesRegistry (); 52 } 53 return instance; 54 } 55 56 57 63 public void init () { 64 72 Vector classes = new Vector (); 73 classes.add ("org.jahia.engines.core.Core_Engine"); 74 classes.add ("org.jahia.engines.updatefield.UpdateField_Engine"); 75 classes.add ("org.jahia.engines.addcontainer.AddContainer_Engine"); 76 classes.add ("org.jahia.engines.updatecontainer.UpdateContainer_Engine"); 77 classes.add ("org.jahia.engines.deletecontainer.DeleteContainer_Engine"); 78 classes.add ("org.jahia.engines.selectdatasource.SelectDataSource_Engine"); 79 classes.add ("org.jahia.engines.xmlsource.XmlSource"); 80 classes.add ("org.jahia.engines.viewdatasourceid.ViewDataSourceID_Engine"); 81 classes.add ("org.jahia.engines.search.Search_Engine"); 82 classes.add ("org.jahia.engines.login.Login_Engine"); 83 classes.add ("org.jahia.engines.logout.Logout_Engine"); 84 classes.add ("org.jahia.engines.filemanager.DAVFilemanager_Engine"); 86 classes.add ("org.jahia.engines.pages.PageProperties_Engine"); 87 classes.add ( 88 "org.jahia.engines.containerlistproperties.ContainerListProperties_Engine"); 89 classes.add ("org.jahia.engines.sitemap.SiteMap_Engine"); 90 classes.add ("org.jahia.engines.selectpage.SelectPage_Engine"); 91 classes.add ("org.jahia.engines.sites.Sites_Engine"); 92 classes.add ("org.jahia.engines.template.Template_Engine"); 93 classes.add ("org.jahia.engines.users.SelectUG_Engine"); 94 classes.add ("org.jahia.engines.versioning.VersioningEngine"); 95 classes.add ("org.jahia.engines.workflow.WorkflowEngine"); 96 classes.add ("org.jahia.engines.lock.LockEngine"); 97 classes.add ("org.jahia.engines.users.EditUserPreferences_Engine"); 98 classes.add ("org.jahia.engines.users.NewUserRegistration_Engine"); 99 classes.add ("org.jahia.engines.mysettings.MySettingsEngine"); 100 classes.add ("org.jahia.engines.importexport.ExportEngine"); 101 102 theRegistry = new Hashtable (); 103 104 for (int i = 0; i < classes.size (); i++) { 105 String className = (String ) classes.get (i); 107 108 try { 110 JahiaEngine engine = getEngineInstance (className); 111 if (engine != null) { 112 theRegistry.put (engine.getName (), engine); 113 logger.debug ("Engine [" + engine.getName () + "] successfully registered."); 114 115 } else { 116 logger.error ("Could not register [" + className + 117 "] engine, null instance returned."); 118 } 119 120 } catch (ClassNotFoundException e) { 121 logger.error ("Could not register [" + className + "] engine", e); 122 } 123 } 124 125 } 126 127 128 132 public Object getEngine (String engineName) { 133 Object engineToGet = theRegistry.get (engineName); 134 if (engineToGet == null) { 135 engineToGet = theRegistry.get (Core_Engine.ENGINE_NAME); 136 } 137 return engineToGet; 138 } 139 140 private JahiaEngine getEngineInstance (String className) 141 throws ClassNotFoundException { 142 JahiaEngine engine = null; 143 144 logger.debug ("Attempting to instantiate engine class [" + className + "]"); 145 try { 146 Class self = Class.forName (className); 147 java.lang.reflect.Method aMethod = self.getMethod ("getInstance", null); 148 149 if (aMethod != null) { 150 try { 151 engine = (JahiaEngine) aMethod.invoke (self, null); 152 153 } catch (java.lang.reflect.InvocationTargetException ite) { 154 logger.error ("Error while invoking singleton constructor for class [" + 155 className + "]:", ite.getTargetException ()); 156 } 157 } else { 158 logger.error ( 159 "Engine [" + className + 160 "] does not have a getInstance() method. Cannot instanciate the engine."); 161 } 162 163 } catch (NoSuchMethodException nme) { 164 logger.error (" Class " + className + 165 " method getInstance NoSuchMethodException ", nme); 166 167 } catch (IllegalAccessException iae) { 168 logger.error (" Class " + className + 169 " method getInstance IllegalAccessException ", iae); 170 171 } catch (ClassCastException ex) { 172 logger.error ("Class " + className + " could not be casted into JahiaEngine"); 173 } 174 return engine; 175 } 176 177 178 } 179 | Popular Tags |