Hello devs,

I'm integrating BundleRepository with a ResolveContext and I found a problem while trying to get some capabilities from repository when using R5 spec findProviders().

I have discovered that findProviders's result is not returning a Content capability only one Identity capability containing attributes from both Identity and Content.

I did a debug and found that BR's SpecXMLPullParser class is the responsible for merging those attributes into one identity capability.

Anyone knows what is the reason for that ?   this behavior is not following the spec, right ?

thanks,

Cristiano


Below is some methods taken from SpecXMLPullParser that shows the current behavior:

    private static Capability parseCapability(XmlPullParser reader, ResourceImpl resource, URI baseUri) throws Exception
    {
        String namespace = reader.getAttributeValue(null, NAMESPACE);
        if (IdentityNamespace.IDENTITY_NAMESPACE.equals(namespace))
        {
*parseIdentityNamespace(reader, resource);**
**            return null;*
        }
        if (ContentNamespace.CONTENT_NAMESPACE.equals(namespace))
        {
            if (resource.getURI() == null)
            {
*  parseContentNamespace(reader, resource, baseUri);**
**                return null;*
            }
            // if the URI is already set, this is a second osgi.content capability.             // The first content capability, which is the main one, is stored in the Resource.             // Subsequent content capabilities are stored are ordinary capabilities.
        }

    private static Resource parseResource(XmlPullParser reader, URI baseUri) throws Exception
    {
        ResourceImpl resource = new ResourceImpl();
        try
        {
            int event;
            while ((event = reader.nextTag()) == XmlPullParser.START_TAG)
            {
                String element = reader.getName();
                if (CAPABILITY.equals(element))
                {
                    Capability capability = parseCapability(reader, resource, baseUri);
*if (capability != null)*
                        resource.addCapability(capability);
                }
                else if (REQUIREMENT.equals(element))
                {
                    Requirement requirement = parseRequirement(reader);
                    if (requirement != null) {
                        resource.addRequire(requirement);
                    }
                }
                else
                {
                    PullParser.ignoreTag(reader);
                }
            }

            PullParser.sanityCheckEndElement(reader, event, RESOURCE);
            return resource;
        }
        catch (Exception e)
        {
            throw new Exception("Error while parsing resource " + resource.getId() + " at line " + reader.getLineNumber() + " and column " + reader.getColumnNumber(), e);
        }
    }

    private static void parseIdentityNamespace(XmlPullParser reader, ResourceImpl resource) throws Exception
    {
        Map<String, Object> attributes = new HashMap<String, Object>();
        parseAttributesDirectives(reader, attributes, new HashMap<String, String>(), CAPABILITY);
        // TODO need to cater for the singleton directive...

        for (Map.Entry<String, Object> entry : attributes.entrySet())
        {
*if (IdentityNamespace.IDENTITY_NAMESPACE.equals(entry.getKey()))**
**                resource.put(Resource.SYMBOLIC_NAME, entry.getValue());*
            else
                resource.put(entry.getKey(), entry.getValue());
        }
    }

Reply via email to