Example #1
0
  private String getErrorMessage(
      ComponentDescriptor descriptor, ComponentRequirement requirement, String causeDescription) {
    StringBuffer msg = new StringBuffer("Component composition failed.");

    msg.append("  Failed to resolve requirement for component of role: '");

    msg.append(descriptor.getRole());

    msg.append("'");

    if (descriptor.getRoleHint() != null) {
      msg.append(" and role-hint: '");

      msg.append(descriptor.getRoleHint());

      msg.append("'. ");
    }

    if (requirement != null) {
      msg.append("Failing requirement: " + requirement.getHumanReadableKey());
    }
    if (causeDescription != null) {
      msg.append(causeDescription);
    }

    return msg.toString();
  }
  private ComponentRequirement getMatchingRequirement(
      ComponentDescriptor componentDescriptor, List requirements) {

    ComponentRequirement retValue = null;

    String role = componentDescriptor.getRole();

    String roleHint = componentDescriptor.getRoleHint();

    if (componentDescriptor.getRoleHint() != null) {
      for (Iterator iterator = requirements.iterator(); iterator.hasNext(); ) {
        ComponentRequirement requirement = (ComponentRequirement) iterator.next();

        if (role.equals(requirement.getRole()) && roleHint.equals(requirement.getRoleHint())) {
          retValue = requirement;

          break;
        }
      }
    } else {
      for (Iterator iterator = requirements.iterator(); iterator.hasNext(); ) {
        ComponentRequirement requirement = (ComponentRequirement) iterator.next();

        if (role.equals(requirement.getRole())) {
          retValue = requirement;

          break;
        }
      }
    }

    return retValue;
  }