org.apache.commons.configuration.PatternSubtreeConfigurationWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of driver-cql-shaded Show documentation
Show all versions of driver-cql-shaded Show documentation
A Shaded CQL ActivityType driver for http://nosqlbench.io/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.configuration;
import java.io.Reader;
import java.io.Writer;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.commons.configuration.event.ConfigurationErrorListener;
import org.apache.commons.configuration.event.ConfigurationListener;
import org.apache.commons.configuration.tree.ConfigurationNode;
import org.apache.commons.configuration.tree.ExpressionEngine;
/**
* Wraps a HierarchicalConfiguration and allows subtrees to be access via a configured path with
* replaceable tokens derived from the ConfigurationInterpolator. When used with injection frameworks
* such as Spring it allows components to be injected with subtrees of the configuration.
* @since 1.6
* @author Commons
* Configuration team
* @version $Id: PatternSubtreeConfigurationWrapper.java 1534064 2013-10-21 08:44:33Z henning $
*/
public class PatternSubtreeConfigurationWrapper extends AbstractHierarchicalFileConfiguration
{
/**
* Prevent recursion while resolving unprefixed properties.
*/
private static ThreadLocal recursive = new ThreadLocal()
{
@Override
protected synchronized Boolean initialValue()
{
return Boolean.FALSE;
}
};
/** The wrapped configuration */
private final AbstractHierarchicalFileConfiguration config;
/** The path to the subtree */
private final String path;
/** True if the path ends with '/', false otherwise */
private final boolean trailing;
/** True if the constructor has finished */
private boolean init;
/**
* Constructor
* @param config The Configuration to be wrapped.
* @param path The base path pattern.
*/
public PatternSubtreeConfigurationWrapper(AbstractHierarchicalFileConfiguration config, String path)
{
this.config = config;
this.path = path;
this.trailing = path.endsWith("/");
this.init = true;
}
@Override
public Object getReloadLock()
{
return config.getReloadLock();
}
@Override
public void addProperty(String key, Object value)
{
config.addProperty(makePath(key), value);
}
@Override
public void clear()
{
getConfig().clear();
}
@Override
public void clearProperty(String key)
{
config.clearProperty(makePath(key));
}
@Override
public boolean containsKey(String key)
{
return config.containsKey(makePath(key));
}
@Override
public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
{
return config.getBigDecimal(makePath(key), defaultValue);
}
@Override
public BigDecimal getBigDecimal(String key)
{
return config.getBigDecimal(makePath(key));
}
@Override
public BigInteger getBigInteger(String key, BigInteger defaultValue)
{
return config.getBigInteger(makePath(key), defaultValue);
}
@Override
public BigInteger getBigInteger(String key)
{
return config.getBigInteger(makePath(key));
}
@Override
public boolean getBoolean(String key, boolean defaultValue)
{
return config.getBoolean(makePath(key), defaultValue);
}
@Override
public Boolean getBoolean(String key, Boolean defaultValue)
{
return config.getBoolean(makePath(key), defaultValue);
}
@Override
public boolean getBoolean(String key)
{
return config.getBoolean(makePath(key));
}
@Override
public byte getByte(String key, byte defaultValue)
{
return config.getByte(makePath(key), defaultValue);
}
@Override
public Byte getByte(String key, Byte defaultValue)
{
return config.getByte(makePath(key), defaultValue);
}
@Override
public byte getByte(String key)
{
return config.getByte(makePath(key));
}
@Override
public double getDouble(String key, double defaultValue)
{
return config.getDouble(makePath(key), defaultValue);
}
@Override
public Double getDouble(String key, Double defaultValue)
{
return config.getDouble(makePath(key), defaultValue);
}
@Override
public double getDouble(String key)
{
return config.getDouble(makePath(key));
}
@Override
public float getFloat(String key, float defaultValue)
{
return config.getFloat(makePath(key), defaultValue);
}
@Override
public Float getFloat(String key, Float defaultValue)
{
return config.getFloat(makePath(key), defaultValue);
}
@Override
public float getFloat(String key)
{
return config.getFloat(makePath(key));
}
@Override
public int getInt(String key, int defaultValue)
{
return config.getInt(makePath(key), defaultValue);
}
@Override
public int getInt(String key)
{
return config.getInt(makePath(key));
}
@Override
public Integer getInteger(String key, Integer defaultValue)
{
return config.getInteger(makePath(key), defaultValue);
}
@Override
public Iterator getKeys()
{
return config.getKeys(makePath());
}
@Override
public Iterator getKeys(String prefix)
{
return config.getKeys(makePath(prefix));
}
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy