List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration
public MapConfiguration(Map map)
From source file:org.apache.james.modules.objectstorage.MapConfigurationBuilder.java
public MapConfiguration build() { return new MapConfiguration(config.build()); }
From source file:org.apache.juddi.config.AppConfig.java
/** * Does the actual work of reading the configuration from System * Properties and/or juddiv3.properties file. When the juddiv3.properties * file is updated the file will be reloaded. By default the reloadDelay is * set to 1 second to prevent excessive date stamp checking. *//* w ww .j av a2s. co m*/ private void loadConfiguration() throws ConfigurationException { //Properties from system properties CompositeConfiguration compositeConfig = new CompositeConfiguration(); compositeConfig.addConfiguration(new SystemConfiguration()); //Properties from file //changed 7-19-2013 AO for JUDDI-627 XMLConfiguration propConfig = null; final String filename = System.getProperty(JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY); if (filename != null) { propConfig = new XMLConfiguration(filename); try { loadedFrom = new File(filename).toURI().toURL(); // propConfig = new PropertiesConfiguration(filename); } catch (MalformedURLException ex) { try { loadedFrom = new URL("file://" + filename); } catch (MalformedURLException ex1) { log.warn("unable to get an absolute path to " + filename + ". This may be ignorable if everything works properly.", ex1); } } } else { //propConfig = new PropertiesConfiguration(JUDDI_PROPERTIES); propConfig = new XMLConfiguration(JUDDI_PROPERTIES); loadedFrom = ClassUtil.getResource(JUDDI_PROPERTIES, this.getClass()); } //Hey! this may break things propConfig.setAutoSave(true); log.info("Reading from properties file: " + loadedFrom); long refreshDelay = propConfig.getLong(Property.JUDDI_CONFIGURATION_RELOAD_DELAY, 1000l); log.debug("Setting refreshDelay to " + refreshDelay); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(refreshDelay); propConfig.setReloadingStrategy(fileChangedReloadingStrategy); compositeConfig.addConfiguration(propConfig); Properties properties = new Properties(); if ("Hibernate".equals(propConfig.getString(Property.PERSISTENCE_PROVIDER))) { if (propConfig.containsKey(Property.DATASOURCE)) properties.put("hibernate.connection.datasource", propConfig.getString(Property.DATASOURCE)); if (propConfig.containsKey(Property.HBM_DDL_AUTO)) properties.put("hibernate.hbm2ddl.auto", propConfig.getString(Property.HBM_DDL_AUTO)); if (propConfig.containsKey(Property.DEFAULT_SCHEMA)) properties.put("hibernate.default_schema", propConfig.getString(Property.DEFAULT_SCHEMA)); if (propConfig.containsKey(Property.HIBERNATE_DIALECT)) properties.put("hibernate.dialect", propConfig.getString(Property.HIBERNATE_DIALECT)); } // initialize the entityManagerFactory. PersistenceManager.initializeEntityManagerFactory(propConfig.getString(Property.JUDDI_PERSISTENCEUNIT_NAME), properties); // Properties from the persistence layer MapConfiguration persistentConfig = new MapConfiguration(getPersistentConfiguration(compositeConfig)); compositeConfig.addConfiguration(persistentConfig); //Making the new configuration globally accessible. config = compositeConfig; }
From source file:org.apache.juddi.config.InstallTest.java
/** * Test of applyReplicationTokenChanges method, of class Install. *///from w w w. j a va 2 s. c o m @Test public void testApplyReplicationTokenChanges() throws Exception { System.out.println("applyReplicationTokenChanges"); InputStream fis = getClass().getClassLoader() .getResourceAsStream("juddi_install_data/root_replicationConfiguration.xml"); ReplicationConfiguration replicationCfg = JAXB.unmarshal(fis, ReplicationConfiguration.class); Properties props = new Properties(); props.put(Property.JUDDI_NODE_ID, "uddi:a_custom_node"); props.put(Property.JUDDI_BASE_URL, "http://juddi.apache.org"); props.put(Property.JUDDI_BASE_URL_SECURE, "https://juddi.apache.org"); Configuration config = new MapConfiguration(props); String thisnode = "uddi:a_custom_node"; ReplicationConfiguration result = Install.applyReplicationTokenChanges(replicationCfg, config, thisnode); StringWriter sw = new StringWriter(); JAXB.marshal(result, sw); Assert.assertFalse(sw.toString().contains("${juddi.nodeId}")); Assert.assertFalse(sw.toString().contains("${juddi.server.baseurlsecure}")); Assert.assertFalse(sw.toString().contains("${juddi.server.baseurl}")); }
From source file:org.apache.marmotta.kiwi.loader.KiWiLoaderConfiguration.java
public KiWiLoaderConfiguration() { this(new MapConfiguration(new HashMap<String, Object>())); }
From source file:org.apache.marmotta.loader.berkeley.BerkeleyDBLoaderBackend.java
/** * Create the RDFHandler to be used for bulk-loading, optionally using the configuration passed as argument. * * @param configuration// www .ja v a2s . c o m * @return a newly created RDFHandler instance */ @Override public LoaderHandler createLoader(Configuration configuration) { Configuration titanCfg = new MapConfiguration(new HashMap<String, Object>()); titanCfg.setProperty("storage.backend", "berkeleyje"); //titanCfg.setProperty("storage.batch-loading", true); if (configuration.containsKey("backend.berkeley.storage-directory")) { titanCfg.setProperty("storage.directory", configuration.getString("backend.berkeley.storage-directory")); } titanCfg.setProperty("storage.buffer-size", 100000); return new TitanLoaderHandler(titanCfg); }
From source file:org.apache.marmotta.loader.core.MarmottaLoader.java
public static Configuration parseOptions(String[] args) throws ParseException { Options options = buildOptions();/* w ww.ja v a 2 s. co m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); Configuration result = new MapConfiguration(new HashMap<String, Object>()); if (cmd.hasOption('B')) { // check backends Set<String> existing = Sets .newHashSet(Iterators.transform(backends.iterator(), new BackendIdentifierFunction())); if (!existing.contains(cmd.getOptionValue('B'))) { throw new ParseException("the backend " + cmd.getOptionValue('B') + " does not exist"); } result.setProperty(LoaderOptions.BACKEND, cmd.getOptionValue('B')); } if (cmd.hasOption('b')) { result.setProperty(LoaderOptions.BASE_URI, cmd.getOptionValue('b')); } if (cmd.hasOption('z')) { result.setProperty(LoaderOptions.COMPRESSION, CompressorStreamFactory.GZIP); } if (cmd.hasOption('j')) { result.setProperty(LoaderOptions.COMPRESSION, CompressorStreamFactory.BZIP2); } if (cmd.hasOption('c')) { result.setProperty(LoaderOptions.CONTEXT, cmd.getOptionValue('c')); } if (cmd.hasOption('t')) { RDFFormat fmt = getRDFFormat(cmd.getOptionValue('t')); if (fmt == null) { throw new ParseException("unrecognized MIME type: " + cmd.getOptionValue('t')); } result.setProperty(LoaderOptions.FORMAT, fmt.getDefaultMIMEType()); } if (cmd.hasOption('f')) { result.setProperty(LoaderOptions.FILES, Arrays.asList(cmd.getOptionValues('f'))); } if (cmd.hasOption('d')) { result.setProperty(LoaderOptions.DIRS, Arrays.asList(cmd.getOptionValues('d'))); } if (cmd.hasOption('a')) { result.setProperty(LoaderOptions.ARCHIVES, Arrays.asList(cmd.getOptionValues('a'))); } if (cmd.hasOption('s')) { result.setProperty(LoaderOptions.STATISTICS_ENABLED, true); result.setProperty(LoaderOptions.STATISTICS_GRAPH, cmd.getOptionValue('s')); } if (cmd.hasOption('D')) { for (Map.Entry e : cmd.getOptionProperties("D").entrySet()) { result.setProperty(e.getKey().toString(), e.getValue()); } } for (LoaderBackend b : backends) { for (Option option : b.getOptions()) { if (cmd.hasOption(option.getOpt())) { String key = String.format("backend.%s.%s", b.getIdentifier(), option.getLongOpt() != null ? option.getLongOpt() : option.getOpt()); if (option.hasArg()) { if (option.hasArgs()) { result.setProperty(key, Arrays.asList(cmd.getOptionValues(option.getOpt()))); } else { result.setProperty(key, cmd.getOptionValue(option.getOpt())); } } else { result.setProperty(key, true); } } } } return result; }
From source file:org.apache.marmotta.loader.core.test.FilesTest.java
public FilesTest(String compression, String filename) { log.info("running test for file {} (compression: {})", filename, compression); cfg = new MapConfiguration(new HashMap<String, Object>()); cfg.setProperty(LoaderOptions.FILES, Collections.singletonList(tempDir.toString() + File.separator + filename)); cfg.setProperty(LoaderOptions.COMPRESSION, compression); }
From source file:org.apache.marmotta.loader.core.test.LoaderTestBase.java
public LoaderTestBase() { cfg = new MapConfiguration(new HashMap<String, Object>()); }
From source file:org.apache.marmotta.loader.hbase.HBaseLoaderBackend.java
/** * Create the RDFHandler to be used for bulk-loading, optionally using the configuration passed as argument. * * @param configuration//w w w . ja va 2 s . c o m * @return a newly created RDFHandler instance */ @Override public LoaderHandler createLoader(Configuration configuration) { Configuration titanCfg = new MapConfiguration(new HashMap<String, Object>()); titanCfg.setProperty("storage.backend", "hbase"); //titanCfg.setProperty("storage.batch-loading", true); if (configuration.containsKey("backend.hbase.host")) { titanCfg.setProperty("storage.hostname", configuration.getString("backend.hbase.host")); } if (configuration.containsKey("backend.hbase.port")) { titanCfg.setProperty("storage.port", configuration.getInt("backend.hbase.port")); } if (configuration.containsKey("backend.hbase.table")) { titanCfg.setProperty("storage.tablename", configuration.getString("backend.hbase.table")); } titanCfg.setProperty("ids.block-size", configuration.getInt("backend.hbase.id-block-size", 500000)); titanCfg.setProperty("storage.buffer-size", 100000); return new TitanLoaderHandler(titanCfg); }
From source file:org.apache.marmotta.platform.core.services.config.ConfigurationServiceImpl.java
/** * Initialise the ConfigurationService. Takes the marmotta.home system property from the servlet * init parameters//from w w w . j a va 2 s. c om * (web.xml) as bootstrap home. In case a system-config.properties file is found in this * directory, the * configuration is then loaded from this file. In case a system-config.properties file does not * yet exist, * the method loads bootstrap settings from the resource default-config.properties in the * classpath (in the * standard bundling, the file is in the kiwi-core-XXX.jar archive). After loading the * configuration, the * service initialises the plugin subsystem and the SOLR home directory by unpacking the default * configuration * if the SOLR configuration does not yet exist. * @param override */ @Override public void initialize(String home, Configuration override) { lock.writeLock().lock(); try { initialising = true; log.info("Apache Marmotta Configuration Service starting up ..."); if (isTomcat7()) { log.info("Apache Marmotta running on Apache Tomcat 7.x"); } else if (isTomcat6()) { log.info("Apache Marmotta running on Apache Tomcat <= 6.x"); } else if (isJetty7()) { log.info("Apache Marmotta running on Jetty 7.x"); } else if (isJetty6()) { log.info("Apache Marmotta running on Jetty <= 6.x"); } else { log.info("Apache Marmotta running on an unknown servlet container"); } setHome(home); if (getHome() != null) { File f1 = new File(getHome()); if (!f1.exists()) { f1.mkdirs(); } // ensure directory for user configuration files File f2 = new File(getHome() + File.separator + DIR_CONFIG); if (!f2.exists()) { f2.mkdirs(); } // ensure directory for logging messages File f3 = new File(getHome() + File.separator + DIR_LOG); if (!f3.exists()) { f3.mkdirs(); } // ensure directory for importing data File f4 = new File(getHome() + File.separator + DIR_IMPORT); if (!f4.exists()) { f4.mkdirs(); } } // the save configuration will be in the home directory try { if (getHome() != null) { configFileName = getHome() + File.separator + "system-config.properties"; metaFileName = getHome() + File.separator + "system-meta.properties"; File configFile = new File(configFileName); if (!configFile.exists()) { log.info("creating system configuration in configuration file {}", configFile.getAbsolutePath()); } else { log.info("reading system configuration from existing configuration file {}", configFile.getAbsolutePath()); } saveConfiguration = new PropertiesConfiguration(configFile); File metaFile = new File(metaFileName); if (!metaFile.exists()) { log.info("creating system configuration metadata in configuration file {}", metaFile.getAbsolutePath()); } else { log.info("reading system configuration metadata from existing configuration file {}", metaFile.getAbsolutePath()); } saveMetadata = new PropertiesConfiguration(metaFile); } else { log.error( "error while initialising configuration: no marmotta.home property given; creating memory-only configuration"); saveConfiguration = new MapConfiguration(new HashMap<String, Object>()); saveMetadata = new MapConfiguration(new HashMap<String, Object>()); } } catch (Exception e) { log.error("error while initialising configuration file {}: {}; creating memory-only configuration", configFileName, e.getMessage()); saveConfiguration = new MapConfiguration(new HashMap<String, Object>()); saveMetadata = new MapConfiguration(new HashMap<String, Object>()); } config = new FallbackConfiguration(); final ConfigurationInterpolator _int = config.getInterpolator(); _int.registerLookup("pattern.quote", new StrLookup() { @Override public String lookup(String key) { return Pattern.quote(_int.getDefaultLookup().lookup(key)); } }); _int.registerLookup("urlencode", new StrLookup() { @Override public String lookup(String key) { try { return URLEncoder.encode(_int.getDefaultLookup().lookup(key), "utf8"); } catch (UnsupportedEncodingException e) { return _int.getDefaultLookup().lookup(key); } } }); config.addConfiguration(saveConfiguration, true); // load all default-config.properties try { Enumeration<URL> configs = this.getClass().getClassLoader() .getResources("config-defaults.properties"); while (configs.hasMoreElements()) { URL url = configs.nextElement(); config.addConfiguration(new PropertiesConfiguration(url)); } } catch (IOException e) { log.error("I/O error while loading default configurations", e); } catch (ConfigurationException e) { log.error("configuration error while loading default configurations", e); } // legacy support (to be removed) try { Enumeration<URL> configs = this.getClass().getClassLoader() .getResources("default-config.properties"); while (configs.hasMoreElements()) { URL url = configs.nextElement(); config.addConfiguration(new PropertiesConfiguration(url)); log.warn( "found legacy configuration file {}; should be replaced with per-module configuration!", url); } } catch (IOException e) { log.error("I/O error while loading default configurations", e); } catch (ConfigurationException e) { log.error("configuration error while loading default configurations", e); } // create the configuration that is responsible for getting metadata about configuration keys in the main // configuration; since the keys will be different, we store changes also to the main save configuration configDescriptions = new FallbackConfiguration(); configDescriptions.addConfiguration(saveMetadata, true); try { Enumeration<URL> configs = this.getClass().getClassLoader() .getResources("config-descriptions.properties"); while (configs.hasMoreElements()) { URL url = configs.nextElement(); configDescriptions.addConfiguration(new PropertiesConfiguration(url)); } } catch (IOException e) { log.error("I/O error while loading configuration descriptions", e); } catch (ConfigurationException e) { log.error("configuration error while loading configuration descriptions", e); } // setup home if it is given as system property, // the bootstrap configuration is overwritten if (getHome() != null) { config.setProperty("marmotta.home", getHome()); } // in case override configuration is given, change all settings in the configuration accordingly if (override != null) { for (Iterator<String> it = override.getKeys(); it.hasNext();) { String key = it.next(); config.setProperty(key, override.getProperty(key)); } } save(); // configuration service is now ready to use initialised = true; loggingStartEvent.fire(new LoggingStartEvent()); // this should maybe move to the KiWiPreStartupFilter ... initDatabaseConfiguration(); save(); log.info("Apache Marmotta Configuration Service: initialisation completed"); configurationInitEvent.fire(new ConfigurationServiceInitEvent()); } finally { lock.writeLock().unlock(); } }