/** * @see org.osgi.service.cm.Configuration#getBundleLocation() */ public String getBundleLocation() { return configuration.getBundleLocation(); } /**
@Override public boolean apply(Bundle bundle) { return StringUtils.equals(configuration.getBundleLocation(), bundle.getLocation()); } }).orNull();
private boolean checkBundleLocation(Configuration config, Bundle bundle) { if ( config == null ) { return false; } String configBundleLocation = config.getBundleLocation(); return checkBundleLocation( configBundleLocation, bundle ); }
private boolean checkBundleLocation(Configuration config, Bundle bundle) { if ( config == null ) { return false; } String configBundleLocation = config.getBundleLocation(); return checkBundleLocation( configBundleLocation, bundle ); }
private final Bundle getBoundBundle(Configuration config) { if (null == config) return null; final String location = config.getBundleLocation(); if (null == location) return null; final Bundle bundles[] = getBundleContext().getBundles(); for (int i = 0; bundles != null && i < bundles.length; i++) { if (bundles[i].getLocation().equals(location)) return bundles[i]; } return null; }
public static void print(final Configuration configuration) { System.out.println(""); System.out.println("Configuration for service (pid) \"" + configuration.getPid() + "\""); System.out.println("(bundle location = " + configuration.getBundleLocation() + ")"); print(configuration.getProperties()); }
private final Bundle getBoundBundle(Configuration config) { if (null == config) return null; final String location = config.getBundleLocation(); if (null == location) return null; final Bundle bundles[] = getBundleContext().getBundles(); for (int i = 0; bundles != null && i < bundles.length; i++) { if (bundles[i].getLocation().equals(location)) return bundles[i]; } return null; }
private Configuration getConfiguration(final ConfigurationAdmin admin, final String pid, final Bundle bundle) { if (admin == null) { return null; } try { // Even if it is possible, we don't build the filter with bundle.location to detect the case where the // configuration exists but can't be managed by iPOJO. final Configuration cfg = admin.getConfiguration(pid); final String bundleLocation = bundle.getLocation(); if (cfg.getBundleLocation() == null || bundleLocation.equals(cfg.getBundleLocation()) || m_context.getBundle().getLocation().equals(cfg.getBundleLocation())) { cfg.setBundleLocation(bundleLocation); return cfg; } // Multi-location if (cfg.getBundleLocation().startsWith("?")) { if (bundle.hasPermission(new ConfigurationPermission(cfg.getBundleLocation(), "target"))) { return cfg; } } // configuration belongs to another bundle, cannot be used here m_logger.log(Log.ERROR, "Cannot use configuration pid=" + pid + " for bundle " + bundleLocation + " because it belongs to bundle " + cfg.getBundleLocation()); } catch (IOException ioe) { m_logger.log(Log.WARNING, "Failed reading configuration for pid=" + pid, ioe); } return null; }
private Configuration getConfiguration(final ConfigurationAdmin admin, final String pid, final Bundle bundle) { if (admin == null) { return null; } try { // Even if it is possible, we don't build the filter with bundle.location to detect the case where the // configuration exists but can't be managed by iPOJO. final Configuration cfg = admin.getConfiguration(pid); final String bundleLocation = bundle.getLocation(); if (cfg.getBundleLocation() == null || bundleLocation.equals(cfg.getBundleLocation()) || m_context.getBundle().getLocation().equals(cfg.getBundleLocation())) { cfg.setBundleLocation(bundleLocation); return cfg; } // Multi-location if (cfg.getBundleLocation().startsWith("?")) { if (bundle.hasPermission(new ConfigurationPermission(cfg.getBundleLocation(), "target"))) { return cfg; } } // configuration belongs to another bundle, cannot be used here m_logger.log(Log.ERROR, "Cannot use configuration pid=" + pid + " for bundle " + bundleLocation + " because it belongs to bundle " + cfg.getBundleLocation()); } catch (IOException ioe) { m_logger.log(Log.WARNING, "Failed reading configuration for pid=" + pid, ioe); } return null; }
protected void doExecute(ConfigurationAdmin admin) throws Exception { Configuration[] configs = admin.listConfigurations(query); for (Configuration config : configs) { System.out.println("----------------------------------------------------------------"); System.out.println("Pid: " + config.getPid()); if (config.getFactoryPid() != null) { System.out.println("FactoryPid: " + config.getFactoryPid()); } System.out.println("BundleLocation: " + config.getBundleLocation()); if (config.getProperties() != null) { System.out.println("Properties:"); Dictionary props = config.getProperties(); for (Enumeration e = props.keys(); e.hasMoreElements();) { Object key = e.nextElement(); System.out.println(" " + key + " = " + props.get(key)); } } } } }
protected void doExecute(ConfigurationAdmin admin) throws Exception { Configuration[] configs = admin.listConfigurations(query); for (Configuration config : configs) { io.out.println("----------------------------------------------------------------"); io.out.println("Pid: " + config.getPid()); if (config.getFactoryPid() != null) { io.out.println("FactoryPid: " + config.getFactoryPid()); } io.out.println("BundleLocation: " + config.getBundleLocation()); if (config.getProperties() != null) { io.out.println("Properties:"); Dictionary props = config.getProperties(); for (Enumeration e = props.keys(); e.hasMoreElements();) { Object key = e.nextElement(); io.out.println(" " + key + " = " + props.get(key)); } } } } }
private void printConfiguration(PrintWriter pw, Configuration config) { ConfigurationRender.infoLine(pw, "", "PID", config.getPid()); if (config.getFactoryPid() != null) { ConfigurationRender.infoLine(pw, " ", "Factory PID", config.getFactoryPid()); } String loc = (config.getBundleLocation() != null) ? config.getBundleLocation() : "Unbound"; ConfigurationRender.infoLine(pw, " ", "BundleLocation", loc); Dictionary props = config.getProperties(); if (props != null) { SortedSet keys = new TreeSet(); for (Enumeration ke = props.keys(); ke.hasMoreElements();) { keys.add(ke.nextElement()); } for (Iterator ki = keys.iterator(); ki.hasNext();) { String key = (String) ki.next(); ConfigurationRender.infoLine(pw, " ", key, props.get(key)); } } pw.println(); }
System.out.println("FactoryPid: " + config.getFactoryPid()); System.out.println("BundleLocation: " + config.getBundleLocation()); if (config.getProperties() != null) { System.out.println("Properties:");
private void printConfiguration(PrintWriter pw, Configuration config) { ConfigurationRender.infoLine(pw, "", "PID", config.getPid()); if (config.getFactoryPid() != null) { ConfigurationRender.infoLine(pw, " ", "Factory PID", config.getFactoryPid()); } String loc = (config.getBundleLocation() != null) ? config.getBundleLocation() : "Unbound"; ConfigurationRender.infoLine(pw, " ", "BundleLocation", loc); Dictionary props = config.getProperties(); if (props != null) { SortedSet keys = new TreeSet(); for (Enumeration ke = props.keys(); ke.hasMoreElements();) { keys.add(ke.nextElement()); } for (Iterator ki = keys.iterator(); ki.hasNext();) { String key = (String) ki.next(); ConfigurationRender.infoLine(pw, " ", key, props.get(key)); } } pw.println(); }
private void readAndApplyConfiguration(File file, ConfigurationAdmin admin) throws Exception { synchronized (this) { if (admin == null) { LOGGER.warn("Cannot apply configuration " + file.getName() + " - no configuration admin"); configurations.put(file, UnmanagedConfiguration.INSTANCE); } else { Properties properties = read(file); String[] pid = parsePid(file.getName()); Dictionary<Object, Object> ht = new Properties(); for (String k : properties.stringPropertyNames()) { ht.put(k, properties.getProperty(k)); } Configuration config = configurations.get(file); if (config == null || config == UnmanagedConfiguration.INSTANCE) { config = getConfiguration(pid[0], pid[1], admin); if (config.getBundleLocation() != null) { config.setBundleLocation(null); } } LOGGER.info("Updating configuration {} in the configuration admin, configuration: {}", config.getPid(), configurations); config.update(ht); configurations.put(file, config); } } }
/** * Returns configuration for the {@link #getSelectedService() selected} service. * * @return configuration data or {@code null} * @throws IllegalStateException if the selected service is {@code null} */ public ConfigurationDTO getConfiguration() { checkThatSelectedServiceIsNotNull(); String pid = selectedService.getPid(); Configuration configuration = getConfiguration(pid); if (configuration != null && configuration.getProperties() != null) { return new ConfigurationDTO().setPid(pid).setBundleLocation(configuration.getBundleLocation()) .setValues(Maps.valueOf(configuration.getProperties())); } return null; }
protected void doInstallFeature(InstallationState state, Feature feature) throws Exception { for (Feature dependency : feature.getDependencies()) { Feature f = getFeature(dependency.getName(), dependency.getVersion()); if (f == null) { throw new Exception("No feature named '" + dependency.getName() + "' with version '" + dependency.getVersion() + "' available"); } doInstallFeature(state, f); } for (String config : feature.getConfigurations().keySet()) { Dictionary<String,String> props = new Hashtable<String, String>(feature.getConfigurations().get(config)); String[] pid = parsePid(config); Configuration cfg = findExistingConfiguration(configAdmin, pid[0], pid[1]); if (cfg == null) { cfg = createConfiguration(configAdmin, pid[0], pid[1]); String key = (pid[1] == null ? pid[0] : pid[0] + "-" + pid[1]); props.put(CONFIG_KEY, key); if (cfg.getBundleLocation() != null) { cfg.setBundleLocation(null); } cfg.update(props); } } Set<Long> bundles = new HashSet<Long>(); for (String bundleLocation : feature.getBundles()) { Bundle b = installBundleIfNeeded(state, bundleLocation); bundles.add(b.getBundleId()); } state.features.put(feature, bundles); }
@Override public void configurationEvent(ConfigurationEvent event) { try { ConfigurationEventProperties cep = new ConfigurationEventProperties(); cep.factoryPid = event.getFactoryPid(); cep.pid = event.getPid(); if (ConfigurationEvent.CM_DELETED != event.getType()) { Configuration configuration = cm.getConfiguration(event .getPid()); cep.location = configuration.getBundleLocation(); Dictionary<String, Object> properties = configuration .getProperties(); if (properties == null) { cep.properties = new HashMap<>(); } else cep.properties = toMap(properties); } ea.postEvent(new Event(TOPIC, dtos.asMap(cep))); } catch (Exception e) { throw new RuntimeException(e); } }
ObjectClassDefinition getObjectClassDefinition( Configuration config, String locale ) { // if the configuration is bound, try to get the object class // definition from the bundle installed from the given location if ( config.getBundleLocation() != null ) { Bundle bundle = getBundle( this.getBundleContext(), config.getBundleLocation() ); if ( bundle != null ) { String id = config.getFactoryPid(); if ( null == id ) { id = config.getPid(); } return getObjectClassDefinition( bundle, id, locale ); } } // get here if the configuration is not bound or if no // bundle with the bound location is installed. We search // all bundles for a matching [factory] PID // if the configuration is a factory one, use the factory PID if ( config.getFactoryPid() != null ) { return this.getObjectClassDefinition( config.getFactoryPid(), locale ); } // otherwise use the configuration PID return this.getObjectClassDefinition( config.getPid(), locale ); }
ObjectClassDefinition getObjectClassDefinition( Configuration config, String locale ) { // if the configuration is bound, try to get the object class // definition from the bundle installed from the given location if ( config.getBundleLocation() != null ) { Bundle bundle = getBundle( this.getBundleContext(), config.getBundleLocation() ); if ( bundle != null ) { String id = config.getFactoryPid(); if ( null == id ) { id = config.getPid(); } return getObjectClassDefinition( bundle, id, locale ); } } // get here if the configuration is not bound or if no // bundle with the bound location is installed. We search // all bundles for a matching [factory] PID // if the configuration is a factory one, use the factory PID if ( config.getFactoryPid() != null ) { return this.getObjectClassDefinition( config.getFactoryPid(), locale ); } // otherwise use the configuration PID return this.getObjectClassDefinition( config.getPid(), locale ); }