Java Code Examples for org.apache.commons.configuration.ConfigurationException

The following are top voted examples for showing how to use org.apache.commons.configuration.ConfigurationException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: KernelHive   File: KernelRepository.java   View source code 6 votes vote down vote up
@Override
public KernelRepositoryEntry getEntryForGraphNodeType(GraphNodeType type)
		throws ConfigurationException {
	config.load(resource);
	
	List<ConfigurationNode> entryNodes = config.getRootNode().getChildren(ENTRY_NODE);
	for(ConfigurationNode node : entryNodes){
		List<ConfigurationNode> typeAttrList = node.getAttributes(ENTRY_NODE_TYPE_ATTRIBUTE);
		
		if(typeAttrList.size()>0){
			String val = (String) typeAttrList.get(0).getValue();
			
			if(type.equals(GraphNodeType.getType(val))){
				return getEntryFromConfigurationNode(node);
			}
		} else{
			throw new ConfigurationException("KH: no required '"+ENTRY_NODE_TYPE_ATTRIBUTE+"' attribute in "+ENTRY_NODE+" node");
		}
	}
	
	return null;
}
 
Example 2
Project: KernelHive   File: RemoteRepositoryConfiguration.java   View source code 6 votes vote down vote up
/**
 * gets instance
 * 
 * @return {@link AppConfiguration} instance
 */
public static RemoteRepositoryConfiguration getInstance() {
	if (_commonConfig == null) {
		try {
			_commonConfig = new RemoteRepositoryConfiguration();
			_commonConfig.reloadConfiguration();
			return _commonConfig;
		} catch (final ConfigurationException e) {
			LOG.severe("KH: " + e.getMessage());
			e.printStackTrace();
			return null;
		}
	} else {
		return _commonConfig;
	}
}
 
Example 3
Project: loom   File: FakeAdapterTest.java   View source code 6 votes vote down vote up
private PropertiesConfiguration loadProperties() throws ConfigurationException {
    String deploymentProperties = "src/test/resources/deployment-fakeAdapterTest.properties";
    PropertiesConfiguration props = new PropertiesConfiguration(deploymentProperties);
    return props;
    // try {
    // Properties prop = null;
    // Resource res = appContext.getResource(deploymentProperties);
    // InputStream in = res.getInputStream();
    // if (in == null) {
    // LOG.warn("Failed to locate properties file on classpath: " + deploymentProperties);
    // } else {
    // LOG.info("Found '" + deploymentProperties + "' on the classpath");
    // prop = new Properties();
    // prop.load(in);
    // }
    // return prop;
    // } catch (IOException e) {
    // LOG.error("Failed to load properties file '" + deploymentProperties + "'", e);
    // throw new RuntimeException("Failed to initialise from properties file " +
    // deploymentProperties);
    // }
}
 
Example 4
Project: openNaEF   File: BuilderConfiguration.java   View source code 6 votes vote down vote up
@Override
protected synchronized void reloadConfigurationInner() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        String __isSystemUserUpdateEnabled = config.getString(KEY_ENABLE_SYSTEM_USER_UPDATE);
        boolean _isSystemUserUpdateEnabled = (__isSystemUserUpdateEnabled == null ? false :
                Boolean.parseBoolean(__isSystemUserUpdateEnabled));

        this.isSystemUserUpdateEnabled = _isSystemUserUpdateEnabled;

        log().info("isSystemUserUpdateEnabled=" + this.isSystemUserUpdateEnabled);
        log().info("reload finished.");
    } catch (ConfigurationException e) {
        log().error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + FILE_NAME);
    }
}
 
Example 5
Project: openNaEF   File: NmsCoreRsvpLspConfiguration.java   View source code 6 votes vote down vote up
@Override
protected boolean loadExtraConfigration() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        for (Object obj : config.getRootNode().getChildren()) {
            Node node = (Node) obj;
            if (node.getName().equals(KEY_HOP_IP_PATH_FIELD_NAME)) {
                List<String> values = new ArrayList<String>();

                for (Object value : node.getChildren()) {
                    values.add((String) ((Node) value).getValue());
                }
                setHopIpPathFieldsName(values);
                return true;
            }
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + getConfigFile());
    }
    return false;
}
 
