Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:gov.nih.nci.logging.api.util.HibernateUtil.java

private static void validateProperties(Properties properties) throws Exception {

    if (properties.containsKey("CLMDS.jndiName")) {
        String jndiName = properties.getProperty("CLMDS.jndiName");
        String hibernateDialect = properties.getProperty("Hibernate.dialect");

        properties.clear();/* www  . ja  v a 2 s  . com*/
        properties.setProperty("CLMDJndiDS.jndiName", jndiName);
        properties.setProperty("hibernate.dialect", hibernateDialect);
    }
    if (properties.containsKey("CLMDS.url") && properties.containsKey("CLMDS.driverClassName")
            && properties.containsKey("CLMDS.password") && properties.containsKey("CLMDS.username")) {

        String driverClassName = properties.getProperty("CLMDS.driverClassName");
        String url = properties.getProperty("CLMDS.url");
        String username = properties.getProperty("CLMDS.username");
        String password = properties.getProperty("CLMDS.password");
        String hibernateDialect = properties.getProperty("Hibernate.dialect");
        properties.clear();
        /*properties.setProperty("CLMConnectionPoolDS.driverClassName",driverClassName);
        properties.setProperty("CLMConnectionPoolDS.url", url);
        properties.setProperty("CLMConnectionPoolDS.username", username);
        properties.setProperty("CLMConnectionPoolDS.password", password);*/
        properties.setProperty("hibernate.connection.driver_class", driverClassName);
        properties.setProperty("hibernate.connection.url", url);
        properties.setProperty("hibernate.connection.username", username);
        properties.setProperty("hibernate.connection.password", password);
        properties.setProperty("hibernate.dialect", hibernateDialect);

    }

}

From source file:com.eviware.soapui.monitor.PropertySupport.java

public static void applySystemProperties(Object target, String scope, ModelItem modelItem) {
    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(target);
    DefaultPropertyExpansionContext context = new DefaultPropertyExpansionContext(modelItem);
    Properties properties = System.getProperties();

    for (PropertyDescriptor descriptor : descriptors) {
        String name = descriptor.getName();
        String key = scope + "." + name;
        if (PropertyUtils.isWriteable(target, name) && properties.containsKey(key)) {
            try {
                String value = context.expand(String.valueOf(properties.get(key)));
                BeanUtils.setProperty(target, name, value);
                SoapUI.log.info("Set property [" + name + "] to [" + value + "] in scope [" + scope + "]");
            } catch (Throwable e) {
                SoapUI.logError(e);/*from  w  ww  .ja v  a2 s .  c o  m*/
            }
        }
    }
}

From source file:fedora.utilities.Log4J.java

/**
 * Initializes Log4J from a properties file.
 * /*from   w  w  w. ja va 2 s.co  m*/
 * @param propFile the Log4J properties file.
 * @param options a set of name-value pairs to use while expanding any
 *                replacement variables (e.g. ${some.name}) in the 
 *                properties file.  These may also be specified in
 *                the properties file itself.  If found, the value
 *                in the properties file will take precendence.
 * @throws IOException if configuration fails due to problems with the file.
 */
public static void initFromPropFile(File propFile, Map<String, String> options) throws IOException {
    Properties props = new Properties();
    props.load(new FileInputStream(propFile));
    if (options != null) {
        for (String name : options.keySet()) {
            String value = options.get(name);
            if (!props.containsKey(name)) {
                props.setProperty(name, value);
            }
        }
    }
    PropertyConfigurator.configure(props);
}

From source file:org.zalando.stups.spring.http.client.ClientHttpRequestFactorySelector.java

