final boolean isPolicySupportActive(QName consumer) {
   return policyProvidersRegistry != null
       && (!policyProvidersRegistry.isEmpty())
       && policyExtractorsRegistry != null
       && (!policyExtractorsRegistry.isEmpty())
       && policyProcessor != null
       && consumer != null;
 }
  public List<EndpointDescription> getEndpointsFor(final QName portType, final QName consumer) {

    EndpointDocumentProvider descriptionProvider = providersRegistry.getPreferredProvider();
    if (descriptionProvider == null) {
      throw new SwordfishException(
          "Couldn't get endpoints for: "
              + portType
              + ", no registered document providers were found");
    }

    List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
    Collection<ServiceDescription<?>> descriptions =
        descriptionProvider.getServiceProviderDescriptions(portType);
    final boolean isPolicySupportActive = isPolicySupportActive(consumer);

    PolicyDescription<?> consumerPolicy = null;

    if (isPolicySupportActive) {
      try {
        consumerPolicy = queryPolicies(consumer).iterator().next();
      } catch (NoSuchElementException e) {
        throw new SwordfishException("Policy support active and no consumer policy assigned.", e);
      }
    } else if (consumer != null) {
      throw new SwordfishException("Policy support requested by consumer" + "but not available. ");
    }

    if (!descriptions.isEmpty()) {
      for (final ServiceDescription<?> description : descriptions) {
        Map<String, PolicyDefinitionDescription> embeddedPolicies = null;
        if (isPolicySupportActive) {
          embeddedPolicies = description.getEmbeddedPolicyDefinitions();
          if (embeddedPolicies.isEmpty()) {
            embeddedPolicies = null;
            final QName serviceProviderName = description.getServiceName();
            final List<PolicyDescription<?>> policies = queryPolicies(serviceProviderName);
            final PolicyDescription<?> agreed =
                policyProcessor.tradeAgreedPolicy(consumerPolicy, policies);
            if (agreed == null) {
              continue;
            }
          }
        }

        Collection<EndpointExtractor> extractors = extractorsRegistry.getExtractors();
        for (EndpointExtractor endpointExtractor : extractors) {
          if (endpointExtractor.canHandle(description)) {
            final EndpointDescription ed = endpointExtractor.extractEndpoint(description);
            if (embeddedPolicies != null) {
              final PolicyDefinitionDescription pdd = embeddedPolicies.get(ed.getName());
              final List<PolicyDescription<?>> policies = queryPolicies(pdd);
              final PolicyDescription<?> agreed =
                  policyProcessor.tradeAgreedPolicy(consumerPolicy, policies);
              if (agreed == null) {
                continue;
              } else {
                ed.setMetadata(new PolicyDescriptionEndpointMetadata(agreed));
              }
            }
            endpoints.add(ed);
            break;
          }
        }
      }
    }
    return endpoints;
  }
 private List<PolicyDescription<?>> queryPolicies(final QName name) {
   final PolicyDefinitionProvider pr = policyProvidersRegistry.getPreferredProvider();
   final Collection<PolicyDefinitionDescription> policyDefinitions = pr.getPolicyDefinitions(name);
   return queryPolicies(policyDefinitions);
 }