List of usage examples for org.apache.commons.configuration XMLConfiguration containsKey
public boolean containsKey(String key)
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests saving a configuration after cloning to ensure that the clone and * the original are completely detached. *///from w w w . ja va 2 s . c o m @Test public void testCloneWithSave() throws ConfigurationException { XMLConfiguration c = (XMLConfiguration) conf.clone(); c.addProperty("test.newProperty", Boolean.TRUE); conf.addProperty("test.orgProperty", Boolean.TRUE); c.save(testSaveConf); XMLConfiguration c2 = new XMLConfiguration(testSaveConf); assertTrue("New property after clone() was not saved", c2.getBoolean("test.newProperty")); assertFalse("Property of original config was saved", c2.containsKey("test.orgProperty")); }
From source file:org.accada.hal.impl.sim.multi.BatchSimulatorServer.java
/** * Initiziale and start BatchSimulatorServer: * <ul><li>set controller</li> * <li>check and load properties from properties file PROPERTIES_FILE_LOCATION</li> * <li>check the batch file location</li></ul> *//* ww w .j a va 2s . c o m*/ public void initialize(SimulatorServerController controller, String propFile, String defaultPropFile) throws SimulatorServerException { this.controller = controller; // load properties XMLConfiguration props; URL fileurl = ResourceLocator.getURL(propFile, defaultPropFile, this.getClass()); try { props = new XMLConfiguration(fileurl); } catch (ConfigurationException ce) { throw new SimulatorServerException("Could not load the properties file."); } // check properties if (!props.containsKey("batchfile")) { throw new SimulatorServerException("Property 'batchfile' not found."); } if (!props.containsKey("iterations")) { throw new SimulatorServerException("Property 'iterations' not found."); } // get properties batchFile = props.getString("batchfile"); try { iterations = props.getInt("iterations"); } catch (NumberFormatException e) { throw new SimulatorServerException("Property 'iterations' must be a number"); } // check batch file if (!new File(batchFile).exists()) { throw new SimulatorServerException("Batch file '" + batchFile + "' not found."); } start(); }
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. *//*from ww w.j a v a 2s .c om*/ 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:pl.otros.logview.gui.LogViewMainFrame.java
/** * @param args porgram CLI arguments// w w w . j a va 2s . c o m * @throws InitializationException * @throws InvocationTargetException * @throws InterruptedException */ public static void main(final String[] args) throws InitializationException, InterruptedException, InvocationTargetException { if (args.length > 0 && "-batch".equals(args[0])) { try { String[] batchArgs = new String[args.length - 1]; System.arraycopy(args, 1, batchArgs, 0, batchArgs.length); BatchProcessor.main(batchArgs); } catch (IOException e) { System.err.println("Error during batch processing: " + e.getMessage()); e.printStackTrace(); } catch (ConfigurationException e) { System.err.println("Error during batch processing: " + e.getMessage()); e.printStackTrace(); } return; } SingleInstanceRequestResponseDelegate singleInstanceRequestResponseDelegate = SingleInstanceRequestResponseDelegate .getInstance(); singleInstance = SingleInstance.request("OtrosLogViewer", singleInstanceRequestResponseDelegate, singleInstanceRequestResponseDelegate, args); if (singleInstance == null) { LOGGER.info("OtrosLogViewer is already running, params send using requestAction"); System.exit(0); } GuiJulHandler handler = new GuiJulHandler(); handler.setLevel(Level.ALL); Logger olvLogger = Logger.getLogger("pl.otros.logview"); olvLogger.setLevel(Level.ALL); olvLogger.addHandler(handler); LOGGER.info("Starting application"); OtrosSplash.setMessage("Starting application"); OtrosSplash.setMessage("Loading configuration"); final XMLConfiguration c = getConfiguration("config.xml"); if (!c.containsKey(ConfKeys.UUID)) { c.setProperty(ConfKeys.UUID, UUID.randomUUID().toString()); } IconsLoader.loadIcons(); OtrosSplash.setMessage("Loading icons"); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { OtrosSplash.setMessage("Loading L&F"); String lookAndFeel = c.getString("lookAndFeel", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); LOGGER.config("Initializing look and feelL: " + lookAndFeel); PlasticLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE); UIManager.setLookAndFeel(lookAndFeel); } catch (Throwable e1) { LOGGER.warning("Cannot initialize LookAndFeel: " + e1.getMessage()); } try { final DataConfiguration c1 = new OtrosConfiguration(c); final LogViewMainFrame mf = new LogViewMainFrame(c1); // mf.exitAction was instantiated in the constructor (previous line) // Not sure retrieving this from most appropriate Apache config // object. mf.exitAction.setConfirm(c.getBoolean("generalBehavior.confirmExit", true)); /* TODO: Implement User Preferences screen or checkbox on exit widget * that will update the same config object something like: * c.setProperty("generalBehavior.confirmExit", newValue); */ mf.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { c.setProperty("gui.state", mf.getExtendedState()); if (mf.getExtendedState() == Frame.NORMAL) { c.setProperty("gui.width", mf.getWidth()); c.setProperty("gui.height", mf.getHeight()); } } @Override public void componentMoved(ComponentEvent e) { c.setProperty("gui.location.x", mf.getLocation().x); c.setProperty("gui.location.y", mf.getLocation().y); } }); mf.addWindowListener(mf.exitAction); SingleInstanceRequestResponseDelegate.openFilesFromStartArgs(mf.otrosApplication, Arrays.asList(args), mf.otrosApplication.getAppProperties().getCurrentDir()); } catch (InitializationException e) { LOGGER.log(Level.SEVERE, "Cannot initialize main frame", e); } } }); }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
private static XMLConfiguration getConfiguration(String file) { XMLConfiguration commonConfiguration = new XMLConfiguration(); File commonConfigurationFile = new File(file); // load common configuration if (commonConfigurationFile.exists()) { LOGGER.info("Loading common configuration from " + commonConfigurationFile.getAbsolutePath()); try {//from w ww .ja va2s . co m commonConfiguration.load(commonConfigurationFile); } catch (ConfigurationException e) { LOGGER.severe("Can't load configuration, creating new " + e.getMessage()); } } else { LOGGER.info("Common configuration file do not exist"); } // load user specific configuration if (!AllPluginables.USER_CONFIGURATION_DIRECTORY.exists()) { LOGGER.info("Creating user specific OtrosLogViewer configuration directory " + AllPluginables.USER_CONFIGURATION_DIRECTORY.getAbsolutePath()); AllPluginables.USER_CONFIGURATION_DIRECTORY.mkdirs(); AllPluginables.USER_FILTER.mkdirs(); AllPluginables.USER_LOG_IMPORTERS.mkdirs(); AllPluginables.USER_MARKERS.mkdirs(); AllPluginables.USER_MESSAGE_FORMATTER_COLORZIERS.mkdirs(); } XMLConfiguration userConfiguration = new XMLConfiguration(); File userConfigurationFile = new File(AllPluginables.USER_CONFIGURATION_DIRECTORY + File.separator + file); userConfiguration.setFile(userConfigurationFile); if (userConfigurationFile.exists()) { try { userConfiguration.load(); } catch (ConfigurationException e) { LOGGER.severe(String.format("Can't load user configuration from %s: %s", userConfigurationFile.getAbsolutePath(), e.getMessage())); } } Iterator<?> keys = commonConfiguration.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); if (!userConfiguration.containsKey(key)) { userConfiguration.setProperty(key, commonConfiguration.getProperty(key)); } } userConfiguration.setAutoSave(true); return userConfiguration; }