Looking for confirmation or insight in how best to specify components and
references, so that the same component can be invoked directly or more
generically through its interface.

Let's say that I have some components, 1 per table to do some export

        property= MappingConstants.CONFIG_TABLE_NAME + "=BigTable",
        service= { BigTableXlExporter.class, XlExportContent.class }
public final class BigTableXlExporter implements XlExportContent {...}

and in another component I can get a specific reference with:
public final class SomeComp
    private BigTableXlExporter exporter;

and in another case i could get a more generic invocation (as part of
config or through a factory:
public final class GenericComp
   private void init(Map<String,Object> props, BundleContext bcontext) {
     ServiceReference servRef;
      try {
         Collection<ServiceReference<T>> servRefs =
bcontext.getServiceReferences(target, props.get("filter"));  //filter to be
like: "(target
        servRef = servRefs.isEmpty() ? null : servRefs.iterator().next();
        catch (InvalidSyntaxException e) {
            throw new IllegalArgumentException("Invalid Filter Syntax
Exception", e);

        //do something with ref....

Does this make sense or are there better ways to do this.

OSGi Developer Mail List

Reply via email to