List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration
public MapConfiguration(Map map)
From source file:org.apache.marmotta.platform.core.services.modules.ModuleServiceImpl.java
@PostConstruct public void initialize() { //default_container_name = configurationService.getStringConfiguration("kiwi.pages.default_container.name",default_container_name); //default_container_number = configurationService.getIntConfiguration("kiwi.pages.default_container.number",default_container_number); modules = new HashSet<String>(); containers = new HashMap<String, ArrayList<String>>(); container_weight = new HashMap<String, Integer>(); configurationMap = new HashMap<String, Configuration>(); jarURLs = new HashMap<String, Configuration>(); try {/*from w w w . j av a 2s .com*/ Enumeration<URL> modulePropertiesEnum = this.getClass().getClassLoader() .getResources("kiwi-module.properties"); while (modulePropertiesEnum.hasMoreElements()) { URL moduleUrl = modulePropertiesEnum.nextElement(); Configuration moduleProperties = null; try { Set<Configuration> configurations = new HashSet<Configuration>(); // get basic module configuration moduleProperties = new PropertiesConfiguration(moduleUrl); configurations.add(moduleProperties); String moduleName = moduleProperties.getString("name"); modules.add(moduleName); String c_name = moduleProperties.getString("container") != null ? moduleProperties.getString("container") : default_container_name; if (containers.get(c_name) == null) { containers.put(c_name, new ArrayList<String>()); } containers.get(c_name).add(moduleName); if (container_weight.get(c_name) == null) { container_weight.put(c_name, -1); } if (moduleProperties.getString("container.weight") != null) { container_weight.put(c_name, Math.max(container_weight.get(c_name), moduleProperties.getInt("container.weight", -1))); } URLConnection urlConnection = moduleUrl.openConnection(); URL jarUrl; if (urlConnection instanceof JarURLConnection) { JarURLConnection conn = (JarURLConnection) urlConnection; jarUrl = conn.getJarFileURL(); } else { String fileUrl = moduleUrl.toString(); jarUrl = new URL(fileUrl.substring(0, fileUrl.lastIndexOf("/"))); } // get the build information try { PropertiesConfiguration buildInfo = new PropertiesConfiguration( new URL("jar:" + jarUrl.toString() + "!/buildinfo.properties")); buildInfo.setDelimiterParsingDisabled(true); configurations.add(buildInfo); } catch (ConfigurationException ex) { } // alternative: maven buildinfo plugin try { PropertiesConfiguration buildInfo = new PropertiesConfiguration( new URL("jar:" + jarUrl.toString() + "!/build.info")); buildInfo.setDelimiterParsingDisabled(true); configurations.add(buildInfo); } catch (ConfigurationException ex) { } // create runtime configuration MapConfiguration runtimeConfiguration = new MapConfiguration(new HashMap<String, Object>()); runtimeConfiguration.setProperty("runtime.jarfile", jarUrl.toString()); configurations.add(runtimeConfiguration); CompositeConfiguration moduleConfiguration = new CompositeConfiguration(configurations); configurationMap.put(moduleName, moduleConfiguration); jarURLs.put(jarUrl.toString(), moduleConfiguration); } catch (ConfigurationException e) { log.error("error parsing kiwi-module.properties file at {}", moduleUrl, e); } } //TODO container should be sortable } catch (IOException ex) { log.error("I/O error while trying to retrieve kiwi-module.properties file", ex); } }
From source file:org.apache.marmotta.platform.core.services.modules.ModuleServiceImpl.java
/** * Provide the current module configuration to the service injecting it * *//*www .j a v a2 s . c om*/ @Override @Produces public ModuleConfiguration getModuleConfiguration(InjectionPoint injectionPoint) { URL jarUrl = injectionPoint.getMember().getDeclaringClass().getProtectionDomain().getCodeSource() .getLocation(); Configuration cfg = jarURLs.get(jarUrl.toString()); if (cfg != null) { return new ModuleConfiguration(cfg); } else { return new ModuleConfiguration(new MapConfiguration(new HashMap<String, Object>())); } }
From source file:org.apache.marmotta.platform.core.services.modules.ModuleServiceImpl.java
/** * Provide the current module configuration for the given class, i.e. the configuration of the * module containing the class.//from w w w.j a va2 s. c o m */ @Override public ModuleConfiguration getModuleConfiguration(Class<?> cls) { URL jarUrl = cls.getProtectionDomain().getCodeSource().getLocation(); Configuration cfg = jarURLs.get(jarUrl.toString()); if (cfg != null) { return new ModuleConfiguration(cfg); } else { return new ModuleConfiguration(new MapConfiguration(new HashMap<String, Object>())); } }
From source file:org.apache.marmotta.platform.core.services.modules.ModuleServiceImpl.java
/** * Return the configuration for the module identified by the name given as argument. Returns an * immutable Apache Commons Configuration object, or null if the module is not found. * * @param moduleName/*from w w w . ja v a 2 s . com*/ * @return */ @Override public ModuleConfiguration getModuleConfiguration(String moduleName) { Configuration cfg = configurationMap.get(moduleName); if (cfg != null) { return new ModuleConfiguration(cfg); } else { return new ModuleConfiguration(new MapConfiguration(new HashMap<String, Object>())); } }
From source file:org.apache.marmotta.platform.core.test.base.AbstractMarmotta.java
protected AbstractMarmotta() { // initialise JNDI environment try {//from w w w .j a va 2s. com NamingManager.setInitialContextFactoryBuilder(new MarmottaInitialContextFactoryBuilder()); } catch (NamingException e) { } catch (IllegalStateException e) { } // initialise CDI environment weld = new Weld(); container = weld.initialize(); cleanJNDI(); // put bean manager into JNDI try { new InitialContext().bind("java:comp/BeanManager", container.getBeanManager()); } catch (NamingException e) { log.error("error adding bean manager to JNDI", e); } // create temporary marmotta home directory home = Files.createTempDir(); // create a temporary configuration with an in-memory database URL for H2 override = new MapConfiguration(new HashMap<String, Object>()); override.setProperty("database.h2.url", "jdbc:h2:mem;MVCC=true;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=10"); override.setProperty("logging.template", "/logback-testing.xml"); override.setProperty("testing.enabled", true); // initialise marmotta using a temporary directory startupService = getService(MarmottaStartupService.class); }
From source file:org.apache.marmotta.platform.user.services.UserConfigurationServiceImpl.java
public Configuration getUserConfiguration(UserAccount user) { Configuration userConfig = userConfigurations.get(user.getLogin()); if (userConfig == null) { String userConfigFile = configurationService.getConfiguration("kiwi.work.dir") + File.separator + "config" + File.separator + user.getLogin() + ".conf"; try {//from ww w .j a v a2 s . c o m File f = new File(userConfigFile); if (f.exists()) { f.createNewFile(); } userConfig = new PropertiesConfiguration(f); } catch (Exception ex) { log.error("could not create user configuration in file #0: #1", userConfigFile, ex.getMessage()); userConfig = new MapConfiguration(new HashMap<String, Object>()); } userConfigurations.put(user.getLogin(), userConfig); } return userConfig; }
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest.java
@Test public void shouldHandleStrategies() throws Exception { final TinkerGraph graph = TinkerFactory.createModern(); GraphTraversalSource g = graph.traversal(); g = g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() { {/*ww w . j av a2s.c o m*/ put(SubgraphStrategy.VERTICES, __.has("name", "marko")); } }))); final Bindings bindings = new SimpleBindings(); bindings.put("g", g); Traversal.Admin<Vertex, Object> traversal = new GremlinGroovyScriptEngine() .eval(g.V().values("name").asAdmin().getBytecode(), bindings); assertEquals("marko", traversal.next()); assertFalse(traversal.hasNext()); // traversal = new GremlinGroovyScriptEngine() .eval(g.withoutStrategies(SubgraphStrategy.class).V().count().asAdmin().getBytecode(), bindings); assertEquals(new Long(6), traversal.next()); assertFalse(traversal.hasNext()); // traversal = new GremlinGroovyScriptEngine() .eval(g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() { { put(SubgraphStrategy.VERTICES, __.has("name", "marko")); } })), ReadOnlyStrategy.instance()).V().values("name").asAdmin().getBytecode(), bindings); assertEquals("marko", traversal.next()); assertFalse(traversal.hasNext()); }
From source file:org.apache.tinkerpop.gremlin.jsr223.JavaTranslator.java
private Object translateObject(final Object object) { if (object instanceof Bytecode.Binding) return translateObject(((Bytecode.Binding) object).value()); else if (object instanceof Bytecode) { try {/* w w w . j a v a 2s. co m*/ final Traversal.Admin<?, ?> traversal = (Traversal.Admin) this.anonymousTraversal.getMethod("start") .invoke(null); for (final Bytecode.Instruction instruction : ((Bytecode) object).getStepInstructions()) { invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments()); } return traversal; } catch (final Throwable e) { throw new IllegalStateException(e.getMessage()); } } else if (object instanceof TraversalStrategyProxy) { final Map<String, Object> map = new HashMap<>(); final Configuration configuration = ((TraversalStrategyProxy) object).getConfiguration(); configuration.getKeys() .forEachRemaining(key -> map.put(key, translateObject(configuration.getProperty(key)))); try { return map.isEmpty() ? ((TraversalStrategyProxy) object).getStrategyClass().getMethod("instance").invoke(null) : ((TraversalStrategyProxy) object).getStrategyClass() .getMethod("create", Configuration.class).invoke(null, new MapConfiguration(map)); } catch (final NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException(e.getMessage(), e); } } else if (object instanceof Map) { final Map<Object, Object> map = new LinkedHashMap<>(((Map) object).size()); for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { map.put(translateObject(entry.getKey()), translateObject(entry.getValue())); } return map; } else if (object instanceof List) { final List<Object> list = new ArrayList<>(((List) object).size()); for (final Object o : (List) object) { list.add(translateObject(o)); } return list; } else if (object instanceof Set) { final Set<Object> set = new HashSet<>(((Set) object).size()); for (final Object o : (Set) object) { set.add(translateObject(o)); } return set; } else return object; }
From source file:org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ProgramVertexProgramStep.java
public ProgramVertexProgramStep(final Traversal.Admin traversal, final VertexProgram vertexProgram) { super(traversal); this.configuration = new HashMap<>(); final MapConfiguration base = new MapConfiguration(this.configuration); base.setDelimiterParsingDisabled(true); vertexProgram.storeState(base);//from w ww .j a va 2 s. co m this.toStringOfVertexProgram = vertexProgram.toString(); this.traverserRequirements = vertexProgram.getTraverserRequirements(); }
From source file:org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ProgramVertexProgramStep.java
@Override public VertexProgram generateProgram(final Graph graph, final Memory memory) { final MapConfiguration base = new MapConfiguration(this.configuration); base.setDelimiterParsingDisabled(true); PureTraversal.storeState(base, ROOT_TRAVERSAL, TraversalHelper.getRootTraversal(this.getTraversal()).clone()); base.setProperty(STEP_ID, this.getId()); if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS)) TraversalVertexProgram.storeHaltedTraversers(base, memory.get(TraversalVertexProgram.HALTED_TRAVERSERS)); return VertexProgram.createVertexProgram(graph, base); }