- for (ProvidedInterface service : getProvidedInterfaces()) {
- if (!(provided.contains(service))) {
- throw new SystemAssemblyException(getName() + ": Service '" + service
- + "' is not provided by any of the subsystems");
+ validateProvidedInterfaces(provided);
+
+ validateRequiredInterfaces(required);
+
+ List<RequiredInterface> reallyRequired = validateRequiredProvidedMatch(
+ provided, required);
+
+ String missingRequired = "";
+ for (RequiredInterface service : reallyRequired) {
+ missingRequired += service + "\n";
+ }
+ if (missingRequired.length() > 0) {
+ throw new SystemAssemblyException(getName()
+ + ": missing required services\n" + missingRequired);
+ }
+ }
+
+ private List<RequiredInterface> validateRequiredProvidedMatch(
+ List<ProvidedInterface> aProvided, List<RequiredInterface> aRequired) {
+ List<RequiredInterface> reallyRequired = new ArrayList<RequiredInterface>(
+ aRequired);
+ // Compute all required interfaces that are not provided
+
+ for (ProvidedInterface service : aProvided) {
+ List<RequiredInterface> fulfilled = Arrays
+ .asList(filterRequiredServices(service, reallyRequired));
+ reallyRequired.removeAll(fulfilled);
+ }
+ // Now remove all optional interfaces from the list.
+ for (Iterator<RequiredInterface> i =
+ reallyRequired.iterator(); i.hasNext(); ) {
+ RequiredInterface req = i.next();
+ if ( req.isOptional() ) {
+ i.remove();