Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.85 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get property values from bundle manifest using BundleContext?
  2. java.util.Dictionary headers = Bundle.getHeaders();
  3.        
  4. Bundle-Properties:
  5. foo.bar.prefix=MS,
  6. foo.bar.hostname=127.0.0.1,
  7. foo.bar.port=8106,
  8. foo.bar.homepath=/foo/bar/E3,
  9. foo.bar.secure=false,
  10.        
  11. java.util.Properties properties = new java.util.Properties();
  12. java.util.Dictionary headers = bcontext.getBundle().getHeaders();
  13. String manifest_key = "Bundle-Properties";
  14. String manifest_value = (String) headers.get(manifest_key);
  15. if (manifest_value != null) {
  16.     String[] t = manifest_value.split(",");
  17.     for (int i = 0; i < t.length; i++) {
  18.         String[] u = t[i].split("=");
  19.         if (1 < u.length) {
  20.             String key = u[0];
  21.             String value = u[1];
  22.             properties.setProperty(key, value);
  23.         }
  24.     }
  25. }
  26.        
  27. Dictionary dict = bundleContext.getBundle().getHeader();