Search in sources :

Example 1 with SimpleFilter

use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.

the class XmlRepository method hasResource.

private boolean hasResource(String type, String name, Version version) {
    CapabilitySet set = capSets.get(IDENTITY_NAMESPACE);
    if (set != null) {
        Map<String, Object> attrs = new HashMap<>();
        attrs.put(CAPABILITY_TYPE_ATTRIBUTE, type);
        attrs.put(IDENTITY_NAMESPACE, name);
        attrs.put(CAPABILITY_VERSION_ATTRIBUTE, version);
        SimpleFilter sf = SimpleFilter.convert(attrs);
        return !set.match(sf, true).isEmpty();
    } else {
        return false;
    }
}
Also used : HashMap(java.util.HashMap) SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter) CapabilitySet(org.apache.karaf.features.internal.resolver.CapabilitySet)

Example 2 with SimpleFilter

use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.

the class SubsystemResolver method associateFragments.

private void associateFragments() {
    SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
    for (Map.Entry<Resource, List<Wire>> entry : wiring.entrySet()) {
        final Resource resource = entry.getKey();
        final Requirement requirement = getSubsystemRequirement(resource);
        if (ResolverUtil.isFragment(resource) && requirement != null) {
            List<Wire> wires = entry.getValue();
            final Resource host = wires.get(0).getProvider();
            final Wire wire = findMatchingWire(sf, wiring.get(host));
            if (wire != null) {
                wires.add(new Wire() {

                    @Override
                    public Capability getCapability() {
                        return wire.getCapability();
                    }

                    @Override
                    public Requirement getRequirement() {
                        return requirement;
                    }

                    @Override
                    public Resource getProvider() {
                        return wire.getProvider();
                    }

                    @Override
                    public Resource getRequirer() {
                        return resource;
                    }
                });
            }
        }
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter) Resource(org.osgi.resource.Resource) Wire(org.osgi.resource.Wire) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap)

Example 3 with SimpleFilter

use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.

the class SubsystemResolver method getBundles.

/**
     * 
     * @return map of bundles and the region they are deployed in
     */
public Map<Resource, String> getBundles() {
    if (bundles == null) {
        String filter = String.format("(&(%s=*)(|(%s=%s)(%s=%s)))", IDENTITY_NAMESPACE, CAPABILITY_TYPE_ATTRIBUTE, TYPE_BUNDLE, CAPABILITY_TYPE_ATTRIBUTE, TYPE_FRAGMENT);
        SimpleFilter sf = SimpleFilter.parse(filter);
        bundles = getResourceMapping(sf);
    }
    return bundles;
}
Also used : SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter)

Example 4 with SimpleFilter

use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.

the class SubsystemResolver method getResourceMapping.

/**
     * 
     * @param resourceFilter
     * @return map from resource to region name
     */
private Map<Resource, String> getResourceMapping(SimpleFilter resourceFilter) {
    Map<String, String> flats = getFlatSubsystemsMap();
    Map<Resource, List<Wire>> wiring = getWiring();
    Map<Resource, String> resources = new HashMap<>();
    SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
    if (wiring != null) {
        for (Resource resource : wiring.keySet()) {
            if (findMatchingCapability(resourceFilter, resource.getCapabilities(null)) != null) {
                // Find the subsystem where this feature is installed
                Wire wire = findMatchingWire(sf, wiring.get(resource));
                if (wire != null) {
                    String region = (String) wire.getCapability().getAttributes().get(IDENTITY_NAMESPACE);
                    region = flats.get(region);
                    resources.put(resource, region);
                }
            }
        }
    }
    return resources;
}
Also used : SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter) Resource(org.osgi.resource.Resource) Wire(org.osgi.resource.Wire)

Example 5 with SimpleFilter

use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.

the class StaxParser method parseRequirement.

private static RequirementImpl parseRequirement(XMLStreamReader reader, ResourceImpl resource) throws XMLStreamException {
    String[] namespace = new String[1];
    Map<String, String> directives = new HashMap<>();
    Map<String, Object> attributes = new HashMap<>();
    parseClause(reader, namespace, directives, attributes);
    sanityCheckEndElement(reader, reader.getEventType(), REQUIREMENT);
    String filterStr = directives.get(Constants.FILTER_DIRECTIVE);
    SimpleFilter sf = (filterStr != null) ? SimpleFilter.parse(filterStr) : SimpleFilter.convert(attributes);
    return new RequirementImpl(resource, namespace[0], directives, attributes, sf);
}
Also used : RequirementImpl(org.apache.karaf.features.internal.resolver.RequirementImpl) HashMap(java.util.HashMap) SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter)

Aggregations

SimpleFilter (org.apache.karaf.features.internal.resolver.SimpleFilter)10 Requirement (org.osgi.resource.Requirement)5 HashMap (java.util.HashMap)4 RequirementImpl (org.apache.karaf.features.internal.resolver.RequirementImpl)4 Capability (org.osgi.resource.Capability)4 CapabilitySet (org.apache.karaf.features.internal.resolver.CapabilitySet)2 Resource (org.osgi.resource.Resource)2 Wire (org.osgi.resource.Wire)2 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DictionaryAsMap (org.apache.felix.utils.collections.DictionaryAsMap)1 CapabilityImpl (org.apache.karaf.features.internal.resolver.CapabilityImpl)1 ResourceImpl (org.apache.karaf.features.internal.resolver.ResourceImpl)1 ResourceUtils.addIdentityRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement)1 ResourceUtils.toFeatureRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement)1