/**
* Can we order the references? References are ordered by their name as
Java
* does not define the order of the methods.
*
* @throws Exception
*/
@Component
static class TestReferenceOrdering {
@Reference(service = LogService.class)
void setA(@SuppressWarnings("unused")
ServiceReference ref) {}
@Reference
void setC(@SuppressWarnings("unused")
LogService log) {}
@Reference(service = LogService.class)
void setB(@SuppressWarnings("unused")
Map<String,Object> map) {}
}
public static void testAnnotationReferenceOrdering() throws Exception {
Builder b = new Builder();
b.addClasspath(new File("bin"));
b.setProperty("Service-Component", "*TestReferenceOrdering");
b.setProperty("Private-Package", "test.component");
b.build();
Document doc = doc(b,
"test.component.BNDAnnotationTest$TestReferenceOrdering");
NodeList nodes = (NodeList) xpath.evaluate("//reference", doc,
XPathConstants.NODESET);
assertEquals("a",
nodes.item(0).getAttributes().getNamedItem("name").getTextContent());
assertEquals("b",
nodes.item(1).getAttributes().getNamedItem("name").getTextContent());
assertEquals("c",
nodes.item(2).getAttributes().getNamedItem("name").getTextContent());
}
See
https://github.com/bndtools/bnd/blob/master/biz.aQute.bndlib.tests/src/test/component/BNDAnnotationTest.java
There is a similar test for ds annotations:
https://github.com/bndtools/bnd/blob/master/biz.aQute.bndlib.tests/src/test/component/DSAnnotationTest.java
Kind regards,
Peter Kriens
On 5 nov. 2013, at 09:29, Ewgenij Sokolovski <[email protected]> wrote:
> Hmm, what kind of order is that supposed to be? I can't observe any name
> ordering in resulting XML files...
>
> Kind regards
> Ewgenij
>
>
> >Peter means it is in the order of the name elements of the @Reference
> >annotations. So you can control the order by setting the name element to
> >values which will sort in your desired order.
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev