List of usage examples for org.apache.commons.configuration CombinedConfiguration CombinedConfiguration
public CombinedConfiguration()
CombinedConfiguration
that uses a union combiner. From source file:nl.isaac.dotcms.plugin.configuration.util.EmptyConfiguration.java
public EmptyConfiguration() { super(new CombinedConfiguration()); }
From source file:org.apache.archiva.configuration.FileTypes.java
@PostConstruct public void initialize() { // TODO: why is this done by hand? // TODO: ideally, this would be instantiated by configuration instead, and not need to be a component String errMsg = "Unable to load default archiva configuration for FileTypes: "; try {/*from w ww . j av a 2 s.c o m*/ CommonsConfigurationRegistry commonsRegistry = new CommonsConfigurationRegistry(); // Configure commonsRegistry Field fld = commonsRegistry.getClass().getDeclaredField("configuration"); fld.setAccessible(true); fld.set(commonsRegistry, new CombinedConfiguration()); commonsRegistry.addConfigurationFromResource("org/apache/archiva/configuration/default-archiva.xml"); // Read configuration as it was intended. ConfigurationRegistryReader configReader = new ConfigurationRegistryReader(); Configuration defaultConfig = configReader.read(commonsRegistry); initialiseTypeMap(defaultConfig); } catch (RegistryException e) { throw new RuntimeException(errMsg + e.getMessage(), e); } catch (SecurityException e) { throw new RuntimeException(errMsg + e.getMessage(), e); } catch (NoSuchFieldException e) { throw new RuntimeException(errMsg + e.getMessage(), e); } catch (IllegalArgumentException e) { throw new RuntimeException(errMsg + e.getMessage(), e); } catch (IllegalAccessException e) { throw new RuntimeException(errMsg + e.getMessage(), e); } this.archivaConfiguration.addChangeListener(this); }
From source file:org.apache.james.container.spring.bean.factory.mailrepositorystore.MailRepositoryStoreBeanFactory.java
/** * This method accept a Configuration object as hint and return the * corresponding MailRepository. The Configuration must be in the form of: * <p/>/*from ww w . j a va2 s. c om*/ * <pre> * <repository destinationURL="[URL of this mail repository]" * type="[repository type ex. OBJECT or STREAM or MAIL etc.]" * model="[repository model ex. PERSISTENT or CACHE etc.]"> * [addition configuration] * </repository> * </pre> * * @param destination the destinationURL used to look up the repository * @return the selected repository * @throws MailRepositoryStoreException if any error occurs while parsing the Configuration or * retrieving the MailRepository */ @SuppressWarnings("deprecation") public synchronized MailRepository select(String destination) throws MailRepositoryStoreException { int idx = destination.indexOf(':'); if (idx == -1) throw new MailRepositoryStoreException("Destination is malformed. Must be a valid URL: " + destination); String protocol = destination.substring(0, idx); String repID = destination; MailRepository reply = repositories.get(repID); StringBuffer logBuffer; if (reply != null) { if (getLogger().isDebugEnabled()) { logBuffer = new StringBuffer(128).append("obtained repository: ").append(repID).append(",") .append(reply.getClass()); getLogger().debug(logBuffer.toString()); } return reply; } else { String repClass = classes.get(protocol); if (getLogger().isDebugEnabled()) { logBuffer = new StringBuffer(128).append("obtained repository: ").append(repClass) .append(" to handle: ").append(protocol).append(" with key ").append(protocol); getLogger().debug(logBuffer.toString()); } // If default values have been set, create a new repository // configuration element using the default values // and the values in the selector. // If no default values, just use the selector. final CombinedConfiguration config = new CombinedConfiguration(); HierarchicalConfiguration defConf = defaultConfigs.get(protocol); if (defConf != null) { config.addConfiguration(defConf); } DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); builder.addProperty("[@destinationURL]", destination); config.addConfiguration(builder); try { // Use the classloader which is used for bean instance stuff @SuppressWarnings("unchecked") Class<MailRepository> clazz = (Class<MailRepository>) getBeanFactory().getBeanClassLoader() .loadClass(repClass); reply = (MailRepository) getBeanFactory().autowire(clazz, ConfigurableListableBeanFactory.AUTOWIRE_AUTODETECT, false); if (reply instanceof LogEnabled) { ((LogEnabled) reply).setLog(logger); } if (reply instanceof Configurable) { ((Configurable) reply).configure(config); } reply = (MailRepository) getBeanFactory().initializeBean(reply, protocol); repositories.put(repID, reply); if (getLogger().isInfoEnabled()) { logBuffer = new StringBuffer(128).append("added repository: ").append(repID).append("->") .append(repClass); getLogger().info(logBuffer.toString()); } return reply; } catch (Exception e) { if (getLogger().isWarnEnabled()) { getLogger().warn("Exception while creating repository:" + e.getMessage(), e); } throw new MailRepositoryStoreException("Cannot find or init repository", e); } } }
From source file:org.apache.james.mailrepository.memory.MemoryMailRepositoryStore.java
private CombinedConfiguration createRepositoryCombinedConfig(MailRepositoryUrl mailRepositoryUrl) { CombinedConfiguration config = new CombinedConfiguration(); HierarchicalConfiguration defaultProtocolConfig = perProtocolMailRepositoryDefaultConfiguration .get(mailRepositoryUrl.getProtocol()); if (defaultProtocolConfig != null) { config.addConfiguration(defaultProtocolConfig); }//from w w w. ja va2 s.c om DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); builder.addProperty("[@destinationURL]", mailRepositoryUrl.asString()); config.addConfiguration(builder); return config; }
From source file:org.apache.james.protocols.lib.ProtocolHandlerChainImpl.java
private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration handlerConfig, List<HierarchicalConfiguration> children) throws ConfigurationException { List<String> c = handlersPackage.getHandlers(); for (String cName : c) { try {//from www. j a v a 2 s . co m CombinedConfiguration conf = new CombinedConfiguration(); HierarchicalConfiguration cmdConf = addHandler(cName); conf.addConfiguration(cmdConf); if (handlerConfig != null) { conf.addConfiguration(handlerConfig); } children.add(conf); } catch (ConfigurationException e) { throw new ConfigurationException("Unable to create configuration for handler " + cName, e); } } }
From source file:org.apache.james.utils.InMemoryMailRepositoryStore.java
private CombinedConfiguration createRepositoryCombinedConfig(String destination, String protocol) { final CombinedConfiguration config = new CombinedConfiguration(); HierarchicalConfiguration defaultProtocolConfig = perProtocolMailRepositoryDefaultConfiguration .get(protocol);// w w w.ja va2s . c o m if (defaultProtocolConfig != null) { config.addConfiguration(defaultProtocolConfig); } DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); builder.addProperty("[@destinationURL]", destination); config.addConfiguration(builder); return config; }
From source file:org.atomictagging.core.configuration.ConfigurationTest.java
/** * Setup for the test. Creates a new empty Configuration. * //from ww w .j a va 2s .c o m * @throws Exception */ @Before public void setUp() throws Exception { Field field = Configuration.class.getDeclaredField("conf"); field.setAccessible(true); confBackup = (CombinedConfiguration) field.get(null); field.set(null, new CombinedConfiguration()); }
From source file:org.chenillekit.core.services.impl.ConfigurationServiceImpl.java
/** * get the configuration from the named resource. * * @param configurationResource the configuration resource * @param mergeWithSysProps merge the configuration resource with system properties * * @return the configuration/*from ww w .j ava2 s.c om*/ */ public Configuration getConfiguration(Resource configurationResource, boolean mergeWithSysProps) { Configuration configuration; assert configurationResource != null; if (!configurationResource.exists()) throw new RuntimeException( String.format("configuration resource '%s' not found", configurationResource.toString())); try { if (configurationResource.getFile().endsWith(".xml")) configuration = new XMLConfiguration(configurationResource.toURL()); else if (configurationResource.getFile().endsWith(".properties")) configuration = new PropertiesConfiguration(configurationResource.toURL()); else if (configurationResource.getFile().endsWith(".plist")) configuration = new PropertyListConfiguration(configurationResource.toURL()); else if (configurationResource.getFile().endsWith(".plist")) configuration = new PropertyListConfiguration(configurationResource.toURL()); else if (configurationResource.getFile().endsWith(".ini")) configuration = new HierarchicalINIConfiguration(configurationResource.toURL()); else throw new RuntimeException(String.format("cant resolve configuration type of resource '%s'", configurationResource.toString())); if (mergeWithSysProps) { CombinedConfiguration mergedConfiguration = new CombinedConfiguration(); mergedConfiguration.addConfiguration((AbstractConfiguration) configuration); mergedConfiguration.addConfiguration((AbstractConfiguration) getConfiguration()); configuration = mergedConfiguration; } } catch (ConfigurationException e) { throw new RuntimeException(e); } return configuration; }