Package org.codehaus.enunciate.contract.validation

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


  protected GenericTypeDefinition(ClassDeclaration delegate) {
    super(delegate);
  }

  public ValidationResult accept(BaseValidator validator) {
    return new ValidationResult();
  }
View Full Code Here


    return true;
  }

  @Override
  public ValidationResult accept(BaseValidator validator) {
    return new ValidationResult();
  }
View Full Code Here

    this.translateIdTo = translateIdTo;
  }

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = super.validateComplexType(complexType);
    for (Attribute attribute : complexType.getAttributes()) {
      if (attribute.isXmlList()) {
        result.addWarning(attribute, "The Objective-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 Objective-C consumers.");
      }

      if (attribute.isCollectionType() && attribute.isBinaryData()) {
        result.addError(attribute, "The Objective-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 Objective-C module.");
      }

      if (this.translateIdTo.equals(attribute.getClientSimpleName())) {
        result.addError(attribute, "In Objective-C, 'id' is a keyword, so we have to translate 'id' to '" + this.translateIdTo + "'. So you either need to rename this accessor or specify something else to translate 'id' to in the configuration using the 'translateIdTo' attribute.");
      }
    }

    if (complexType.getValue() != null) {
      if (complexType.getValue().isXmlList()) {
        result.addWarning(complexType.getValue(), "The Objective-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 Objective-C consumers.");
      }

      if (complexType.getValue().isCollectionType() && complexType.getValue().isBinaryData()) {
        result.addError(complexType.getValue(), "The Objective-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 Objective-C module.");
      }

      if (this.translateIdTo.equals(complexType.getValue().getClientSimpleName())) {
        result.addError(complexType.getValue(), "In Objective-C, 'id' is a keyword, so we have to translate 'id' to '" + this.translateIdTo + "'. So you either need to rename this accessor or specify something else to translate 'id' to in the configuration using the 'translateIdTo' attribute.");
      }
    }

    for (Element element : complexType.getElements()) {
      if (element.isXmlList()) {
        result.addWarning(element, "The Objective-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 Objective-C consumers.");
      }

      if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
        result.addError(element, "The Objective-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 Objective-C module.");
      }

      if (this.translateIdTo.equals(element.getClientSimpleName())) {
        result.addError(element, "In Objective-C, 'id' is a keyword, so we have to translate 'id' to '" + this.translateIdTo + "'. So you either need to rename this accessor or specify something else to translate 'id' to in the configuration using the 'translateIdTo' attribute.");
      }
    }


    return result;
