Java Code Examples for org.osgi.framework.Bundle#getHeaders()

The following examples show how to use org.osgi.framework.Bundle#getHeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Test9.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean runTest() {
  try {
    Bundle bundle = Util.installBundle(bc, "bundleEnd151_test-1.0.0.jar");
    bundle.start();
    
    for (int i = 0; i < loops; i++) {   
      for (int o = 0; o < locales.length; o++) {
        bundle.getHeaders(locales[o]);
      }
    }
    
    bundle.uninstall();
  } catch (BundleException e) {
    e.printStackTrace();
  } 
  return true;
}
 
Example 2
Source File: JythonPlugin.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return the package names available for the passed bundles
 */
public List<String> setBundlesAndGetPackageNames(Bundle[] bundles) {
    List<Bundle> acceptedBundles = new ArrayList<Bundle>();
    List<String> names = new ArrayList<String>();
    for (int i = 0; i < bundles.length; ++i) {
        boolean addedSomePackage = false;
        Bundle bundle = bundles[i];
        Dictionary<String, String> headers = bundle.getHeaders();
        addedSomePackage |= addPackageNames(bundle, names, headers.get("Provide-Package"));
        addedSomePackage |= addPackageNames(bundle, names, headers.get("Export-Package"));
        if (addedSomePackage) {
            acceptedBundles.add(bundle);
        }
    }
    this.bundles = acceptedBundles.toArray(new Bundle[acceptedBundles.size()]);
    //for(Bundle b:this.bundles){
    //    System.out.println("Accepted:"+b.getHeaders().get("Bundle-Name"));
    //}
    return names;
}
 
Example 3
Source File: ComponentBuilder.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
/**
 * reads component.xml from given bundle & returns an object representation  of it
 *
 * @param registeredBundle The bundle that is being registered
 * @param bundleContext    The bundle context of the UI bundles
 * @return Component
 */
public static Component build(Bundle registeredBundle, BundleContext bundleContext) {
    Component component = null;
    Dictionary headers = registeredBundle.getHeaders();
    try {
        URL url = registeredBundle.getEntry("META-INF/component.xml");
        if (url != null) {
            if (log.isDebugEnabled()) {
                log.debug("Found component.xml in bundle : " + registeredBundle.getSymbolicName());
            }
            //found a Carbon OSGi bundle that should amend for admin UI
            String bundleVersion = (String) headers.get("Bundle-Version");
            String bundleName = (String) headers.get("Bundle-Name");
            InputStream inputStream = url.openStream();
            component = build(inputStream, bundleName, bundleVersion,
                    bundleContext);
        }
    } catch (Exception e) {
        log.error("Cannot build component.xml for " + registeredBundle.getSymbolicName(), e);
    }
    return component;
}
 
Example 4
Source File: BundleUpgradeParser.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static CatalogUpgrades parseBundleManifestForCatalogUpgrades(Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) {
    // TODO Add support for the other options described in the proposal:
    //   https://docs.google.com/document/d/1Lm47Kx-cXPLe8BO34-qrL3ZMPosuUHJILYVQUswEH6Y/edit#
    //   section "Bundle Upgrade Metadata"
    
    Dictionary<String, String> headers = bundle.getHeaders();
    String upgradesForBundlesHeader = headers.get(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES);
    Multimap<VersionedName,VersionRangedName> upgradesForBundles = parseUpgradeForBundlesHeader(upgradesForBundlesHeader, bundle);
    return CatalogUpgrades.builder()
            .removedLegacyItems(parseForceRemoveLegacyItemsHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS), bundle, typeSupplier))
            .removedBundles(parseForceRemoveBundlesHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_BUNDLES), bundle))
            .upgradeBundles(upgradesForBundles)
            .upgradeTypes(parseUpgradeForTypesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_TYPES), bundle, typeSupplier, 
                upgradesForBundlesHeader==null ? null : upgradesForBundles))
            .build();
}
 
Example 5
Source File: BundleUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return whether the given bundle has all of its dependencies satisfied
 *         (including optional dependencies)
 */
public static boolean areBundlesDependenciesSatisfied(String bundleId) {
  Bundle bundle = Platform.getBundle(bundleId);

  if (bundle == null) {
    return false;
  }

  // TODO: we need to do this using the bundle APIs, and not in such a brute
  // force way

  Dictionary<String, String> headers = bundle.getHeaders();

  String requiredBundles[] = headers.get("Require-Bundle").split(",");

  for (String requiredBundleId : requiredBundles) {
    String id = requiredBundleId.split(";")[0];

    if (!isBundleInstalled(id)) {
      return false;
    }
  }

  return true;
}
 