public static ClientHttpRequestFactory getRequestFactory(TimeoutConfig timeoutConfig) {
    Properties properties = System.getProperties();
    String proxyHost = properties.getProperty("http.proxyHost");
    int proxyPort = properties.containsKey("http.proxyPort")
            ? Integer.valueOf(properties.getProperty("http.proxyPort"))
            : 80;// w  w w.j  a v a  2s.co  m
    if (HTTP_COMPONENTS_AVAILABLE) {
        HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) HttpComponentsClientRequestFactoryCreator
                .createRequestFactory(proxyHost, proxyPort);
        factory.setReadTimeout(timeoutConfig.getReadTimeout());
        factory.setConnectTimeout(timeoutConfig.getConnectTimeout());
        factory.setConnectionRequestTimeout(timeoutConfig.getConnectionRequestTimeout());
        return factory;
    } else {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(timeoutConfig.getConnectTimeout());
        requestFactory.setReadTimeout(timeoutConfig.getReadTimeout());
        if (proxyHost != null) {
            requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
        }
        return requestFactory;
    }
}

From source file:gobblin.runtime.locks.JobLockFactory.java

/**
 * Gets an instance of {@link JobLock}./*w  ww.  j  a  v a 2 s.com*/
 *
 * @param properties the properties used to determine which instance of {@link JobLock} to create and the
 *                   relevant settings
 * @param jobLockEventListener the {@link JobLock} event listener
 * @return an instance of {@link JobLock}
 * @throws JobLockException throw when the {@link JobLock} fails to initialize
 */
public static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener)
        throws JobLockException {
    Preconditions.checkNotNull(properties);
    Preconditions.checkNotNull(jobLockEventListener);
    JobLock jobLock;
    if (properties.containsKey(ConfigurationKeys.JOB_LOCK_TYPE)) {
        try {
            Class<?> jobLockClass = Class.forName(
                    properties.getProperty(ConfigurationKeys.JOB_LOCK_TYPE, FileBasedJobLock.class.getName()));
            jobLock = (JobLock) ConstructorUtils.invokeConstructor(jobLockClass, properties);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | NoSuchMethodException | InvocationTargetException e) {
            throw new JobLockException(e);
        }
    } else {
        jobLock = new FileBasedJobLock(properties);
    }
    if (jobLock instanceof ListenableJobLock) {
        ((ListenableJobLock) jobLock).setEventListener(jobLockEventListener);
    }
    return jobLock;
}

From source file:com.hightail.metrics.reporter.NewRelicReporterFactory.java

private static NewRelicReporter buildNewRelicHttpV1Instance(Properties properties)
        throws CannotCreateInstanceException {

    List<String> errorMsgs = new ArrayList<String>();

    if (!properties.containsKey(NewRelicConstants.METRIC_REGISTRY)
            || properties.get(NewRelicConstants.METRIC_REGISTRY) == null) {
        errorMsgs.add(NewRelicConstants.METRIC_REGISTRY + " is not provided");
    }//from www . j a  va 2  s .c  om

    if (!properties.containsKey(NewRelicConstants.LICENSE_KEY)
            || StringUtils.isBlank(properties.getProperty(NewRelicConstants.LICENSE_KEY))) {
        errorMsgs.add(NewRelicConstants.LICENSE_KEY + " is not provided");
    }

    if (!properties.containsKey(NewRelicConstants.COMPONENT_NAME)
            || StringUtils.isBlank(properties.getProperty(NewRelicConstants.COMPONENT_NAME))) {
        errorMsgs.add(NewRelicConstants.COMPONENT_NAME + " is not provided");
    }

    if (!properties.containsKey(NewRelicConstants.APP_ID)
            || StringUtils.isBlank(properties.getProperty(NewRelicConstants.APP_ID))) {
        errorMsgs.add(NewRelicConstants.APP_ID + " is not provided");
    }

    if (!errorMsgs.isEmpty()) {
        logger.error("Cannot instantiate New Relic Reporter because mandatory attributes are not provided: "
                + errorMsgs.toString());
        throw new CannotCreateInstanceException(errorMsgs.toString());
    }

    MetricRegistry registry = (MetricRegistry) properties.get(NewRelicConstants.METRIC_REGISTRY);
    String licenseKey = properties.getProperty(NewRelicConstants.LICENSE_KEY);
    String componentName = properties.getProperty(NewRelicConstants.COMPONENT_NAME);
    String appId = properties.getProperty(NewRelicConstants.APP_ID);

    String prefix = (properties.containsKey(NewRelicConstants.PREFIX))
            ? properties.getProperty(NewRelicConstants.PREFIX)
            : NewRelicConstants.DEFAULT_PREFIX;
    TimeUnit rateUnit = (properties.containsKey(NewRelicConstants.RATE_UNIT))
            ? (TimeUnit) properties.get(NewRelicConstants.RATE_UNIT)
            : NewRelicConstants.DEFAULT_RATE_UNIT;
    TimeUnit durationUnit = (properties.containsKey(NewRelicConstants.DURATION_UNIT))
            ? (TimeUnit) properties.get(NewRelicConstants.DURATION_UNIT)
            : NewRelicConstants.DEFAULT_DURATION_UNIT;
    MetricFilter filter = (properties.containsKey(NewRelicConstants.METRIC_FILTER))
            ? (MetricFilter) properties.get(NewRelicConstants.METRIC_FILTER)
            : NewRelicConstants.DEFAULT_METRIC_FILTER;

    NewRelic newRelic = new NewRelic(NewRelicConstants.DEFAULT_URL, licenseKey, componentName, appId);

    return NewRelicHTTPv1Reporter.forRegistry(registry).prefixedWith(prefix).convertRatesTo(rateUnit)
            .convertDurationsTo(durationUnit).filter(filter).build(newRelic);
}

