List of usage examples for org.apache.commons.configuration ConfigurationConverter getMap
public static Map getMap(Configuration config)
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator.java
private String convertToString(final Object object) { if (object instanceof Bytecode.Binding) return ((Bytecode.Binding) object).variable(); else if (object instanceof Bytecode) return this.internalTranslate("__", (Bytecode) object); else if (object instanceof Traversal) return convertToString(((Traversal) object).asAdmin().getBytecode()); else if (object instanceof String) { return (((String) object).contains("\"") ? "\"\"\"" + object + "\"\"\"" : "\"" + object + "\"") .replace("$", "\\$"); } else if (object instanceof Set) { final Set<String> set = new HashSet<>(((Set) object).size()); for (final Object item : (Set) object) { set.add(convertToString(item)); }/*from w w w . jav a2s.c o m*/ return set.toString() + " as Set"; } else if (object instanceof List) { final List<String> list = new ArrayList<>(((List) object).size()); for (final Object item : (List) object) { list.add(convertToString(item)); } return list.toString(); } else if (object instanceof Map) { final StringBuilder map = new StringBuilder("new LinkedHashMap(){{"); for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { map.append("put(").append(convertToString(entry.getKey())).append(",") .append(convertToString(entry.getValue())).append(");"); } return map.append("}}").toString(); } else if (object instanceof Long) return object + "L"; else if (object instanceof Double) return object + "d"; else if (object instanceof Float) return object + "f"; else if (object instanceof Integer) return "(int) " + object; else if (object instanceof Class) return ((Class) object).getCanonicalName(); else if (object instanceof P) return convertPToString((P) object, new StringBuilder()).toString(); else if (object instanceof SackFunctions.Barrier) return "SackFunctions.Barrier." + object.toString(); else if (object instanceof VertexProperty.Cardinality) return "VertexProperty.Cardinality." + object.toString(); else if (object instanceof TraversalOptionParent.Pick) return "TraversalOptionParent.Pick." + object.toString(); else if (object instanceof Enum) return ((Enum) object).getDeclaringClass().getSimpleName() + "." + object.toString(); else if (object instanceof Element) { final String id = convertToString(((Element) object).id()); String temp = this.traversalSource.equals("__") ? "g" : this.traversalSource; if (object instanceof Vertex) temp = temp + ".V(" + id + ").next()"; else if (object instanceof Edge) temp = temp + ".E(" + id + ").next()"; else { final VertexProperty vertexProperty = (VertexProperty) object; temp = temp + ".V(" + convertToString(vertexProperty.element().id()) + ").properties(" + convertToString(vertexProperty.key()) + ").hasId(" + id + ").next()"; } return temp; } else if (object instanceof Lambda) { final String lambdaString = ((Lambda) object).getLambdaScript().trim(); return lambdaString.startsWith("{") ? lambdaString : "{" + lambdaString + "}"; } else if (object instanceof TraversalStrategyProxy) { final TraversalStrategyProxy proxy = (TraversalStrategyProxy) object; if (proxy.getConfiguration().isEmpty()) return proxy.getStrategyClass().getCanonicalName() + ".instance()"; else return proxy.getStrategyClass().getCanonicalName() + ".create(new org.apache.commons.configuration.MapConfiguration(" + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + "))"; } else if (object instanceof TraversalStrategy) { return convertToString(new TraversalStrategyProxy(((TraversalStrategy) object))); } else return null == object ? "null" : object.toString(); }
From source file:org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.java
protected Neo4jGraph(final Configuration configuration) { this.configuration.copy(configuration); final String directory = this.configuration.getString(CONFIG_DIRECTORY); final Map neo4jSpecificConfig = ConfigurationConverter.getMap(this.configuration.subset(CONFIG_CONF)); this.baseGraph = Neo4jFactory.Builder.open(directory, neo4jSpecificConfig); this.initialize(this.baseGraph, configuration); }
From source file:org.apache.tinkerpop.gremlin.python.jsr223.JythonTranslator.java
@Override protected String resolveTraversalStrategyProxy(final TraversalStrategyProxy proxy) { // since this is jython we don't need a traversal proxy here - we need the actual JVM version of the strategy // since this script will be executed in Jython. if (proxy.getConfiguration().isEmpty()) return proxy.getStrategyClass().getCanonicalName() + ".instance()"; else//from w w w.j av a2 s . c o m return proxy.getStrategyClass().getCanonicalName() + ".create(org.apache.commons.configuration.MapConfiguration(" + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + "))"; }
From source file:org.apache.tinkerpop.gremlin.python.jsr223.PythonTranslator.java
protected String convertToString(final Object object) { if (object instanceof Bytecode.Binding) return ((Bytecode.Binding) object).variable(); else if (object instanceof Bytecode) return this.internalTranslate("__", (Bytecode) object); else if (object instanceof Traversal) return convertToString(((Traversal) object).asAdmin().getBytecode()); else if (object instanceof String) return ((String) object).contains("\"") ? "\"\"\"" + object + "\"\"\"" : "\"" + object + "\""; else if (object instanceof Set) { final Set<String> set = new LinkedHashSet<>(((Set) object).size()); for (final Object item : (Set) object) { set.add(convertToString(item)); }// w w w. java 2 s .co m return "set(" + set.toString() + ")"; } else if (object instanceof List) { final List<String> list = new ArrayList<>(((List) object).size()); for (final Object item : (List) object) { list.add(convertToString(item)); } return list.toString(); } else if (object instanceof Map) { final StringBuilder map = new StringBuilder("{"); for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { map.append(convertToString(entry.getKey())).append(":").append(convertToString(entry.getValue())) .append(","); } return map.length() > 1 ? map.substring(0, map.length() - 1) + "}" : map.append("}").toString(); } else if (object instanceof Long) return object + "L"; else if (object instanceof TraversalStrategyProxy) { final TraversalStrategyProxy proxy = (TraversalStrategyProxy) object; if (proxy.getConfiguration().isEmpty()) return "TraversalStrategy(\"" + proxy.getStrategyClass().getSimpleName() + "\")"; else return "TraversalStrategy(\"" + proxy.getStrategyClass().getSimpleName() + "\"," + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + ")"; } else if (object instanceof TraversalStrategy) { return convertToString(new TraversalStrategyProxy((TraversalStrategy) object)); } else if (object instanceof Boolean) return object.equals(Boolean.TRUE) ? "True" : "False"; else if (object instanceof Class) return ((Class) object).getCanonicalName(); else if (object instanceof VertexProperty.Cardinality) return "Cardinality." + SymbolHelper.toPython(object.toString()); else if (object instanceof SackFunctions.Barrier) return "Barrier." + SymbolHelper.toPython(object.toString()); else if (object instanceof TraversalOptionParent.Pick) return "Pick." + SymbolHelper.toPython(object.toString()); else if (object instanceof Enum) return convertStatic(((Enum) object).getDeclaringClass().getSimpleName() + ".") + SymbolHelper.toPython(object.toString()); else if (object instanceof P) return convertPToString((P) object, new StringBuilder()).toString(); else if (object instanceof Element) { final String id = convertToString(((Element) object).id()); if (object instanceof Vertex) return "Vertex(" + id + "," + convertToString(((Vertex) object).label()) + ")"; else if (object instanceof Edge) { final Edge edge = (Edge) object; return "Edge(" + id + "," + convertToString(edge.outVertex()) + "," + convertToString(edge.label()) + "," + convertToString(edge.inVertex()) + ")"; } else { final VertexProperty vertexProperty = (VertexProperty) object; return "VertexProperty(" + id + "," + convertToString(vertexProperty.label()) + "," + convertToString(vertexProperty.value()) + "," + convertToString(vertexProperty.element()) + ")"; } } else if (object instanceof Lambda) return convertLambdaToString((Lambda) object); else return null == object ? "None" : object.toString(); }
From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java
/** * Create a configuration according to the supplied {@link Configuration}; you must include * the property "graph.graphname" with a value in the configuration; you can then * open your graph using graph.graphname without having to supply the * Configuration or File each time using the {@link org.janusgraph.core.ConfiguredGraphFactory}. *///from www .j av a2 s . c o m public void createConfiguration(final Configuration config) { Preconditions.checkArgument(config.containsKey(PROPERTY_GRAPH_NAME), String.format("Please include the property \"%s\" in your configuration.", PROPERTY_GRAPH_NAME)); final Map<Object, Object> map = ConfigurationConverter.getMap(config); final Vertex v = graph.addVertex(T.label, VERTEX_LABEL); map.forEach((key, value) -> v.property((String) key, value)); v.property(PROPERTY_TEMPLATE, false); graph.tx().commit(); }
From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java
/** * Create a template configuration according to the supplied {@link Configuration}; if * you already created a template configuration or the supplied {@link Configuration} * contains the property "graph.graphname", we throw a {@link RuntimeException}; you can then use * this template configuration to create a graph using the * ConfiguredGraphFactory create signature and supplying a new graphName. *///www . ja va 2s .c om public void createTemplateConfiguration(final Configuration config) { Preconditions.checkArgument(!config.containsKey(PROPERTY_GRAPH_NAME), String .format("Your template configuration may not contain the property \"%s\".", PROPERTY_GRAPH_NAME)); Preconditions.checkState(null == getTemplateConfiguration(), "You may only have one template configuration and one exists already."); final Map<Object, Object> map = ConfigurationConverter.getMap(config); final Vertex v = graph.addVertex(); v.property(PROPERTY_TEMPLATE, true); map.forEach((key, value) -> v.property((String) key, value)); graph.tx().commit(); }
From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java
/** * Update configuration corresponding to supplied graphName; we update supplied existing * properties and add new ones to the {@link Configuration}; The supplied {@link Configuration} must include a * property "graph.graphname" and it must match supplied graphName; * NOTE: The updated configuration is only guaranteed to take effect if the {@link Graph} corresponding to * graphName has been closed and reopened on every JanusGraph Node. *///ww w . j a v a2 s .c o m public void updateConfiguration(final String graphName, final Configuration config) { final Map<Object, Object> map = ConfigurationConverter.getMap(config); if (config.containsKey(PROPERTY_GRAPH_NAME)) { final String graphNameOnConfig = (String) map.get(PROPERTY_GRAPH_NAME); Preconditions.checkArgument(graphName.equals(graphNameOnConfig), String.format("Supplied graphName %s does not match property value supplied on config: %s.", graphName, graphNameOnConfig)); } else { map.put(PROPERTY_GRAPH_NAME, graphName); } log.warn( "Configuration {} is only guaranteed to take effect when graph {} has been closed and reopened on all Janus Graph Nodes.", graphName, graphName); updateVertexWithProperties(PROPERTY_GRAPH_NAME, graphName, map); }
From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java
/** * Update template configuration by updating supplied existing properties and adding new ones to the * {@link Configuration}; your updated Configuration may not contain the property "graph.graphname"; * NOTE: Any graph using a configuration that was created using the template configuration must-- * 1) be closed and reopened on every JanusGraph Node 2) have its corresponding Configuration removed * and 3) recreate the graph-- before the update is guaranteed to take effect. *//*from www . j a v a2 s .c om*/ public void updateTemplateConfiguration(final Configuration config) { Preconditions.checkArgument(!config.containsKey(PROPERTY_GRAPH_NAME), String.format( "Your updated template configuration may not contain the property \"%s\".", PROPERTY_GRAPH_NAME)); log.warn( "Any graph configuration created using the template configuration are only guaranteed to have their configuration updated " + "according to this new template configuration when the graph in question has been closed on every Janus Graph Node, its " + "corresponding Configuration has been removed, and the graph has been recreated."); updateVertexWithProperties(PROPERTY_TEMPLATE, true, ConfigurationConverter.getMap(config)); }
From source file:org.seedstack.seed.core.commands.ApplicationConfigurationCommand.java
@Override public Object execute(Object object) throws Exception { return ConfigurationConverter.getMap(application.getConfiguration()); }
From source file:org.seedstack.seed.core.internal.application.ApplicationDiagnosticCollector.java
@Override public Map<String, Object> collect() { Map<String, Object> result = new HashMap<String, Object>(); if (applicationId != null) { result.put("id", applicationId); }/*from w w w . j a v a 2 s .c o m*/ if (applicationName != null) { result.put("name", applicationName); } if (applicationVersion != null) { result.put("version", applicationVersion); } if (activeProfiles != null) { result.put("active-profiles", activeProfiles); } if (storageLocation != null) { result.put("storage-location", storageLocation); } if (configuration != null) { result.put("configuration", ConfigurationConverter.getMap(configuration)); } return result; }