- // TODO provided interfaces by components could be
- // provide subclasses or implementations of the
- // provided interfaces of the container.
- // The code below assumes an exact match.
- if (!(provided.contains(service))) {
- throw new SystemAssemblyException(getQualifiedName() + ": Service '"
- + service
- + "' is not provided by any of its components");
+ findProvidedInterface(service);
+ }
+ }
+
+ /**
+ * Finds the component and provided interface that matches a provided interface of this
+ * container.
+ * @param aProvided Interface to provide externally.
+ * @return Pair of component and provided interface
+ * @throws SystemAssemblyException In case there are multiple matches or no match at all.
+ */
+ private Pair<Component,ProvidedInterface> findProvidedInterface(ProvidedInterface aProvided) {
+ List<Pair<Component,ProvidedInterface>> result =
+ new ArrayList<Pair<Component,ProvidedInterface>>();
+ for (Component component: _components) {
+ for (ProvidedInterface provided: component.getProvidedInterfaces()) {
+ if ( aProvided.equals(provided) ) {
+ result.add(new Pair<Component,ProvidedInterface>(component, provided));
+ }