Package org.codehaus.enunciate.contract.validation

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


*/
public class CSharpValidator extends BaseValidator {

  @Override
  public ValidationResult validateEndpointInterface(EndpointInterface ei) {
    ValidationResult result = super.validateEndpointInterface(ei);
    Map<String, Declaration> paramsByName = new HashMap<String, Declaration>();
    for (WebMethod webMethod : ei.getWebMethods()) {
      for (WebParam webParam : webMethod.getWebParameters()) {
        //no out or in/out non-header parameters!
        if (webParam.isHeader()) {
          //unique parameter names for all header parameters of a given ei
          Declaration conflict = paramsByName.put(webParam.getElementName(), webParam);
          if (conflict != null) {
            result.addError(webParam, "C# requires that all header parameters defined in the same endpoint interface have unique names. " +
              "This parameter conflicts with the one at " + (conflict.getPosition() == null ? "(unknown source position)" : conflict.getPosition()));
          }

          DecoratedTypeMirror paramType = (DecoratedTypeMirror) webParam.getType();
          if (paramType.isCollection()) {
            result.addError(webParam, "C# can't handle header parameters that are collections.");
          }

        }
        else if (webParam.getMode() != javax.jws.WebParam.Mode.IN) {
          result.addError(webParam, "C# doesn't support non-header parameters of mode " + webParam.getMode());
        }

        //parameters/results can't be maps
        if (webParam.getType() instanceof MapType) {
          result.addError(webParam, "C# can't handle types that are maps.");
        }
      }

      //web result cannot be a header.
      if (webMethod.getWebResult().isHeader()) {
        Declaration conflict = paramsByName.put(webMethod.getWebResult().getElementName(), webMethod);
        if (conflict != null) {
          result.addError(webMethod, "C# requires that all header parameters defined in the same endpoint interface have unique names. " +
            "This parameter conflicts with the one at " + (conflict.getPosition() == null ? "(unknown source position)" : conflict.getPosition()));
        }
      }

      if (webMethod.getWebResult().getType() instanceof MapType) {
        result.addError(webMethod, "C# can't handle types that are maps.");
      }

      if (capitalize(webMethod.getClientSimpleName()).equals(ei.getClientSimpleName())) {
        result.addError(webMethod, "C# can't handle methods that are of the same name as their containing class. Either rename the method, or use the @org.codehaus.enunciate.ClientName annotation to rename the method (or type) on the client-side.");
      }
    }

    return result;
  }
View Full Code Here


    return Character.toString(string.charAt(0)).toUpperCase() + string.substring(1);
  }

  @Override
  public ValidationResult validateSimpleType(SimpleTypeDefinition simpleType) {
    ValidationResult result = super.validateSimpleType(simpleType);
    if (simpleType.getValue() != null) {
      if (capitalize(simpleType.getValue().getClientSimpleName()).equals(simpleType.getClientSimpleName())) {
        result.addError(simpleType.getValue(), "C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @org.codehaus.enunciate.ClientName annotation to rename the property/field on the client-side.");
      }
    }
    return result;
  }
View Full Code Here

    return result;
  }

  @Override
  public ValidationResult validateEnumType(EnumTypeDefinition enumType) {
    ValidationResult result = super.validateEnumType(enumType);
    for (EnumConstantDeclaration enumItem : ((EnumDeclaration) enumType.getDelegate()).getEnumConstants()) {
      String simpleName = enumItem.getSimpleName();
      ClientName clientNameInfo = enumItem.getAnnotation(ClientName.class);
      if (clientNameInfo != null) {
        simpleName = clientNameInfo.value();
      }

      if ("event".equals(simpleName)) {
        result.addError(enumItem, "C# can't handle an enum constant named 'Event'. Either rename the enum constant, or use the @org.codehaus.enunciate.ClientName annotation to rename it on the client-side.");
      }
      else if (simpleName.equals(enumType.getClientSimpleName())) {
        result.addError(enumItem, "C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @org.codehaus.enunciate.ClientName annotation to rename the property/field on the client-side.");
      }
    }
    return result;
  }
View Full Code Here

    return result;
  }

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = super.validateComplexType(complexType);
    for (Attribute attribute : complexType.getAttributes()) {
      if (capitalize(attribute.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
        result.addError(attribute, "C# can't handle properties/fields that are of the same name as their containing class.");
      }
    }

    if (complexType.getValue() != null) {
      if (capitalize(complexType.getValue().getClientSimpleName()).equals(complexType.getClientSimpleName())) {
        result.addError(complexType.getValue(), "C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @org.codehaus.enunciate.ClientName annotation to rename the property/field on the client-side.");
      }
    }

    for (Element element : complexType.getElements()) {
      if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
        result.addError(element, "C# 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 (capitalize(element.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
        result.addError(element, "C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @org.codehaus.enunciate.ClientName annotation to rename the property/field on the client-side.");
      }
    }

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

    return result;
  }
View Full Code Here

*/
public class XMLValidator extends BaseValidator {

  @Override
  public ValidationResult validate(EnunciateFreemarkerModel model) {
    ValidationResult result = super.validate(model);

    for (SchemaInfo schema : model.getNamespacesToSchemas().values()) {
      for (ImplicitSchemaElement element : schema.getImplicitSchemaElements()) {
        if (element.getElementName() == null || "".equals(element.getElementName())) {
          result.addError(element.getPosition(), "Implicit schema elements must have a non-null and non-empty element name.");
        }
      }
    }

    return result;
View Full Code Here

    return result;
  }

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