View Full Code Here

    this.enforceNoFieldAccessors = enforceNoFieldAccessors;
  }

  @Override
  public ValidationResult validateEndpointInterface(EndpointInterface ei) {
    ValidationResult result = super.validateEndpointInterface(ei);

    TreeSet<WebFault> allFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
    if (!isGWTTransient(ei)) {
      if ((this.enforceNamespaceConformance) && (!ei.getPackage().getQualifiedName().startsWith(this.gwtModuleNamespace))) {
        result.addError(ei, String.format("The package of the endpoint interface, %s, must start with the GWT module namespace, %s.", ei.getPackage().getQualifiedName(), gwtModuleNamespace));
      }

      for (WebMethod webMethod : ei.getWebMethods()) {
        if (!isGWTTransient(webMethod)) {
          if (!isSupported(webMethod.getWebResult())) {
            result.addError(webMethod, "GWT doesn't support '" + webMethod.getWebResult() + "' as a return type.");
          }
          for (WebParam webParam : webMethod.getWebParameters()) {
            if (!isSupported(webParam.getType())) {
              result.addError(webParam, "GWT doesn't support '" + webParam.getType() + "' as a parameter type.");
            }
          }

          allFaults.addAll(webMethod.getWebFaults());
        }
      }

      if (ei.getEndpointImplementations().size() > 1) {
        ArrayList<String> impls = new ArrayList<String>();
        for (EndpointImplementation impl : ei.getEndpointImplementations()) {
          impls.add(impl.getQualifiedName());
        }
        result.addError(ei, "Sorry, GWT doesn't support two endpoint implementations for interface '" + ei.getQualifiedName() +
          "'.  Found " + ei.getEndpointImplementations().size() + " implementations (" + impls.toString() + ").");
      }
      else if (ei.getEndpointImplementations().isEmpty()) {
        result.addError(ei, "GWT requires an implementation for each service interface.");
      }
    }
   
    for (WebFault fault : allFaults) {
      if (!isGWTTransient(fault)) {
        if ((this.enforceNamespaceConformance) && (!fault.getPackage().getQualifiedName().startsWith(this.gwtModuleNamespace)) && (!isKnownGwtType(fault))) {
          result.addError(fault, String.format("The package of the fault, %s, must start with the GWT module namespace, %s.", fault.getPackage().getQualifiedName(), gwtModuleNamespace));
        }
      }
    }

    return result;
View Full Code Here

    return false;
  }

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = super.validateComplexType(complexType);
    if (!isGWTTransient(complexType)) {
      if (!hasDefaultConstructor(complexType)) {
        result.addError(complexType, "The mapping from GWT to JAXB requires a public no-arg constructor.");
      }

      if ((this.enforceNamespaceConformance)
        && (!complexType.getPackage().getQualifiedName().startsWith(this.gwtModuleNamespace))
        && (!isKnownGwtType(complexType))) {
        result.addError(complexType, String.format("The package of the complex type, %s, must start with the GWT module namespace, %s.", complexType.getPackage().getQualifiedName(), gwtModuleNamespace));
      }

      for (Attribute attribute : complexType.getAttributes()) {
        if (!isGWTTransient(attribute)) {
          if ((attribute.getDelegate() instanceof FieldDeclaration) && (enforceNoFieldAccessors)) {
            result.addError(attribute, "If you're mapping to GWT, you can't use fields for your accessors. ");
          }

          if (!isSupported(attribute.getAccessorType())) {
            result.addError(attribute, "GWT doesn't support the '" + attribute.getAccessorType() + "' type.");
          }
        }
      }

      for (Element element : complexType.getElements()) {
        if (!isGWTTransient(element)) {
          if ((element.getDelegate() instanceof FieldDeclaration) && (enforceNoFieldAccessors)) {
            result.addError(element, "If you're mapping to GWT, you can't use fields for your accessors. ");
          }

          if (!isSupported(element.getAccessorType())) {
            result.addError(element, "GWT doesn't support the '" + element.getAccessorType() + "' type.");
          }

          if (this.generateJsonOverlays) {
            if (element instanceof ElementRef && ((ElementRef) element).isElementRefs()) {
              result.addWarning(complexType, "GWT overlay types don't fully support the @XmlElementRefs annotation. The items in the collection will only be available to the client-side in the form of a raw, untyped JsArray. Consider redesigning using a collection of a single type. See http://jira.codehaus.org/browse/ENUNCIATE-543 for more information, and feel free to contribute your ideas on how to solve this problem.");
            }
            else if (element.getAnnotation(XmlElements.class) != null) {
              result.addWarning(complexType, "GWT overlay types don't fully support the @XmlElements annotation. The items in the collection will only be available to the client-side in the form of a raw, untyped JsArray. Consider redesigning using a collection of a single type. See http://jira.codehaus.org/browse/ENUNCIATE-543 for more information, and feel free to contribute your ideas on how to solve this issue.");
            }
          }
        }
      }

      Value value = complexType.getValue();
      if (value != null) {
        if (!isGWTTransient(value)) {
          if ((value.getDelegate() instanceof FieldDeclaration) && (enforceNoFieldAccessors)) {
            result.addError(value, "If you're mapping to GWT, you can't use fields for your accessors. ");
          }

          if (!isSupported(value.getAccessorType())) {
            result.addError(value, "GWT doesn't support the '" + value.getAccessorType() + "' type.");
          }
        }
      }
    }

    if (((DecoratedTypeMirror) complexType.getSuperclass()).isInstanceOf(Map.class.getName())) {
      result.addError(complexType, "Enunciate can't generate GWT code that handles types that implement java.util.Map. I'm afraid you'll have to disable the GWT module or use @XmlJavaTypeAdapter to adapt the type.");
    }

    return result;
  }
View Full Code Here

  }


  @Override
  public ValidationResult validateSimpleType(SimpleTypeDefinition simpleType) {
    ValidationResult result = super.validateSimpleType(simpleType);
    if (!isGWTTransient(simpleType)) {
      if ((this.enforceNamespaceConformance)
        && (!simpleType.getPackage().getQualifiedName().startsWith(this.gwtModuleNamespace))
        && (!isKnownGwtType(simpleType))) {
        result.addError(simpleType, String.format("The package of the simple type, %s, must start with the GWT module namespace, %s.", simpleType.getPackage().getQualifiedName(), gwtModuleNamespace));
      }

      if (!hasDefaultConstructor(simpleType)) {
        result.addError(simpleType, "The mapping from GWT to JAXB requires a public no-arg constructor.");
      }
    }
    return result;
  }
View Full Code Here

  }


  @Override
  public ValidationResult validateEnumType(EnumTypeDefinition enumType) {
    ValidationResult result = super.validateEnumType(enumType);
    if (!isGWTTransient(enumType)) {
      if ((this.enforceNamespaceConformance)
        && (!enumType.getPackage().getQualifiedName().startsWith(this.gwtModuleNamespace))
        && (!isKnownGwtType(enumType))) {
        result.addError(enumType, String.format("The package of the enum type, %s, must start with the GWT module namespace, %s.", enumType.getPackage().getQualifiedName(), gwtModuleNamespace));
      }
    }
    return result;
  }
