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.pepstock.jem.node.StartUpSystem.java

/**
 * Loads affintiies loaders from JEM configuration.
 *//*from w w w  .  jav  a2  s  .  co  m*/
private static void loadDynamicAffinities() throws ConfigurationException {
    // load factories, checking if they are configured. If not, exception
    // occurs
    AffinityFactory affinityFactory = JEM_NODE_CONFIG.getExecutionEnviroment().getAffinityFactory();
    if (affinityFactory != null) {

        // load all factories for affinity factory
        // for all factories checking which have the right className. If
        // not,
        // exception occurs, otherwise it's loaded
        if (affinityFactory.getClassName() != null) {
            String className = affinityFactory.getClassName();
            try {
                // load by Class.forName of loader
                Object objectFactory = Class.forName(className).newInstance();

                // check if it's a AffinityLoader. if not, exception occurs.
                if (objectFactory instanceof AffinityLoader) {
                    AffinityLoader loader = (AffinityLoader) objectFactory;

                    // gets properties defined. If not empty, substitutes
                    // the value of property with variables
                    Properties propsOfFactory = affinityFactory.getProperties();
                    if (!propsOfFactory.isEmpty()) {
                        // scans all properties
                        for (Enumeration<Object> e = propsOfFactory.keys(); e.hasMoreElements();) {
                            // gets key and value
                            String key = e.nextElement().toString();
                            String value = propsOfFactory.getProperty(key);
                            // substitutes variables if present
                            // and sets new value for the key
                            propsOfFactory.setProperty(key, substituteVariable(value));
                        }
                    }
                    LogAppl.getInstance().emit(NodeMessage.JEMC049I, className);
                    // initializes the factory with properties defined
                    // and puts in the list if everything went good
                    loader.init(propsOfFactory);
                    // locks the access to file to avoid multiple accesses

                    Result result = loader.load(new SystemInfo());
                    if (result != null) {
                        Main.EXECUTION_ENVIRONMENT.getDynamicAffinities().addAll(result.getAffinities());
                        Main.EXECUTION_ENVIRONMENT.setMemory(result.getMemory());
                        Main.EXECUTION_ENVIRONMENT.setParallelJobs(result.getParallelJobs());
                    }
                    Main.setAffinityLoader(loader);
                } else {
                    LogAppl.getInstance().emit(NodeMessage.JEMC089E, className);
                }

            } catch (Exception e) {
                LogAppl.getInstance().emit(NodeMessage.JEMC031E, e, className);
            }
            // in this case the class name is null so ignore, emitting a
            // warning
        } else {
            LogAppl.getInstance().emit(NodeMessage.JEMC038W, ConfigKeys.FACTORY_ALIAS,
                    affinityFactory.toString());
        }
    }
    LogAppl.getInstance().emit(NodeMessage.JEMC050I, Main.EXECUTION_ENVIRONMENT);
}

From source file:io.personium.plugin.base.PluginConfig.java

/**
 * ?./*from   w  w w. j a  v  a2s.  c o  m*/
 */
private synchronized void doReload() {
    Logger log = LoggerFactory.getLogger(PluginConfig.class);
    Properties properties = getUnitConfigDefaultProperties();
    Properties propertiesOverride = getPersoniumConfigProperties();
    // ????????????
    if (!properties.isEmpty()) {
        this.props.clear();
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            if (!(entry.getKey() instanceof String)) {
                continue;
            }
            this.props.setProperty((String) entry.getKey(), (String) entry.getValue());
        }
    }
    if (!propertiesOverride.isEmpty()) {
        this.propsOverride.clear();
        for (Map.Entry<Object, Object> entry : propertiesOverride.entrySet()) {
            if (!(entry.getKey() instanceof String)) {
                continue;
            }
            this.propsOverride.setProperty((String) entry.getKey(), (String) entry.getValue());
        }
    }
    for (Object keyObj : propsOverride.keySet()) {
        String key = (String) keyObj;
        String value = this.propsOverride.getProperty(key);
        if (value == null) {
            continue;
        }
        log.debug("Overriding Config " + key + "=" + value);
        this.props.setProperty(key, value);
    }
}

