📄 configurationadminfactory.java
字号:
return; } pidsForLocation.remove(sr); if (pidsForLocation.isEmpty()) { locationToPids.remove(bundleLocation); } } void updateTargetServicesMatching(ConfigurationDictionary cd) throws IOException { String servicePid = (String) cd.get(SERVICE_PID); String factoryPid = (String) cd.get(FACTORY_PID); String bundleLocation = (String) cd.get(BUNDLE_LOCATION); if (servicePid == null) { return; } if (factoryPid == null) { updateManagedServicesMatching(servicePid, bundleLocation); } else { updateManagedServiceFactoriesMatching(servicePid, factoryPid, bundleLocation); } } private void updateManagedServiceFactoriesMatching(String servicePid, String factoryPid, String bundleLocation) throws IOException { ServiceReference[] srs = getTargetServiceReferences( ManagedServiceFactory.class, factoryPid); ConfigurationDictionary cd = store.load(servicePid); if (cd == null) { updateManagedServiceFactories(srs, servicePid, factoryPid, bundleLocation); } else { updateManagedServiceFactories(srs, servicePid, factoryPid, cd); } } void updateManagedServiceFactories(ServiceReference[] srs, String servicePid, String factoryPid, ConfigurationDictionary cd) throws IOException { ConfigurationDictionary bound = bindLocationIfNeccesary(srs, cd); String boundLocation = (String) bound.get(BUNDLE_LOCATION); ServiceReference[] filtered = filterOnMatchingLocations(srs, boundLocation); for (int i = 0; i < filtered.length; ++i) { configurationDispatcher.dispatchUpdateFor(filtered[i], servicePid, factoryPid, bound); } } void updateManagedServiceFactories(ServiceReference[] srs, String servicePid, String factoryPid, String boundLocation) { ServiceReference[] filtered = filterOnMatchingLocations(srs, boundLocation); for (int i = 0; i < filtered.length; ++i) { configurationDispatcher.dispatchUpdateFor(filtered[i], servicePid, factoryPid, null); } } private void updateManagedServiceFactory(ServiceReference sr) throws IOException { final String factoryPid = (String) sr.getProperty(SERVICE_PID); ConfigurationDictionary[] cds = store.loadAll(factoryPid); if (cds == null || cds.length == 0) { return; } ServiceReference[] srs = new ServiceReference[] { sr }; for (int i = 0; i < cds.length; ++i) { String servicePid = (String) cds[i].get(SERVICE_PID); updateManagedServiceFactories(srs, servicePid, factoryPid, cds[i]); } } // // private void updateManagedServicesMatching(String servicePid, String bundleLocation) throws IOException { ServiceReference[] srs = getTargetServiceReferences( ManagedService.class, servicePid); ConfigurationDictionary cd = store.load(servicePid); if (cd == null) { updateManagedServices(srs, servicePid, bundleLocation); } else { updateManagedServices(srs, servicePid, cd); } } private void updateManagedServices(ServiceReference[] srs, String servicePid, String boundLocation) { ServiceReference[] filtered = filterOnMatchingLocations(srs, boundLocation); for (int i = 0; i < filtered.length; ++i) { configurationDispatcher.dispatchUpdateFor(filtered[i], servicePid, null, null); } } private void updateManagedServices(ServiceReference[] srs, String servicePid, ConfigurationDictionary cd) throws IOException { ConfigurationDictionary bound = bindLocationIfNeccesary(srs, cd); String boundLocation = (String) bound.get(BUNDLE_LOCATION); ServiceReference[] filtered = filterOnMatchingLocations(srs, boundLocation); for (int i = 0; i < filtered.length; ++i) { configurationDispatcher.dispatchUpdateFor(filtered[i], servicePid, null, bound); } } private void updateManagedService(ServiceReference sr) throws IOException { final String servicePid = (String) sr.getProperty(SERVICE_PID); ServiceReference[] srs = new ServiceReference[] { sr }; ConfigurationDictionary cd = store.load(servicePid); if (cd == null) { for (int i = 0; i < srs.length; ++i) { configurationDispatcher.dispatchUpdateFor(srs[i], servicePid, null, null); } } else { cd = bindLocationIfNeccesary(srs, cd); String boundLocation = (String) cd.get(BUNDLE_LOCATION); srs = filterOnMatchingLocations(srs, boundLocation); for (int i = 0; i < srs.length; ++i) { configurationDispatcher.dispatchUpdateFor(srs[i], servicePid, null, cd); } } } ServiceReference[] getTargetServiceReferences(Class c, String pid) { String filter = "(" + SERVICE_PID + "=" + pid + ")"; try { ServiceReference[] srs = Activator.bc.getServiceReferences(c .getName(), filter); return srs == null ? new ServiceReference[0] : srs; } catch (InvalidSyntaxException e) { Activator.log.error("Faulty ldap filter " + filter, e); return new ServiceReference[0]; } } void delete(final ConfigurationImpl c) throws IOException { try { AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { ConfigurationDictionary cd = store.delete(c.getPid()); if (cd != null) { updateTargetServicesMatching(cd); } return null; } }); } catch (PrivilegedActionException e) { throw (IOException) e.getException(); } } void update(final ConfigurationImpl c) throws IOException { // TODO: // Should plugins still be called if service with // servicePid is not registered? try { AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { store.store(c.getPid(), c.getFactoryPid(), c.properties); updateTargetServicesMatching(c.properties); return null; } }); } catch (PrivilegedActionException e) { throw (IOException) e.getException(); } } String generatePid(final String factoryPid) throws IOException { try { return (String) AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { return store.generatePid(factoryPid); } }); } catch (PrivilegedActionException e) { throw (IOException) e.getException(); } } ConfigurationDictionary load(final String pid) throws IOException { try { return (ConfigurationDictionary) AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { return store.load(pid); } }); } catch (PrivilegedActionException e) { throw (IOException) e.getException(); } } Configuration[] listConfigurations(String filterString) throws IOException, InvalidSyntaxException { Enumeration configurationPids = store.listPids(); Vector matchingConfigurations = new Vector(); while (configurationPids.hasMoreElements()) { String pid = (String) configurationPids.nextElement(); ConfigurationDictionary d = store.load(pid); if (d == null) { continue; } if (filterString == null) { matchingConfigurations.addElement(new ConfigurationImpl(d)); } else { Filter filter = Activator.bc.createFilter(filterString); if (filter.match(d)) { matchingConfigurations.addElement(new ConfigurationImpl(d)); } } } Configuration[] c = null; if (matchingConfigurations.size() > 0) { c = new Configuration[matchingConfigurations.size()]; matchingConfigurations.copyInto(c); } return c; } // ///////////////////////////////////////////////////////////////////////// // ServiceFactory Implementation // ///////////////////////////////////////////////////////////////////////// public Object getService(Bundle bundle, ServiceRegistration registration) { // For now we don't keep track of the services returned internally return new ConfigurationAdminImpl(bundle); } public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) { // For now we do nothing here } // ///////////////////////////////////////////////////////////////////////// // Configuration implementation // ///////////////////////////////////////////////////////////////////////// class ConfigurationImpl implements Configuration { private String bundleLocation; private final String factoryPid; private final String servicePid; ConfigurationDictionary properties; private boolean deleted = false; ConfigurationImpl(String bundleLocation, String factoryPid, String servicePid) { this(bundleLocation, factoryPid, servicePid, null); } ConfigurationImpl(String bundleLocation, String factoryPid, String servicePid, ConfigurationDictionary properties) { this.bundleLocation = bundleLocation; this.factoryPid = factoryPid; this.servicePid = servicePid; this.properties = properties; if (this.properties == null) this.properties = new ConfigurationDictionary(); } ConfigurationImpl(ConfigurationDictionary properties) { this.bundleLocation = (String) properties.get(BUNDLE_LOCATION); this.factoryPid = (String) properties.get(FACTORY_PID); this.servicePid = (String) properties.get(SERVICE_PID); this.properties = properties; } public void delete() throws IOException { throwIfDeleted(); ConfigurationAdminFactory.this.delete(this); deleted = true; } public String getBundleLocation() { throwIfDeleted();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -