Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.DataFormatException


      myValue = null;
    } else {
      try {
        myValue = Integer.parseInt(theValue);
      } catch (NumberFormatException e) {
        throw new DataFormatException(e);
      }
    }
  }
View Full Code Here


            if (nextValue.isEmpty()) {
              continue;
            }
            BaseRuntimeElementDefinition<?> childElementDef = nextChild.getChildElementDefinitionByDatatype(nextValue.getClass());
            if (childElementDef == null) {
              throw new DataFormatException("Found value of type[" + nextValue.getClass().getSimpleName() + "] which is not valid for field[" + nextChild.getElementName() + "] in " + childDef.getName());
            }
            getAllChildElementsOfType(nextValue, childElementDef, theType, theList);
          }
        }
      }
View Full Code Here

    if ("true".equals(theValue)) {
      myValue = Boolean.TRUE;
    } else if ("false".equals(theValue)) {
      myValue = Boolean.FALSE;
    } else {
      throw new DataFormatException("Invalid boolean string: '" + theValue + "'");
    }
  }
View Full Code Here

      myValue=null;
    }else {
      try {
        myValue = new URI(theValue);
      } catch (URISyntaxException e) {
        throw new DataFormatException("Unable to parse URI value", e);
      }
    }
  }
View Full Code Here

  private void validateAndThrowDataFormatExceptionIfInvalid() {
    boolean haveLowerBound = myLowerBound != null && myLowerBound.isEmpty() == false;
    boolean haveUpperBound = myUpperBound != null && myUpperBound.isEmpty() == false;
    if (haveLowerBound && haveUpperBound) {
      if (myLowerBound.getValue().after(myUpperBound.getValue())) {
        throw new DataFormatException("Lower bound of " + myLowerBound.getValueAsString() + " is after upper bound of " + myUpperBound.getValueAsString());
      }
    }

    if (haveLowerBound) {
      if (myLowerBound.getComparator() == null) {
        myLowerBound.setComparator(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS);
      }
      switch (myLowerBound.getComparator()) {
      case GREATERTHAN:
      case GREATERTHAN_OR_EQUALS:
      default:
        break;
      case LESSTHAN:
      case LESSTHAN_OR_EQUALS:
        throw new DataFormatException("Lower bound comparator must be > or >=, can not be " + myLowerBound.getComparator().getCode());
      }
    }

    if (haveUpperBound) {
      if (myUpperBound.getComparator() == null) {
        myUpperBound.setComparator(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS);
      }
      switch (myUpperBound.getComparator()) {
      case LESSTHAN:
      case LESSTHAN_OR_EQUALS:
      default:
        break;
      case GREATERTHAN:
      case GREATERTHAN_OR_EQUALS:
        throw new DataFormatException("Upper bound comparator must be < or <=, can not be " + myUpperBound.getComparator().getCode());
      }
    }

  }
View Full Code Here

        if (isPrecisionAllowed(YEAR)) {
          setValue((ourYearFormat).parse(theValue));
          setPrecision(YEAR);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support YEAR precision): " + theValue);
        }
      } else if (theValue.length() == 7) {
        // E.g. 1984-01 (this is valid according to the spec)
        if (isPrecisionAllowed(MONTH)) {
          setValue((ourYearMonthFormat).parse(theValue));
          setPrecision(MONTH);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support MONTH precision): " + theValue);
        }
      } else if (theValue.length() == 8) {
        //Eg. 19840101 (allow this just to be lenient)
        if (isPrecisionAllowed(DAY)) {
          setValue((ourYearMonthDayNoDashesFormat).parse(theValue));
          setPrecision(MONTH);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support DAY precision): " + theValue);
        }
      } else if (theValue.length() == 10) {
        // E.g. 1984-01-01 (this is valid according to the spec)
        if (isPrecisionAllowed(DAY)) {
          setValue((ourYearMonthDayFormat).parse(theValue));
          setPrecision(DAY);
          clearTimeZone();
        } else {
          throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support DAY precision): " + theValue);
        }
      } else if (theValue.length() >= 18) {
        int dotIndex = theValue.indexOf('.', 18);
        if (dotIndex == -1 && !isPrecisionAllowed(SECOND)) {
          throw new DataFormatException("Invalid date/time string (data type does not support SECONDS precision): " + theValue);
        } else if (dotIndex > -1 && !isPrecisionAllowed(MILLI)) {
          throw new DataFormatException("Invalid date/time string (data type " + getClass().getSimpleName() + " does not support MILLIS precision):" + theValue);
        }

        Calendar cal;
        try {
          cal = DatatypeConverter.parseDateTime(theValue);
        } catch (IllegalArgumentException e) {
          throw new DataFormatException("Invalid data/time string (" + e.getMessage() + "): " + theValue);
        }
        myValue = cal.getTime();
        if (dotIndex == -1) {
          setPrecision(TemporalPrecisionEnum.SECOND);
        } else {
          setPrecision(TemporalPrecisionEnum.MILLI);
        }

        clearTimeZone();
        if (theValue.endsWith("Z")) {
          myTimeZoneZulu = true;
        } else if (theValue.indexOf('+', 19) != -1 || theValue.indexOf('-', 19) != -1) {
          myTimeZone = cal.getTimeZone();
        }

      } else {
        throw new DataFormatException("Invalid date/time string (invalid length): " + theValue);
      }
    } catch (ParseException e) {
      throw new DataFormatException("Invalid date string (" + e.getMessage() + "): " + theValue);
    }
  }
View Full Code Here

  }

  public BaseRuntimeChildDefinition getChildByNameOrThrowDataFormatException(String theName) throws DataFormatException {
    BaseRuntimeChildDefinition retVal = myNameToChild.get(theName);
    if (retVal == null) {
      throw new DataFormatException("Unknown child name '" + theName + "' in element " + getName() + " - Valid names are: " + new TreeSet<String>(myNameToChild.keySet()));
    }
    return retVal;
  }
View Full Code Here

        }
      }
      setValue(value);
     
    } catch (XMLStreamException e) {
      throw new DataFormatException("String does not appear to be valid XML/XHTML (error is \""+e.getMessage() + "\"): " + theValue, e);
    } catch (FactoryConfigurationError e) {
      throw new ConfigurationException(e);
    }
  }
View Full Code Here

        ew.add(next);
      }
      ew.close();
      return w.toString();
    } catch (XMLStreamException e) {
      throw new DataFormatException("Problem with the contained XML events", e);
    } catch (FactoryConfigurationError e) {
      throw new ConfigurationException(e);
    }
  }
View Full Code Here

  }

  @Override
  public void setValueAsQueryToken(String theQualifier, String theValue) {
    if (theValue.length() < 2) {
      throw new DataFormatException("Invalid qualified date parameter: "+theValue);
    }

    char char0 = theValue.charAt(0);
    char char1 = theValue.charAt(1);
    if (Character.isDigit(char0)) {
      setValueAsString(theValue);
    } else {
      int dateStart = 2;
      if (Character.isDigit(char1)) {
        dateStart = 1;
      }
     
      String comparatorString = theValue.substring(0, dateStart);
      QuantityCompararatorEnum comparator = QuantityCompararatorEnum.VALUESET_BINDER.fromCodeString(comparatorString);
      if (comparator==null) {
        throw new DataFormatException("Invalid date qualifier: "+comparatorString);
      }
     
      String dateString = theValue.substring(dateStart);
      setValueAsString(dateString);
      setComparator(comparator);
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.parser.DataFormatException

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.