public static Enumeration compoundEnumerations(Enumeration list1, Enumeration list2) { if (list2 == null || !list2.hasMoreElements()) return list1; if (list1 == null || !list1.hasMoreElements()) return list2; Vector compoundResults = new Vector(); while (list1.hasMoreElements()) compoundResults.add(list1.nextElement()); while (list2.hasMoreElements()) { Object item = list2.nextElement(); if (!compoundResults.contains(item)) // don't add duplicates compoundResults.add(item); } return compoundResults.elements(); }
/** * Populates the entries list with recursively found class entries. * * @param bundle The bundle to get class entries for. * @param entries The list to add the class entries to. * @param startPath The start path to look for entries. */ protected void collectClassEntries(Bundle bundle, List<Class> entries, String startPath) { Enumeration<String> entryPathEnumeration = bundle.getEntryPaths(startPath); while (entryPathEnumeration.hasMoreElements()) { String entryPath = entryPathEnumeration.nextElement(); if (entryPath.endsWith("/")) { collectClassEntries(bundle, entries, entryPath); } else if (entryPath.endsWith(".class")) { try { String classQName = entryPath.substring(0, entryPath.length() - 6).replace(File.separatorChar, '.'); if (classQName.startsWith("WEB-INF.classes.")) { classQName = classQName.substring(16); } Class entryClass = bundle.loadClass(classQName); // If not activatorMode is true then there will be classes in this list already on the // first // call to this method. Therefore we skip duplicates. if (!entries.contains(entryClass)) { entries.add(entryClass); } } catch (ClassNotFoundException cnfe) { this.activatorLogger.warn("Failed to load bundle class!", cnfe); } catch (NoClassDefFoundError ncdfe) { this.activatorLogger.warn("Failed to load bundle class!", ncdfe); } } } }
public ServiceRegistrationImpl( BundleImpl bundle, long serviceId, String[] classNames, Object service, Dictionary<String, ?> properties) { this.bundle = bundle; this.serviceId = serviceId; this.classNames = classNames; this.service = service; if ((properties == null) || properties.isEmpty()) this.properties = EMPTY_PROPERTIES; else { Enumeration<String> keys = properties.keys(); Map<String, Object> thisProperties = newCaseInsensitiveMapInstance(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (Constants.OBJECTCLASS.equalsIgnoreCase(key) || Constants.SERVICE_ID.equalsIgnoreCase(key)) continue; else if (thisProperties.containsKey(key)) throw new IllegalArgumentException(key); else thisProperties.put(key, properties.get(key)); } this.properties = thisProperties.isEmpty() ? EMPTY_PROPERTIES : thisProperties; } }
public Map getSystemProperties() { Map map = new HashMap(); Properties props = System.getProperties(); for (Enumeration e = props.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String val = (String) props.get(key); map.put(key, val); } return map; }
/** Prepares the factory for bundle shutdown. */ public void stop() { if (logger.isTraceEnabled()) logger.trace("Preparing to stop all protocol providers of" + this); synchronized (registeredAccounts) { for (Enumeration<ServiceRegistration> registrations = registeredAccounts.elements(); registrations.hasMoreElements(); ) { ServiceRegistration reg = registrations.nextElement(); stop(reg); reg.unregister(); } registeredAccounts.clear(); } }
/** Prepares the factory for bundle shutdown. */ public void stop() { logger.trace("Preparing to stop all SIP protocol providers."); Enumeration registrations = this.registeredAccounts.elements(); while (registrations.hasMoreElements()) { ServiceRegistration reg = ((ServiceRegistration) registrations.nextElement()); ProtocolProviderServiceSipImpl provider = (ProtocolProviderServiceSipImpl) SipActivator.getBundleContext().getService(reg.getReference()); // do an attempt to kill the provider provider.shutdown(); reg.unregister(); } registeredAccounts.clear(); }
public Map getBundleManifest(long bundleId) { Bundle b = Activator.bc.getBundle(bundleId); Dictionary d = b.getHeaders(); Map result = new HashMap(); int i = 0; for (Enumeration e = d.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String val = (String) d.get(key); result.put(key, val); i += 2; } result.remove("Application-Icon"); return result; }
@Override public Enumeration<URL> getResources(String name) throws IOException { try { equinoxContainer.checkAdminPermission(this, AdminPermission.RESOURCE); } catch (SecurityException e) { return null; } checkValid(); if (isFragment()) { return null; } ModuleClassLoader classLoader = getModuleClassLoader(false); Enumeration<URL> result = null; if (classLoader != null) { result = classLoader.getResources(name); } else { result = new ClasspathManager((Generation) module.getCurrentRevision().getRevisionInfo(), null) .findLocalResources(name); } return result != null && result.hasMoreElements() ? result : null; }