Example 6
Project: KernelHive   File: EngineGraphConfiguration.java   View source code 6 votes vote down vote up
private Node createGraphNodeForEngine(final EngineGraphNodeDecorator node)
		throws ConfigurationException {
	try {
		final Node configNode = createNodeForEngine(node);
		final Node sendToNode = createSendToSubNode(node.getGraphNode());
		final Node childrenNode = createChildrenSubNode(node.getGraphNode());
		final Node propertiesNode = createPropertiesSubNode(node
				.getGraphNode());
		final Node sourcesNode = createKernelsSubNode(node);
		configNode.addChild(childrenNode);
		configNode.addChild(sendToNode);
		configNode.addChild(propertiesNode);
		configNode.addChild(sourcesNode);
		return configNode;
	} catch (final NullPointerException e) {
		throw new ConfigurationException(e);
	}
}
 
Example 7
Project: KernelHive   File: EngineGraphConfiguration.java   View source code 6 votes vote down vote up
private IKernelString loadKernel(final ConfigurationNode node)
		throws ConfigurationException {
	String src;
	String srcId;

	final List<ConfigurationNode> idSourceAttrs = node
			.getAttributes(KERNEL_ID_ATTRIBUTE);
	if (idSourceAttrs.size() > 0) {
		srcId = (String) idSourceAttrs.get(0).getValue();
	} else {
		throw new ConfigurationException("KH: no required attribute '"
				+ KERNEL_ID_ATTRIBUTE + "' found in " + KERNEL + " node");
	}

	final List<ConfigurationNode> srcAttrs = node
			.getAttributes(KERNEL_SRC_ATTRIBUTE);
	if (srcAttrs.size() > 0) {
		src = (String) srcAttrs.get(0).getValue();
	} else {
		throw new ConfigurationException(
				"KH: no required attribute 'src' in " + KERNEL + " node");
	}

	final Map<String, Object> properties = loadKernelProperties(node);
	return new KernelString(srcId, src, properties);
}
 
Example 8
Project: openNaEF   File: NmsCorePseudoWireConfiguration.java   View source code 6 votes vote down vote up
@Override
protected boolean loadExtraConfigration() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        for (Object obj : config.getRootNode().getChildren()) {
            Node node = (Node) obj;
            if (node.getName().equals(KEY_RELATED_LSP_FIELD_NAME)) {
                setRelatedRsvplspFieldName((String) node.getValue());
                return true;
            }
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + getConfigFile());
    }
    return false;
}
 
Example 9
Project: athena   File: YangXmlUtilsTest.java   View source code 6 votes vote down vote up
/**
 * Tests getting a single object configuration via passing the path and the map of the desired values.
 *
 * @throws ConfigurationException if the testing xml file is not there.
 */
@Test
public void testGetXmlConfigurationFromMap() throws ConfigurationException {
    Map<String, String> pathAndValues = new HashMap<>();
    pathAndValues.put("capable-switch.id", "openvswitch");
    pathAndValues.put("switch.id", "ofc-bridge");
    pathAndValues.put("controller.id", "tcp:1.1.1.1:1");
    pathAndValues.put("controller.ip-address", "1.1.1.1");
    XMLConfiguration cfg = utils.getXmlConfiguration(OF_CONFIG_XML_PATH, pathAndValues);
    testCreateConfig.load(getClass().getResourceAsStream("/testCreateSingleYangConfig.xml"));
    assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);

    assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()),
                 IteratorUtils.toList(cfg.getKeys()));

    assertEquals("Wrong string configuaration", utils.getString(testCreateConfig),
                 utils.getString(cfg));
}
 
Example 10
Project: KernelHive   File: GUIGraphConfiguration.java   View source code 6 votes vote down vote up
private Node createGraphNodeForGUI(GUIGraphNodeDecorator node, File file)
		throws ConfigurationException {
	try {
		Node configNode = createNodeForGUI(node);
		Node sendToNode = createSendToSubNode(node.getGraphNode());
		Node childrenNode = createChildrenSubNode(node.getGraphNode());
		Node propertiesNode = createPropertiesSubNode(node.getGraphNode());
		Node sourcesNode = createSourceFilesSubNode(node, file);
		configNode.addChild(childrenNode);
		configNode.addChild(sendToNode);
		configNode.addChild(propertiesNode);
		configNode.addChild(sourcesNode);
		return configNode;
	} catch (NullPointerException e) {
		throw new ConfigurationException(e);
	}
}
 