From source file:com.impetus.client.hbase.schemamanager.HBaseSchemaManager.java

/**
 * Sets the external properties./*from   w  w  w . j  a  v a  2 s . co m*/
 * 
 * @param name
 *            the name
 * @param hColumnDescriptor
 *            the h column descriptor
 */
private void setExternalProperties(String name, HColumnDescriptor hColumnDescriptor) {
    Properties properties = externalProperties != null ? externalProperties.get(name) : null;
    if (properties != null && !properties.isEmpty()) {
        for (Object obj : properties.keySet()) {
            hColumnDescriptor.setValue(Bytes.toBytes(obj.toString()),
                    Bytes.toBytes(properties.get(obj).toString()));
        }
    }
}

From source file:fr.fastconnect.factory.tibco.bw.maven.run.LaunchDesignerMojo.java

private void updateAliasesFile() throws IOException {
    File aliasesFile = getAliasesFile();
    File designer5Prefs = getDesigner5Prefs();

    Properties prefs = new SortedProperties();
    FileInputStream fisPrefs = new FileInputStream(designer5Prefs);
    prefs.load(fisPrefs);//from w  w  w .j  a v a2 s  .co  m
    fisPrefs.close();

    Integer maxFileAliasPref = 0;
    for (Object k : prefs.keySet()) {
        String key = (String) k;

        if (key.startsWith(FILE_ALIAS_PREFIX)) {
            maxFileAliasPref++;
        }
    }

    Properties aliases = new Properties();
    FileInputStream fis = new FileInputStream(aliasesFile);
    aliases.load(fis);
    fis.close();

    String projectVersion = getProject().getVersion();
    Properties duplicates = new Properties();

    for (Object k : aliases.keySet()) {
        String key = (String) k;
        String value = aliases.getProperty(key);
        if (key.contains(projectVersion) && key.endsWith(":jar")) {
            getLog().debug(key);
            key = key.replace(projectVersion, "${project.version}");
            duplicates.put(key, value);
        }
    }

    if (!duplicates.isEmpty()) {
        for (Object k : duplicates.keySet()) {
            String key = (String) k;
            String value = duplicates.getProperty(key);
            key = key.replace(TIBCO_ALIAS_PREFIX, "");

            prefs.put(FILE_ALIAS_PREFIX + maxFileAliasPref.toString(), key + "=" + value);
            maxFileAliasPref++;
        }

        FileOutputStream fosPrefs = new FileOutputStream(designer5Prefs);
        prefs.store(fosPrefs, "");
        fis.close();

        aliases.putAll(duplicates);

        FileOutputStream fos = new FileOutputStream(aliasesFile);
        aliases.store(fos, "");
        fis.close();
    }
}

From source file:org.mule.context.DefaultMuleContextFactory.java

/**
 * Creates a new MuleContext using the given configurationBuilder and configuration. Properties if
 * provided are used to replace "property placeholder" value in configuration
 * files./*  w w w  .  j a  va 2  s  .com*/
 */
public MuleContext createMuleContext(ConfigurationBuilder configurationBuilder, Properties properties,
        MuleConfiguration configuration) throws InitialisationException, ConfigurationException {
    // Create MuleContext
    DefaultMuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
    contextBuilder.setMuleConfiguration(configuration);
    MuleContext muleContext = doCreateMuleContext(contextBuilder);

    // Configure with startup properties
    if (properties != null && !properties.isEmpty()) {
        new SimpleConfigurationBuilder(properties).configure(muleContext);
    }

    // Configure with configurationBuilder
    configurationBuilder.configure(muleContext);

    notifyMuleContextConfiguration(muleContext);

    return muleContext;
}

From source file:org.elasticsearch.hadoop.cfg.Settings.java

