Ejemplo n.º 1
0
 private static void doBundle(ResourceImpl resource, Headers headers) {
   CapabilityImpl capability = new CapabilityImpl(Capability.BUNDLE);
   capability.addProperty(Resource.SYMBOLIC_NAME, getSymbolicName(headers));
   if (headers.getHeader(Constants.BUNDLE_NAME) != null) {
     capability.addProperty(Resource.PRESENTATION_NAME, headers.getHeader(Constants.BUNDLE_NAME));
   }
   capability.addProperty(Resource.VERSION, Property.VERSION, getVersion(headers));
   capability.addProperty(Resource.MANIFEST_VERSION, getManifestVersion(headers));
   resource.addCapability(capability);
 }
Ejemplo n.º 2
0
 private static String getSymbolicName(Headers headers) {
   String bsn = headers.getHeader(Constants.BUNDLE_SYMBOLICNAME);
   if (bsn == null) {
     bsn = headers.getHeader(Constants.BUNDLE_NAME);
     if (bsn == null) {
       bsn = "Untitled-" + headers.hashCode();
     }
   }
   Clause[] clauses = Parser.parseHeader(bsn);
   return clauses[0].getName();
 }
Ejemplo n.º 3
0
 private static String getManifestVersion(Headers headers) {
   String v = headers.getHeader(Constants.BUNDLE_MANIFESTVERSION);
   if (v == null) {
     v = "1";
   }
   return v;
 }
Ejemplo n.º 4
0
 private static void doExports(ResourceImpl resource, Headers headers) {
   Clause[] clauses = Parser.parseHeader(headers.getHeader(Constants.EXPORT_PACKAGE));
   for (int i = 0; clauses != null && i < clauses.length; i++) {
     CapabilityImpl capability = createCapability(Capability.PACKAGE, clauses[i]);
     resource.addCapability(capability);
   }
 }
Ejemplo n.º 5
0
  private static void doFragment(ResourceImpl resource, Headers headers) {
    // Check if we are a fragment
    Clause[] clauses = Parser.parseHeader(headers.getHeader(Constants.FRAGMENT_HOST));
    if (clauses != null && clauses.length == 1) {
      // We are a fragment, create a requirement
      // to our host.
      RequirementImpl r = new RequirementImpl(Capability.BUNDLE);
      StringBuffer sb = new StringBuffer();
      sb.append("(&(symbolicname=");
      sb.append(clauses[0].getName());
      sb.append(")");
      appendVersion(
          sb,
          VersionRange.parseVersionRange(
              clauses[0].getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE)));
      sb.append(")");
      r.setFilter(sb.toString());
      r.addText("Required Host " + clauses[0].getName());
      r.setExtend(true);
      r.setOptional(false);
      r.setMultiple(false);
      resource.addRequire(r);

      // And insert a capability that we are available
      // as a fragment. ### Do we need that with extend?
      CapabilityImpl capability = new CapabilityImpl(Capability.FRAGMENT);
      capability.addProperty("host", clauses[0].getName());
      capability.addProperty("version", Property.VERSION, getVersion(clauses[0]));
      resource.addCapability(capability);
    }
  }
Ejemplo n.º 6
0
 public ResourceImpl createResource(Headers headers) {
   String bsn = headers.getHeader(Constants.BUNDLE_SYMBOLICNAME);
   if (bsn == null) {
     return null;
   }
   ResourceImpl resource = new ResourceImpl();
   populate(headers, resource);
   return resource;
 }
Ejemplo n.º 7
0
  private static void doImportExportServices(ResourceImpl resource, Headers headers) {
    Clause[] imports = Parser.parseHeader(headers.getHeader(Constants.IMPORT_SERVICE));
    for (int i = 0; imports != null && i < imports.length; i++) {
      RequirementImpl ri = new RequirementImpl(Capability.SERVICE);
      ri.setFilter(createServiceFilter(imports[i]));
      ri.addText("Import Service " + imports[i].getName());

      String avail = imports[i].getDirective("availability");
      String mult = imports[i].getDirective("multiple");
      ri.setOptional("optional".equalsIgnoreCase(avail));
      ri.setMultiple(!"false".equalsIgnoreCase(mult));
      resource.addRequire(ri);
    }

    Clause[] exports = Parser.parseHeader(headers.getHeader(Constants.EXPORT_SERVICE));
    for (int i = 0; exports != null && i < exports.length; i++) {
      CapabilityImpl cap = createServiceCapability(exports[i]);
      resource.addCapability(cap);
    }
  }
