Package org.apache.commons.configuration

Examples of org.apache.commons.configuration.CombinedConfiguration$ConfigData


  public ConfigElement combine(ConfigElement combinee) {
    HierarchicalConfiguration conf2 = this.configuration;
    HierarchicalConfiguration conf1 = ((ConfigurationConfig) combinee).configuration;
    NodeCombiner combiner = new UnionCombiner();
    CombinedConfiguration cc = new CombinedConfiguration(combiner);
    cc.addConfiguration(conf1);
    cc.addConfiguration(conf2);
    ConfigurationConfig combined = new ConfigurationConfig();
    cc.setExpressionEngine(new XPathExpressionEngine());
    combined.configuration = cc;
    return combined;
  }
View Full Code Here


            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 );
View Full Code Here

    }

    public void addConfigurationFromResource( String resource, String prefix )
        throws RegistryException
    {
        CombinedConfiguration configuration = (CombinedConfiguration) this.configuration;
        if ( resource.endsWith( ".properties" ) )
        {
            try
            {
                logger.debug( "Loading properties configuration from classloader resource: {}", resource );
                configuration.addConfiguration( new PropertiesConfiguration( resource ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from resource '" + resource + "': " + e.getMessage(), e );
            }
        }
        else if ( resource.endsWith( ".xml" ) )
        {
            try
            {
                logger.debug( "Loading XML configuration from classloader resource: {}", resource );
                configuration.addConfiguration( new XMLConfiguration( resource ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from resource '" + resource + "': " + e.getMessage(), e );
View Full Code Here

    }

    public void addConfigurationFromFile( File file, String prefix )
        throws RegistryException
    {
        CombinedConfiguration configuration = (CombinedConfiguration) this.configuration;
        if ( file.getName().endsWith( ".properties" ) )
        {
            try
            {
                logger.debug( "Loading properties configuration from file: {}", file );
                configuration.addConfiguration( new PropertiesConfiguration( file ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from file '" + file.getName() + "': " + e.getMessage(), e );
            }
        }
        else if ( file.getName().endsWith( ".xml" ) )
        {
            try
            {
                logger.debug( "Loading XML configuration from file: {}", file );
                configuration.addConfiguration( new XMLConfiguration( file ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from file '" + file.getName() + "': " + e.getMessage(), e );
View Full Code Here

    public void initialize()
        throws RegistryException
    {
        try
        {
            CombinedConfiguration configuration;
            if ( StringUtils.isNotBlank( properties ) )
            {
                try
                {
                    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
                    DefaultExpressionEngine expressionEngine = new DefaultExpressionEngine();
                    expressionEngine.setPropertyDelimiter( propertyDelimiter );
                    builder.setExpressionEngine( expressionEngine );

                    StringSearchInterpolator interpolator = new StringSearchInterpolator( "${", "}" );
                    // interpolation as plexus did it before
                    interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );

                    String interpolatedProps = interpolator.interpolate( properties );

                    logger.debug( "Loading configuration into commons-configuration, xml {}", interpolatedProps );
                    builder.load( new StringReader( interpolatedProps ) );
                    configuration = builder.getConfiguration( false );
                    configuration.setExpressionEngine( expressionEngine );
                    //configuration.set
                }
                catch ( InterpolationException e )
                {
                    throw new RuntimeException( e.getMessage(), e );
                }
            }
            else
            {
                logger.debug( "Creating a default configuration - no configuration was provided" );
                configuration = new CombinedConfiguration();
            }

            configuration.addConfiguration( new SystemConfiguration() );

            this.configuration = configuration;
        }
        catch ( ConfigurationException e )
        {
View Full Code Here

        this.properties = properties;
    }

    public Registry getSection( String name )
    {
        CombinedConfiguration combinedConfiguration = (CombinedConfiguration) configuration;
        Configuration configuration = combinedConfiguration.getConfiguration( name );
        return configuration == null ? null : new CommonsConfigurationRegistry( configuration );
    }
View Full Code Here

            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 );
View Full Code Here

    }

    public void addConfigurationFromResource( String resource, String prefix )
        throws RegistryException
    {
        CombinedConfiguration configuration = (CombinedConfiguration) this.configuration;
        if ( resource.endsWith( ".properties" ) )
        {
            try
            {
                logger.debug( "Loading properties configuration from classloader resource: {}", resource );
                configuration.addConfiguration( new PropertiesConfiguration( resource ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from resource '" + resource + "': " + e.getMessage(), e );
            }
        }
        else if ( resource.endsWith( ".xml" ) )
        {
            try
            {
                logger.debug( "Loading XML configuration from classloader resource: {}", resource );
                configuration.addConfiguration( new XMLConfiguration( resource ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from resource '" + resource + "': " + e.getMessage(), e );
View Full Code Here

    }

    public void addConfigurationFromFile( File file, String prefix )
        throws RegistryException
    {
        CombinedConfiguration configuration = (CombinedConfiguration) this.configuration;
        if ( file.getName().endsWith( ".properties" ) )
        {
            try
            {
                logger.debug( "Loading properties configuration from file: {}", file );
                configuration.addConfiguration( new PropertiesConfiguration( file ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from file '" + file.getName() + "': " + e.getMessage(), e );
            }
        }
        else if ( file.getName().endsWith( ".xml" ) )
        {
            try
            {
                logger.debug( "Loading XML configuration from file: {}", file );
                configuration.addConfiguration( new XMLConfiguration( file ), null, prefix );
            }
            catch ( ConfigurationException e )
            {
                throw new RegistryException(
                    "Unable to add configuration from file '" + file.getName() + "': " + e.getMessage(), e );
View Full Code Here

    public void initialize()
        throws RegistryException
    {
        try
        {
            CombinedConfiguration configuration;
            if ( StringUtils.isNotBlank( properties ) )
            {
                try
                {
                    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
                    DefaultExpressionEngine expressionEngine = new DefaultExpressionEngine();
                    expressionEngine.setPropertyDelimiter( propertyDelimiter );
                    builder.setExpressionEngine( expressionEngine );

                    StringSearchInterpolator interpolator = new StringSearchInterpolator( "${", "}" );
                    // interpolation as plexus did it before
                    interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );

                    String interpolatedProps = interpolator.interpolate( properties );

                    logger.debug( "Loading configuration into commons-configuration, xml {}", interpolatedProps );
                    builder.load( new StringReader( interpolatedProps ) );
                    configuration = builder.getConfiguration( false );
                    configuration.setExpressionEngine( expressionEngine );
                    //configuration.set
                }
                catch ( InterpolationException e )
                {
                    throw new RuntimeException( e.getMessage(), e );
                }
            }
            else
            {
                logger.debug( "Creating a default configuration - no configuration was provided" );
                configuration = new CombinedConfiguration();
            }

            configuration.addConfiguration( new SystemConfiguration() );

            this.configuration = configuration;
        }
        catch ( ConfigurationException e )
        {
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.CombinedConfiguration$ConfigData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.