org.osgi.framework.namespace.BundleNamespace的实例源码

项目:osc-core    文件RequirementParser.java   
static List<Requirement> parseRequireBundle(String header) throws IllegalArgumentException {
    if (header == null) {
           return Collections.emptyList();
       }

    Clause[] clauses = Parser.parseHeader(header);
    List<Requirement> requirements = new ArrayList<>(clauses.length);
    for (Clause requireClause : clauses) {
        String bsn = requireClause.getName();
        String versionRangeStr = requireClause.getAttribute(org.osgi.framework.Constants.BUNDLE_VERSION_ATTRIBUTE);

        String filter = toBundleFilter(bsn,versionRangeStr);
        Requirement requirement = new RequirementBuilderImpl(BundleNamespace.BUNDLE_NAMESPACE)
            .addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE,filter)
            .build();
        requirements.add(requirement);
    }
    return requirements;
}
项目:osc-core    文件RequirementParser.java   
private static String toBundleFilter(String bsn,String versionRangeStr) {
    final String filterStr;

    String bsnFilter = String.format("(%s=%s)",BundleNamespace.BUNDLE_NAMESPACE,bsn);

    if (versionRangeStr == null) {
        filterStr = bsnFilter;
    } else {
        VersionRange versionRange = new VersionRange(versionRangeStr);
        if (versionRange.isExact()) {
            String exactVersionFilter = String.format("(%s=%s)",BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE,versionRange.getLeft());
            filterStr = String.format("(&%s%s)",bsnFilter,exactVersionFilter);
        } else if (versionRange.getRight() == null) {
            filterStr = String.format("(&%s%s)",lowerVersionFilter(versionRange));
        } else {
            filterStr = String.format("(&%s%s%s)",lowerVersionFilter(versionRange),upperVersionFilter(versionRange));
        }
    }
    return filterStr;
}
项目:osgi-jpms-layer    文件EquinoxJPMSSupport.java   
private ModuleRevisionBuilder createBuilder(ModuleReference ref) {
    ModuleDescriptor desc = ref.descriptor();
    ModuleRevisionBuilder builder = new ModuleRevisionBuilder();
    builder.setSymbolicName(desc.name());

    Version version = desc.version().map((v) -> {
        try {
            return Version.valueOf(v.toString());
        } catch (IllegalArgumentException e) {
            return Version.emptyVersion;
        }
    }).orElse(Version.emptyVersion);
    builder.setVersion(version);

    // add bundle and identity capabilities,do not create host capability for JPMS
    builder.addCapability(
            BundleNamespace.BUNDLE_NAMESPACE,Map.of(),Map.of(
                    BundleNamespace.BUNDLE_NAMESPACE,desc.name(),version));
    builder.addCapability(
            IdentityNamespace.IDENTITY_NAMESPACE,Map.of(
                    IdentityNamespace.IDENTITY_NAMESPACE,IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE,version));

    for(Exports exports : desc.exports()) {
        // Todo map targets to x-friends directive.
        builder.addCapability(
                PackageNamespace.PACKAGE_NAMESPACE,Map.of(PackageNamespace.PACKAGE_NAMESPACE,exports.source()));
    }

    for(Provides provides : desc.provides()) {
        builder.addCapability(
                JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE,Map.of(
                        JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE,provides.service(),JpmsServiceNamespace.CAPABILITY_PROVIDES_WITH,provides.providers()));
    }

    for (Requires requires : desc.requires()) {
        Map<String,String> directives = new HashMap<>();

        // determine the resolution value based on the STATIC modifier
        String resolution = requires.modifiers().contains(Requires.Modifier.STATIC) ? Namespace.RESOLUTION_OPTIONAL : Namespace.RESOLUTION_MANDATORY;
        directives.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE,resolution);
        // determine the visibility value based on the TRANSITIVE modifier
        String visibility = requires.modifiers().contains(Requires.Modifier.TRANSITIVE) ? BundleNamespace.VISIBILITY_REEXPORT : BundleNamespace.VISIBILITY_PRIVATE;
        directives.put(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE,visibility);
        // create a bundle filter based on the requires name 
        directives.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE,"(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + requires.name() + ")");

        builder.addRequirement(BundleNamespace.BUNDLE_NAMESPACE,directives,Collections.emptyMap());
    }

    for(String uses : desc.uses()) {
        builder.addRequirement(JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE,Map.of(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE,Namespace.RESOLUTION_OPTIONAL,Namespace.REQUIREMENT_FILTER_DIRECTIVE,"(" + JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE + "=" + uses + ")"),Map.of(JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE,uses));
    }
    return builder;
}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...