Example 11
Project: athena   File: YangXmlUtilsTest.java   View source code 6 votes vote down vote up
/**
 * Tests getting a multiple object nested configuration via passing the path
 * and a list of YangElements containing with the element and desired value.
 *
 * @throws ConfigurationException
 */
@Test
public void getXmlConfigurationFromYangElements() throws ConfigurationException {

    assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);
    testCreateConfig.load(getClass().getResourceAsStream("/testYangConfig.xml"));
    List<YangElement> elements = new ArrayList<>();
    elements.add(new YangElement("capable-switch", ImmutableMap.of("id", "openvswitch")));
    elements.add(new YangElement("switch", ImmutableMap.of("id", "ofc-bridge")));
    List<ControllerInfo> controllers =
            ImmutableList.of(new ControllerInfo(IpAddress.valueOf("1.1.1.1"), 1, "tcp"),
                             new ControllerInfo(IpAddress.valueOf("2.2.2.2"), 2, "tcp"));
    controllers.stream().forEach(cInfo -> {
        elements.add(new YangElement("controller", ImmutableMap.of("id", cInfo.target(),
                                                                   "ip-address", cInfo.ip().toString())));
    });
    XMLConfiguration cfg =
            new XMLConfiguration(YangXmlUtils.getInstance()
                                         .getXmlConfiguration(OF_CONFIG_XML_PATH, elements));
    assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()),
                 IteratorUtils.toList(cfg.getKeys()));
    assertEquals("Wrong string configuaration", utils.getString(testCreateConfig),
                 utils.getString(cfg));
}
 
Example 12
Project: KernelHive   File: GUIGraphConfiguration.java   View source code 6 votes vote down vote up
private GUIGraphNodeDecorator loadGraphNodeForGUI(ConfigurationNode node)
		throws ConfigurationException {

	IGraphNode graphNode = loadGraphNode(node);
	int x = -1, y = -1;

	List<ConfigurationNode> xAttrList = node
			.getAttributes(NODE_X_ATTRIBUTE);
	List<ConfigurationNode> yAttrList = node
			.getAttributes(NODE_Y_ATTRIBUTE);
	if (xAttrList.size() > 0) {
		x = Integer.parseInt((String) xAttrList.get(0).getValue());
	}
	if (yAttrList.size() > 0) {
		y = Integer.parseInt((String) yAttrList.get(0).getValue());
	}

	GUIGraphNodeDecorator guiNode = new GUIGraphNodeDecorator(graphNode);
	guiNode.setX(x);
	guiNode.setY(y);

	return guiNode;
}
 
Example 13
Project: KernelHive   File: GUIGraphConfiguration.java   View source code 6 votes vote down vote up
@Override
public void saveGraphForGUI(List<GUIGraphNodeDecorator> guiGraphNodes,
		File file) throws ConfigurationException {
	XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setRootNode(tempConfig.getRootNode());
		config.getRootNode().removeChildren();
		for (GUIGraphNodeDecorator guiNode : guiGraphNodes) {
			config.getRoot().addChild(createGraphNodeForGUI(guiNode, file));
		}
		config.save(file);
	} catch (ConfigurationException e) {
		config = tempConfig;
		config.save(file);
		throw e;
	}
}
 
Example 14
Project: KernelHive   File: AbstractGraphConfiguration.java   View source code 6 votes vote down vote up
protected Node createNode(final IGraphNode node)
		throws ConfigurationException {
	final Node configNode = new Node(NODE);
	final Node idAttr = new Node(NODE_ID_ATTRIBUTE, node.getNodeId());
	idAttr.setAttribute(true);
	final Node hashAttr = new Node(NODE_HASH_ATTRIBUTE, node.hashCode());
	hashAttr.setAttribute(true);
	final Node parentAttr = new Node(NODE_PARENT_ID_ATTRIBUTE,
			node.getParentNode() != null ? node.getParentNode().getNodeId()
					: "");
	parentAttr.setAttribute(true);
	final Node nameAttr = new Node(NODE_NAME_ATTRIBUTE, node.getName());
	nameAttr.setAttribute(true);
	final Node typeAttr = new Node(NODE_TYPE_ATTRIBUTE, node.getType()
			.toString());
	typeAttr.setAttribute(true);
	configNode.addAttribute(idAttr);
	configNode.addAttribute(parentAttr);
	configNode.addAttribute(hashAttr);
	configNode.addAttribute(nameAttr);
	configNode.addAttribute(typeAttr);
	return configNode;
}
 
Example 15
Project: KernelHive   File: AbstractGraphConfiguration.java   View source code 6 votes vote down vote up
protected Node createPropertiesSubNode(final IGraphNode node)
		throws ConfigurationException {
	final Node propertiesNode = new Node(PROPERTIES_NODE);
	final Set<String> keySet = node.getProperties().keySet();
	for (final String key : keySet) {
		final Node propertyNode = new Node(PROPERTY_NODE);
		final Node keyAttr = new Node(PROPERTY_NODE_KEY_ATTRIBUTE, key);
		keyAttr.setAttribute(true);
		final Node valueAttr = new Node(PROPERTY_NODE_VALUE_ATTRIBUTE, node
				.getProperties().get(key));
		valueAttr.setAttribute(true);
		propertyNode.addAttribute(keyAttr);
		propertyNode.addAttribute(valueAttr);
		propertiesNode.addChild(propertyNode);
	}
	return propertiesNode;
}
 
Example 16
Project: momo-2   File: CommandHandler.java   View source code 6 votes vote down vote up
/**
 * Normalize all guild commands
 * @param collection All commands
 * @throws ConfigurationException If apache config throws an exception
 */
private static void normalizeCommands(Collection<Command> collection) throws ConfigurationException {
	Collection<File> found = FileUtils.listFiles(new File("resources/guilds"),
			TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
	found.add(new File("resources/guilds/template.properties"));
	for (File f : found) {
		if (f.getName().equals("GuildProperties.properties") || f.getName().equals("template.properties")) {
			PropertiesConfiguration config = new PropertiesConfiguration(f);
			List<String> enabledCommands = config.getList("EnabledCommands").stream()
					.map(object -> Objects.toString(object, null))
					.collect(Collectors.toList());
			List<String> disabledCommands = config.getList("DisabledCommands").stream()
					.map(object -> Objects.toString(object, null))
					.collect(Collectors.toList());
			for (Command c : collection) {
				if (!enabledCommands.contains(c.toString()) && !disabledCommands.contains(c.toString())) {
					enabledCommands.add(c.toString());
				}
			}
			config.setProperty("EnabledCommands", enabledCommands);
			config.save();
		}
	}
}
 
Example 17
Project: KernelHive   File: EngineGraphConfigurationTest.java   View source code 5 votes vote down vote up
@Test
public void testSaveAndLoadGraphForEngine() throws IOException,
		ConfigurationException, GraphNodeBuilderException {
	File f = File.createTempFile("test", "test");
	List<EngineGraphNodeDecorator> list = new ArrayList<EngineGraphNodeDecorator>();
	list.add(new EngineGraphNodeDecorator(new GraphNodeBuilder()
			.setId("test").setType(GraphNodeType.GENERIC).build()));

	config.saveGraphForEngine(list, f);
	List<EngineGraphNodeDecorator> result = config.loadGraphForEngine(f);
	assertEquals(list, result);
}
 
Example 18
Project: jbake-rtl-jalaali   File: Main.java   View source code 5 votes vote down vote up
protected void run(String[] args) {
	SLF4JBridgeHandler.removeHandlersForRootLogger();
	SLF4JBridgeHandler.install();
	LaunchOptions res = parseArguments( args );

	final CompositeConfiguration config;
	try {
		config = ConfigUtil.load( res.getSource() );
	} catch( final ConfigurationException e ) {
		throw new JBakeException( "Configuration error: " + e.getMessage(), e );
	}

	run(res, config);
}
 
Example 19
Project: athena   File: YangXmlUtilsTest.java   View source code 5 votes vote down vote up
/**
 * Test reading an XML configuration and retrieving the requested elements.
 *
 * @throws ConfigurationException
 */
@Test
public void testReadLastXmlConfiguration() throws ConfigurationException {
    testCreateConfig.load(getClass().getResourceAsStream("/testYangConfig.xml"));
    List<YangElement> elements = utils.readXmlConfiguration(testCreateConfig,
                                                            "controller");
    List<YangElement> expected = ImmutableList.of(
            new YangElement("controller", ImmutableMap.of("id", "tcp:1.1.1.1:1",
                                                          "ip-address", "1.1.1.1")),
            new YangElement("controller", ImmutableMap.of("id", "tcp:2.2.2.2:2",
                                                          "ip-address", "2.2.2.2")));
    assertEquals("Wrong elements collected", expected, elements);
}
 
Example 20
Project: athena   File: XmlDriverLoader.java   View source code 5 votes vote down vote up
/**
 * Loads the specified drivers resource as an XML stream and parses it to
 * produce a ready-to-register driver provider.
 *
 * @param driversStream stream containing the drivers definitions
 * @param resolver      driver resolver
 * @return driver provider
 * @throws java.io.IOException if issues are encountered reading the stream
 *                             or parsing the driver definitions within
 */
public DefaultDriverProvider loadDrivers(InputStream driversStream,
                                         DriverResolver resolver) throws IOException {
    try {
        XMLConfiguration cfg = new XMLConfiguration();
        cfg.setRootElementName(DRIVERS);
        cfg.setAttributeSplittingDisabled(true);

        cfg.load(driversStream);
        return loadDrivers(cfg, resolver);
    } catch (ConfigurationException e) {
        throw new IOException("Unable to load drivers", e);
    }
}
 
Example 21
Project: Equella   File: UpgradeToEmbeddedTomcat.java   View source code 5 votes vote down vote up
private File getUpgradeZip(Path installPath, File versionProps) throws ConfigurationException
{
	final PropertiesConfiguration props = new PropertiesConfiguration(versionProps);
	final String mmr = (String) props.getProperty("version.mmr");
	final String display = (String) props.getProperty("version.display");
	String filename = MessageFormat.format("tle-upgrade-{0} ({1}).zip", mmr, display);
	return installPath.resolve("manager/updates/" + filename).toFile();
}
 
Example 22
Project: nightwatch   File: Configuration.java   View source code 5 votes vote down vote up
public static void init(String configFilePath) {
    try {
        defultConfigFilePath = configFilePath;
        config = new PropertiesConfiguration(defultConfigFilePath);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 23
Project: Yidu   File: IndexAction.java   View source code 5 votes vote down vote up
@SkipValidation
@Override
public String execute() {
    logger.debug("execute start.");

    File lockFile = new File(LOCK_FILE);
    if (lockFile.exists()) {
        addActionError(getText("errors.install.file.exist", new String[] { LOCK_FILE }));
        return ERROR;
    }

    // 设定文件初期读入
    try {
        PropertiesConfiguration jdbcConf = new PropertiesConfiguration("jdbc.properties");
        String dburl = jdbcConf.getString(YiDuConfig.JDBC_URL).substring(prefixjdbc.length());
        String[] dbinfo = StringUtils.split(dburl, ":");
        dbhost = dbinfo[0];
        dbinfo = StringUtils.split(dbinfo[1], "/");
        dbport = dbinfo[0];
        // 数据库名暂时固定
        dbname = "yidu";
        dbusername = jdbcConf.getString(YiDuConfig.JDBC_USERNAME);
        dbpassword = jdbcConf.getString(YiDuConfig.JDBC_PASSWORD);
        PropertiesConfiguration languageConf = new PropertiesConfiguration(Thread.currentThread()
                .getContextClassLoader().getResource("language/package.properties"));
        title = languageConf.getString(YiDuConfig.TITLE);
        siteKeywords = languageConf.getString(YiDuConfig.SITEKEYWORDS);
        siteDescription = languageConf.getString(YiDuConfig.SITEDESCRIPTION);
        name = languageConf.getString(YiDuConfig.NAME);
        url = languageConf.getString(YiDuConfig.URL);
        copyright = languageConf.getString(YiDuConfig.COPYRIGHT);
        beianNo = languageConf.getString(YiDuConfig.BEIANNO);
        analyticscode = languageConf.getString(YiDuConfig.ANALYTICSCODE);

    } catch (ConfigurationException e) {
        logger.error(e);
    }
    logger.debug("execute normally end.");
    return INPUT;
}
 
Example 24
Project: newblog   File: HttpHelper.java   View source code 5 votes vote down vote up
private HttpHelper() {
    try {
        initHttpClient();
    } catch (ConfigurationException e) {
        log.info("configuratio exception.", e);
    }
}
 
Example 25
Project: athena   File: ApplicationArchive.java   View source code 5 votes vote down vote up
private ApplicationDescription parsePlainAppDescription(InputStream stream)
        throws IOException {
    XMLConfiguration cfg = new XMLConfiguration();
    cfg.setAttributeSplittingDisabled(true);
    cfg.setDelimiterParsingDisabled(true);
    try {
        cfg.load(stream);
        return loadAppDescription(cfg);
    } catch (ConfigurationException e) {
        throw new IOException("Unable to parse " + APP_XML, e);
    }
}
 
Example 26
Project: loom   File: AdapterConfigTest.java   View source code 5 votes vote down vote up
/**
 * Test loading from a file vs load the same file into the PropertiesConfiguration the config
 *
 * @throws ConfigurationException
 */
@Test
public void testLoadingViaFileVsProperties() throws ConfigurationException, AdapterConfigException {
    AdapterConfig config = new AdapterConfig("./src/test/resources/test.properties");
    AdapterConfig config2 = new AdapterConfig(new PropertiesConfiguration("./src/test/resources/test.properties"));

    Assert.assertEquals(config.getAdapterClass(), config2.getAdapterClass());
    Assert.assertEquals(config.getAdapterDir(), config2.getAdapterDir());
    Assert.assertEquals(config.getAuthEndpoint(), config2.getAuthEndpoint());
    Assert.assertEquals(config.getProviderId(), config2.getProviderId());
    Assert.assertEquals(config.getProviderName(), config2.getProviderName());
    Assert.assertEquals(config.getProviderType(), config2.getProviderType());
    Assert.assertEquals(config.getCollectThreads(), config2.getCollectThreads());
    Assert.assertEquals(config.getSchedulingInterval(), config2.getSchedulingInterval());
}
 
Example 27
Project: visitormanagement   File: EmailService.java   View source code 5 votes vote down vote up
/** Test smtp authentication configuration.
 * 
 * @param smtpConfiguration
 * @throws MessagingException
 * @throws ConfigurationException
 */
public void authenticateAndLoadConfiguration(EmailConfigurationDTO smtpConfiguration) throws MessagingException, ConfigurationException {
	Transport transport = getSession().getTransport(SMTP_PROTOCOL);
	try {
		transport.connect(smtpConfiguration.getHost(), smtpConfiguration.getPort(),	smtpConfiguration.getUserName(), 
				smtpConfiguration.getPassword());
	} finally {
		transport.close();
	}
	updateMailSenderConfig();
}
 
Example 28
Project: KernelHive   File: KernelRepository.java   View source code 5 votes vote down vote up
@Override
public List<KernelRepositoryEntry> getEntries()
		throws ConfigurationException {
	config.load(resource);
	
	List<KernelRepositoryEntry> entries = new ArrayList<>();
	
	List<ConfigurationNode> entryNodes = config.getRoot().getChildren(ENTRY_NODE);
	for(ConfigurationNode node : entryNodes){
		entries.add(getEntryFromConfigurationNode(node));
	}		
	return entries;
}
 
Example 29
Project: HTAPBench   File: RandomExecutor.java   View source code 5 votes vote down vote up
public static void main (String[]args) throws ConfigurationException, HTAPBException{
    // Initialize log4j
    String log4jPath = System.getProperty("log4j.configuration");
    if (log4jPath != null) {
        org.apache.log4j.PropertyConfigurator.configure(log4jPath);
    } else {
        throw new RuntimeException("Missing log4j.properties file");
    }
    
    String configFile = "config/htapb_config_postgres.xml";
    XMLConfiguration xmlConfig = new XMLConfiguration(configFile);
    xmlConfig.setExpressionEngine(new XPathExpressionEngine());
    
    
    WorkloadSetup setup = new WorkloadSetup(xmlConfig);
    setup.computeWorkloadSetup();
    
    
    DensityConsultant density = new DensityConsultant(10000);
    System.out.println("Density: "+density.getDensity());
    System.out.println("Delta TS: "+density.getDeltaTs());
    System.out.println("Target TPS "+density.getTargetTPS());
    
    long deltaTs = density.getDeltaTs();
    
    Clock clock = new Clock(deltaTs,false);
    
    System.out.println("Clock: current TS "+clock.getCurrentTs());

    int year = RandomParameters.randBetween(1993, 1997);
    int month = RandomParameters.randBetween(1, 12);
    long date1 = RandomParameters.convertDatetoLong(year, month, 1);
    long date2 = RandomParameters.convertDatetoLong(year+1, month, 1);
    Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));  
    Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
    
    System.out.println(ts1.toString());
    System.out.println(ts2.toString());
    
}
 
Example 30
Project: KernelHive   File: KernelRepository.java   View source code 5 votes vote down vote up
private Map<String, Object> getKernelProperties(ConfigurationNode node) throws ConfigurationException{
	List<ConfigurationNode> propertiesNodeList = node.getChildren(KERNEL_PROPERTY_NODE);
	Map<String, Object> properties = new HashMap<String, Object>(propertiesNodeList.size());
	
	for(ConfigurationNode pNode : propertiesNodeList){
		String key;
		Object value;
		
		List<ConfigurationNode> keyAttrList = pNode.getAttributes(KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE);
		List<ConfigurationNode> valueAttrList = pNode.getAttributes(KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE);
		
		if(keyAttrList.size()>0){
			key = (String) keyAttrList.get(0).getValue();
		} else{
			throw new ConfigurationException("KH: no required '"+KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE+"' attribute in "+KERNEL_PROPERTY_NODE+" node");
		}
		
		if(valueAttrList.size()>0){
			value = valueAttrList.get(0).getValue();
		} else{
			throw new ConfigurationException("KH: no required '"+KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE+"' attribute in "+KERNEL_PROPERTY_NODE+" node");
		}
		
		properties.put(key, value);
	}
	return properties;
}
 
Example 31
Project: obevo   File: DbFileMerger.java   View source code 5 votes vote down vote up
public void execute(DbFileMergerArgs args) {
    try {
        PropertiesConfiguration config = new PropertiesConfiguration(args.getDbMergeConfigFile());
        DbPlatform dialect = DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType"));
        this.generateDiffs(dialect, DbMergeInfo.parseFromProperties(config), args.getOutputDir());
    } catch (ConfigurationException e) {
        throw new DeployerRuntimeException(e);
    }
}
 
Example 32
Project: automatic-mower   File: CustomSettingLoader.java   View source code 5 votes vote down vote up
/**
 * A private constructor to avoid the instantiation
 */
private CustomSettingLoader() {
	try {
		this.configuration = new XMLConfiguration("");
	} catch (ConfigurationException e) {
		LoggerFactory.getLogger(CustomSettingLoader.class).warn(e.getMessage());
	}
}
 
Example 33
Project: athena   File: XmlConfigParser.java   View source code 5 votes vote down vote up
public static HierarchicalConfiguration loadXml(InputStream xmlStream) {
    XMLConfiguration cfg = new XMLConfiguration();
    try {
        cfg.load(xmlStream);
        return cfg;
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException("Cannot load xml from Stream", e);
    }
}
 
Example 34
Project: BUbiNG   File: StartupConfiguration.java   View source code 5 votes vote down vote up
private void checkRootDir() throws ConfigurationException {
	if (rootDirChecked) return;
	final File d = new File(rootDir);
	if (crawlIsNew) {
		if (d.exists()) throw new ConfigurationException("Root directory " + d + " exists");
		if (! d.mkdirs()) throw new ConfigurationException("Cannot create root directory " + d);
	}
	else if (! d.exists()) throw new ConfigurationException("Cannot find root directory " + rootDir + " for the crawl");
	rootDirChecked = true;
}
 
Example 35
Project: Equella   File: UpgradeToEmbeddedTomcat.java   View source code 5 votes vote down vote up
private void updateMandatoryProperties(final UpgradeResult result, File configDir) throws ConfigurationException,
	IOException
{
	PropertyFileModifier propMod = new PropertyFileModifier(new File(configDir,
		PropertyFileModifier.MANDATORY_CONFIG))
	{
		@Override
		protected boolean modifyProperties(PropertiesConfiguration props)
		{
			// Add Tomcat ports
			String url = (String) props.getProperty("admin.url");
			String port = getPort(url);
			String tomcatComment = System.lineSeparator()
				+ "# Tomcat ports. Specify the ports Tomcat should create connectors for";
			PropertiesConfigurationLayout layout = props.getLayout();
			layout.setLineSeparator(System.lineSeparator());
			if( url.contains("https") )
			{
				String httpsProp = "https.port";
				props.setProperty(httpsProp, port);
				layout.setComment(httpsProp, tomcatComment);
				props.setProperty("#http.port", "");
			}
			else
			{
				String httpProp = "http.port";
				props.setProperty(httpProp, port);
				layout.setComment(httpProp, tomcatComment);
				props.setProperty("#https.port", "");
			}
			props.setProperty("#ajp.port", "8009");

			// Remove Tomcat location
			props.clearProperty("tomcat.location");

			return true;
		}
	};
	propMod.updateProperties();
}
 
Example 36
Project: BUbiNG   File: StartupConfiguration.java   View source code 5 votes vote down vote up
private void chkSubDir(final String dir) throws ConfigurationException {
	final File d = subDir(rootDir, dir);
	if (crawlIsNew) {
		if (d.exists()) throw new ConfigurationException("Directory " + d + " exists");
		if (! d.mkdirs()) throw new ConfigurationException("Cannot create directory " + d);
	}
	else if (! d.exists()) throw new ConfigurationException("Directory " + d + " does not exist");
}
 
Example 37
Project: KernelHive   File: EngineGraphConfiguration.java   View source code 5 votes vote down vote up
private List<EngineGraphNodeDecorator> loadGraphFromXMLForEngine()
		throws ConfigurationException {
	final List<EngineGraphNodeDecorator> engineNodes = loadGraphNodesForEngine();
	final List<IGraphNode> nodes = new ArrayList<IGraphNode>();
	for (final EngineGraphNodeDecorator n : engineNodes) {
		nodes.add(n.getGraphNode());
	}
	linkGraphNodes(nodes);
	return engineNodes;
}
 
Example 38
Project: redirector   File: DataServiceInfo.java   View source code 5 votes vote down vote up
private ServiceInfo obtainServiceInfo() {
    try {
        Configuration config = new PropertiesConfiguration(CONFIG_FILE_NAME);
        return new ServiceInfo(config);
    } catch (ConfigurationException ce) {
        log.warn("Failed to load configuration file: {}", CONFIG_FILE_NAME);
    } catch (Exception e) {
        log.warn("Exception appears while configuration file is loading", e);
    }
    return null;
}
 
Example 39
Project: KernelHive   File: EngineGraphConfiguration.java   View source code 5 votes vote down vote up
private Map<String, Object> loadKernelProperties(
		final ConfigurationNode node) throws ConfigurationException {
	final List<ConfigurationNode> propList = node
			.getChildren(KERNEL_PROPERTY_NODE);
	final Map<String, Object> properties = new HashMap<String, Object>();
	for (final ConfigurationNode propNode : propList) {
		String key;
		Object value;

		final List<ConfigurationNode> keyAttrList = propNode
				.getAttributes(KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE);
		if (keyAttrList.size() > 0) {
			key = (String) keyAttrList.get(0).getValue();
		} else {
			throw new ConfigurationException("KH: no required attribute '"
					+ KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE + "' in "
					+ KERNEL_PROPERTY_NODE + " node");
		}
		final List<ConfigurationNode> valueAttrList = propNode
				.getAttributes(KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE);
		if (valueAttrList.size() > 0) {
			value = valueAttrList.get(0).getValue();
		} else {
			throw new ConfigurationException("KH: no required attribute '"
					+ KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE + "' in "
					+ KERNEL_PROPERTY_NODE + " node");
		}
		properties.put(key, value);
	}
	return properties;
}
 
Example 40
Project: KernelHive   File: EngineGraphConfiguration.java   View source code 5 votes vote down vote up
@Override
public void saveGraphForEngine(
		final List<EngineGraphNodeDecorator> graphNodes, final Writer writer)
		throws ConfigurationException {
	final XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	final File tempFile = config.getFile();
	try {
		config.clear();
		final List<ConfigurationNode> rootAttrs = tempConfig.getRootNode()
				.getAttributes();
		config.setRootNode((ConfigurationNode) tempConfig.getRootNode()
				.clone());
		config.getRootNode().removeChildren();
		for (final ConfigurationNode n : rootAttrs) {
			config.getRootNode()
					.addAttribute((ConfigurationNode) n.clone());
		}
		final List<ConfigurationNode> inputDataURLNodes = tempConfig
				.getRoot().getChildren(INPUT_DATA_NODE);
		for (final ConfigurationNode node : inputDataURLNodes) {
			config.getRootNode().addChild(node);
		}
		for (final EngineGraphNodeDecorator engineNode : graphNodes) {
			config.getRoot().addChild(createGraphNodeForEngine(engineNode));
		}
		config.save(writer);
	} catch (final ConfigurationException e) {
		config = tempConfig;
		config.save(tempFile);
	}

}