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:org.apache.ode.store.hib.DbConfStoreConnectionFactory.java

public DbConfStoreConnectionFactory(DataSource ds, Properties initialProps, boolean createDatamodel,
        String txFactoryClassName) {
    _ds = ds;//from w w w.  java  2s .  co  m

    // Don't want to pollute original properties
    Properties properties = new Properties();
    for (Object prop : initialProps.keySet()) {
        properties.put(prop, initialProps.get(prop));
    }

    __log.debug("using data source: " + ds);
    _dataSources.put(_guid, ds);

    if (createDatamodel) {
        properties.put(Environment.HBM2DDL_AUTO, "create-drop");
    }

    // Note that we don't allow the following properties to be overriden by the client.
    if (properties.containsKey(Environment.CONNECTION_PROVIDER))
        __log.warn("Ignoring user-specified Hibernate property: " + Environment.CONNECTION_PROVIDER);
    if (properties.containsKey(Environment.TRANSACTION_MANAGER_STRATEGY))
        __log.warn("Ignoring user-specified Hibernate property: " + Environment.TRANSACTION_MANAGER_STRATEGY);
    if (properties.containsKey(Environment.SESSION_FACTORY_NAME))
        __log.warn("Ignoring user-specified Hibernate property: " + Environment.SESSION_FACTORY_NAME);

    properties.put(SessionManager.PROP_GUID, _guid);
    properties.put(Environment.CONNECTION_PROVIDER, DataSourceConnectionProvider.class.getName());
    properties.put(Environment.TRANSACTION_MANAGER_STRATEGY, HibernateTransactionManagerLookup.class.getName());
    properties.put(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JTATransactionFactory");
    properties.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");

    if (__log.isDebugEnabled())
        __log.debug("Store connection properties: " + properties);

    initTxMgr(txFactoryClassName);
    SessionManager.registerTransactionManager(_guid, _txMgr);

    _sessionFactory = getDefaultConfiguration().setProperties(properties).buildSessionFactory();
}

From source file:net.comze.framework.orm.datasource.DbcpDataSourceFactory.java

private BasicDataSource initialize(Properties properties) {
    ObjectUtils.notNull(properties, "properties");
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(properties.getProperty(JDBC_DRIVER));
    basicDataSource.setUrl(properties.getProperty(JDBC_URL));
    basicDataSource.setUsername(properties.getProperty(JDBC_USERNAME));
    basicDataSource.setPassword(properties.getProperty(JDBC_PASSWORD));

    if (properties.containsKey(DBCP_INITIALSIZE)) {
        basicDataSource.setInitialSize(Integer.parseInt(properties.getProperty(DBCP_INITIALSIZE)));
    }/* w  ww . j  a v  a2  s  .  c o m*/
    if (properties.containsKey(DBCP_MAXACTIVE)) {
        basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(DBCP_MAXACTIVE)));
    }
    if (properties.containsKey(DBCP_MAXIDLE)) {
        basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(DBCP_MAXIDLE)));
    }
    if (properties.containsKey(DBCP_MAXWAIT)) {
        basicDataSource.setMaxWait(Long.parseLong(properties.getProperty(DBCP_MAXWAIT)));
    }
    if (properties.containsKey(DBCP_MINEVICTABLEIDLETIMEMILLIS)) {
        basicDataSource.setMinEvictableIdleTimeMillis(
                Long.parseLong(properties.getProperty(DBCP_MINEVICTABLEIDLETIMEMILLIS)));
    }
    if (properties.containsKey(DBCP_MINIDLE)) {
        basicDataSource.setMinIdle(Integer.parseInt(properties.getProperty(DBCP_MINIDLE)));
    }
    if (properties.containsKey(DBCP_NUMTESTSPEREVICTIONRUN)) {
        basicDataSource.setNumTestsPerEvictionRun(
                Integer.parseInt(properties.getProperty(DBCP_NUMTESTSPEREVICTIONRUN)));
    }
    if (properties.containsKey(DBCP_REMOVEABANDONED)) {
        basicDataSource.setRemoveAbandoned(Boolean.parseBoolean(properties.getProperty(DBCP_REMOVEABANDONED)));
    }
    if (properties.containsKey(DBCP_REMOVEABANDONEDTIMEOUT)) {
        basicDataSource.setRemoveAbandonedTimeout(
                Integer.parseInt(properties.getProperty(DBCP_REMOVEABANDONEDTIMEOUT)));
    }
    if (properties.containsKey(DBCP_TESTONBORROW)) {
        basicDataSource.setTestOnBorrow(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONBORROW)));
    }
    if (properties.containsKey(DBCP_TESTONCREATE)) {
        basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONCREATE)));
    }
    if (properties.containsKey(DBCP_TESTONRETURN)) {
        basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONRETURN)));
    }
    if (properties.containsKey(DBCP_TESTWHILEIDLE)) {
        basicDataSource.setTestWhileIdle(Boolean.parseBoolean(properties.getProperty(DBCP_TESTWHILEIDLE)));
    }
    if (properties.containsKey(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS)) {
        basicDataSource.setTimeBetweenEvictionRunsMillis(
                Long.parseLong(properties.getProperty(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS)));
    }
    if (properties.containsKey(DBCP_VALIDATIONQUERY)) {
        basicDataSource.setValidationQuery(properties.getProperty(DBCP_VALIDATIONQUERY));
    }
    if (properties.containsKey(DBCP_VALIDATIONQUERYTIMEOUT)) {
        basicDataSource.setValidationQueryTimeout(
                Integer.parseInt(properties.getProperty(DBCP_VALIDATIONQUERYTIMEOUT)));
    }
    return basicDataSource;
}

