Java 类org.apache.commons.configuration.tree.xpath.XPathExpressionEngine 实例源码

项目:atf-toolbox-java    文件:ConfigurationManager.java   
private void loadConfiguration() {
    Properties sysProps = System.getProperties();
    String configFileName = sysProps.getProperty("test.config.filename");

    if (StringUtils.isEmpty(configFileName)) {
        configFileName = defaultConfigurationFileName;
    }

    try {
        AllConfiguration = new DefaultConfigurationBuilder(configFileName).getConfiguration();
        ((HierarchicalConfiguration) AllConfiguration).setExpressionEngine(new XPathExpressionEngine());
    } catch (Exception e) {
        Fail.fail("failed to read config file", e);
        log.error("Failed to read config file", e);
    }
}
项目:grit    文件:Configuration.java   
/**
 * Loads the configuration from the specified File.
 * 
 * @param file
 *            the file the config is stored in
 * @throws ConfigurationException
 *             if the configuration file can't be read.
 * @throws FileNotFoundException
 *             if the file can't be found
 */
public Configuration(File file) throws ConfigurationException,
        FileNotFoundException {

    LOGGER.info("Loading configuration from file: "
            + file.getAbsolutePath());

    if (!file.exists()) {
        LOGGER.warning("Could not find configuration file: "
                + file.getAbsolutePath());
        throw new FileNotFoundException(file.getAbsolutePath());
    }
    m_configXML = file;
    m_config = new XMLConfiguration(file);

    // set xpath engine for more powerful queries
    m_config.setExpressionEngine(new XPathExpressionEngine());
    loadToMember();
    // save();
}
项目:HTAPBench    文件:RandomExecutor.java   
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());

}
项目:zefiro    文件:JBrickConfigManager.java   
private JBrickConfigManager(String pStrConfigurationFilePath) {
       mXMLConfiguration = new XMLConfiguration();
       mXMLConfiguration.setFileName(pStrConfigurationFilePath);
       mXMLConfiguration.setExpressionEngine(new XPathExpressionEngine());
    try {
        mXMLConfiguration.load();
    } catch (ConfigurationException e) {
        mLog.error(e,"Error while reading configuration from file ",this.getStrConfigFileName());
        throw new JBrickException(e, "jBrickException.configManager.errorWhileReadingConfiguration", e.getMessage());
    }
    mLog.debug("ConfigManager initialized using file ", pStrConfigurationFilePath);
}
项目:qaf    文件:XPathUtils.java   
public static XMLConfiguration read(String src) {
    try {
        // remove all namespaces from xml
        src = removeNSAndPreamble(src);
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(new ByteArrayInputStream(src.getBytes()));
        config.setExpressionEngine(new XPathExpressionEngine());
        return config;

    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}
项目:proxyma    文件:ProxymaContext.java   
/**
 * Default constructor for this Class
 *
 * @param contextName the name of the context to create
 * @param contextBaseURI Base URI of the context
 * @param configurationFile proxyma configuration file to load
 * @param logsDirectoryPath directory where to write all the logs
 */
public ProxymaContext (String contextName, String contextBaseURI, String configurationFile, String logsDirectoryPath) {
    // Initialize private attributes
    try {
        this.contextName = contextName;
        this.proxymaContextBasePath = contextBaseURI;
        this.logsDirectoryPath = logsDirectoryPath;
        proxyFoldersByURLEncodedName = new ConcurrentHashMap<String, ProxyFolderBean>();
        proxyFoldersByDestinationHost = new ConcurrentHashMap<String, LinkedList<ProxyFolderBean>>();
        config = new XMLConfiguration(configurationFile);
        config.setExpressionEngine(new XPathExpressionEngine());
        if (this.log == null) {
            //create a unique logger for the whole context
            String name = ProxymaTags.DEFAULT_LOGGER_PREFIX + "." + contextName;
            this.log = Logger.getLogger(name);

            String logFile = logsDirectoryPath + "proxyma-" + contextName + ".log";
            String level = getSingleValueParameter(ProxymaTags.GLOBAL_LOGLEVEL);
            int maxSize = Integer.parseInt(getSingleValueParameter(ProxymaTags.GLOBAL_LOGFILE_MAXSIZE));
            int retention = Integer.parseInt(getSingleValueParameter(ProxymaTags.GLOBAL_LOGFILES_RETENTION));
            ProxymaLoggersUtil.initializeContextLogger(this.log, logFile, level, maxSize, retention);
        }
        this.defaultEncoding = getSingleValueParameter(ProxymaTags.GLOBAL_DEFAULT_ENCODING);
        this.proxymaVersion = "Proxyma-NG (Rel. " + getSingleValueParameter(ProxymaTags.CONFIG_FILE_VERSION) + ")";
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.SEVERE, null, ex);
    }
}
项目:grit    文件:State.java   
/**
 * Loads the state from the specified File.
 * 
 * @param file
 *            the file the config is stored in
 * @throws ConfigurationException
 *             if the config file is malformed
 * @throws FileNotFoundException
 *             if the specified file can't be found
 */
public State(File file) throws ConfigurationException,
        FileNotFoundException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getAbsolutePath());
    }
    m_state = new XMLConfiguration(file);
    m_stateFile = file;

    // set xpath engine for more powerful queries
    m_state.setExpressionEngine(new XPathExpressionEngine());
}
项目:Tank    文件:BaseCommonsXmlConfig.java   
/**
     * Constructor pulls file out of the jar or reads from disk and sets up refresh policy.
     * 
     * @param expressionEngine
     *            the expression engine to use. Null results in default expression engine
     */
    protected void readConfig() {
        try {
            ExpressionEngine expressionEngine = new XPathExpressionEngine();
            String configPath = getConfigName();
            FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();

            File dataDirConfigFile = new File(configPath);
//            LOG.info("Reading settings from " + dataDirConfigFile.getAbsolutePath());
            if (!dataDirConfigFile.exists()) {
                // Load a default from the classpath:
                // Note: we don't let new XMLConfiguration() lookup the resource
                // url directly because it may not be able to find the desired
                // classloader to load the URL from.
                URL configResourceUrl = this.getClass().getClassLoader().getResource(configPath);
                if (configResourceUrl == null) {
                    throw new RuntimeException("unable to load resource: " + configPath);
                }

                XMLConfiguration tmpConfig = new XMLConfiguration(configResourceUrl);
                // Copy over a default configuration since none exists:
                // Ensure data dir location exists:
                if (dataDirConfigFile.getParentFile() != null && !dataDirConfigFile.getParentFile().exists()
                        && !dataDirConfigFile.getParentFile().mkdirs()) {
                    throw new RuntimeException("could not create directories.");
                }
                tmpConfig.save(dataDirConfigFile);
                LOG.info("Saving settings file to " + dataDirConfigFile.getAbsolutePath());
            }

            if (dataDirConfigFile.exists()) {
                config = new XMLConfiguration(dataDirConfigFile);
            } else {
                // extract from jar and write to
                throw new IllegalStateException("Config file does not exist or cannot be created");
            }
            if (expressionEngine != null) {
                config.setExpressionEngine(expressionEngine);
            }
            configFile = dataDirConfigFile;
            // reload at most once per thirty seconds on configuration queries.
            config.setReloadingStrategy(reloadingStrategy);
            initConfig(config);
        } catch (ConfigurationException e) {
            LOG.error("Error reading settings file: " + e, e);
            throw new RuntimeException(e);
        }
    }