微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。