Example 6
Source File: Test10.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean runTest() {
  try {
    Bundle fragment = Util.installBundle(bc, "bundleEnd152_test-1.0.0.jar");
    Bundle bundle = Util.installBundle(bc, "bundleEnd151_test-1.0.0.jar");
    bundle.start();

    for (int i = 0; i < loops; i++) {   
      for (int o = 0; o < locales.length; o++) {
        bundle.getHeaders(locales[o]);
      }
    }
    
    bundle.uninstall();
    fragment.uninstall();
  } catch (BundleException e) {
    e.printStackTrace();
  } 
  return true;
}
 
Example 7
Source File: AppDeployerUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether the given bundle is a project artifact. If yes, return the app name. If no,
 * return null
 *
 * @param bundle - bundle to check
 * @return - app name
 */
public static String getProjectArtifactName(Bundle bundle) {
    Dictionary dictionary = bundle.getHeaders();
    if (dictionary != null) {

        // Iterate through the headers and find the WSO2-Project-Artifact custom header
        for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {

            String headerKey = (String) e.nextElement();
            if (AppDeployerConstants.WSO2_APP_NAME_HEADER.equals(headerKey)) {

                // retireve the header value
                String headerValue = (String) dictionary.get(headerKey);
                if (headerValue != null) {
                    return headerValue;
                }
            }
        }
    }
    return null;
}
 
Example 8
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the symbolic name of the specified bundle. All directives and
 * parameters attached to the symbolic name attribute will be stripped.
 *
 * @param bundle
 *          the bundle
 * @return The bundles symbolic name or null if not specified.
 */
public static String symbolicName(Bundle bundle)
{
  if (bundle == null) {
    return null;
  }

  final Dictionary<String, String> d = bundle.getHeaders("");
  String bsn = d.get("Bundle-SymbolicName");
  if (bsn != null && bsn.length() > 0) {
    // Remove parameters and directives from the value
    final int semiPos = bsn.indexOf(';');
    if (-1 < semiPos) {
      bsn = bsn.substring(0, semiPos).trim();
    }
  }
  return bsn;
}
 
Example 9
Source File: LogConfigImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the symbolic name of the specified bundle. All directives and
 * parameters attached to the symbolic name attribute will be
 * stripped.
 *
 * @param bundle
 *            the bundle
 * @return The bundles symbolic name or null if not specified.
 */
private static String getSymbolicName(Bundle bundle) {
  if (bundle == null) {
    return null;
  }

  final Dictionary<String, String> d = bundle.getHeaders("");
  String bsn = d.get("Bundle-SymbolicName");
  if (bsn != null && bsn.length() >0) {
    // Remove parameters and directives from the value
    final int semiPos = bsn.indexOf(';');
    if (-1<semiPos) {
      bsn = bsn.substring(0, semiPos).trim();
    }
  }
  return bsn;
}
 
Example 10
Source File: Activator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void bundleChanged(BundleEvent event) {
        Bundle bundle = event.getBundle();
        switch (event.getType()) {
        case BundleEvent.STARTED:
//            System.err.println("started " + bundle.getSymbolicName());
            Dictionary<?,?> headers = bundle.getHeaders();
            load(queue.offer(bundle, provides(headers), requires(headers), needs(headers)));
            break;
        case BundleEvent.STOPPED:
//            System.err.println("stopped " + bundle.getSymbolicName());
            if (framework.getState() == Bundle.STOPPING) {
//                System.err.println("fwork stopping during " + bundle.getSymbolicName());
//                ActiveQueue.stop();
            } else {
                unload(queue.retract(bundle));
            }
            break;
        }
    }
 
Example 11
Source File: AppDeployerUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Checking whether a bundle contains the WSO2-Application-Deployer header
 *
 * @param bundle - input bundle
 * @return - if found header - true, else - false
 */
