Package com.betfair.cougar.codegen

Examples of com.betfair.cougar.codegen.ValidationException


                return null;
            }
            return attribute;

        } catch (final Exception e) {
            throw new ValidationException(name + " - Failed to extract " + attributeName + " from node", node, e);
        }
    }
View Full Code Here


    }

    protected String getAndValidateAttribute(String name, Node node, String attributeName) throws ValidationException {
        String out = getAttribute(name, node, attributeName);
        if (out == null || out.length() == 0) {
            throw new ValidationException(name + " - type not defined", node);
        }
        return out;
    }
View Full Code Here

            return;
        }
        if (allowSimpleCollections && isSimpleCollection(name, node, type)) {
            return;
        }
        throw new ValidationException(">>>" + name + "<<< - type is not stringable: " + type, node);
    }
View Full Code Here

        try {
            Boolean exists = (Boolean)factory.newXPath().evaluate("//simpleType[@name='" + type + "']", topLevel, XPathConstants.BOOLEAN);
            return exists;
        } catch (XPathExpressionException e) {
            throw new ValidationException("Unable to parse XPath //parameter", node, e);
        }
    }
View Full Code Here

          String name = getAttribute(getName(), st, "name");
          String type = getAttribute(getName(), st, "type");
         
          // check for simpleType duplicates
          if(definedSimpleTypes.contains(name)){
            throw new ValidationException("The data type " + name + " is already defined", st);
          }else{
            definedSimpleTypes.add(name);
          }
         
          replaceSimpleType(doc, name, type);
View Full Code Here

    final XPathFactory factory = XPathFactory.newInstance();
        NodeList nodes;
        try {
        nodes = (NodeList) factory.newXPath().evaluate(xPath, doc, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
      throw new ValidationException("Unable to parse XPath "+xPath, doc, e);
    }
        for (int i = 0; i < nodes.getLength(); i++) {
          Node n = nodes.item(i);
          Node attrNode = getAttributeNode(getName(), n, "type");
          String content = attrNode.getTextContent();
View Full Code Here

  @Override
  public void validate(Node node) throws ValidationException {
    String name = getAttribute(getName(), node, "name");
    if (name == null || name.length() < 1) {
      throw new ValidationException("exceptions must have a name", node);
    } else if (Character.isLowerCase(name.charAt(0))) {
      throw new ValidationException("exceptions must start with a capital letter", node);
    } else if (exceptionNames.contains(name)) {
      throw new ValidationException("The exception " + name + " is already defined", node);
    }
        exceptionNames.add(name);
         // Ensure there is at least one parameter, and it's an enum.
         Node firstParam = getFirstChildWithName (node, "parameter");

         // Ensure that the parameter has valid values
         getFirstChildWithName(firstParam, "validValues");

        //Check that all params in the exception type are firstly
        List<Node> parameters = getChildrenWithName(getName(), node, "parameter");
        for (Node param : parameters) {
            String paramName = getAttribute(getName(), param, "name");
            String paramType = getAttribute(getName(), param, "type");
            checkTypeIsSimple( paramName, param, paramType, false);

            //We simply don't permit this dude in exceptions
            if (paramType.toLowerCase().equals("datetime")) {
                throw new ValidationException("Datetime arguments [" + paramName + "] are not permitted as exception parameters", param);
            }
            if (paramName.equals("message") || paramName.equals("Message")) {
                throw new ValidationException("Exceptions can't have a parameter named [message]", param);
            }
            if (paramName.equals("localizedMessage") || paramName.equals("LocalizedMessage")) {
                throw new ValidationException("Exceptions can't have a parameter named [localizedMessage]", param);
            }
            if (paramName.equals("cause") || paramName.equals("Cause")) {
                throw new ValidationException("Exceptions can't have a parameter named [cause]", param);
            }
            if (paramName.equals("stackTrace") || paramName.equals("StackTrace")) {
                throw new ValidationException("Exceptions can't have a parameter named [stackTrace]", param);
            }
            if (paramName.equals("stackTraceDepth") || paramName.equals("StackTraceDepth")) {
                throw new ValidationException("Exceptions can't have a parameter named [stackTraceDepth]", param);
            }
            if (paramName.equals("suppressed") || paramName.equals("Suppressed")) {
                throw new ValidationException("Exceptions can't have a parameter named [suppressed]", param);
            }
        }
  }
View Full Code Here

  @Override
  public void validate(Node node) throws ValidationException {
    // Check that the data type name starts with a capital letter
    String name = getAttribute(getName(), node, "name");
    if (name == null || name.length() < 1) {
      throw new ValidationException("Operations must have a name", node);
    } else if (Character.isUpperCase(name.charAt(0))) {
      throw new ValidationException("Operations must start with a lower-case letter", node);
    } else if (namesUsed.contains(name)) {
      throw new ValidationException("The operation " + name + " is already defined", node);
    }
    namesUsed.add(name);
    Node parameters = getFirstChildWithName(node, "parameters");
        if (parameters == null) {
            throw new ValidationException(name + " - Node does not have any parameters children defined", node);
        }

    Node request = getFirstChildWithName(parameters, "request");
        if (request == null) {
            throw new ValidationException("The operation " + name + " has no request defined", 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 version = getAttribute(getName(), node, "version");
        if (version == null || version.length() < 1) {
            throw new ValidationException("Interface must have a version", node);
        }
        String[] split = version.split("\\.");
        if (split.length!=2) {
            throw new ValidationException("Interface version must be of the form x.y: "+version, node);
        }
        for (String s : split) {
            try {
                int i = Integer.parseInt(s);
                if (i<0) {
                    throw new ValidationException("All components of the interface version must be numeric and >=0: "+version, node);
                }
            }
            catch (NumberFormatException nfe) {
                throw new ValidationException("All components of the interface version must be numeric: "+version, node);//NOSONAR
            }
        }
  }
View Full Code Here

            if (!checkComposite(type, n)) {
              validateDataType(type, n);
            }
          }
    } catch (XPathExpressionException e) {
      throw new ValidationException("Unable to parse XPath //parameter", node, e);
    }

  }
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.