Search code examples
javaosgiapache-felixosgi-bundlefelix-dependency-manager

How to force (to 1.2.0) OSGi XMLNS for OSGi R7 Metatype annotations


I am updating a project to OSGi R6 Annotations (I have constraints running OSGi R7 due to my the dependencies deployed to my container) and have run into a problem where my old Apache Felix SCR annotation had dashes in them, which is not possible with OSGi R6.

I am trying to keep my existing OSGi properties as is (containing the dashes) while moving to the OSGi R6 annotations, however this is proving difficult.

What i am trying to do now is use OSGi R7 annotations that support dashes via $_$, and looking for some way i can force the /target/classes/OSGI-INF/metatype XML files to have

<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.2.0"...

instead of

<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.4.0"...

..which is the incompatibility in my application (the 1.4.0 namespace cannot be resolved, and no I cannot update my Metatype service).

Is there any way I can force the XMLNS on my metatype XML generation? I can force it on the Component XML files at /target/classes/OSGI-INF by specifying @Component(xmlns="http://www.osgi.org/xmlns/metatype/v1.2.0") however this set it for the Component and not the Metatype (and i need it for the metatype).

Im using:

   <groupId>org.apache.felix</groupId>
   <artifactId>maven-bundle-plugin</artifactId>
   <version>4.1.0</version>

Any thoughts on how I can achieve this?


Solution

  • The only time Bnd will emit the Metatype 1.4 namespace is if you use the PREFIX_ constants to prefix element names, if you use a single element annotation where the name comes from the type rather than the element, or if you use the name mapping of $_$ to -. Since you want to use this last item, then the xml must use the 1.4 namespace since all processors of the xml must understand the new name mapping rules. If you could force the namespace version to a lower version, then an older processor would not recognize the newer features used by the xml document and incorrectly handle them.

    So if you want to use Metatype 1.4 features which require runtime understanding of those features, then you must use runtime component which understand those Metatype 1.4 features.