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); }
/** * 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))); }
if (b.getState() <= Bundle.RESOLVED || b.getHeaders().get(Constants.FRAGMENT_HOST) != null) continue;
@Activate public void activate(ComponentContext componentContext) { Dictionary<String, Object> config = componentContext.getProperties(); separator = (config.get("separator") != null) ? (String) config.get("separator") : ","; }
private void init(Bundle b) { Attributes attrs = getMainAttributes(); Dictionary headers = b.getHeaders(); for (Object o : Collections.list(headers.keys())) { attrs.putValue((String)o, (String)headers.get(o)); } }
/** * Create an EventProperties from the specified dictionary. * * <p> * The specified properties will be copied into this EventProperties. * Properties whose key is not of type {@code String} will be ignored. A * property with the key "event.topics" will be ignored. * * @param properties The properties to use for this EventProperties object * (may be {@code null}). */ EventProperties(Dictionary<String, ?> properties) { int size = (properties == null) ? 0 : properties.size(); Map<String, Object> p = new HashMap<String, Object>(size); if (size > 0) { for (Enumeration<?> e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); if ((key instanceof String) && !EVENT_TOPIC.equals(key)) { Object value = properties.get(key); p.put((String) key, value); } } } // safely publish the map this.properties = Collections.unmodifiableMap(p); }
@Activate public void activate(ComponentContext context) { this.path = (String) context.getProperties().get(ReasoningService.SERVICE_PATH); } }
/** * @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("-", ".")); } }
private void init(Bundle b) { Attributes attrs = getMainAttributes(); Dictionary headers = b.getHeaders(); for (Object o : Collections.list(headers.keys())) { attrs.putValue((String)o, (String)headers.get(o)); } }
/** * 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))); }
private void applyAuthSupplier(Dictionary<String, String> d, HTTPConduit c) { Enumeration<String> keys = d.keys(); while (keys.hasMoreElements()) { String k = keys.nextElement(); if (k.startsWith("authSupplier")) { String v = d.get(k); Object obj; try { obj = Class.forName(v).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException(e); } if (obj instanceof HttpAuthSupplier) { c.setAuthSupplier((HttpAuthSupplier)obj); } } } } }
/** Return the path at which to mount this servlet, or null * if it must not be mounted. */ private String getServletPath(ComponentContext ctx) { final Dictionary<?, ?> config = ctx.getProperties(); String result = (String)config.get(SERVLET_PATH_NAME); if(result != null && result.trim().length() == 0) { result = null; } return result; }
private static boolean isFragment(Bundle bundle) { return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null; } }
/** * Constructs an event. * * @param topic The topic of the event. * @param properties The event's properties (may be <code>null</code>). A * property whose key is not of type <code>String</code> will be * ignored. * @throws IllegalArgumentException If topic is not a valid topic name. */ public Event(String topic, Dictionary/* <String,Object> */properties) { validateTopicName(topic); this.topic = topic; int size = (properties == null) ? 1 : (properties.size() + 1); Map p = new HashMap(size); if (properties != null) { for (Enumeration e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); if (key instanceof String) { Object value = properties.get(key); p.put(key, value); } } } p.put(EventConstants.EVENT_TOPIC, topic); this.properties = p; // safely publish the map }
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; } }
protected String getBundleVersion(String pSymbolicName) { BundleContext context = JolokiaServlet.getCurrentBundleContext(); if (context != null) { for (Bundle bundle: context.getBundles()) { if (pSymbolicName.equalsIgnoreCase(bundle.getSymbolicName())) { Dictionary headers = bundle.getHeaders(); return (String) headers.get("Bundle-Version"); } } } return null; }
private void applyProxyAuthorization(Dictionary<String, String> d, HTTPConduit c) { Enumeration<String> keys = d.keys(); ProxyAuthorizationPolicy p = c.getProxyAuthorization(); while (keys.hasMoreElements()) { String k = keys.nextElement(); if (k.startsWith("proxyAuthorization.")) { if (p == null) { p = new ProxyAuthorizationPolicy(); c.setProxyAuthorization(p); } String v = d.get(k); k = k.substring("proxyAuthorization.".length()); if ("UserName".equals(k)) { p.setUserName(v); } else if ("Password".equals(k)) { p.setPassword(v); } else if ("Authorization".equals(k)) { p.setAuthorization(v); } else if ("AuthorizationType".equals(k)) { p.setAuthorizationType(v); } } } }
private 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; }
/** * This service is being activated so setup it: * <ul> * <li>Create and open the {@link MetadataDependencyRegistryTracker}.</li> * </ul> */ protected void activate(final ComponentContext componentContext) { this.registryTracker = new MetadataDependencyRegistryTracker(componentContext.getBundleContext(), this); this.registryTracker.open(); for (final Bundle b : componentContext.getBundleContext().getBundles()) { if (!MY_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName())) { continue; } final Object v = b.getHeaders().get("Bundle-Version"); if (v != null) { final String version = v.toString(); bundleVersionInfo = extractVersionInfoFromString(version); } break; } }
private void applyAuthorization(Dictionary<String, String> d, HTTPConduit c) { Enumeration<String> keys = d.keys(); AuthorizationPolicy p = c.getAuthorization(); while (keys.hasMoreElements()) { String k = keys.nextElement(); if (k.startsWith("authorization.")) { if (p == null) { p = new AuthorizationPolicy(); c.setAuthorization(p); } String v = d.get(k); k = k.substring("authorization.".length()); if ("UserName".equals(k)) { p.setUserName(v); } else if ("Password".equals(k)) { p.setPassword(v); } else if ("Authorization".equals(k)) { p.setAuthorization(v); } else if ("AuthorizationType".equals(k)) { p.setAuthorizationType(v); } } } }