public Settings merge(Properties properties) {
    if (properties == null || properties.isEmpty()) {
        return this;
    }//from  w w w. jav a  2  s  .  c  o m

    Enumeration<?> propertyNames = properties.propertyNames();

    Object prop = null;
    for (; propertyNames.hasMoreElements();) {
        prop = propertyNames.nextElement();
        if (prop instanceof String) {
            Object value = properties.get(prop);
            setProperty((String) prop, value.toString());
        }
    }

    return this;
}

From source file:org.pepstock.jem.node.StartUpSystem.java

/**
 * load the listeners of the jem configuration checking if they are
 * configured//from ww w.  j  ava  2 s.  c  om
 * 
 * @param conf the jem node config
 * @param substituter a VariableSubstituter containing all the System
 *            properties
 * @throws ConfigurationException if some error occurs
 */
private static void loadListeners() throws ConfigurationException {
    // load listeners, checking if they are configured. If not, they are
    // optional, so go ahead
    List<Listener> listeners = JEM_ENV_CONFIG.getListeners();
    if (listeners != null && !listeners.isEmpty()) {
        // for all listener checking which have the right className. If
        // not, execption occurs, otherwise it's loaded
        for (Listener listener : listeners) {
            if (listener.getClassName() != null) {
                String className = listener.getClassName();
                try {
                    // load by Class.forName of listener
                    ObjectAndClassPathContainer oacp = ClassLoaderUtil.loadAbstractPlugin(listener, PROPERTIES);
                    Object objectListener = oacp.getObject();

                    // check if it's a JobLifecycleListener. if not,
                    // exception occurs. if yes, it's loaded on a
                    // EventListenerManager
                    if (objectListener instanceof JobLifecycleListener) {
                        JobLifecycleListener lister = (JobLifecycleListener) objectListener;
                        Main.JOB_LIFECYCLE_LISTENERS_SYSTEM.addListener(JobLifecycleListener.class, lister);
                        // gets properties defined. If not empty,
                        // substitutes the value of property with
                        // variables
                        Properties propsOfListener = listener.getProperties();
                        if (propsOfListener != null) {
                            if (!propsOfListener.isEmpty()) {
                                // scans all properties
                                for (Enumeration<Object> e = propsOfListener.keys(); e.hasMoreElements();) {
                                    // gets key and value
                                    String key = e.nextElement().toString();
                                    String value = propsOfListener.getProperty(key);
                                    // substitutes variables if present
                                    // and sets new value for the key
                                    propsOfListener.setProperty(key, substituteVariable(value));
                                }
                            }
                        } else {
                            // creates however an empty collection to
                            // avoid null pointer
                            propsOfListener = new Properties();
                        }
                        // initialize the listener passing parameters
                        // properties
                        lister.init(propsOfListener);
                        LogAppl.getInstance().emit(NodeMessage.JEMC037I, className);
                    } else {
                        LogAppl.getInstance().emit(NodeMessage.JEMC036E, className);
                        throw new ConfigurationException(
                                NodeMessage.JEMC036E.toMessage().getFormattedMessage(className));
                    }
                } catch (Exception e) {
                    LogAppl.getInstance().emit(NodeMessage.JEMC031E, e, className);
                    throw new ConfigurationException(
                            NodeMessage.JEMC031E.toMessage().getFormattedMessage(className));
                }
                // in this case the class name is null so ignore,
                // emitting a warning
            } else {
                LogAppl.getInstance().emit(NodeMessage.JEMC038W, ConfigKeys.LISTENER_ALIAS,
                        listener.toString());
            }
        }
    }
}

From source file:org.pepstock.jem.node.StartUpSystem.java

/**
 * load the factories of the jem configuration checking if they are
 * configured//from  w w w  . j av  a2s .  c o m
 * 
 * @param conf the jem node config
 * @param substituter a VariableSubstituter containing all the System
 *            properties
 * @throws ConfigurationException if some error occurs
 */
