Example usage for java.util Properties size

List of usage examples for java.util Properties size

Introduction

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

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:org.rdv.ConfigurationManager.java

/**
 * Save the application configuration to the specified file.
 * /*from w ww . j a  v  a  2s .c o  m*/
 * @param configFile  the file to save the configuration to
 * @since             1.3
 */
public static void saveConfiguration(File configFile) {
    PrintWriter out;
    try {
        out = new PrintWriter(new BufferedWriter(new FileWriter(configFile)));
    } catch (IOException e) {
        return;
    }

    out.println("<?xml version=\"1.0\"?>");
    out.println("<rdv>");

    RBNBController rbnb = RBNBController.getInstance();
    out.println("  <rbnb>");
    out.println("    <host>" + rbnb.getRBNBHostName() + "</host>");
    out.println("    <port>" + rbnb.getRBNBPortNumber() + "</port>");
    out.println("    <state>" + RBNBController.getStateName(rbnb.getState()) + "</state>");
    out.println("    <timeScale>" + rbnb.getTimeScale() + "</timeScale>");
    out.println("    <playbackRate>" + rbnb.getPlaybackRate() + "</playbackRate>");
    out.println("  </rbnb>");

    LocalChannelManager localChannelManager = LocalChannelManager.getInstance();
    if (localChannelManager.hasChannels()) {
        for (LocalChannel localChannel : localChannelManager.getChannels()) {
            out.print("  <localChannel name=\"" + localChannel.getName() + "\"");
            if (localChannel.getUnit() != null) {
                out.print(" unit=\"" + localChannel.getUnit() + "\"");
            }
            out.println(" formula=\"" + localChannel.getFormula() + "\">");
            for (Entry<String, String> variable : localChannel.getVariables().entrySet()) {
                out.println("    <variable name=\"" + variable.getKey() + "\" channel=\"" + variable.getValue()
                        + "\"/>");
            }
            out.println("  </localChannel>");
        }
    }

    List<DataPanel> dataPanels = DataPanelManager.getInstance().getDataPanels();
    Iterator<DataPanel> it = dataPanels.iterator();
    while (it.hasNext()) {
        DataPanel dataPanel = it.next();
        Properties properties = dataPanel.getProperties();

        if (isPanelDetached(dataPanel, properties)) {
            if (dataPanel.subscribedChannelCount() == 0) // A detached panel with no channels subscribed, or a non-existing detached panel 
                continue; // don't add to configuration
        }

        out.println("  <dataPanel id=\"" + dataPanel.getClass().getName() + "\">");

        if (dataPanel.subscribedChannelCount() > 0) {
            out.println("    <channels>");
            Iterator<String> channels = dataPanel.subscribedChannels().iterator();
            while (channels.hasNext()) {
                String channel = channels.next();
                out.println("      <channel>" + channel + "</channel>");
            }
            out.println("    </channels>");
        }

        if (properties.size() > 0) {
            out.println("    <properties>");
            for (Enumeration<?> keys = properties.propertyNames(); keys.hasMoreElements();) {
                String key = (String) keys.nextElement();
                String value = properties.getProperty(key);
                out.println("      <entry key=\"" + key + "\">" + value + "</entry>");
            }
            out.println("    </properties>");
        }

        out.println("  </dataPanel>");
    }

    out.print("</rdv>");
    out.close();
}

From source file:com.honnix.yaacs.admin.lifecycle.Lifecycle.java

private void createAdapterServers() {
    Properties props = PropertiesLoader.loadProperties(ACPropertiesConstant.ADAPTER_PROPERTIES_FILE_NAME);

    adapterServerMap = new HashMap<String, AdapterServer>(props.size());

    Enumeration<?> propEnum = props.propertyNames();

    while (propEnum.hasMoreElements()) {
        String key = (String) propEnum.nextElement();
        String value = props.getProperty(key);

        try {//  w  w  w  .  j a va 2  s.co m
            AdapterServer adapterServer = (AdapterServer) Class.forName(value).getConstructor(ACServer.class)
                    .newInstance(acServer);

            adapterServerMap.put(key, adapterServer);
        } catch (Exception e) {
            StringBuilder sb = new StringBuilder("Error create adapter server \"").append(value).append("\".");

            LOG.error(sb.toString(), e);
        }
    }
}

From source file:org.jajuk.util.UpgradeManager.java

/**
 * For Jajuk < 1.9: bootstrap file is now in XML format
 * <br>//w  w w  . ja  v a  2 s  .c o m
 * If it exists and contains data in 1.7 or 1.8 format, it convert it to new XML
 * format (to handle backslashes properly, old format just drop them)
 * <br>
 * This method doesn't yet validate provided workspace paths but only the bootstrap file
 * structure itself.
 */
