📄 configurationadminfactory.java
字号:
return bundleLocation; } public String getFactoryPid() { throwIfDeleted(); return factoryPid; } public String getPid() { throwIfDeleted(); return servicePid; } public Dictionary getProperties() { throwIfDeleted(); if (properties == null) { return null; } return properties.createCopyIfRealAndRemoveLocation(); } public void setBundleLocation(String bundleLocation) { throwIfDeleted(); this.bundleLocation = bundleLocation; ConfigurationDictionary old = properties; if (properties == null) { properties = new ConfigurationDictionary(); } else { properties = properties.createCopy(); } properties.remove(DYNAMIC_BUNDLE_LOCATION); if (bundleLocation == null) { properties.remove(BUNDLE_LOCATION); } else { properties.put(BUNDLE_LOCATION, bundleLocation); } try { update(); } catch (IOException e) { this.properties = old; } } public void update() throws IOException { throwIfDeleted(); ensureAutoPropertiesAreWritten(); ConfigurationAdminFactory.this.update(this); } public void update(Dictionary properties) throws IOException { throwIfDeleted(); ConfigurationDictionary.validateDictionary(properties); ConfigurationDictionary old = this.properties; if (properties == null) { this.properties = new ConfigurationDictionary(); } else { this.properties = ConfigurationDictionary .createDeepCopy(properties); } try { update(); } catch (IOException e) { this.properties = old; throw e; } catch (Exception e) { Activator.log.error("Error while updating properties.", e); this.properties = old; } } void ensureAutoPropertiesAreWritten() { if (this.properties == null) return; this.properties.put(SERVICE_PID, getPid()); if (getFactoryPid() != null) { this.properties.put(FACTORY_PID, getFactoryPid()); } if (getBundleLocation() != null) { this.properties.put(BUNDLE_LOCATION, getBundleLocation()); } } private void throwIfDeleted() { if (deleted) { throw new IllegalStateException("Configuration for " + servicePid + " has been deleted."); } } } // ///////////////////////////////////////////////////////////////////////// // ConfigurationAdmin implementation // ///////////////////////////////////////////////////////////////////////// class ConfigurationAdminImpl implements ConfigurationAdmin { private Bundle callingBundle; private String callingBundleLocation; ConfigurationAdminImpl(Bundle callingBundle) { this.callingBundle = callingBundle; this.callingBundleLocation = callingBundle.getLocation(); } public Configuration createFactoryConfiguration(String factoryPid) throws IOException { return createFactoryConfiguration(factoryPid, callingBundleLocation); } public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException { ConfigurationImpl c = new ConfigurationImpl(location, factoryPid, ConfigurationAdminFactory.this.generatePid(factoryPid)); if (Activator.r3TestCompliant()) c.update(); return c; } public Configuration getConfiguration(String pid) { ConfigurationDictionary d; try { d = ConfigurationAdminFactory.this.load(pid); } catch (IOException e) { d = null; } if (d == null) { return new ConfigurationImpl(callingBundleLocation, null, pid); } String bundleLocation = (String) d.get(BUNDLE_LOCATION); if (bundleLocation != null && !bundleLocation.equals(callingBundleLocation) && !callingBundle.hasPermission(ADMIN_PERMISSION)) { throw new SecurityException( "Not owner of the requested configuration, owned by " + bundleLocation + " caller is " + callingBundleLocation); } String factoryPid = (String) d.get(FACTORY_PID); return new ConfigurationImpl(bundleLocation, factoryPid, pid, d); } public Configuration getConfiguration(String pid, String location) { ConfigurationDictionary d; try { d = ConfigurationAdminFactory.this.load(pid); } catch (IOException e) { d = null; } if (d == null) { ConfigurationImpl c = new ConfigurationImpl(location, null, pid); if (location != null) c.setBundleLocation(location); return c; } String bundleLocation = (String) d.get(BUNDLE_LOCATION); String factoryPid = (String) d.get(FACTORY_PID); return new ConfigurationImpl(bundleLocation, factoryPid, pid, d); } public Configuration[] listConfigurations(final String filterString) throws IOException, InvalidSyntaxException { Configuration[] configurations = null; try { configurations = (Configuration[]) AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException, InvalidSyntaxException { return ConfigurationAdminFactory.this .listConfigurations(filterString); } }); } catch (PrivilegedActionException e) { configurations = null; if (e.getException().getClass() == InvalidSyntaxException.class) { throw (InvalidSyntaxException) e.getException(); } throw (IOException) e.getException(); } return configurations; } } // ///////////////////////////////////////////////////////////////////////// // Service Event handling // ///////////////////////////////////////////////////////////////////////// public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.UNINSTALLED) { String uninstalledBundleLocation = event.getBundle().getLocation(); existingBundleLocations.remove(uninstalledBundleLocation); findAndUnbindConfigurationsDynamicallyBoundTo(uninstalledBundleLocation); } else if (event.getType() == BundleEvent.INSTALLED) { String installedBundleLocation = event.getBundle().getLocation(); existingBundleLocations.put(installedBundleLocation, installedBundleLocation); } } public void serviceChanged(ServiceEvent event) { ServiceReference sr = event.getServiceReference(); int eventType = event.getType(); String[] objectClasses = (String[]) sr.getProperty("objectClass"); for (int i = 0; i < objectClasses.length; ++i) { serviceChanged(sr, eventType, objectClasses[i]); } } private void serviceChanged(ServiceReference sr, int eventType, String objectClass) { if (ManagedServiceFactory.class.getName().equals(objectClass)) { managedServiceFactoryChanged(sr, eventType); } else if (ManagedService.class.getName().equals(objectClass)) { managedServiceChanged(sr, eventType); } else if (ConfigurationPlugin.class.getName().equals(objectClass)) { pluginManager.configurationPluginChanged(sr, eventType); } } private void managedServiceFactoryChanged(ServiceReference sr, int eventType) { final String factoryPid = (String) sr.getProperty(SERVICE_PID); switch (eventType) { case ServiceEvent.REGISTERED: configurationDispatcher.addQueueFor(sr); if (factoryPid == null) { String bundleLocation = sr.getBundle().getLocation(); Activator.log .error("[CM] ManagedServiceFactory w/o valid service.pid registered by " + bundleLocation); return; } addToLocationToPidsAndCheck(sr); if (Activator.log.doDebug()) { Activator.log.debug("[CM] ManagedServiceFactory registered: " + factoryPid); } try { updateManagedServiceFactory(sr); } catch (IOException e) { Activator.log.error("Error while notifying services.", e); } break; case ServiceEvent.MODIFIED: break; case ServiceEvent.UNREGISTERING: removeFromLocationToPids(sr); configurationDispatcher.removeQueueFor(sr); break; } } private void managedServiceChanged(ServiceReference sr, int eventType) { final String servicePid = (String) sr.getProperty(SERVICE_PID); switch (eventType) { case ServiceEvent.REGISTERED: configurationDispatcher.addQueueFor(sr); if (servicePid == null) { String bundleLocation = sr.getBundle().getLocation(); Activator.log .error("[CM] ManagedService w/o valid service.pid registered by " + bundleLocation); return; } addToLocationToPidsAndCheck(sr); if (Activator.log.doDebug()) { Activator.log.debug("[CM] ManagedService registered: " + servicePid); } try { updateManagedService(sr); } catch (IOException e) { Activator.log.error("Error while notifying services.", e); } break; case ServiceEvent.MODIFIED: break; case ServiceEvent.UNREGISTERING: removeFromLocationToPids(sr); configurationDispatcher.removeQueueFor(sr); break; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -