Example usage for java.util Properties isEmpty

List of usage examples for java.util Properties isEmpty

Introduction

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

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

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);//from  ww  w  .jav a 2s . co m
        }
    }

    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.tacitknowledge.flip.spring.config.FeatureServiceHandlerParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(FeatureServiceDirectFactory.class);
    RootBeanDefinition factoryBean = (RootBeanDefinition) factoryBuilder.getBeanDefinition();
    parserContext.getRegistry().registerBeanDefinition(FlipSpringAspect.FEATURE_SERVICE_FACTORY_BEAN_NAME,
            factoryBean);/*from  w w w.j a  va 2 s.  co  m*/

    MutablePropertyValues factoryPropertyValues = new MutablePropertyValues();
    factoryBean.setPropertyValues(factoryPropertyValues);

    String environmentBean = element.getAttribute("environment");
    if (environmentBean != null && !environmentBean.isEmpty()) {
        factoryPropertyValues.addPropertyValue("environment", new RuntimeBeanNameReference(environmentBean));
    }

    Element contextProvidersElement = DomUtils.getChildElementByTagName(element, "context-providers");
    if (contextProvidersElement != null) {
        List contextProvidersList = parserContext.getDelegate().parseListElement(contextProvidersElement,
                factoryBean);
        if (contextProvidersList != null && !contextProvidersList.isEmpty()) {
            factoryPropertyValues.addPropertyValue("contextProviders", contextProvidersList);
        }
    }

    Element propertyReadersElement = DomUtils.getChildElementByTagName(element, "property-readers");
    if (propertyReadersElement != null && propertyReadersElement.hasChildNodes()) {
        List propertyReadersList = parserContext.getDelegate().parseListElement(propertyReadersElement,
                factoryBean);
        if (propertyReadersList != null && !propertyReadersList.isEmpty()) {
            factoryPropertyValues.addPropertyValue("propertyReaders", propertyReadersList);
        }
    }

    Element propertiesElement = DomUtils.getChildElementByTagName(element, "properties");
    if (propertiesElement != null && propertiesElement.hasChildNodes()) {
        Properties properties = parserContext.getDelegate().parsePropsElement(propertiesElement);
        if (properties != null && !properties.isEmpty()) {
            factoryPropertyValues.addPropertyValue("properties", properties);
        }
    }

    BeanDefinitionBuilder featureServiceBuilder = BeanDefinitionBuilder.genericBeanDefinition();
    BeanDefinition featureServiceRawBean = featureServiceBuilder.getRawBeanDefinition();
    featureServiceRawBean.setFactoryBeanName(FlipSpringAspect.FEATURE_SERVICE_FACTORY_BEAN_NAME);
    featureServiceRawBean.setFactoryMethodName("createFeatureService");
    parserContext.getRegistry().registerBeanDefinition(FlipSpringAspect.FEATURE_SERVICE_BEAN_NAME,
            featureServiceBuilder.getBeanDefinition());

    return null;
}

From source file:hr.fer.zemris.vhdllab.platform.preference.DatabasePreferences.java

@Override
protected void flushSpi() throws BackingStoreException {
    Properties props = getProperties();
    if (!props.isEmpty()) {
        StringWriter writer = new StringWriter();
        try {//from   w  w  w .ja  va  2 s .c om
            props.store(writer, null);
        } catch (IOException e) {
            throw new UnhandledException(e);
        }
        PreferencesFile file = getFile();
        String data = writer.toString();
        if (file == null) {
            file = new PreferencesFile(absolutePath(), data);
        } else {
            file.setData(data);
        }
        manager.setFile(file);
    }
}

From source file:py.org.icarusdb.example.rest.client.CountryClientService.java

/**
 * connects to RESTful services via POST when @param parameters have values
 * otherwise connects via GET//  w  w w.  j av a  2s.  c o  m
 * 
 * @param connectUri valid URI, http://servername:port/modulename/serviceuri/servicename[/action]
 * @param parameters
 * 
 * @return {@link Country} or empty list 
 */