From source file:com.adaptris.core.services.metadata.SimpleSequenceNumberService.java

private static String nextSequenceNumber(Properties p, Long maximum) {
    if (!p.containsKey(PROPERTY_KEY)) {
        p.setProperty(PROPERTY_KEY, ONE);
    }/*from w  w  w. java  2 s  . c o m*/
    if (greaterThanMaximum(p.getProperty(PROPERTY_KEY), maximum)) {
        p.setProperty(PROPERTY_KEY, ONE);
    }
    return p.getProperty(PROPERTY_KEY);
}

From source file:org.springframework.xd.distributed.util.ServerProcessUtils.java

/**
 * Start a container instance.  Upon test completion, the method
 * {@link com.oracle.tools.runtime.java.JavaApplication#close()}
 * should be invoked to shut down the server. This method may also be
 * invoked as part of failover testing.//w  w  w .  j a v  a 2s .  c o m
 * <p />
 * Note that this method returns immediately. In order to verify
 * that the container was started, invoke {@link #waitForContainers}
 * to block until the container(s) are started.
 *
 * @param properties system properties to pass to the admin server; at minimum
 *                   must contain key {@code zk.client.connect} to indicate
 *                   the ZooKeeper connect string
 *
 * @return container server application reference
 * @throws IOException if an exception is thrown launching the process
 *
 * @see #waitForContainers
 */
public static JavaApplication<SimpleJavaApplication> startContainer(Properties properties) throws IOException {
    Assert.state(properties.containsKey("zk.client.connect"), "Property 'zk.client.connect' required");

    return launch(ContainerServerApplication.class, false, properties, null);
}

From source file:net.gcolin.simplerepo.maven.Resolver.java

public static String resolve(String value, Properties props, Model model) {
    if (value == null) {
        return null;
    }//w ww . jav a2s  .  com
    Matcher matcher = VAR_PATTERN.matcher(value);
    StringBuffer result = new StringBuffer();
    while (matcher.find()) {
        String expr = matcher.group(1);
        if (props.containsKey(expr)) {
            matcher.appendReplacement(result, props.getProperty(expr));
        } else {
            if (expr.startsWith("project.")) {
                expr = expr.substring(8);
            }
            try {
                matcher.appendReplacement(result, String.valueOf(BeanUtils.getProperty(model, expr)));
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
    matcher.appendTail(result);
    return result.toString();
}

From source file:com.wavemaker.common.util.SystemUtils.java

/**
 * Add all properties from p that are not set in org.
 */// w  w  w .j  av a2 s.  c o  m
public static void addAllUnlessSet(Properties org, Properties p) {
    for (String s : CastUtils.<String>cast(p.keySet())) {
        if (!org.containsKey(s)) {
            org.setProperty(s, p.getProperty(s));
        }
    }
}