private static void loadFactories() throws ConfigurationException {
    // load factories, checking if they are configured. If not, exception
    // occurs
    List<Factory> factories = JEM_ENV_CONFIG.getFactories();
    if (factories == null) {
        LogAppl.getInstance().emit(NodeMessage.JEMC009E, ConfigKeys.FACTORIES_ELEMENT);
        throw new ConfigurationException(
                NodeMessage.JEMC009E.toMessage().getFormattedMessage(ConfigKeys.FACTORIES_ELEMENT));
    }
    if (factories.isEmpty()) {
        LogAppl.getInstance().emit(NodeMessage.JEMC009E, ConfigKeys.FACTORY_ALIAS);
        throw new ConfigurationException(
                NodeMessage.JEMC009E.toMessage().getFormattedMessage(ConfigKeys.FACTORY_ALIAS));
    }

    // for all factories checking which have the right className. If not,
    // execption occurs, otherwise it's loaded
    for (Factory factory : factories) {
        if (factory.getClassName() != null) {
            String className = factory.getClassName();
            try {

                ObjectAndClassPathContainer oacp = ClassLoaderUtil.loadAbstractPlugin(factory, PROPERTIES);
                Object objectFactory = oacp.getObject();

                // check if it's a JemFactory. if not, exception occurs. if
                // yes, it's loaded on a map
                // with all factory. Remember the the key of map is getType
                // result, put to lowercase to ignore case
                // during the search by key
                if (objectFactory instanceof JemFactory) {
                    JemFactory jf = (JemFactory) objectFactory;

                    // gets properties defined. If not empty, substitutes
                    // the value of property with variables
                    Properties propsOfFactory = factory.getProperties();
                    if (propsOfFactory != null) {
                        if (!propsOfFactory.isEmpty()) {
                            // scans all properties
                            for (Enumeration<Object> e = propsOfFactory.keys(); e.hasMoreElements();) {
                                // gets key and value
                                String key = e.nextElement().toString();
                                String value = propsOfFactory.getProperty(key);
                                // substitutes variables if present
                                // and sets new value for the key
                                propsOfFactory.setProperty(key, substituteVariable(value));
                            }
                        }
                    } else {
                        // creates however an emtpy collection to avoid null
                        // pointer
                        propsOfFactory = new Properties();
                    }

                    jf.setClassPath(oacp.getClassPath());
                    // initializes the factory with properties defined
                    // and puts in the list if everything went good
                    jf.init(propsOfFactory);

                    Main.FACTORIES_LIST.put(jf.getType().toLowerCase(), jf);

                    LogAppl.getInstance().emit(NodeMessage.JEMC032I, className, jf.getType());
                } else {
                    LogAppl.getInstance().emit(NodeMessage.JEMC040E, className);
                }

            } catch (Exception e) {
                LogAppl.getInstance().emit(NodeMessage.JEMC031E, e, className);
            }
            // in this case the class name is null so ignore, emitting a
            // warning
        } else {
            LogAppl.getInstance().emit(NodeMessage.JEMC038W, ConfigKeys.FACTORY_ALIAS, factory.toString());
        }
    }
}

From source file:org.pentaho.platform.plugin.services.metadata.MetadataDomainRepository.java

/**
 * Imports the localizations for the passed resourceName into the domain. the
 * property files should be located in the same folder as resourceName
 * following this naming pattern./*from   w  ww .ja  v  a2  s.c o  m*/
 * 
 * If resourceName = "bi-developers/resources/metadata.xmi"
 * 
 * then a United States English property file for it would be
 * "bi-developers/resources/metadata_en_US.properties
 * 
 * Both file names share the string "metadata".
 * 
 * @param domain
 * @param resourceName
 * @throws DomainStorageException
 */
