Package com.betfair.cougar.codegen

Examples of com.betfair.cougar.codegen.ValidationException


  }

 
  private void validateDataType(String type, Node nthrows ValidationException {
      if (!dataTypesDefined.contains(type)) {
        throw new ValidationException("Data type "+type+" is not valid in this IDL", n);
      }
  }
View Full Code Here


        boolean needsIDs = false;
        if (grandParent.getLocalName().equals("exceptionType")) {
            // Only the first child of an exception type needs an ID
            Node firstParam = getFirstChildWithName(grandParent, "parameter");
            if (firstParam == null) {
                throw new ValidationException(getName() + " - Node does not have any parameter children defined", node);
            }
            if (firstParam.equals(parent)) {
                needsIDs = true;
            }
        }

        // Ensure that all enumerations are of type string.
        String type = getAttribute(getName(), parent, "type");
        if (!type.equals("string")) {
            throw new ValidationException(getName() + " - Valid values is not of base type string.", node);
        }

        // If it's a simpleType enumeration, it must start with an upper case letter
        if (parent.getLocalName().equals("simpleType")) {
            String name = getAttribute(getName(), parent, "name");
            if (name == null || name.length() < 1) {
                throw new ValidationException("Data types must have a name", node);
            } else if (Character.isLowerCase(name.charAt(0))) {
                throw new ValidationException("Simple type names must start with a capital letter", node);
            }
        }
        Set<Integer> idsUsed = new HashSet<Integer>();
        Set<String> namesUsed = new HashSet<String>();

        List<Node> values = getChildrenWithName(getName(), node, "value");
        if (values.size() == 0) {
            throw new ValidationException(getName() + " - Valid values list does not have any children defined", node);
        }
        for (Node val : values) {
            Integer id = getAttributeAsInt(getName(), val, "id");

            if (needsIDs == (id == null)) {
                if (needsIDs) {
                    throw new ValidationException(getName() + " - no ID defined for valid value", val);
                } else {
                    throw new ValidationException(getName() + " - ID defined for valid value which does not require one", val);
                }
            }

            if (id != null) {
                if (idsUsed.contains(id)) {
                    throw new ValidationException(getName() + " - duplicate id: " + id, val);
                }
                idsUsed.add(id);
            }
            String vvName = getAttribute(getName(), val, "name");
            if (vvName != null) {
                if (vvName.length() < 1) {
                    throw new ValidationException("Valid values must have a name", node);
                } else if (Character.isLowerCase(vvName.charAt(0))) {
                    throw new ValidationException("Valid value names must start with a capital letter", node);
                }
                if (namesUsed.contains(vvName)) {
                    throw new ValidationException(getName() + " - duplicate name: " + vvName, val);
                }
                namesUsed.add(vvName);
            } else {
                throw new ValidationException(getName() + " - no name defined for valid value", val);
            }


        }
View Full Code Here

   
  }
 
  private void addName(Node node, String className) throws ValidationException {
    if (!classNamesUsed.add(className)) {
      throw new ValidationException("The class name "+className+" is already used", node);
    }
  }
View Full Code Here

  @Override
  public void validate(Node node) throws ValidationException {
    // Check that the data type name starts with a upper case letter
         String name = getAttribute(getName(), node, "name");
         if (name == null || name.length() < 1) {
           throw new ValidationException("Data types must have a name", node);
         } else if (Character.isLowerCase(name.charAt(0))) {
           throw new ValidationException("Data types must start with a capital letter", node);
         } else if (namesUsed.contains(name)) {
       throw new ValidationException("The data type " + name + " is already defined", node);
     }
         namesUsed.add(name);
  }
View Full Code Here

  public void validate(Node node) throws ValidationException {
      if (node.getParentNode().getLocalName().equals("interface")) {
        // Check that the data type name starts with a upper case letter
             String name = getAttribute(getName(), node, "name");
             if (name == null || name.length() < 1) {
               throw new ValidationException("Parameters must have a name", node);
             } else if (Character.isUpperCase(name.charAt(0))) {
               throw new ValidationException("Parameters must start with a lower case letter", node);
             }
      }
  }
View Full Code Here

   
    List<Node> values = getChildrenWithName(getName(), node, "parameter");
    for (Node val: values) {
      String name = getAttribute(getName(), val, "name");
      if (namesUsed.contains(name)) {
        throw new ValidationException(getName() + " - duplicate name: " +name, val);
      }
            if (reservedNames.contains(name)) {
                throw new ValidationException(getName() + " - Reserved parameter name: " +name, val);
            }
      namesUsed.add(name);


      validateExtensions(val);
View Full Code Here

            return;
        }

        Node extensions = getFirstChildWithName(node, "extensions");
        if (extensions == null) {
            throw new ValidationException(getName() + " - Node does not have any extensions children defined", node);
        }
        Node styleNode = getFirstChildWithName(extensions, "style");
        if (styleNode == null) {
            throw new ValidationException(getName() + " - style not defined", node);
        }
    String style = styleNode.getTextContent();
    if (style == null || style.length() == 0) {
      throw new ValidationException(getName() + " - style not defined", node);
    }
   
    if (style.equals("body")) {
            // body style params must be in a POST method
            try {
                final XPathFactory factory = XPathFactory.newInstance();
                String method = (String)
                    factory.newXPath().evaluate("../../../extensions/method", node, XPathConstants.STRING);
                if (method == null || ! method.equals("POST")) {
                    throw new ValidationException(getName() + " - body style cannot be used in a non-POST method", node);
                }
                return;
            }
            catch (XPathExpressionException e) {
                throw new ValidationException("Unable to parse XPath ../../../extensions/method", node, e);
            }
    }

        if ((style.equals("header")) || (style.equals("query"))) {
      checkTypeIsSimple(getName(), node, type, true);
            return;
    }

    throw new ValidationException(getName() + " - unsupported style: "+style, node);
  }
View Full Code Here

  public void validate(Node node) throws ValidationException {
    List<Node> values = getChildrenWithName(getName(), node, "parameter");
    for (Node val: values) {
      String type = getAttribute(getName(), val, "type");
      if (type == null) {
        throw new ValidationException(getName() + " - type not defined", node);
      }
      if(type.startsWith("map(")) {
        String[] types = type.split("[()]");
        String[] mapTypes = types[1].split(",");
        checkTypeIsSimple(getName(), node, mapTypes[0].trim(), false);
View Full Code Here

TOP

Related Classes of com.betfair.cougar.codegen.ValidationException

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.