View Full Code Here

  private final HashMap<String, EndpointInterface> visitedEndpoints = new HashMap<String, EndpointInterface>();

  @Override
  public ValidationResult validateEndpointInterface(EndpointInterface ei) {
    ValidationResult result = super.validateEndpointInterface(ei);

    EndpointInterface visited = visitedEndpoints.put(ei.getServiceName(), ei);
    if (visited != null) {
      if (visited.getTargetNamespace().equals(ei.getTargetNamespace())) {
        result.addError(ei, "Ummm... you already have a service named " + ei.getServiceName() + " at " +
          visited.getPosition() + ".  You need to disambiguate.");
      }
    }

    for (WebMethod webMethod : ei.getWebMethods()) {
      for (WebParam webParam : webMethod.getWebParameters()) {
        if ((webParam.isHeader()) && ("".equals(webParam.getAnnotation(javax.jws.WebParam.class).name()))) {
          //todo: lift this constraint by serializing the parameter names to some file you can load for metadata...
          result.addError(webParam, "For now, Enunciate requires you to specify a 'name' on the @WebParam annotation if it's a header.");
        }
      }
    }

    if (ei.getEndpointImplementations().size() > 1) {
      ArrayList<String> impls = new ArrayList<String>();
      for (EndpointImplementation impl : ei.getEndpointImplementations()) {
        impls.add(impl.getQualifiedName());
      }
      result.addError(ei, "Sorry, JAXWS-RI module doesn't support two endpoint implementations for interface '" + ei.getQualifiedName() +
        "'.  Found " + ei.getEndpointImplementations().size() + " implementations (" + impls.toString() + ").");
    }
    else if (ei.getEndpointImplementations().isEmpty()) {
      result.addError(ei, "JAXWS-RI module requires an implementation for each service interface.");
    }

    return result;
  }
View Full Code Here

    this.enableJaxrs = enableJaxrs;
  }

  @Override
  public ValidationResult validateEndpointInterface(EndpointInterface ei) {
    ValidationResult result = super.validateEndpointInterface(ei);

    if (enableJaxws) {
      EndpointInterface visited = visitedEndpoints.put(ei.getServiceName(), ei);
      if (visited != null) {
        if (visited.getTargetNamespace().equals(ei.getTargetNamespace())) {
          result.addError(ei, "Ummm... you already have a service named " + ei.getServiceName() + " at " +
            visited.getPosition() + ".  You need to disambiguate.");
        }
      }

      if (ei.isInterface()) {
        WebService eiAnnotation = ei.getAnnotation(WebService.class);
        if (!"".equals(eiAnnotation.serviceName())) {
          result.addError(ei, "CXF fails if you specify 'serviceName' on an endpoint interface.");
        }
        if (!"".equals(eiAnnotation.portName())) {
          result.addError(ei, "CXF fails if you specify 'portName' on an endpoint interface.");
        }
        for (MethodDeclaration m : ei.getMethods()) {
          javax.jws.WebMethod wm = m.getAnnotation(javax.jws.WebMethod.class);
          if (wm != null && wm.exclude()) {
            result.addError(m, "CXF fails if you specify 'exclude=true' on an endpoint interface.");
          }
        }
      }

      for (WebMethod webMethod : ei.getWebMethods()) {
        for (WebParam webParam : webMethod.getWebParameters()) {
          if ((webParam.isHeader()) && ("".equals(webParam.getAnnotation(javax.jws.WebParam.class).name()))) {
            //todo: lift this constraint by serializing the parameter names to some file you can load for metadata...
            result.addError(webParam, "For now, Enunciate requires you to specify a 'name' on the @WebParam annotation if it's a header.");
          }
        }

        for (WebFault webFault : webMethod.getWebFaults()) {
          if (webFault.getExplicitFaultBeanType() != null) {
            ElementDeclaration faultBean = webFault.findExplicitFaultBean();
            if (!webFault.getSimpleName().equals(faultBean.getName())) {
              result.addError(webMethod, "Because of some inconsistencies with the JAX-WS implementation of CXF, the CXF module cannot have methods that " +
                "throw exceptions that are named differently than the element name of their explicit fault beans. Apply @XmlRootElement ( name = \""
                + webFault.getSimpleName() + "\" ) to  explicit fault bean " + webFault.getExplicitFaultBeanType() + " to apply the workaround.");
            }
          }
          else {
            String ns = webFault.getTargetNamespace() == null ? "" : webFault.getTargetNamespace();
            String eins = ei.getTargetNamespace() == null ? "" : ei.getTargetNamespace();
            if (!ns.equals(eins)) {
              result.addError(webMethod, "CXF doesn't handle throwing exceptions that are defined in a different namespace " +
                "from the namespace of the endpoint interface.");
            }
          }
        }
      }
View Full Code Here

*/
public class PHPValidator extends BaseValidator {

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = super.validateComplexType(complexType);
    if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) {
      result.addError(complexType, "PHP 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 PHP client library doesn't fully support the @XmlElementRefs annotation. The items in the collection will be read-only and will only be available to PHP 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 PHP client library doesn't fully support the @XmlElements annotation. The items in the collection will be read-only and will only be available to PHP 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.