public List<CountryDTO> getCountries(String connectUri, Properties parameters) {
    try {
        createConnection(connectUri);

        if (parameters == null || parameters.isEmpty()) {
            response = request.get(String.class);
        } else {
            request.body(MediaType.APPLICATION_JSON, new ObjectMapper().writeValueAsString(parameters));

            response = request.post(String.class);
        }

        retrieveInfo();

    } catch (JsonGenerationException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return countries;
}

From source file:py.org.icarusdb.example.rest.client.StateClientService.java

/**
 * connects to RESTful services via POST when @param parameters have values
 * otherwise connects via GET/*from   w  ww.j a  va2 s. co  m*/
 * 
 * @param connectUri valid URI, http://servername:port/modulename/serviceuri/servicename[/action]
 * @param parameters
 * 
 * @return {@link State} or empty list 
 */
public List<StateDTO> getStates(String connectUri, Properties parameters) {
    try {
        createConnection(connectUri);

        if (parameters == null || parameters.isEmpty()) {
            response = request.get(String.class);
        } else {
            request.body(MediaType.APPLICATION_JSON, new ObjectMapper().writeValueAsString(parameters));

            response = request.post(String.class);
        }

        retrieveInfo();

    } catch (JsonGenerationException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return states;
}

From source file:org.apache.pig.TestMain.java

@Test
public void testlog4jConf() throws Exception {
    Properties properties = Main.log4jConfAsProperties(null);
    assertTrue(properties.isEmpty());
    properties = Main.log4jConfAsProperties("");
    assertTrue(properties.isEmpty());/*from ww  w  .ja  v a  2 s.  c  om*/
    // Test for non-existent file
    properties = Main.log4jConfAsProperties("non-existing-" + System.currentTimeMillis());
    assertTrue(properties.isEmpty());

    // Create tmp file in under build/test/classes
    File tmpFile = File.createTempFile("pig-log4jconf", ".properties", new File("build/test/classes"));
    tmpFile.deleteOnExit();
    Files.write("A=B", tmpFile, Charset.forName("UTF-8"));
    // Read it as a resource
    properties = Main.log4jConfAsProperties(tmpFile.getName());
    assertEquals("B", properties.getProperty("A"));
    // Read it as a file
    properties = Main.log4jConfAsProperties(tmpFile.getAbsolutePath());
    assertEquals("B", properties.getProperty("A"));
}

From source file:edu.amc.sakai.user.ResourcePropertiesEditStub.java

public ResourcePropertiesEditStub(Properties defaultConfig, Properties configOverrides) {
    super();/*from  w ww.  j a va2  s.  c o m*/
    if (defaultConfig != null && !(defaultConfig.isEmpty())) {
        for (Enumeration i = defaultConfig.propertyNames(); i.hasMoreElements();) {
            String propertyName = (String) i.nextElement();
            String propertyValue = StringUtils.trimToNull((String) defaultConfig.getProperty(propertyName));
            if (propertyValue == null) {
                continue;
            }
            String[] propertyValues = propertyValue.split(";");
            if (propertyValues.length > 1) {
                for (String splitPropertyValue : propertyValues) {
                    super.addPropertyToList(propertyName, splitPropertyValue);
                }
            } else {
                super.addProperty(propertyName, propertyValue);
            }
        }
    }

    if (configOverrides != null && !(configOverrides.isEmpty())) {
        // slightly different... configOverrides are treated as complete
        // overwrites of existing values.
        for (Enumeration i = configOverrides.propertyNames(); i.hasMoreElements();) {
            String propertyName = (String) i.nextElement();
            super.removeProperty(propertyName);
            String propertyValue = StringUtils.trimToNull((String) configOverrides.getProperty(propertyName));
            String[] propertyValues = propertyValue.split(";");
            if (propertyValues.length > 1) {
                for (String splitPropertyValue : propertyValues) {
                    super.addPropertyToList(propertyName, splitPropertyValue);
                }
            } else {
                super.addProperty(propertyName, propertyValue);
            }
        }
    }
}

From source file:org.apache.falcon.oozie.process.NativeOozieProcessWorkflowBuilder.java

private void copyPropsWithoutOverride(Properties buildProps, Properties suppliedProps) {
    if (suppliedProps == null || suppliedProps.isEmpty()) {
        return;//  w w  w  .  j ava2 s . c  o  m
    }
    for (String propertyName : suppliedProps.stringPropertyNames()) {
        if (buildProps.containsKey(propertyName)) {
            LOG.warn("User provided property {} is already declared in the entity and will be ignored.",
                    propertyName);
            continue;
        }
        String propertyValue = suppliedProps.getProperty(propertyName);
        buildProps.put(propertyName, propertyValue);
    }
}

From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.commands.ListPools.java

private void printPool(final PoolDefinition pool) throws BackingStoreException {
    printf("Pool %s", pool.getPoolId());
    printf(StringUtils.EMPTY);/*from   w w  w. j a v a  2  s  .  c om*/

    final Properties driverProperties = pool.getDriverProperties();
    if (!driverProperties.isEmpty()) {
        printf("Driver Properties:");
        final SortedSet<String> names = new TreeSet<String>();
        final Enumeration<?> propertyNames = driverProperties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            names.add((String) propertyNames.nextElement());
        }
        for (final String key : names) {
            printf("  %35s: %s", key, StringUtils.trimToEmpty(driverProperties.getProperty(key)));
        }
        printf(StringUtils.EMPTY);
    }

    printf("Pool Statistics:");
    final BoneCPDataSource dataSource = (BoneCPDataSource) PoolActivator.getInstance().getRegistry()
            .getDataSource(pool.getPoolId());

    // test connectivity (this also works around a bug in BoneCP which would result in an NPE below)
    try {
        final Connection connection = dataSource.getConnection();
        if (connection instanceof ConnectionHandle) {
            printf("  %35s: %s", "connectionTest",
                    ((ConnectionHandle) connection).isValid(1000) ? "OK" : "NOT OK");
        } else {
            printf("  %35s: %s", "connectionSample", connection.toString());
        }
        connection.close();
    } catch (final SQLException e) {
        printf("  unable to connect to pool: %s", e.getMessage());
    }

    // total number of leased connections
    printf("  %35s: %d", "totalLeased", dataSource.getTotalLeased());
    printf(StringUtils.EMPTY);

    printf("Effective Pool Config:");
    final TreeMap<String, String> poolConfig = readPoolConfig(dataSource);
    for (final Entry<String, String> entry : poolConfig.entrySet()) {
        printf("  %35s: %s", entry.getKey(), entry.getValue());
    }
}

From source file:com.ibm.watson.app.common.codegen.languages.WatsonAppJaxRSServerCodegen.java

public WatsonAppJaxRSServerCodegen() {
    super();/*from  ww  w.ja v  a  2s . c  o  m*/
    final Properties config = loadConfiguration();

    if (config.isEmpty()) {
        System.err.println("WARNING: No configuration supplied - using defaults");
    }

    // Override values defined in JaxRSServerCodegen
    invokerPackage = config.getProperty("invokerPackage", "com.ibm.watson.app.common.rest.api");
    groupId = config.getProperty("groupId", "com.ibm.watson.app");
    artifactId = config.getProperty("artifactId", "framework-ega-rest-api");
    artifactVersion = config.getProperty("artifactVersion", "1.0.0");
    // sourceFolder = config.getProperty("sourceFolder", "src/main/java"); // Default should be fine for this, no need to externalize
    title = config.getProperty("title", "Watson Gallery App Server Interface");

    // Override values defined in DefaultCodegen
    outputFolder = "generated-code" + File.separator + "watsonAppJavaJaxRS";
    templateDir = "WatsonAppJaxRS";
    apiPackage = config.getProperty("apiPackage", invokerPackage);
    modelPackage = config.getProperty("modelPackage", invokerPackage + ".model");

    additionalProperties.put("invokerPackage", invokerPackage);
    additionalProperties.put("groupId", groupId);
    additionalProperties.put("artifactId", artifactId);
    additionalProperties.put("artifactVersion", artifactVersion);
    additionalProperties.put("title", title);

    apiTemplateFiles.put("apiInterface.mustache", "Interface.java");

    supportingFiles.clear();
    supportingFiles.add(new SupportingFile("ApiException.mustache",
            (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator),
            "ApiException.java"));
    supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache",
            (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator),
            "ApiResponseMessage.java"));
    supportingFiles.add(new SupportingFile("NotFoundException.mustache",
            (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator),
            "NotFoundException.java"));

    // The follow will generate Java Client classes for the API as well as the Jax-RS bindings 
    boolean enableClientGeneration = BooleanUtils
            .toBoolean(config.getProperty("enableClientGeneration", "false"));
    if (enableClientGeneration) {
        apiTemplateFiles.put("apiClient.mustache", "Client.java");

        supportingFiles.add(new SupportingFile("abstractClientApi.mustache",
                (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator),
                "AbstractClientApi.java"));
    }

}