Ejemplo n.º 8
0
  private static void doImports(ResourceImpl resource, Headers headers) {
    Clause[] clauses = Parser.parseHeader(headers.getHeader(Constants.IMPORT_PACKAGE));
    for (int i = 0; clauses != null && i < clauses.length; i++) {
      RequirementImpl requirement = new RequirementImpl(Capability.PACKAGE);

      createImportFilter(requirement, Capability.PACKAGE, clauses[i]);
      requirement.addText("Import package " + clauses[i]);
      requirement.setOptional(
          Constants.RESOLUTION_OPTIONAL.equalsIgnoreCase(
              clauses[i].getDirective(Constants.RESOLUTION_DIRECTIVE)));
      resource.addRequire(requirement);
    }
  }
Ejemplo n.º 9
0
 private static void doExecutionEnvironment(ResourceImpl resource, Headers headers) {
   Clause[] clauses =
       Parser.parseHeader(headers.getHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
   if (clauses != null && clauses.length > 0) {
     StringBuffer sb = new StringBuffer();
     sb.append("(|");
     for (int i = 0; i < clauses.length; i++) {
       sb.append("(");
       sb.append(Capability.EXECUTIONENVIRONMENT);
       sb.append("=");
       sb.append(clauses[i].getName());
       sb.append(")");
     }
     sb.append(")");
     RequirementImpl req = new RequirementImpl(Capability.EXECUTIONENVIRONMENT);
     req.setFilter(sb.toString());
     req.addText("Execution Environment " + sb.toString());
     resource.addRequire(req);
   }
 }
Ejemplo n.º 10
0
  private static void doRequires(ResourceImpl resource, Headers headers) {
    Clause[] clauses = Parser.parseHeader(headers.getHeader(Constants.REQUIRE_BUNDLE));
    for (int i = 0; clauses != null && i < clauses.length; i++) {
      RequirementImpl r = new RequirementImpl(Capability.BUNDLE);

      VersionRange v =
          VersionRange.parseVersionRange(
              clauses[i].getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE));

      StringBuffer sb = new StringBuffer();
      sb.append("(&(symbolicname=");
      sb.append(clauses[i].getName());
      sb.append(")");
      appendVersion(sb, v);
      sb.append(")");
      r.setFilter(sb.toString());

      r.addText("Require Bundle " + clauses[i].getName() + "; " + v);
      r.setOptional(
          Constants.RESOLUTION_OPTIONAL.equalsIgnoreCase(
              clauses[i].getDirective(Constants.RESOLUTION_DIRECTIVE)));
      resource.addRequire(r);
    }
  }
Ejemplo n.º 11
0
 private static String getVersion(Headers headers) {
   String v = headers.getHeader(Constants.BUNDLE_VERSION);
   return VersionCleaner.clean(v);
 }
Ejemplo n.º 12
0
 private static void doCategories(ResourceImpl resource, Headers headers) {
   Clause[] clauses = Parser.parseHeader(headers.getHeader(Constants.BUNDLE_CATEGORY));
   for (int i = 0; clauses != null && i < clauses.length; i++) {
     resource.addCategory(clauses[i].getName());
   }
 }
Ejemplo n.º 13
0
  static void populate(Headers headers, ResourceImpl resource) {
    String bsn = getSymbolicName(headers);
    String v = getVersion(headers);

    resource.put(Resource.ID, bsn + "/" + v);
    resource.put(Resource.SYMBOLIC_NAME, bsn);
    resource.put(Resource.VERSION, v);
    if (headers.getHeader(Constants.BUNDLE_NAME) != null) {
      resource.put(Resource.PRESENTATION_NAME, headers.getHeader(Constants.BUNDLE_NAME));
    }
    if (headers.getHeader(Constants.BUNDLE_DESCRIPTION) != null) {
      resource.put(Resource.DESCRIPTION, headers.getHeader(Constants.BUNDLE_DESCRIPTION));
    }
    if (headers.getHeader(BUNDLE_LICENSE) != null) {
      resource.put(Resource.LICENSE_URI, headers.getHeader(BUNDLE_LICENSE));
    }
    if (headers.getHeader(Constants.BUNDLE_COPYRIGHT) != null) {
      resource.put(Resource.COPYRIGHT, headers.getHeader(Constants.BUNDLE_COPYRIGHT));
    }
    if (headers.getHeader(Constants.BUNDLE_DOCURL) != null) {
      resource.put(Resource.DOCUMENTATION_URI, headers.getHeader(Constants.BUNDLE_DOCURL));
    }
    if (headers.getHeader(BUNDLE_SOURCE) != null) {
      resource.put(Resource.SOURCE_URI, headers.getHeader(BUNDLE_SOURCE));
    }

    doCategories(resource, headers);
    doBundle(resource, headers);
    doImportExportServices(resource, headers);
    doFragment(resource, headers);
    doRequires(resource, headers);
    doExports(resource, headers);
    doImports(resource, headers);
    doExecutionEnvironment(resource, headers);
  }