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); } }
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); } }
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); } }
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); } }
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); } }