public static boolean isAppDeployer(Bundle bundle) {
    Dictionary dictionary = bundle.getHeaders();
    if (dictionary != null) {

        // Iterate through the headers and find the WSO2-Project-Artifact custom header
        for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {

            String headerKey = (String) e.nextElement();
            if (AppDeployerConstants.WSO2_APP_DEPLOYER_HEADER.equals(headerKey)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source File: FrameworkCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int cmdHeaders(Dictionary<String, ?> opts,
                      Reader in,
                      PrintWriter out,
                      Session session)
{
  final Bundle[] b = getBundles((String[]) opts.get("bundle"),
                          opts.get("-i") != null);
  final String locale = (String) opts.get("-l");
  boolean found = false;
  for (final Bundle element : b) {
    if (element != null) {
      out.println("Bundle: " + showBundle(element));
      final Dictionary<String, String> d = (locale == null ? element.getHeaders()
          : element.getHeaders(locale));
      for (final Enumeration<String> e = d.keys(); e.hasMoreElements();) {
        final String key = e.nextElement();
        out.println("  " + key + " = " + Util.showObject(d.get(key)));
      }
      found = true;
    }
  }
  if (!found) {
    out.println("ERROR! No matching bundle");
    return 1;
  }
  return 0;
}
 
Example 13
Source File: ReadyMarkerUtils.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Provides a string to debug bundle information.
 *
 * @param bundle the bundle
 * @return a debug string
 */
public static String debugString(final Bundle bundle) {
    return "Bundle [getState()=" + bundle.getState() + ", getHeaders()=" + bundle.getHeaders() + ", getBundleId()="
            + bundle.getBundleId() + ", getLocation()=" + bundle.getLocation() + ", getRegisteredServices()="
            + Arrays.toString(bundle.getRegisteredServices()) + ", getServicesInUse()="
            + Arrays.toString(bundle.getServicesInUse()) + ", getSymbolicName()=" + bundle.getSymbolicName()
            + ", getLastModified()=" + bundle.getLastModified() + ", getBundleContext()="
            + bundle.getBundleContext() + ", getVersion()=" + bundle.getVersion() + "]";
}
 
Example 14
Source File: SlingModelsScriptEngineFactory.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
SlingModelsScriptEngineFactory(Bundle bundle) {
    super();
    setEngineName("Apache Sling Models");
    // really the only time this is null is during testing
    if (bundle != null && bundle.getHeaders() != null && bundle.getHeaders().get(Constants.BUNDLE_VERSION) != null) {
        setEngineVersion(bundle.getHeaders().get(Constants.BUNDLE_VERSION).toString());
    }
    setNames("sling-models-exporter", "sling-models");
}
 
Example 15
Source File: Activator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void processLoadedBundles() {
        List<Bundle> toLoad = new ArrayList<Bundle>();
        for (Bundle b : context.getBundles()) {
            if (b.getState() == Bundle.ACTIVE) {
                Dictionary<?,?> headers = b.getHeaders();
                toLoad.addAll(queue.offer(b, provides(headers), requires(headers), needs(headers)));
            }
        }
//        System.err.println("processing already loaded bundles: " + toLoad);
        load(toLoad);
    }
 
Example 16
Source File: UIBundleDeployer.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * 1)Search for the UIBundle header
 * 2)Check for UI bundle fragments - for backward compatibility
 *
 * @param bundle
 * @param action
 * @throws CarbonException
 */
private void processUIBundle(Bundle bundle, String action) throws CarbonException {
    Dictionary headers = bundle.getHeaders();

    String value = (String) headers.get("Carbon-Component");
    if (value != null && "UIBundle".equals(value)) { //this is a UI Bundle
        if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) {
            if(log.isDebugEnabled()){
                log.debug("UI component add action received in UIBundleDeployer  : "+action);
            }
            if(log.isDebugEnabled()){
                log.debug("Adding bundle resource paths  : "+ bundle );
            }
            bundleBasedUIResourceProvider.addBundleResourcePaths(bundle);
            if(log.isDebugEnabled()){
                log.debug("processComponentXML in   : "+ bundle +"   "+action);
            }
            processComponentXML(bundle, action);
        } else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)){
            if(log.isDebugEnabled()){
                log.debug("UI component add action received in UIBundleDeployer  : "+action);
            }
            if(log.isDebugEnabled()){
                log.debug("Removing bundle resource paths  : "+ bundle );
            }
            bundleBasedUIResourceProvider.removeBundleResourcePaths(bundle);
            if(log.isDebugEnabled()){
                log.debug("processComponentXML in   : "+ bundle +"   "+action);
            }
            processComponentXML(bundle, action);
        }

    }
}
 
Example 17
Source File: Activator.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> getManifestInfo() {
	Map<String, String> result = new LinkedHashMap<String, String>();
	Bundle bundle = getContext().getBundle();
	Dictionary headers = bundle.getHeaders();
	Enumeration enumer = headers.keys();
	while (enumer.hasMoreElements()) {
		Object elem = enumer.nextElement();
		result.put(String.valueOf(elem), String.valueOf(headers.get(elem)));
	}
	return result;
}
 
Example 18
Source File: OSGiJaxwsEndpointManager.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Version getBundleVersion(Bundle bundle) {
    Dictionary<?, ?> headers = bundle.getHeaders();
    String version = (String) headers.get(Constants.BUNDLE_VERSION);
    return (version != null) ? Version.parseVersion(version) : Version.emptyVersion;
}
 
Example 19
Source File: OSGIBusListener.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Version getBundleVersion(Bundle bundle) {
    Dictionary<?, ?> headers = bundle.getHeaders();
    String version = (String) headers.get(Constants.BUNDLE_VERSION);
    return (version != null) ? Version.parseVersion(version) : Version.emptyVersion;
}
 
Example 20
Source File: GoPluginManifest.java    From gocd with Apache License 2.0 4 votes vote down vote up
public GoPluginManifest(Bundle bundle) {
    headers = bundle.getHeaders();
}