use of org.apache.commons.configuration.HierarchicalConfiguration in project archaius by Netflix.
the class ConcurrentMapConfigurationTest method testPerformance.
@Test
public void testPerformance() {
MyListener listener = new MyListener();
BaseConfiguration baseConfig = new BaseConfiguration();
baseConfig.addConfigurationListener(listener);
HierarchicalConfiguration hConfig = new HierarchicalConfiguration();
hConfig.addConfigurationListener(listener);
ConcurrentMapConfiguration conf = new ConcurrentMapConfiguration();
conf.addConfigurationListener(listener);
testConfigurationSet(baseConfig);
testConfigurationSet(hConfig);
testConfigurationSet(conf);
testConfigurationAdd(baseConfig);
testConfigurationAdd(hConfig);
testConfigurationAdd(conf);
testConfigurationGet(baseConfig);
testConfigurationGet(hConfig);
testConfigurationGet(conf);
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project blueprints by tinkerpop.
the class Neo4j2GraphConfiguration method configureGraphInstance.
public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException {
final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION);
if (graphFile == null || graphFile.length() == 0) {
throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION);
}
final boolean highAvailabilityMode = context.getProperties().getBoolean(Tokens.REXSTER_GRAPH_HA, false);
// get the <properties> section of the xml configuration
final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties();
SubnodeConfiguration neo4jSpecificConfiguration;
try {
neo4jSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES);
} catch (IllegalArgumentException iae) {
throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES);
}
try {
// properties to initialize the neo4j instance.
final HashMap<String, String> neo4jProperties = new HashMap<String, String>();
// read the properties from the xml file and convert them to properties
// to be injected into neo4j.
final Iterator<String> neo4jSpecificConfigurationKeys = neo4jSpecificConfiguration.getKeys();
while (neo4jSpecificConfigurationKeys.hasNext()) {
String key = neo4jSpecificConfigurationKeys.next();
// replace the ".." put in play by apache commons configuration. that's expected behavior
// due to parsing key names to xml.
neo4jProperties.put(key.replace("..", "."), neo4jSpecificConfiguration.getString(key));
}
if (highAvailabilityMode) {
if (!neo4jProperties.containsKey("ha.machine_id")) {
throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.machine_id] in the <properties> of the configuration");
}
if (!neo4jProperties.containsKey("ha.server")) {
throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.server] <properties> of the configuration");
}
if (!neo4jProperties.containsKey("ha.initial_hosts")) {
throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.initial_hosts] <properties> of the configuration");
}
return new Neo4j2HaGraph(graphFile, neo4jProperties);
} else {
return new Neo4j2Graph(graphFile, neo4jProperties);
}
} catch (GraphConfigurationException gce) {
throw gce;
} catch (Exception ex) {
throw new GraphConfigurationException(ex);
}
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.
the class OptionsParamApi method setPermittedAddresses.
/**
* Sets the client addresses that will be allowed to access the API.
*
* @param addrs the client addresses that will be allowed to access the API.
* @since TODO Add Version
*/
public void setPermittedAddresses(List<DomainMatcher> addrs) {
if (addrs == null || addrs.isEmpty()) {
((HierarchicalConfiguration) getConfig()).clearTree(ADDRESS_KEY);
this.permittedAddresses = Collections.emptyList();
this.permittedAddressesEnabled = Collections.emptyList();
return;
}
this.permittedAddresses = new ArrayList<>(addrs);
((HierarchicalConfiguration) getConfig()).clearTree(ADDRESS_KEY);
int size = addrs.size();
ArrayList<DomainMatcher> enabledAddrs = new ArrayList<>(size);
for (int i = 0; i < size; ++i) {
String elementBaseKey = ADDRESS_KEY + "(" + i + ").";
DomainMatcher addr = addrs.get(i);
getConfig().setProperty(elementBaseKey + ADDRESS_VALUE_KEY, addr.getValue());
getConfig().setProperty(elementBaseKey + ADDRESS_REGEX_KEY, Boolean.valueOf(addr.isRegex()));
getConfig().setProperty(elementBaseKey + ADDRESS_ENABLED_KEY, Boolean.valueOf(addr.isEnabled()));
if (addr.isEnabled()) {
enabledAddrs.add(addr);
}
}
enabledAddrs.trimToSize();
this.permittedAddressesEnabled = enabledAddrs;
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.
the class ExtensionParam method parse.
@Override
protected void parse() {
try {
List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_EXTENSIONS_KEY);
Map<String, Boolean> extensions = new HashMap<>();
for (HierarchicalConfiguration sub : fields) {
if (!sub.getBoolean(EXTENSION_ENABLED_KEY, true)) {
extensions.put(sub.getString(EXTENSION_NAME_KEY, ""), Boolean.FALSE);
}
}
extensionsState = Collections.unmodifiableMap(extensions);
} catch (ConversionException e) {
LOGGER.error("Error while loading extensions' state: " + e.getMessage(), e);
extensionsState = Collections.emptyMap();
}
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.
the class AddOnLoader method saveAddOnsRunState.
private static void saveAddOnsRunState(Map<AddOn, List<String>> runnableAddOns) {
HierarchicalConfiguration config = (HierarchicalConfiguration) Model.getSingleton().getOptionsParam().getConfig();
config.clearTree(ADDONS_RUNNABLE_BASE_KEY);
int i = 0;
for (Map.Entry<AddOn, List<String>> runnableAddOnEntry : runnableAddOns.entrySet()) {
String elementBaseKey = ADDONS_RUNNABLE_KEY + "(" + i + ").";
AddOn addOn = runnableAddOnEntry.getKey();
config.setProperty(elementBaseKey + ADDON_RUNNABLE_ID_KEY, addOn.getId());
config.setProperty(elementBaseKey + ADDON_RUNNABLE_VERSION_KEY, Integer.valueOf(addOn.getFileVersion()));
String extensionBaseKey = elementBaseKey + ADDON_RUNNABLE_ALL_EXTENSIONS_KEY;
for (String extension : runnableAddOnEntry.getValue()) {
config.addProperty(extensionBaseKey, extension);
}
i++;
}
try {
Model.getSingleton().getOptionsParam().getConfig().save();
} catch (ConfigurationException e) {
logger.error("Failed to save state of runnable add-ons:", e);
}
}
Aggregations