    HashMap<String, WebMessagePart> implicitElementNames = new HashMap<String, WebMessagePart>();
    for (WebMethod webMethod : ei.getWebMethods()) {
      for (WebMessage webMessage : webMethod.getMessages()) {
        for (WebMessagePart webMessagePart : webMessage.getParts()) {
          if (!(webMessagePart instanceof WebFault) && (webMessagePart.isImplicitSchemaElement())) {
            ImplicitSchemaElement el = ((ImplicitSchemaElement) webMessagePart);
            WebMessagePart otherPart = implicitElementNames.put(el.getElementName(), webMessagePart);
            if (otherPart != null && ((ImplicitSchemaElement)otherPart).getTypeQName() != null && !((ImplicitSchemaElement)otherPart).getTypeQName().equals(el.getTypeQName())) {
              result.addError(webMethod, "Web method defines a message part named '" + el.getElementName() +
                "' that is identical to the name of a web message part defined in " + otherPart.getWebMethod().getPosition() + ".  Please use annotations to disambiguate.");
            }
          }
        }
      }
View Full Code Here

    this.clientConversion = new ClientClassnameForMethod(packageConversions);
  }

  @Override
  public ValidationResult validateComplexType(ComplexTypeDefinition complexType) {
    ValidationResult result = new ValidationResult();

    String[] propOrder = complexType.getPropertyOrder();
    List<String> assertedProperties = propOrder != null ? new ArrayList<String>(Arrays.asList(propOrder)) : Collections.<String>emptyList();
    for (Element element : complexType.getElements()) {
      assertedProperties.remove(element.getSimpleName());
    }
    for (Attribute attribute : complexType.getAttributes()) {
      assertedProperties.remove(attribute.getSimpleName());
    }
    if (complexType.getAnyElement() != null) {
      assertedProperties.remove(complexType.getAnyElement().getSimpleName());
    }
    if (complexType.getValue() != null) {
      //it seems broken to state an @xmlValue property in the property order, but wsgen does it, so we'll account for the case here.
      assertedProperties.remove(complexType.getValue().getSimpleName());
    }

    if (!assertedProperties.isEmpty()) {
      result.addError(complexType, "Properties are declared in the @XmlType.propOrder element, but are not in the element accessor list: [" +
        assertedProperties + "]. Perhaps you're missing a setter method for these properties? If so, this is an Enunciate limitation and not a JAXB " +
        "limitation. Either add some no-op setter methods for these properties, or disable the java-client module.");
    }

    if (!serverSideTypesToUse.isEmpty()) {
      try {
        if (!complexType.getQualifiedName().equals(clientConversion.convert(complexType))) {
          result.addError(complexType, "If you're using server-side types in your client library, you can't convert the name of "
            + complexType.getQualifiedName() + " to " + clientConversion.convert(complexType) + ".");
        }
      }
      catch (TemplateModelException e) {
        throw new IllegalStateException(e);
View Full Code Here

    return result;
  }

  @Override
  public ValidationResult validateEndpointInterface(EndpointInterface ei) {
    ValidationResult result = super.validateEndpointInterface(ei);
    if (!serverSideTypesToUse.isEmpty()) {
      for (WebMethod webMethod : ei.getWebMethods()) {
        for (WebFault webFault : webMethod.getWebFaults()) {
          try {
            if (!webFault.getQualifiedName().equals(clientConversion.convert(webFault))) {
              result.addError(webFault, "If you're using server-side types in your client library, you can't convert the name of "
                + webFault.getQualifiedName() + " to " + clientConversion.convert(webFault) + ".");
            }
          }
          catch (TemplateModelException e) {
            throw new IllegalStateException(e);
          }
        }
      }
    }

    if (ei.getEndpointImplementations().size() > 1) {
      ArrayList<String> impls = new ArrayList<String>();
      for (EndpointImplementation impl : ei.getEndpointImplementations()) {
        impls.add(impl.getQualifiedName());
      }
      result.addError(ei, "Sorry, the Java client 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, "The Java client module requires an implementation for each endpoint interface.");
    }

    return result;
  }
View Full Code Here

    this.enforceNoFieldAccessors = enforceNoFieldAccessors;
  }

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

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

      if (ei.getEndpointImplementations().size() > 1) {
        ArrayList<String> impls = new ArrayList<String>();
        for (EndpointImplementation impl : ei.getEndpointImplementations()) {
          impls.add(impl.getQualifiedName());
        }
        result.addError(ei, "Sorry, AMF 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, "AMF requires an implementation for each service interface.");
      }
    }
   
    return result;
  }
View Full Code Here

    return result;
  }

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

      if (!disabledRules.contains("as3.conflicting.names")) {
        if ("Date".equals(complexType.getClientSimpleName())) {
          result.addError(complexType, "ActionScript can't handle a class named 'Date'.  It conflicts with the top-level ActionScript class of the same name. Either rename the class, or use the @org.codehaus.enunciate.ClientName annotation to rename the class on the client-side.");
        }
        else if ("Event".equals(complexType.getClientSimpleName())) {
          result.addError(complexType, "The Enunciate-generated ActionScript code can't handle a class named 'Event'.  It conflicts with the ActionScript remoting class of the same name. Either rename the class, or use the @org.codehaus.enunciate.ClientName annotation to rename the class on the client-side.");
        }
      }

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

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

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

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

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

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

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

    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.