Package org.codehaus.enunciate.contract.validation

Examples of org.codehaus.enunciate.contract.validation.ValidationResult


    enunciate.setConfig(config);
    processor = new EnunciateAnnotationProcessor(enunciate) {
      @Override
      protected ValidationResult validate(EnunciateFreemarkerModel model, Validator validator) {
        ValidationResult result = new ValidationResult();
        result.addWarning(beanThree, "test warning.");
        result.addError(beanTwo, "test error");
        result.addError(beanTwo, "test error2");
        return result;
      }

      @Override
      protected Messager getMessager() {
View Full Code Here


  private final HashSet<String> jaxwsBeans = new HashSet<String>();
  private final TreeSet<WebFault> faultSet = new TreeSet<WebFault>(new TypeDeclarationComparator());

  @Override
  public ValidationResult validateEndpointInterface(EndpointInterface ei) {
    ValidationResult result = super.validateEndpointInterface(ei);
    TreeSet<WebFault> unvisitedFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
    for (WebMethod webMethod : ei.getWebMethods()) {
      for (WebMessage webMessage : webMethod.getMessages()) {
        if (webMessage instanceof RequestWrapper) {
          result.aggregate(validateRequestWrapper((RequestWrapper) webMessage, jaxwsBeans));
        }
        else if (webMessage instanceof ResponseWrapper) {
          result.aggregate(validateResponseWrapper((ResponseWrapper) webMessage, jaxwsBeans));
        }
        else if (webMessage instanceof WebFault) {
          WebFault webFault = (WebFault) webMessage;
          if (faultSet.add(webFault)) {
            unvisitedFaults.add(webFault);
          }
        }
      }
    }

    for (WebFault webFault : unvisitedFaults) {
      result.aggregate(validateWebFault(webFault, jaxwsBeans));
    }

    return result;
  }
View Full Code Here

   * @param alreadyVisited The list of bean names already visited.
   * @return The validation result.
   */
  public ValidationResult validateRequestWrapper(RequestWrapper wrapper, Set<String> alreadyVisited) {
    AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment();
    ValidationResult result = new ValidationResult();

    String requestBeanName = wrapper.getRequestBeanName();
    if (!alreadyVisited.add(requestBeanName)) {
      result.addError(wrapper.getWebMethod(), requestBeanName + " conflicts with another generated bean name.  Please use the @RequestWrapper " +
        "annotation to customize the bean name.");
    }

    return result;
  }
View Full Code Here

   * @param alreadyVisited The list of bean names already visited.
   * @return The validation result.
   */
  public ValidationResult validateResponseWrapper(ResponseWrapper wrapper, Set<String> alreadyVisited) {
    AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment();
    ValidationResult result = new ValidationResult();

    String responseBeanName = wrapper.getResponseBeanName();
    if (!alreadyVisited.add(responseBeanName)) {
      result.addError(wrapper.getWebMethod(), responseBeanName + " conflicts with another generated bean name.  Please use the @ResponseWrapper " +
        "annotation to customize the bean name.");
    }

    return result;
  }
View Full Code Here

   * @param alreadyVisited The bean names that have alrady been visited.
   * @return The validation result.
   */
  public ValidationResult validateWebFault(WebFault webFault, Set<String> alreadyVisited) {
    AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment();
    ValidationResult result = new ValidationResult();

    if (webFault.isImplicitSchemaElement()) {
      String faultBeanFQN = webFault.getImplicitFaultBeanQualifiedName();
      if (!alreadyVisited.add(faultBeanFQN)) {
        result.addError(webFault, faultBeanFQN + " conflicts with another generated bean name.  Please use the @WebFault annotation " +
          "to customize the fault bean name.");
      }
    }

    return result;
View Full Code Here

    this.allowWildcardServlet = allowWildcardServlet;
  }

  @Override
  public ValidationResult validateRootResources(List<RootResource> rootResources) {
    ValidationResult result = new ValidationResult();

    for (RootResource rootResource : rootResources) {

      if (rootResource.getDelegate() instanceof InterfaceDeclaration) {
        if (!isExternallyManagedLifecycle(rootResource)) {
          result.addWarning(rootResource, "The Jersey runtime doesn't support interfaces as root resources. The @Path parameter will need to be applied to the " +
            "implementation class. If the lifecycle of this root resource is to be managed externally (e.g. by Spring or something), then let Enunciate know by " +
            "annotating this class with @" + ExternallyManagedLifecycle.class.getName() + ".");
        }
      }
      else {
        List<ConstructorDeclaration> candidates = new ArrayList<ConstructorDeclaration>();
        boolean externallyManagedLifecycle = isExternallyManagedLifecycle(rootResource);
        CONSTRUCTOR_LOOP:
        for (ConstructorDeclaration constructor : ((ClassDeclaration) rootResource.getDelegate()).getConstructors()) {
          if (constructor.getModifiers().contains(Modifier.PUBLIC)) {
            for (ParameterDeclaration constructorParam : constructor.getParameters()) {
              if (!externallyManagedLifecycle && !isSuppliableByJAXRS(constructorParam)) {
                //none of those annotation are available. not a candidate constructor.
                continue CONSTRUCTOR_LOOP;
              }
            }

            candidates.add(constructor);
          }
        }

        if (candidates.isEmpty() && !externallyManagedLifecycle) {
          result.addWarning(rootResource, "A JAX-RS root resource must have a public constructor for which the JAX-RS runtime can provide all parameter values. " +
            "If the resource lifecycle is to be managed externally (e.g. by Spring or something), then please let Enunciate know by applying the @" +
            ExternallyManagedLifecycle.class.getName() + " annotation to the resource.");
        }
        else {
          while (!candidates.isEmpty()) {
            ConstructorDeclaration candidate = candidates.remove(0);
            for (ConstructorDeclaration other : candidates) {
              if (candidate.getParameters().size() == other.getParameters().size()) {
                result.addWarning(rootResource, "Ambiguous JAX-RS constructors (same parameter count).");
              }
            }
          }
        }
      }

      for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
        if ("/*".equals(resourceMethod.getServletPattern())) {
          if (!allowWildcardServlet) {
            result.addError(resourceMethod, "This JAX-RS resource method is designed to catch all requests (including requests to " +
              "Enunciate-generated documentation and other static files). If this is what you want, then please set 'disableWildcardServletError' to 'true'" +
              "in the Enunciate config for the Jersey module.  Otherwise, enable the rest subcontext or adjust the @Path annotation to be more specific.");
          }
          else {
            result.addWarning(resourceMethod, "JAX-RS resource method is designed to catch all requests.");
          }
        }

        for (String producesMime : resourceMethod.getProducesMime()) {
          try {
            MediaType.valueOf(producesMime);
          }
          catch (Exception e) {
            result.addError(resourceMethod, "Invalid produces MIME type: " + producesMime + "(" + e.getMessage() + ").");
          }
        }

        if (resourceMethod.getHttpMethods().size() > 1) {
          result.addError(resourceMethod, "You must not apply multiple HTTP operations to the same method: " + resourceMethod.getHttpMethods());
        }

        for (String method : resourceMethod.getHttpMethods()) {
          if ("GET".equalsIgnoreCase(method) && (resourceMethod.getRepresentationMetadata() == null)) {
            result.addWarning(resourceMethod, "A resource method that is mapped to HTTP GET should probably have an output payload. (Does it return void?)");
          }

          if ("GET".equalsIgnoreCase(method) && resourceMethod.getEntityParameter() != null) {
            result.addError(resourceMethod, "A resource method that is mapped to HTTP GET must not specify an entity parameter.");
          }
        }
      }
    }

View Full Code Here

*/
public class CValidator extends BaseValidator {

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = super.validateComplexType(complexType);
    for (Attribute attribute : complexType.getAttributes()) {
      if (attribute.isXmlList()) {
        result.addWarning(attribute, "The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.");
      }

      if (attribute.isCollectionType() && attribute.isBinaryData()) {
        result.addError(attribute, "The C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.");
      }
    }

    if (complexType.getValue() != null) {
      if (complexType.getValue().isXmlList()) {
        result.addWarning(complexType.getValue(), "The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.");
      }

      if (complexType.getValue().isCollectionType() && complexType.getValue().isBinaryData()) {
        result.addError(complexType.getValue(), "The C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.");
      }
    }

    for (Element element : complexType.getElements()) {
      if (element.isXmlList()) {
        result.addWarning(element, "The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.");
      }

      if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
        result.addError(element, "The C client doesn't have a built-in way of serializing a Map. So you're going to have to use @XmlJavaTypeAdapter to supply " +
          "your own adapter for the Map, or disable the C module.");
      }

      if (element.isCollectionType()) {
        if (element.getChoices().size() > 1) {
          result.addWarning(element, "The C client code doesn't fully support multiple choices for a collection. It has to separate each choice into its own array. " +
            "This makes the C API a bit awkward to use and makes it impossible to preserve the order of the collection. If order is relevant, consider breaking out " +
            "the choices into their own collection or otherwise refactoring the API.");
        }

        if (element.isBinaryData()) {
          result.addError(element, "The C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.");
        }

        for (Element choice : element.getChoices()) {
          if (choice.isNillable()) {
            result.addWarning(choice, "The C client code doesn't support nillable items in a collection (the nil items will be skipped). This may cause confusion to C consumers.");
          }
        }
      }
    }

View Full Code Here

*/
public class RubyValidator extends BaseValidator {

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = super.validateComplexType(complexType);
    if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) {
      result.addError(complexType, "Ruby requires your class name to be upper-case. Please rename the class or apply the @org.codehaus.enunciate.ClientName annotation to the class.");
    }
    for (Element element : complexType.getElements()) {
      if (element instanceof ElementRef && ((ElementRef) element).isElementRefs()) {
        result.addWarning(complexType, "The Ruby client library doesn't fully support the @XmlElementRefs annotation. The items in the collection will be read-only and will only be available to Ruby clients in the form of a Hash. Consider redesigning using a collection of a single type. See http://jira.codehaus.org/browse/ENUNCIATE-542 for more information.");
      }
      else if (element.getAnnotation(XmlElements.class) != null) {
        result.addWarning(complexType, "The Ruby client library doesn't fully support the @XmlElements annotation. The items in the collection will be read-only and will only be available to Ruby clients in the form of a Hash. Consider redesigning using a collection of a single type. See http://jira.codehaus.org/browse/ENUNCIATE-542 for more information.");
      }
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of org.codehaus.enunciate.contract.validation.ValidationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.