List of usage examples for org.apache.commons.configuration HierarchicalConfiguration HierarchicalConfiguration
public HierarchicalConfiguration(HierarchicalConfiguration c)
HierarchicalConfiguration
and copies all data contained in the specified configuration into the new one. From source file:edu.kit.dama.staging.util.StagingConfigurationManager.java
/** * Perform the configuration for the staging. This covers reading the * configuration from one supported source (env. variable, file, resource) * and the actual setup. If anything fails the staging will not work and a * StagingIntitializationException is thrown. *//*from ww w. j av a 2s.c o m*/ private void configure() { boolean initialized = false; try { LOGGER.debug("Searching for staging configuration URL"); URL configUrl = DataManagerSettings.getConfigurationURL(); if (configUrl == null) { throw new StagingIntitializationException("No configuration file found."); } LOGGER.debug("Trying to configure staging from URL {}", configUrl); stagingConfig = new HierarchicalConfiguration(new XMLConfiguration(configUrl)) .configurationAt(STAGING_CONFIG_ROOT); initialized = true; } catch (org.apache.commons.configuration.ConfigurationException ce) { LOGGER.warn("Failed to configure staging using provided configuration", ce); } if (!initialized) { throw new StagingIntitializationException( "Staging not initialized. Probably, the provided configuration is invalid."); } LOGGER.debug("Configuring staging persistence"); configurePU(stagingConfig); LOGGER.debug("Obtaining staging access points from database"); List<StagingAccessPointConfiguration> accessPoints = StagingConfigurationPersistence.getSingleton(stagingPU) .findAllAccessPointConfigurations(); for (StagingAccessPointConfiguration accessPoint : accessPoints) { configureAccessPoint(accessPoint); } LOGGER.debug("Configurung external adapters"); configureAdapters(stagingConfig); LOGGER.debug("Configuring remote access"); configureRemoteAccess(stagingConfig); LOGGER.debug("Configuring mail notification"); configureMailNotifier(); LOGGER.debug("Configuration finished."); }
From source file:edu.kit.dama.mdm.core.MetaDataManagement.java
/** * Load configuration from XML-File//from w w w .j a va2s. c o m */ private void loadConfiguration() { String firstImplementation = null; String firstPersistenceUnit = null; HierarchicalConfiguration hc = null; List<String> persistenceUnits = null; URL configURL = null; try { configURL = DataManagerSettings.getConfigurationURL(); LOGGER.debug("Loading configuration from {}", configURL); hc = new HierarchicalConfiguration(new XMLConfiguration(configURL)); LOGGER.debug("Configuration successfully loaded"); } catch (ConfigurationException ex) { // error in configuration // reason see debug log message: LOGGER.error("Failed to load configuration.", ex); throw new RuntimeException(ex); } SubnodeConfiguration configurationAt = hc.configurationAt(CONFIG_ROOT); List fields = configurationAt.configurationsAt(CONFIG_PERSISTENCE_IMPL); LOGGER.debug("Found {} configured persistence implementations", fields.size()); persistenceUnitMap = new HashMap<>(); persistenceClassMap = new HashMap<>(); persistenceUnitDefaultMap = new HashMap<>(); String implementationName; IPersistenceFactory iPersistenceFactory = null; for (Iterator it = fields.iterator(); it.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); LOGGER.debug("Reading sub-configuration"); // First get all persistence units. persistenceUnits = new ArrayList<>(); try { List<HierarchicalConfiguration> persistenceUnitsList = sub .configurationsAt(CONFIG_PERSISTENCE_UNIT); if (persistenceUnitsList == null) { persistenceUnitsList = new LinkedList<>(); } LOGGER.debug("Configuration contains {} persistence units.", persistenceUnitsList.size()); firstPersistenceUnit = null; for (HierarchicalConfiguration item : persistenceUnitsList) { String value = item.getString("."); String defaultAttribute = item.getString("[@default]"); LOGGER.debug("PersistenceUnit found: " + value); LOGGER.debug("@default = {}", defaultAttribute); if (Boolean.parseBoolean(defaultAttribute)) { if (firstPersistenceUnit == null) { LOGGER.debug("{} is used as default persistence unit.", value); firstPersistenceUnit = value; } else { LOGGER.warn( "{} is an additional persistence unit defined as default. We'll ignore this.", value); } } LOGGER.debug("Adding persistence unit to list of units."); persistenceUnits.add(value); } } catch (Exception any) { LOGGER.error("Failed to read persistence units.", any); } LOGGER.debug("firstPersistenceUnit: " + firstPersistenceUnit); if ((persistenceUnits.size() > 0) && (firstPersistenceUnit == null)) { LOGGER.debug("No default persistence unit defined. Using first entry ({})", persistenceUnits.get(0)); firstPersistenceUnit = persistenceUnits.get(0); } LOGGER.debug("Getting implementation name."); implementationName = sub.getString(CONFIG_PERSISTENCE_NAME); LOGGER.debug("Implementation name '{}' found.", implementationName); if (firstImplementation == null) { LOGGER.debug("Using implementation '{}' as first implementation.", implementationName); firstImplementation = implementationName; } LOGGER.debug("Testing implementation '{}'", implementationName); if (sub.containsKey(CONFIG_DEFAULT_PERSISTENCE)) { LOGGER.debug("'{}' is configured as default implementation.", implementationName); if (defaultImplementation != null) { LOGGER.warn("{} is an additional implementation defined as default. We'll ignore this.", implementationName); } else { defaultImplementation = implementationName; } } Class<?> loadClass; boolean success = false; String persistenceClass = sub.getString(CONFIG_PERSISTENCE_CLASS); try { LOGGER.debug("Loading class '{}': ", persistenceClass); loadClass = getClass().getClassLoader().loadClass(persistenceClass); LOGGER.debug("Checking IPersistenceFactory.class.assignableFrom({})", persistenceClass); success = IPersistenceFactory.class.isAssignableFrom(loadClass); iPersistenceFactory = null; if (success) { LOGGER.debug("Creating instance of class {}", persistenceClass); iPersistenceFactory = (IPersistenceFactory) loadClass.newInstance(); LOGGER.debug("Persistence factory successfully instantiated."); } else { LOGGER.error("IPersistenceFactory seems not to be assignable from class {}", persistenceClass); } } catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) { LOGGER.error("Failed to create instance of persistence implementation " + persistenceClass, ex); success = false; } if (success) { persistenceUnitMap.put(implementationName, persistenceUnits); persistenceClassMap.put(implementationName, iPersistenceFactory); persistenceUnitDefaultMap.put(implementationName, firstPersistenceUnit); } else { throw new edu.kit.dama.mdm.core.exception.ConfigurationException( "Failed to initialize persistence factory from URL '" + configURL + "'. See logfile for details."); } } if (defaultImplementation == null) { LOGGER.debug("Default implementation not set, yet. Using first one ({}) as default.", firstImplementation); defaultImplementation = firstImplementation; } }
From source file:edu.kit.dama.scheduler.servlet.JobSchedulerInitializerListener.java
/** * Load configuration from XML-File/*w w w. j ava 2 s .c om*/ */ private void loadConfiguration() { URL configURL; HierarchicalConfiguration hc; try { configURL = DataManagerSettings.getConfigurationURL(); LOGGER.debug("Loading configuration from {}", configURL); hc = new HierarchicalConfiguration(new XMLConfiguration(configURL)); LOGGER.debug("Configuration successfully loaded"); } catch (ConfigurationException ex) { // error in configuration // reason see debug log message: LOGGER.warn("Failed to load configuration, using default values.", ex); loadDefaultConfiguration(); return; } SubnodeConfiguration configurationAt = hc.configurationAt(CONFIG_ROOT); if (configurationAt != null) { String jobStoreDriverParam = null; try { jobStoreDriverParam = configurationAt.getString(JOB_STORE_DRIVER, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_DRIVER); } if (jobStoreDriverParam != null) { jobStoreDriver = jobStoreDriverParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_DRIVER, DEFAULT_JOB_STORE_DRIVER); jobStoreDriver = DEFAULT_JOB_STORE_DRIVER; } String jobStoreConnectionStringParam = null; try { jobStoreConnectionStringParam = configurationAt.getString(JOB_STORE_CONNECTION_STRING, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_CONNECTION_STRING); } if (jobStoreConnectionStringParam != null) { jobStoreConnectionString = jobStoreConnectionStringParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_CONNECTION_STRING, DEFAULT_JOB_STORE_CONNECTION_STRING); jobStoreConnectionString = DEFAULT_JOB_STORE_CONNECTION_STRING; } String jobStoreUserParam = null; try { jobStoreUserParam = configurationAt.getString(JOB_STORE_USER, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_USER); } if (jobStoreUserParam != null) { jobStoreUser = jobStoreUserParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_USER, DEFAULT_JOB_STORE_USER); jobStoreUser = DEFAULT_JOB_STORE_USER; } String jobStorePasswordParam = null; try { jobStorePasswordParam = configurationAt.getString(JOB_STORE_PASSWORD, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_PASSWORD); } if (jobStoreUserParam != null) { jobStorePassword = jobStorePasswordParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_PASSWORD, DEFAULT_JOB_STORE_PASSWORD); jobStorePassword = DEFAULT_JOB_STORE_PASSWORD; } Boolean waitOnShutdownParam = null; try { waitOnShutdownParam = configurationAt.getBoolean(CONFIG_WAIT_ON_SHUTDOWN, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", CONFIG_WAIT_ON_SHUTDOWN); } if (waitOnShutdownParam != null) { waitOnShutdown = waitOnShutdownParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_WAIT_ON_SHUTDOWN, DEFAULT_WAIT_ON_SHUTDOWN); waitOnShutdown = DEFAULT_WAIT_ON_SHUTDOWN; } Boolean addDefaultSchedulesParam = null; try { addDefaultSchedulesParam = configurationAt.getBoolean(ADD_DEFAULT_SCHEDULES, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", ADD_DEFAULT_SCHEDULES); } if (addDefaultSchedulesParam != null) { addDefaultSchedules = addDefaultSchedulesParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", ADD_DEFAULT_SCHEDULES, DEFAULT_ADD_DEFAULT_SCHEDULES); addDefaultSchedules = DEFAULT_ADD_DEFAULT_SCHEDULES; } Integer startDelaySecondsParam = null; try { startDelaySecondsParam = configurationAt.getInteger(CONFIG_START_DELAY_SECONDS, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", CONFIG_START_DELAY_SECONDS); } if (startDelaySecondsParam != null) { startDelaySeconds = startDelaySecondsParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_START_DELAY_SECONDS, DEFAULT_START_DELAY_SECONDS); startDelaySeconds = DEFAULT_START_DELAY_SECONDS; } } else { LOGGER.info("No scheduler configuration node found in datamanager config. Using default values."); } }