From source file:com.googlecode.fascinator.redbox.plugins.curation.mint.IngestedRelationshipsTransformer.java

/**
 * Transform method/*from  w  w w  .j  a  va  2 s.  c  om*/
 * 
 * @param object
 *            : DigitalObject to be transformed
 * @param jsonConfig
 *            : String containing configuration for this item
 * @return DigitalObject The object after being transformed
 * @throws TransformerException
 */
@Override
public DigitalObject transform(DigitalObject in, String jsonConfig) throws TransformerException {
    // Read item config and reset before we start
    JsonSimpleConfig itemConfig = null;
    try {
        itemConfig = new JsonSimpleConfig(jsonConfig);
    } catch (IOException ex) {
        throw new TransformerException("Error reading item configuration!", ex);
    }
    reset();

    // Test, have we done this before?
    Properties properties = null;
    try {
        properties = in.getMetadata();
    } catch (StorageException ex) {
        throw new TransformerException("Error reading properties: ", ex);
    }
    boolean hasRun = properties.containsKey(PROPERTY_FLAG);
    if (hasRun) {
        return in;
    }

    // Where are we getting out data from?
    String pid = itemConfig.getString(null, "sourcePid");
    JsonSimple data = getJsonFromStorage(in, pid);
    if (data == null) {
        log.error("Failed to retrieve data from storage: '{}'", in.getId());
        return in;
    }

    // Look in config for what relationships to map
    boolean saveChanges = false;
    Map<String, JsonSimple> relations = itemConfig.getJsonSimpleMap("relations");

    // And loop through them all
    for (String field : relations.keySet()) {
        List<String> path = itemConfig.getStringList("sourcePath");
        if (path == null) {
            // Empty is ok, null is not
            path = new ArrayList<String>();
        }

        // Get our data
        path.add(field);

        // As some fields can be ingested as multi-values, we'll use a List
        List<String> values = null;
        values = data.getStringList(path.toArray());
        if (values == null) {
            String value = data.getString(null, path.toArray());
            if (value != null && !value.equals("")) {
                values = new ArrayList<String>();
                values.add(value);
            }
        }
        if (values != null) {
            // And work out supporting values
            String prefix = relations.get(field).getString(null, "prefix");
            String relation = relations.get(field).getString("hasAssociationWith", "relation");
            String reverseRelation = relations.get(field).getString("hasAssociationWith", "reverseRelation");

            // Now finish up
            if (prefix == null) {
                log.error("Relationship '{}' has incorrect configuration!", field);
            } else {
                for (String value : values) {
                    if (!value.equals("")) {
                        // Add this relationship (if needed)
                        if (addWithDuplicateTest(data, prefix + value, relation, reverseRelation)) {
                            saveChanges = true;
                        }
                    }
                }
            }
        }
    }

    // If changed, store
    if (saveChanges) {
        saveObjectData(in, data, pid);
        // Value is not important, just having it set
        properties.setProperty(PROPERTY_FLAG, "hasRun");
        try {
            in.close();
        } catch (StorageException ex) {
            throw new TransformerException("Error updating properties: ", ex);
        }
    }

    return in;
}

