1 17 18 package org.sape.carbon.core.bootstrap; 19 20 import org.sape.carbon.core.component.ComponentKeeper; 21 import org.sape.carbon.core.component.ComponentKeeperConfiguration; 22 import org.sape.carbon.core.component.ComponentKeeperFactory; 23 import org.sape.carbon.core.config.ConfigurationRuntimeException; 24 import org.sape.carbon.core.config.ConfigurationService; 25 import org.sape.carbon.core.config.ConfigurationServiceFactory; 26 import org.sape.carbon.core.config.DefaultConfigurationServiceFactory; 27 import org.sape.carbon.core.config.InvalidConfigurationException; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 33 41 class DefaultLoader implements Loader { 42 43 private Log log = LogFactory.getLog(this.getClass()); 44 45 54 public ConfigurationService fetchConfigurationService() { 55 56 if (log.isTraceEnabled()) { 57 log.trace("Loading Carbon Configuration Service"); 58 } 59 60 Class configurationServiceFactoryClass = null; 62 63 String configurationServiceFactoryClassName = 64 BootStrapper.getInstance(). 65 getDeploymentProperty(CONFIG_SERVICE_FACTORY_PROPERTY); 66 67 if (configurationServiceFactoryClassName == null 68 || configurationServiceFactoryClassName.equals("")) { 69 70 configurationServiceFactoryClassName = 71 DefaultConfigurationServiceFactory.class.getName(); 72 } 73 74 if (log.isTraceEnabled()) { 75 log.trace("ConfigurationServiceFactory to be used [" 76 + configurationServiceFactoryClassName + "]"); 77 } 78 79 try { 80 configurationServiceFactoryClass = Class.forName( 82 configurationServiceFactoryClassName); 83 84 ConfigurationServiceFactory configurationServiceFactory = 86 (ConfigurationServiceFactory) 87 configurationServiceFactoryClass.newInstance(); 88 89 return configurationServiceFactory.getInstance( 92 new BootConfigurationDocument()); 93 94 } catch (ClassNotFoundException cnfe) { 95 throw new BootStrapException(this.getClass(), 96 "Specified ConfigurationServiceFactory [" 97 + configurationServiceFactoryClassName 98 + "] was not found", cnfe); 99 } catch (ClassCastException cce) { 100 throw new BootStrapException(this.getClass(), 101 "Specified ConfigurationServiceFactory [" 102 + configurationServiceFactoryClassName 103 + "] was not of the correct type: [" 104 + ConfigurationServiceFactory.class.getName() + "]", cce); 105 } catch (InstantiationException ie) { 106 throw new BootStrapException(this.getClass(), 107 "Could not instantiate ConfigurationServiceFactory: [" 108 + configurationServiceFactoryClassName + "]", ie); 109 } catch (IllegalAccessException iae) { 110 throw new BootStrapException(this.getClass(), 111 "Could not instantiate ConfigurationServiceFactory: [" 112 + configurationServiceFactoryClassName + "]", iae); 113 } catch (InvalidConfigurationException ice) { 114 throw new BootStrapException (this.getClass(), 115 "Could not load root configuration document due to " + 116 "a missing system property. The property referenced was " + 117 "?? and must be defined if the current type of root " + 118 "deployment is to be used.", ice); 119 } 120 } 121 122 131 public ComponentKeeper fetchComponentKeeper(ConfigurationService 132 configurationService) { 133 134 if (log.isTraceEnabled()) { 135 log.trace("Loading Carbon component keeper Service"); 136 } 137 138 ComponentKeeperConfiguration keeperConfiguration; 139 try { 140 keeperConfiguration = (ComponentKeeperConfiguration) 141 configurationService.fetchConfiguration( 142 DefaultLoader.COMPONENT_KEEPER_CONFIGURATION); 143 } catch (ConfigurationRuntimeException ce) { 144 throw new BootStrapException(this.getClass(), 145 "Caught ConfigurationException while retrieving " 146 + "component keeper configuration", ce); 147 } 148 149 Class keeperFactoryClass = 150 keeperConfiguration.getComponentKeeperFactoryClass(); 151 152 if (log.isTraceEnabled()) { 153 log.trace("Instantiating ComponentKeeperFactory [" 154 + keeperFactoryClass.getName() + "]"); 155 } 156 157 ComponentKeeperFactory keeperFactory; 158 try { 159 keeperFactory = 160 (ComponentKeeperFactory) keeperFactoryClass.newInstance(); 161 } catch (ClassCastException cce) { 162 throw new BootStrapException(this.getClass(), 163 "Specified ComponentKeeperFactory [" 164 + keeperFactoryClass.getName() 165 + "] was not of the correct type: [" 166 + ComponentKeeperFactory.class.getName() + "]", cce); 167 } catch (InstantiationException ie) { 168 throw new BootStrapException(this.getClass(), 169 "Could not instantiate ComponentKeeperFactory: [" 170 + keeperFactoryClass.getName() + "]", ie); 171 } catch (IllegalAccessException iae) { 172 throw new BootStrapException(this.getClass(), 173 "Could not instantiate ComponentKeeperFactory: [" 174 + keeperFactoryClass.getName() + "]", iae); 175 } 176 177 return keeperFactory.getInstance(keeperConfiguration); 179 } 180 181 182 public static final String COMPONENT_KEEPER_CONFIGURATION = 183 "/core/ComponentKeeper"; 184 185 188 public static final String CONFIG_SERVICE_FACTORY_PROPERTY = 189 "carbon.config.ServiceFactory"; 190 191 192 193 } 194 | Popular Tags |