本文整理了Java中java.util.Dictionary
类的一些代码示例,展示了Dictionary
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dictionary
类的具体详情如下:
包路径:java.util.Dictionary
类名称:Dictionary
[英]Note: Do not use this class since it is obsolete. Please use the Map interface for new implementations.
Dictionary is an abstract class which is the superclass of all classes that associate keys with values, such as Hashtable.
[中]注意:不要使用此类,因为它已过时。请使用映射接口进行新的实现。
Dictionary是一个抽象类,它是所有将键与值关联的类(如Hashtable)的超类。
代码示例来源:origin: stanfordnlp/CoreNLP
private static <K,V> void log(RedwoodChannels channels, String description, Dictionary<K,V> dict) {
//(a real data structure)
Map<K, V> map = Generics.newHashMap();
//(copy to map)
Enumeration<K> keys = dict.keys();
while(keys.hasMoreElements()){
K key = keys.nextElement();
V value = dict.get(key);
map.put(key,value);
}
//(log like normal)
log(channels, description, map);
}
代码示例来源:origin: org.postgresql/postgresql
public void start(BundleContext context) throws Exception {
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, Driver.class.getName());
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, org.postgresql.util.DriverInfo.DRIVER_NAME);
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION, org.postgresql.util.DriverInfo.DRIVER_VERSION);
try {
_registration = context.registerService(DataSourceFactory.class.getName(),
new PGDataSourceFactory(), properties);
} catch (NoClassDefFoundError e) {
String msg = e.getMessage();
if (msg != null && msg.contains("org/osgi/service/jdbc/DataSourceFactory")) {
if (!Boolean.getBoolean("pgjdbc.osgi.debug")) {
return;
}
new IllegalArgumentException("Unable to load DataSourceFactory. "
+ "Will ignore DataSourceFactory registration. If you need one, "
+ "ensure org.osgi.enterprise is on the classpath", e).printStackTrace();
// just ignore. Assume OSGi-enterprise is not loaded
return;
}
throw e;
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* Dictionary does not have an equals.
* Please use Map.equals().
*
* <p>Follows the equals contract of Java 2's Map.</p>
* @param d1 the first directory.
* @param d2 the second directory.
* @return true if the directories are equal.
* @since Ant 1.5
* @deprecated since 1.6.x.
*/
@Deprecated
public static boolean equals(Dictionary<?, ?> d1, Dictionary<?, ?> d2) {
if (d1 == d2) {
return true;
}
if (d1 == null || d2 == null) {
return false;
}
if (d1.size() != d2.size()) {
return false;
}
// don't need the opposite check as the Dictionaries have the
// same size, so we've also covered all keys of d2 already.
return StreamUtils.enumerationAsStream(d1.keys())
.allMatch(key -> d1.get(key).equals(d2.get(key)));
}
代码示例来源:origin: stackoverflow.com
private Dictionary<Integer, Integer> listViewItemHeights = new Hashtable<Integer, Integer>();
private int getScroll() {
View c = listView.getChildAt(0); //this is the first visible row
int scrollY = -c.getTop();
listViewItemHeights.put(listView.getFirstVisiblePosition(), c.getHeight());
for (int i = 0; i < listView.getFirstVisiblePosition(); ++i) {
if (listViewItemHeights.get(i) != null) // (this is a sanity check)
scrollY += listViewItemHeights.get(i); //add all heights of the views that are gone
}
return scrollY;
}
代码示例来源:origin: org.apache.ant/ant
/**
* Dictionary does not know the putAll method. Please use Map.putAll().
* @param m1 the to directory.
* @param m2 the from directory.
* @param <K> type of the key
* @param <V> type of the value
* @since Ant 1.6
* @deprecated since 1.6.x.
*/
@Deprecated
public static <K, V> void putAll(Dictionary<? super K, ? super V> m1,
Dictionary<? extends K, ? extends V> m2) {
StreamUtils.enumerationAsStream(m2.keys()).forEach(key -> m1.put(key, m2.get(key)));
}
代码示例来源:origin: apache/felix
public void deleteProperty(String key) throws Exception{
Dictionary dic = configuration.getProperties();
Enumeration keys = dic.keys();
while (keys.hasMoreElements()) {
String k = (String) keys.nextElement();
if (k.equals(key)) {
dic.remove(k);
configuration.update(dic);
}
}
}
}
代码示例来源:origin: spring-projects/spring-roo
/**
* Method to populate current Repositories using OSGi Service
* @throws Exception
*/
private void populateRepositories() throws Exception {
// Cleaning Repositories
repositories.clear();
// Validating that RepositoryAdmin exists
Validate.notNull(getRepositoryAdmin(), "RepositoryAdmin not found");
// Checking if exists installed Repos and adding to repositories
Enumeration persistedRepos = installedRepos.keys();
while (persistedRepos.hasMoreElements()) {
String repositoryURL = (String) persistedRepos.nextElement();
// Checking if is a valid URL
if (repositoryURL.startsWith("http") || repositoryURL.startsWith("file")) {
// Installing persisted repositories
getRepositoryAdmin().addRepository(repositoryURL);
}
}
for (Repository repo : getRepositoryAdmin().listRepositories()) {
repositories.add(repo);
}
}
代码示例来源:origin: org.apache.geronimo.plugins/console-base-portlets
private static boolean checkBlueprintBundle(Bundle bundle){
// OSGi enterprise spec(r4.2) 121.3.4 (Page 206)
// check blueprint header
Object bpHeader = bundle.getHeaders().get(BundleUtil.BLUEPRINT_HEADER);
if (bpHeader!=null && (String)bpHeader!="") return true;
// check blueprint definitions
Enumeration<URL> enu = bundle.findEntries("OSGI-INF/blueprint/", "*.xml", false);
if (enu!=null && enu.hasMoreElements()) return true;
return false;
}
代码示例来源:origin: org.apache.sling/org.apache.sling.hc.core
@Activate
protected void activate(final ComponentContext ctx) {
bundleContext = ctx.getBundleContext();
componentContext = ctx;
healthCheckFilter = new HealthCheckFilter(bundleContext);
final Dictionary properties = ctx.getProperties();
filterTags = PropertiesUtil.toStringArray(properties.get(PROP_FILTER_TAGS), new String[] {});
combineTagsWithOr = PropertiesUtil.toBoolean(properties.get(PROP_COMBINE_TAGS_WITH_OR), DEFAULT_COMBINE_TAGS_WITH_OR);
log.debug("Activated, will select HealthCheck having tags {} {}", Arrays.asList(filterTags), combineTagsWithOr ? "using OR" : "using AND");
}
代码示例来源:origin: org.eclipse.tycho/org.eclipse.osgi
private void register(BundleContext context, String serviceClass, Object service, boolean setRanking, Dictionary<String, Object> properties) {
if (properties == null)
properties = new Hashtable<>(7);
Dictionary<String, String> headers = context.getBundle().getHeaders();
properties.put(Constants.SERVICE_VENDOR, headers.get(Constants.BUNDLE_VENDOR));
if (setRanking) {
properties.put(Constants.SERVICE_RANKING, Integer.valueOf(Integer.MAX_VALUE));
}
properties.put(Constants.SERVICE_PID, context.getBundle().getBundleId() + "." + service.getClass().getName()); //$NON-NLS-1$
registrations.add(context.registerService(serviceClass, service, properties));
}
}
代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons
@Activate
@SuppressWarnings("squid:S1149")
protected final void activate(ComponentContext context) throws Exception {
Dictionary<?, ?> properties = context.getProperties();
doActivate(context);
String[] filters = PropertiesUtil.toStringArray(properties.get(PROP_FILTER_PATTERN));
if (filters == null || filters.length == 0) {
throw new ConfigurationException(PROP_FILTER_PATTERN, "At least one filter pattern must be specified.");
}
for (String pattern : filters) {
Dictionary<String, String> filterProps = new Hashtable<String, String>();
log.debug("Adding filter ({}) to pattern: {}", this.toString(), pattern);
filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX, pattern);
filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)");
ServiceRegistration filterReg = context.getBundleContext().registerService(Filter.class.getName(), this, filterProps);
filterRegistrations.add(filterReg);
}
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception
*/
@Test
public void testAllBundlesActiveAndFeaturesInstalled() throws Exception {
// Asssert all bundles except fragments are ACTIVE.
for (Bundle b : bundleCtx.getBundles()) {
System.out.println(String.format("Checking state of bundle [symbolicName=%s, state=%s]",
b.getSymbolicName(), b.getState()));
if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null)
assertTrue(b.getState() == Bundle.ACTIVE);
}
// Check that according to the FeaturesService, all Ignite features except ignite-log4j are installed.
Feature[] features = featuresSvc.getFeatures(IGNITE_FEATURES_NAME_REGEX);
assertNotNull(features);
assertEquals(EXPECTED_FEATURES, features.length);
for (Feature f : features) {
if (IGNORED_FEATURES.contains(f.getName()))
continue;
boolean installed = featuresSvc.isInstalled(f);
System.out.println(String.format("Checking if feature is installed [featureName=%s, installed=%s]",
f.getName(), installed));
assertTrue(installed);
assertEquals(PROJECT_VERSION.replaceAll("-", "."), f.getVersion().replaceAll("-", "."));
}
}
代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons
@SuppressWarnings("squid:S1149")
protected final void registerAsSlingFilter(ComponentContext ctx, int ranking, String pattern) {
Dictionary<String, String> filterProps = new Hashtable<String, String>();
filterProps.put("service.ranking", String.valueOf(ranking));
filterProps.put("sling.filter.scope", "REQUEST");
filterProps.put("sling.filter.pattern", StringUtils.defaultIfEmpty(pattern, ".*"));
filterRegistration = ctx.getBundleContext().registerService(Filter.class.getName(), this, filterProps);
}
代码示例来源:origin: spring-projects/spring-roo
public void start(final BundleContext context) throws Exception {
startLevelServiceReference = context.getServiceReference(StartLevel.class.getName());
startLevel = (StartLevel) context.getService(startLevelServiceReference);
for (final Bundle bundle : context.getBundles()) {
final String value = bundle.getHeaders().get("Service-Component");
if (value != null) {
List<String> componentDescriptions = Arrays.asList(value.split("\\s*,\\s*"));
for (String desc : componentDescriptions) {
final URL url = bundle.getResource(desc);
process(url);
代码示例来源:origin: apache/ignite
Class<?> cls = null;
Bundle[] bundles = bundle.getBundleContext().getBundles();
if (b.getState() <= Bundle.RESOLVED || b.getHeaders().get(Constants.FRAGMENT_HOST) != null)
continue;
代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.reasoners.jena
@Activate
public void activate(ComponentContext context) {
this.path = (String) context.getProperties().get(ReasoningService.SERVICE_PATH);
}
}
代码示例来源:origin: apache/jackrabbit-oak
protected static String lookup(ComponentContext context, String property) {
//Prefer property from BundleContext first
if (context.getBundleContext().getProperty(property) != null) {
return context.getBundleContext().getProperty(property);
}
if (context.getProperties().get(property) != null) {
return context.getProperties().get(property).toString();
}
return null;
}
}
代码示例来源:origin: opencast/opencast
/**
* Check the existence of the given dictionary. Throw an exception if null.
*/
public static void checkDictionary(Dictionary properties, ComponentContext componentContext)
throws ConfigurationException {
if (properties == null) {
String dicName = componentContext.getProperties().get("service.pid").toString();
throw new ConfigurationException("*", "Dictionary for " + dicName + " does not exist");
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.junit.core
protected void activate(ComponentContext ctx) {
bundleContext = ctx.getBundleContext();
bundleContext.addBundleListener(this);
// Initially consider all bundles as "changed"
for(Bundle b : bundleContext.getBundles()) {
if(getSlingTestRegexp(b) != null) {
changedBundles.add(b.getSymbolicName());
log.debug("Will look for test classes inside bundle {}", b.getSymbolicName());
}
}
lastModified = System.currentTimeMillis();
pid = (String)ctx.getProperties().get(Constants.SERVICE_PID);
}
代码示例来源:origin: rhuss/jolokia
private String getConfigurationFromConfigAdmin(ConfigKey pkey) {
ConfigurationAdmin configAdmin = (ConfigurationAdmin) configAdminTracker.getService();
if (configAdmin == null) {
return null;
}
try {
Configuration config = configAdmin.getConfiguration(CONFIG_ADMIN_PID);
if (config == null) {
return null;
}
Dictionary<?, ?> props = config.getProperties();
if (props == null) {
return null;
}
return (String) props.get(CONFIG_PREFIX + "." + pkey.getKeyValue());
} catch (IOException e) {
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!