View Javadoc

1   package com.atlassian.plugin.osgi.factory.transform.model;
2   
3   import java.util.Map;
4   import java.util.Collections;
5   import java.util.HashMap;
6   
7   import com.atlassian.plugin.osgi.util.OsgiHeaderUtil;
8   
9   /**
10   * Encapsulates the package exports from the system bundle
11   *
12   * @since 2.2.0
13   */
14  public class SystemExports
15  {
16      private final Map<String, Map<String,String>> exports;
17  
18      public static final SystemExports NONE = new SystemExports("");
19  
20      /**
21       * Constructs an instance by parsing the exports line from the manifest
22       *
23       * @param exportsLine The Export-Package header value
24       */
25      public SystemExports(String exportsLine)
26      {
27          if (exportsLine == null)
28          {
29              exportsLine = "";
30          }
31          this.exports = Collections.unmodifiableMap(OsgiHeaderUtil.parseHeader(exportsLine));
32      }
33  
34      /**
35       * Constructs a package export, taking into account any attributes on the system export, including the version.
36       * The version is handled special, in that is added as an exact match, i.e. [1.0,1.0].
37       *
38       * @param pkg The java package
39       * @return The full export line to use for a host component import
40       */
41      public String getFullExport(String pkg)
42      {
43          if (exports.containsKey(pkg))
44          {
45              Map<String,String> attrs = new HashMap<String,String>(exports.get(pkg));
46              if (attrs.containsKey("version"))
47              {
48                  final String version = attrs.get("version");
49                  attrs.put("version", "[" + version + "," + version + "]");
50              }
51              return OsgiHeaderUtil.buildHeader(pkg, attrs);
52          }
53          return pkg;
54      }
55  
56      /**
57       * @param pkg The package to check
58       * @return True if the package is being exported, false otherwise
59       */
60      public boolean isExported(String pkg)
61      {
62          return exports.containsKey(pkg);
63      }
64  }