On Mon, Apr 28, 2008 at 3:37 PM, <[EMAIL PROTECTED]> wrote: > Hi all, > > I have another question concerning multiplicity. Given my sample > configuration > > <component name="CrawlerControllerComponent"> > ... > <reference name="crawlers" multiplicity="1..n" > target="CrawlerComponent SpecialCrawlerComponent"> > <binding.sca /> > </reference> > > </component> > > <component name="CrawlerComponent"> > <implementation.java class="impl.CrawlerImpl"/> > <service name="Crawler"> > <interface.java interface="interfaces.Crawler" /> > > </service> > </component> > > <component name="SpecialCrawlerComponent"> > <implementation.java class="impl.SpecialCrawlerImpl"/> > <service name="Crawler"> > <interface.java interface="interfaces.Crawler" /> > </service> > </component> > > > I want to create a ServiceReference to one of the Crawlers. > Without multiplicity (assuming the reference name would be "crawler"), > the code would look like this: > > ServiceReference<Crawler> crawlerRef = > componentContext.getServiceReference(Crawler.class, "crawler"); > return crawlerRef.getService(); > > > But How can I achieve this using multiplicity ? How can I choose for > what target a ServiceReference is created? > By simply using this code > ServiceReference<Crawler> crawlerRef = > componentContext.getServiceReference(Crawler.class, "crawlers"); > return crawlerRef.getService(); > always a ServiceReference to the first target (CrawlerComponent) is > created. > > > Bye, > Daniel >
Hi Daniel Good question. The OASIS TC has proposed a solution to this issue ( http://www.osoa.org/jira/browse/JAVA-9) but this isn't part of the API we have implemented as we have taken the V1 API. Can you raise a JIRA for this as I can't see one already and at least in that way we can track it. Is it possible for you to inject the references you need. You can specify a reference with multiplicity as a collection, for example, from itest/references @Reference(name = "dServiceReferences") public List<ServiceReference<DComponent>> dServiceReferences; Which is populated by <component name="AComponent"> ... <reference name="dServiceReferences" target="DComponent DComponent1" /> </component> <component name="DComponent"> <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> </component> <component name="DComponent1"> <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> </component> See the test for alternatives. Regards Simon