Example usage for java.util Dictionary get

List of usage examples for java.util Dictionary get

Introduction

In this page you can find the example usage for java.util Dictionary get.

Prototype

public abstract V get(Object key);

Source Link

Document

Returns the value to which the key is mapped in this dictionary.

Usage

From source file:com.savoirtech.eos.pattern.factory.AbstractManagedServiceFactory.java

protected static String getProperty(String name, Dictionary<String, ?> configProperties, String defaultValue) {
    final Object value = configProperties.get(name);
    return value == null ? defaultValue : String.valueOf(value);
}

From source file:org.jboss.tools.pde.sourcelookup.core.internal.utils.BundleUtil.java

public static IArtifactKey getArtifactKey(File file) {
    if (file == null || !file.exists()) {
        return null;
    }//from   www.ja  v a 2  s  .co  m
    String id = null;
    String version = null;
    try {
        Dictionary<String, String> manifest = BundlesAction.loadManifest(file);
        if (manifest != null) {
            id = ManifestElement.parseHeader("Bundle-SymbolicName", manifest.get("Bundle-SymbolicName"))[0]
                    .getValue();
            version = manifest.get("Bundle-Version");
        }
    } catch (Exception e) {
        return null;
    }

    if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(version)) {
        return BundlesAction.createBundleArtifactKey(id, version);
    }
    return null;
}

From source file:com.savoirtech.eos.pattern.factory.AbstractManagedServiceFactory.java

protected static String getProperty(String name, boolean required, Dictionary<String, ?> configProperties)
        throws ConfigurationException {
    final Object value = configProperties.get(name);
    if (value != null) {
        return String.valueOf(value);
    } else if (required) {
        throw new ConfigurationException(name, String.format("Configuration property %s is required.", name));
    } else {//  w ww  .  ja va 2  s . c  om
        return null;
    }
}

From source file:org.mqnaas.api.AddressLoader.java

/**
 * Reads the address where the REST API should be published from <literal>org.mqnaas.ws.configuration.cfg</literal> configuration file. If no
 * information or file is provided, it returns the default address.
 * //from   w ww  . j  a va 2  s.  c om
 * @return Address configured in > in <literal>ws.address</literal> property of file <literal>org.mqnaas.ws.configuration.cfg</literal>, with no
 *         final slash at the end. Default <literal>http://0.0.0.0:9000</literal> address if file does not exist, or a malformed URL was defined
 *         in it.
 */
public static String getServerAddress() {

    ConfigurationAdmin configAdmin = getConfigurationAdmin();

    if (configAdmin == null) {
        log.warn("Could not get ConfigurationAdmin. Using defult address: " + DEFAULT_ADDRESS);
        return DEFAULT_ADDRESS;
    }
    try {
        Dictionary<String, Object> wsProperties = configAdmin.getConfiguration(ADDRESS_CONFIG_FILE)
                .getProperties();
        String address = (String) wsProperties.get(ADDRESS_PROPERTY);

        if (address == null) {
            log.warn("No URI present in WS configuration file. Using defult address: " + DEFAULT_ADDRESS);
            return DEFAULT_ADDRESS;
        }

        try {
            new URI(address);
        } catch (URISyntaxException e) {
            log.warn("Malformed URI in WS configuration file. Using defult address: " + DEFAULT_ADDRESS, e);
            return DEFAULT_ADDRESS;
        }

        return StringUtils.removeEnd(address, "/");

    } catch (Exception e) {
        log.warn("Could not get WS address from configuration file. Using defult address: " + DEFAULT_ADDRESS,
                e);
        return DEFAULT_ADDRESS;
    }

}

From source file:org.apache.whirr.karaf.command.support.ConfigurationReader.java

/**
 * Builds the Configuration from Configuration Admin.
 *
 * @param pid/* w  w w  .  j  a  v a 2s . co m*/
 * @return
 */
public static PropertiesConfiguration fromConfigAdmin(ConfigurationAdmin configurationAdmin, String pid) {
    List<String> ignoredKeys = Arrays.asList("service.pid", "felix.fileinstall.filename");
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    try {
        Configuration configuration = configurationAdmin.getConfiguration(pid);
        Dictionary properties = configuration.getProperties();
        Enumeration keys = properties.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = properties.get(key);
            if (!ignoredKeys.contains(key)) {
                propertiesConfiguration.addProperty(String.valueOf(key), value);
            }
        }
    } catch (IOException e) {
        System.err.println(String.format("No configuration found for pid:%s.", pid));
        return null;
    }
    return propertiesConfiguration;
}

From source file:Main.java

/**
 * Returns a semicolumn separated list of keys and values in the dictionary.
 * //from w w w . j ava  2 s. c o  m
 * Here is an example of returned String "key1 = value1; key2 = value2;"
 * 
 * 
 * 
 * @param dict
 *            Dictionary<Object,Object>
 * @return : String.
 */
public static String dictionaryToString(Dictionary<Object, Object> dict) {
    Enumeration<Object> keys = dict.keys();
    Object key, value;
    StringBuffer result = new StringBuffer();

    while (keys.hasMoreElements()) {
        key = keys.nextElement();
        value = dict.get(key);

        result.append(key.toString());
        result.append(" = ");
        result.append(value.toString());
        result.append("; ");
    }

    return result.toString();
}

From source file:spring.osgi.utils.OsgiStringUtils.java

/**
 * Returns the name of the given <code>Bundle</code> in a null-safe
 * manner.//from  w ww  .  j  a  v a 2 s  .c  o m
 *
 * @param bundle OSGi bundle (can be <code>null</code>)
 * @return bundle name
 */
public static String nullSafeName(Bundle bundle) {
    if (bundle == null)
        return NULL_STRING;

    Dictionary headers = bundle.getHeaders();

    if (headers == null)
        return NULL_STRING;

    String name = (String) headers.get(org.osgi.framework.Constants.BUNDLE_NAME);

    return (name == null ? NULL_STRING : name);

}

From source file:org.eclipse.virgo.ide.runtime.core.ServerUtils.java

/**
 * Returns the {@link JavaVersion} of the given {@link IJavaProject}
 *//*from  ww w. j a v  a  2  s.  c om*/
public static JavaVersion getJavaVersion(IProject project) {
    IJavaProject javaProject = JdtUtils.getJavaProject(project);
    if (javaProject != null) {

        // first check the manifest for that
        // Bundle-RequiredExecutionEnvironment
        BundleManifest bundleManifest = BundleManifestCorePlugin.getBundleManifestManager()
                .getBundleManifest(javaProject);
        Dictionary<String, String> manifest = bundleManifest.toDictionary();
        if (manifest != null && manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT) != null) {
            String javaVersion = manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
            return JAVA_VERSION_MAPPING.get(javaVersion);
        }

        // second check the project for a matching jvm
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(JRE_CONTAINER_PATH, javaProject);
            if (container != null && container instanceof JREContainer) {
                // reflection hack to get the internal jvm install
                Field field = JREContainer.class.getDeclaredField("fVMInstall");
                field.setAccessible(true);
                IVMInstall vm = (IVMInstall) field.get((JREContainer) container);

                IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
                // check for strict match
                for (IExecutionEnvironment executionEnvironment : manager.getExecutionEnvironments()) {
                    if (executionEnvironment.isStrictlyCompatible(vm)) {
                        return JAVA_VERSION_MAPPING.get(executionEnvironment.getId());
                    }
                }

                // check for default
                for (IExecutionEnvironment executionEnvironment : manager.getExecutionEnvironments()) {
                    if (executionEnvironment.getDefaultVM() != null
                            && executionEnvironment.getDefaultVM().equals(vm)) {
                        return JAVA_VERSION_MAPPING.get(executionEnvironment.getId());
                    }
                }

                // check for compatibility
                for (IExecutionEnvironment executionEnvironment : manager.getExecutionEnvironments()) {
                    if (Arrays.asList(executionEnvironment.getCompatibleVMs()).contains(vm)) {
                        return JAVA_VERSION_MAPPING.get(executionEnvironment.getId());
                    }
                }
            }
        } catch (Exception e) {
            SpringCore.log(e);
        }
    }
    return null;
}

From source file:spring.osgi.utils.OsgiStringUtils.java

/**
 * Returns the bundle name and symbolic name - useful when logging bundle
 * info./*from w  ww.  j  a v  a  2s . co m*/
 *
 * @param bundle OSGi bundle (can be null)
 * @return the bundle name and symbolic name
 */
public static String nullSafeNameAndSymName(Bundle bundle) {
    if (bundle == null)
        return NULL_STRING;

    Dictionary dict = bundle.getHeaders();

    if (dict == null)
        return NULL_STRING;

    StringBuilder buf = new StringBuilder();
    String name = (String) dict.get(org.osgi.framework.Constants.BUNDLE_NAME);
    if (name == null)
        buf.append(NULL_STRING);
    else
        buf.append(name);
    buf.append(" (");
    String sname = (String) dict.get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);

    if (sname == null)
        buf.append(NULL_STRING);
    else
        buf.append(sname);

    buf.append(")");

    return buf.toString();
}

From source file:org.osgi.jmx.codec.Util.java

public static Map<String, String> getBundleHeaders(Bundle b) {
    Map<String, String> headers = new Hashtable<String, String>();
    Dictionary h = b.getHeaders();
    for (Enumeration keys = h.keys(); keys.hasMoreElements();) {
        String key = (String) keys.nextElement();
        headers.put(key, (String) h.get(key));
    }/*from   ww w. j  a  v a 2  s .  c  o  m*/
    return headers;
}