public static void upgradeBootstrapFile() {
    try {
        String KEY_TEST = "test";
        String KEY_FINAL = "final";
        File bootstrapOld = new File(SessionService.getBootstrapPath(Const.FILE_BOOTSTRAP_OLD));
        File bootstrapOldOldHome = new File(System.getProperty("user.home") + "/" + Const.FILE_BOOTSTRAP_OLD);
        File bootstrapNew = new File(SessionService.getBootstrapPath());
        // Fix for #1473 : move the bootstrap file if required (See #1473)
        if (UtilSystem.isUnderWindows() && !bootstrapOld.equals(bootstrapOldOldHome) && !bootstrapOld.exists()
                && bootstrapOldOldHome.exists()) {
            try {
                FileUtils.copyFileToDirectory(bootstrapOldOldHome, new File(UtilSystem.getUserHome()));
                UtilSystem.deleteFile(bootstrapOldOldHome);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        if (bootstrapOld.exists() && !bootstrapNew.exists()) {
            Properties prop = null;
            // Try to load a bootstrap file using plain text old format
            prop = new Properties();
            FileInputStream fis = new FileInputStream(
                    SessionService.getBootstrapPath(Const.FILE_BOOTSTRAP_OLD));
            prop.load(fis);
            fis.close();
            // If it exists and contains pre-1.7 bootstrap format (a single line with a raw path),
            // convert it to 1.7 format first
            if (prop.size() == 1) {
                // We get something like <... path ...> = <nothing>
                String path = (String) prop.keys().nextElement();
                // we use this path for both test and final workspace
                prop.clear();
                prop.put(KEY_TEST, path);
                prop.put(KEY_FINAL, path);
            }
            // Make sure to populate both test and final release
            if (!prop.containsKey(KEY_TEST)) {
                prop.put(KEY_TEST, UtilSystem.getUserHome());
            }
            if (!prop.containsKey(KEY_FINAL)) {
                prop.put(KEY_FINAL, UtilSystem.getUserHome());
            }
            // Write down the new bootstrap file
            SessionService.commitBootstrapFile(prop);
            // Delete old bootstrap file
            bootstrapOld.delete();
        }
    } catch (Exception e) {
        // Do not throw any exception from here. display raw stack trace, Logs facilities 
        // are not yet available.
        e.printStackTrace();
    }
}

From source file:org.springframework.jndi.JndiTemplate.java

/**
 * Create a new JNDI initial context. Invoked by {@link #getContext}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 * @return the initial Context instance/*from w ww  . j a v  a2 s.  c o  m*/
 * @throws NamingException in case of initialization errors
 */
protected Context createInitialContext() throws NamingException {
    Hashtable<?, ?> icEnv = null;
    Properties env = getEnvironment();
    if (env != null) {
        icEnv = new Hashtable<>(env.size());
        CollectionUtils.mergePropertiesIntoMap(env, icEnv);
    }
    return new InitialContext(icEnv);
}

From source file:cn.vlabs.duckling.vwb.service.config.impl.DomainServiceImpl.java

private void refineDomain(int siteId) {
    Map<String, String> domains = siteConfig.getPropertyStartWith(siteId, KeyConstants.SITE_DOMAIN_KEY);
    Properties prop = compact(domains);
    if (prop.size() != domains.size()) {
        log.info("Domain name's config is inconsist. it will be refined...");
        for (String key : domains.keySet()) {
            if (!prop.containsKey(key)) {
                siteConfig.removeProperty(siteId, key);
                cache.removeEntry(GLOBAL_SITE_ID, domains.get(key));
            }/*from w w  w .j  a va  2s . com*/
        }
        siteConfig.setProperty(siteId, prop);
    }
}

From source file:de.alpharogroup.lang.ClassUtilsTest.java

/**
 * Test method for//from   ww w .j  a v  a2s  .co m
 * {@link de.alpharogroup.lang.ClassUtils#getResourceAsStream(java.lang.Class, java.lang.String)}
 * .
 *
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
@Test(enabled = false)
public void testGetRessourceAsStream() throws IOException {
    final String propertiesFilename = "resources.properties";
    final String pathFromObject = PackageUtils.getPackagePathWithSlash(this);
    final String path = pathFromObject + propertiesFilename;

    final ClassUtilsTest obj = new ClassUtilsTest();
    final InputStream is = ClassExtensions.getResourceAsStream(obj.getClass(), path);
    this.result = is != null;
    AssertJUnit.assertTrue("InputStream should not be null", this.result);
    final Properties prop = new Properties();
    prop.load(is);
    this.result = prop.size() == 3;
    AssertJUnit.assertTrue("Size of prop should be 3.", this.result);
}

From source file:com.adaptris.interlok.types.DefaultSerializableMessage.java

/**
 * Convenience method to do the same as {@link #setMessageHeaders(Map)} converting any non-string
 * keys/values into Strings.//from w w  w  .j a v  a  2 s  .  c  o m
 * 
 * @param props the properties that should become message headers; null means to clear all
 *        headers.
 * @return the current DefaultSerializableMessage object for method chaining
 * @see #setMessageHeaders(Map)
 */
public DefaultSerializableMessage withHeadersFromProperties(Properties props) {
    if (props == null) {
        setMessageHeaders(null);
    } else {
        Map<String, String> result = new HashMap<>(props.size());
        for (Map.Entry e : props.entrySet()) {
            result.put(e.getKey().toString(), e.getValue().toString());
        }
        setMessageHeaders(result);
    }
    return this;
}

From source file:org.jsecurity.jndi.JndiTemplate.java

/**
 * Create a new JNDI initial context. Invoked by {@link #execute}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 *
 * @return the initial Context instance/*  w w w .  jav a2  s  . c o  m*/
 * @throws NamingException in case of initialization errors
 */
@SuppressWarnings({ "unchecked" })
protected Context createInitialContext() throws NamingException {
    Properties env = getEnvironment();
    Hashtable icEnv = null;
    if (env != null) {
        icEnv = new Hashtable(env.size());
        for (Enumeration en = env.propertyNames(); en.hasMoreElements();) {
            String key = (String) en.nextElement();
            icEnv.put(key, env.getProperty(key));
        }
    }
    return new InitialContext(icEnv);
}

From source file:org.wso2.carbon.registry.indexing.IndexingManager.java

private void readLastAccessTime() {
    try {/*from   w  ww  .  j a va  2 s .c  o m*/
        final String lastAccessTimeLocation = getLastAccessTimeLocation();
        if (registry.resourceExists(lastAccessTimeLocation)) {
            Properties properties = registry.get(lastAccessTimeLocation).getProperties();
            if (properties != null && properties.size() != 0) {
                for (Object key : properties.keySet()) {
                    lastAccessTime.put(Integer.parseInt((String) key),
                            new Date(Long.parseLong((String) ((List) properties.get(key)).get(0))));
                }
            }
        }
    } catch (RegistryException e) {
        log.error("Could not read last activity time when starting indexing", e);
    }
}

From source file:com.splicemachine.derby.utils.SpliceAdmin.java

/**
 * Get the values of all properties for the current connection.
 *
 * @param rs array of result set objects that contains all of the defined properties
 *           for the JVM, service, database, and app.
 * @throws SQLException Standard exception policy.
 **///from   w w  w .  j av  a2  s . c  o m
public static void SYSCS_GET_ALL_PROPERTIES(ResultSet[] rs) throws SQLException {
    try {
        LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
        TransactionController tc = lcc.getTransactionExecute();

        // Fetch all the properties.
        Properties jvmProps = addTypeToProperties(System.getProperties(), "JVM", true);
        Properties dbProps = addTypeToProperties(tc.getProperties()); // Includes both database and service properties.
        ModuleFactory monitor = Monitor.getMonitorLite();
        Properties appProps = addTypeToProperties(monitor.getApplicationProperties(), "APP", false);

        // Merge the properties using the correct search order.
        // SEARCH ORDER: JVM, Service, Database, App
        appProps.putAll(dbProps); // dbProps already has been overwritten with service properties.
        appProps.putAll(jvmProps);
        ArrayList<ExecRow> rows = new ArrayList<>(appProps.size());

        // Describe the format of the input rows (ExecRow).
        //
        // Columns of "virtual" row:
        //   KEY         VARCHAR
        //   VALUE         VARCHAR
        //   TYPE         VARCHAR (JVM, SERVICE, DATABASE, APP)
        DataValueDescriptor[] dvds = new DataValueDescriptor[] { new SQLVarchar(), new SQLVarchar(),
                new SQLVarchar() };
        int numCols = dvds.length;
        ExecRow dataTemplate = new ValueRow(numCols);
        dataTemplate.setRowArray(dvds);

        // Transform the properties into rows.  Sort the properties by key first.
        ArrayList<String> keyList = new ArrayList<>();
        for (Object o : appProps.keySet()) {
            if (o instanceof String)
                keyList.add((String) o);
        }
        Collections.sort(keyList);
        for (String key : keyList) {
            String[] typedValue = (String[]) appProps.get(key);
            dvds[0].setValue(key);
            dvds[1].setValue(typedValue[0]);
            dvds[2].setValue(typedValue[1]);
            rows.add(dataTemplate.getClone());
        }

        // Describe the format of the output rows (ResultSet).
        ResultColumnDescriptor[] columnInfo = new ResultColumnDescriptor[numCols];
        columnInfo[0] = new GenericColumnDescriptor("KEY",
                DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 50));
        columnInfo[1] = new GenericColumnDescriptor("VALUE",
                DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 40));
        columnInfo[2] = new GenericColumnDescriptor("TYPE",
                DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 10));
        EmbedConnection defaultConn = (EmbedConnection) getDefaultConn();
        Activation lastActivation = defaultConn.getLanguageConnection().getLastActivation();
        IteratorNoPutResultSet resultsToWrap = new IteratorNoPutResultSet(rows, columnInfo, lastActivation);
        resultsToWrap.openCore();
        EmbedResultSet ers = new EmbedResultSet40(defaultConn, resultsToWrap, false, null, true);
        rs[0] = ers;
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
}