From source file:org.apache.cassandra.hadoop.pig.CassandraStorage.java

private void initSchema() {
    UDFContext context = UDFContext.getUDFContext();
    Properties property = context.getUDFProperties(CassandraStorage.class);

    String schemaContextKey = getSchemaContextKey();
    // Only get the schema if we haven't already gotten it
    if (!property.containsKey(schemaContextKey)) {
        Cassandra.Client client = null;//from w  w w.j  a v a  2 s  . c om
        try {
            client = createConnection(ConfigHelper.getInitialAddress(conf), ConfigHelper.getRpcPort(conf),
                    true);
            CfDef cfDef = null;
            client.set_keyspace(keyspace);
            KsDef ksDef = client.describe_keyspace(keyspace);
            List<CfDef> defs = ksDef.getCf_defs();
            for (CfDef def : defs) {
                if (column_family.equalsIgnoreCase(def.getName())) {
                    cfDef = def;
                    break;
                }
            }
            property.setProperty(schemaContextKey, cfdefToString(cfDef));
        } catch (TException e) {
            throw new RuntimeException(e);
        } catch (InvalidRequestException e) {
            throw new RuntimeException(e);
        } catch (NotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java

private Set<GnucashAccount> getAccountsByProperty(final GnucashFile aBooks, final Properties props,
        final String prefix) {

    Set<GnucashAccount> retval = new HashSet<GnucashAccount>();
    for (int i = 0; props.containsKey(prefix + "." + i); i++) {
        String idOrName = props.getProperty(prefix + "." + i);
        GnucashAccount account = aBooks.getAccountByIDorName(idOrName, idOrName);
        if (account == null) {
            LOGGER.error("account '" + idOrName + "' given in property '" + prefix + "." + i + "' not found");
        } else {/*w  w w.j  a v a2s . c o  m*/
            retval.add(account);
        }
    }
    return retval;
}

From source file:org.cloudfoundry.identity.uaa.integration.TestProfileEnvironment.java

private TestProfileEnvironment() {

    List<Resource> resources = new ArrayList<Resource>();

    for (String location : DEFAULT_PROFILE_CONFIG_FILE_LOCATIONS) {
        location = environment.resolvePlaceholders(location);
        Resource resource = recourceLoader.getResource(location);
        if (resource != null && resource.exists()) {
            resources.add(resource);// w  w w  . j  av a 2  s.c om
        }
    }

    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(resources.toArray(new Resource[resources.size()]));
    factory.setDocumentMatchers(Collections.singletonMap("platform",
            environment.acceptsProfiles("postgresql") ? "postgresql" : "hsqldb"));
    factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
    Properties properties = factory.getObject();

    logger.debug("Decoding environment properties: " + properties.size());
    if (!properties.isEmpty()) {
        for (Enumeration<?> names = properties.propertyNames(); names.hasMoreElements();) {
            String name = (String) names.nextElement();
            String value = properties.getProperty(name);
            if (value != null) {
                properties.setProperty(name, environment.resolvePlaceholders(value));
            }
        }
        if (properties.containsKey("spring_profiles")) {
            properties.setProperty(StandardEnvironment.ACTIVE_PROFILES_PROPERTY_NAME,
                    properties.getProperty("spring_profiles"));
        }
        // System properties should override the ones in the config file, so add it last
        environment.getPropertySources().addLast(new PropertiesPropertySource("uaa.yml", properties));
    }

    EnvironmentPropertiesFactoryBean environmentProperties = new EnvironmentPropertiesFactoryBean();
    environmentProperties.setEnvironment(environment);
    environmentProperties.setDefaultProperties(properties);
    Map<String, ?> debugProperties = environmentProperties.getObject();
    logger.debug("Environment properties: " + debugProperties);
}

From source file:com.adaptris.core.management.webserver.JettyServerComponent.java

private Server configure(Server server, Properties config) throws Exception {
    // TODO This is all wrong. Can't get server attributes from the SErvletContext
    // OLD-SKOOL Do it via SystemProperties!!!!!
    // Add Null Prodction in to avoid System.setProperty issues during tests.
    // Or in fact if people decide to not enable JMXServiceUrl in bootstrap.properties
    if (config.containsKey(Constants.CFG_JMX_LOCAL_ADAPTER_UID)) {
        // server.setAttribute(ATTR_JMX_ADAPTER_UID, config.getProperty(Constants.CFG_JMX_LOCAL_ADAPTER_UID));
        System.setProperty(ATTR_JMX_ADAPTER_UID, config.getProperty(Constants.CFG_JMX_LOCAL_ADAPTER_UID));
    }/*from w  w  w  . j  a  v a 2  s  . c  om*/
    if (config.containsKey(Constants.BOOTSTRAP_PROPERTIES_RESOURCE_KEY)) {
        System.setProperty(ATTR_BOOTSTRAP_PROPERTIES,
                config.getProperty(Constants.BOOTSTRAP_PROPERTIES_RESOURCE_KEY));
    }
    return server;
}

From source file:hudson.plugins.sonar.SonarRunnerBuilder.java

@VisibleForTesting
void populateConfiguration(ExtendedArgumentListBuilder args, Run<?, ?> build, FilePath workspace,
        TaskListener listener, EnvVars env, SonarInstallation si) throws IOException, InterruptedException {
    if (si != null) {
        args.append("sonar.jdbc.url", si.getDatabaseUrl());
        args.appendMasked("sonar.jdbc.username", si.getDatabaseLogin());
        args.appendMasked("sonar.jdbc.password", si.getDatabasePassword());
        args.append("sonar.host.url", si.getServerUrl());
        if (StringUtils.isNotBlank(si.getServerAuthenticationToken())) {
            args.appendMasked("sonar.login", si.getServerAuthenticationToken());
        } else if (StringUtils.isNotBlank(si.getSonarLogin())) {
            args.appendMasked("sonar.login", si.getSonarLogin());
            args.appendMasked("sonar.password", si.getSonarPassword());
        }/*from  ww w  .j a  v a 2s. c  o m*/
    }

    // Project properties
    if (StringUtils.isNotBlank(getProject())) {
        String projectSettingsFile = env.expand(getProject());
        FilePath projectSettingsFilePath = BuilderUtils.getModuleRoot(build, workspace)
                .child(projectSettingsFile);
        if (!projectSettingsFilePath.exists()) {
            // because of the poor choice of getModuleRoot() with CVS/Subversion, people often get confused
            // with where the build file path is relative to. Now it's too late to change this behavior
            // due to compatibility issue, but at least we can make this less painful by looking for errors
            // and diagnosing it nicely. See HUDSON-1782

            // first check if this appears to be a valid relative path from workspace root
            if (workspace == null) {
                String msg = "Project workspace is null";
                listener.fatalError(msg);
                throw new AbortException(msg);
            }
            FilePath projectSettingsFilePath2 = workspace.child(projectSettingsFile);
            if (projectSettingsFilePath2.exists()) {
                // This must be what the user meant. Let it continue.
                projectSettingsFilePath = projectSettingsFilePath2;
            } else {
                // neither file exists. So this now really does look like an error.
                String msg = "Unable to find SonarQube project settings at " + projectSettingsFilePath;
                listener.fatalError(msg);
                throw new AbortException(msg);
            }
        }
        args.append("project.settings", projectSettingsFilePath.getRemote());
    }

    // Additional properties
    Properties p = new Properties();
    p.load(new StringReader(env.expand(getProperties())));
    loadProperties(args, p);

    if (!p.containsKey("sonar.projectBaseDir")) {
        FilePath moduleRoot = BuilderUtils.getModuleRoot(build, workspace);
        args.append("sonar.projectBaseDir", moduleRoot.getRemote());
    }
}

From source file:com.carrotgarden.maven.aws.cfn.CloudForm.java

protected Map<String, String> loadTemplateParameters(final File templateFile,
        final Map<String, String> pluginParams) throws Exception {

    final Map<String, String> stackParams = new TreeMap<String, String>();

    final Set<String> nameSet = loadParameterNames(templateFile);

    final Properties propsProject = project().getProperties();
    final Properties propsCommand = session().getUserProperties();
    final Properties propsSystem = session().getSystemProperties();

    for (final String name : nameSet) {

        if (pluginParams.containsKey(name)) {
            stackParams.put(name, pluginParams.get(name));
            continue;
        }/*from   ww  w . j a  v  a2  s .  c o m*/

        if (propsProject.containsKey(name)) {
            stackParams.put(name, propsProject.get(name).toString());
            continue;
        }

        if (propsCommand.containsKey(name)) {
            stackParams.put(name, propsCommand.get(name).toString());
            continue;
        }

        if (propsSystem.containsKey(name)) {
            stackParams.put(name, propsSystem.get(name).toString());
            continue;
        }

    }

    return stackParams;

}

From source file:com.sshtools.common.ui.SessionProviderFactory.java

SessionProviderFactory() {

    ExtensionClassLoader classloader = ConfigurationLoader.getExtensionClassLoader();

    try {/* ww  w . j  ava  2  s .  c om*/
        Enumeration enumr = classloader.getResources("session.provider");
        URL url = null;
        Properties properties;
        InputStream in;
        SessionProvider provider;
        String name;
        String id;

        while (enumr.hasMoreElements()) {
            try {
                url = (URL) enumr.nextElement();
                in = url.openStream();
                properties = new Properties();
                properties.load(in);
                IOUtil.closeStream(in);

                if (properties.containsKey("provider.class") && properties.containsKey("provider.name")) {

                    Class cls = classloader.loadClass(properties.getProperty("provider.class"));

                    String optionsClassName = properties.getProperty("provider.options");
                    Class optionsClass = optionsClassName == null || optionsClassName.equals("") ? null
                            : classloader.loadClass(optionsClassName);

                    String pageclass;
                    int num = 1;
                    Vector pages = new Vector();
                    do {
                        pageclass = properties.getProperty("property.page." + String.valueOf(num), null);
                        if (pageclass != null) {
                            pages.add(classloader.loadClass(pageclass));
                            num++;
                        }
                    } while (pageclass != null);

                    Class[] propertypages = new Class[pages.size()];
                    pages.toArray(propertypages);
                    name = properties.getProperty("provider.name");
                    int weight = Integer.parseInt(properties.getProperty("provider.weight"));
                    id = properties.getProperty("provider.id", name);
                    provider = new SessionProvider(id, name, cls, properties.getProperty("provider.shortdesc"),
                            properties.getProperty("provider.mnemonic"),
                            properties.getProperty("provider.smallicon"),
                            properties.getProperty("provider.largeicon"), optionsClass, propertypages, weight);

                    providers.put(id, provider);

                    log.info("Installed " + provider.getName() + " session provider");
                }
            } catch (ClassNotFoundException ex) {
                log.warn("Session provider class not found", ex);
            } catch (IOException ex) {
                log.warn("Failed to read " + url.toExternalForm(), ex);
            }
        }
    } catch (IOException ex) {
    }
}