protected void importLocalizations(Domain domain, String resourceName) throws DomainStorageException {

    // the parent file is the folder that fileName is in
    ISolutionFile[] propertiesFiles = getLocalePropertyFiles(resourceName);

    if (propertiesFiles != null) {
        LocalizationUtil localizationUtil = new LocalizationUtil();

        String locale = null;
        String propertiesFileNamePrefix = getPropertiesFilePrefix(resourceName);
        ISolutionRepository repo = PentahoSystem.get(ISolutionRepository.class, getSession());

        for (ISolutionFile propertyFile : propertiesFiles) {
            InputStream inputStream = null;
            try {
                // We need to get the resource input stream by passing the first
                // parameter as either following examples
                //     solution-folder/metadata_en_US.properties
                //     solution-folder/resources/metadata/mymodel_en_US.properties
                // passing false in the second parameter means to get me the file
                // as named in parameter 1 - do not manipulate the file name I passeds
                inputStream = repo.getResourceInputStream(
                        propertyFile.getSolutionPath()
                                .replaceFirst(String.valueOf(ISolutionRepository.SEPARATOR), "")
                                + ISolutionRepository.SEPARATOR + propertyFile.getFileName(),
                        false, ISolutionRepository.ACTION_EXECUTE);
                Properties properties = new Properties();
                properties.load(inputStream);
                if (properties.isEmpty()) {
                    String message = Messages.getErrorString(
                            "MetadataDomainRepository.ERROR_0008_EMPTY_LOCALIZATION_PROPERTY_FILE", //$NON-NLS-1$
                            propertyFile.getFileName());
                    DomainStorageException dse = new DomainStorageException(message, null);
                    throw dse;
                }
                locale = getLocaleFromPropertyFilename(propertyFile.getFileName(), propertiesFileNamePrefix);
                if (logger.isDebugEnabled()) {
                    List<String> messages = localizationUtil.analyzeImport(domain, properties, locale);
                    for (String message : messages) {
                        logger.debug(message);
                    }
                }

                localizationUtil.importLocalizedProperties(domain, properties, locale);
            } catch (FileNotFoundException fnfe) {
                throw new DomainStorageException(Messages.getErrorString(
                        "MetadataDomainRepository.ERROR_0009_EXCEPTION_READING_LOCALIZATION_PROPERTY_FILE",
                        propertyFile.getFileName()), fnfe);
            } catch (IOException ioe) {
                throw new DomainStorageException(Messages.getErrorString(
                        "MetadataDomainRepository.ERROR_0009_EXCEPTION_READING_LOCALIZATION_PROPERTY_FILE",
                        propertyFile.getFileName()), ioe);
            } finally {
                try {
                    inputStream.close();
                } catch (IOException ioe) {
                    throw new DomainStorageException(Messages.getErrorString(
                            "MetadataDomainRepository.ERROR_0009_EXCEPTION_READING_LOCALIZATION_PROPERTY_FILE",
                            propertyFile.getFileName()), ioe);
                }
            }
        }
    }
}

From source file:org.codice.ddf.platform.util.properties.PropertiesLoader.java

/**
 * Will attempt to load properties from a file using the given classloader without replacing the
 * system properties with their value. If that fails, several other methods will be tried until
 * the properties file is located.//from   w w w.j ava2 s.c o  m
 *
 * @param propertiesFile the resource name or the file path of the properties file
 * @param classLoader the class loader with access to the properties file
 * @return Properties deserialized from the specified file, or empty if the load failed
 */
public Properties loadPropertiesWithoutSystemPropertySubstitution(String propertiesFile,
        ClassLoader classLoader) {

    Properties properties = new Properties();
    if (propertiesFile == null) {
        LOGGER.debug("Properties file must not be null.");
        return properties;
    }
    Iterator<BiFunction<String, ClassLoader, Properties>> strategiesIterator = PROPERTY_LOADING_STRATEGIES
            .iterator();
    do {
        properties = strategiesIterator.next().apply(propertiesFile, classLoader);
    } while (properties.isEmpty() && strategiesIterator.hasNext());
    return properties;
}