Example #1
0
  /**
   * Factory method which tries to parse an untyped value.
   *
   * @param pTyped
   * @param pUriStr
   * @return <code>Value</code> instance
   * @throws IllegalArgumentException if parsing failed.
   */
  public static Value parse(boolean pTyped, URIString pUriStr) throws IllegalArgumentException {
    // TODO: tracing TRC.debug(uriStr.toString());
    if (pTyped) return parseTypedValue(pUriStr);
    URIString uriStr = pUriStr.deepCopy();
    Value value;
    try {
      StringValue strVal = (StringValue) StringValue.parse(uriStr);

      // string like value
      // is this string an instance reference?
      try {
        URI ref = URI.parseRef(new URIString(strVal.toString()), false);
        value = new ReferenceValue(ref);
      } catch (IllegalArgumentException e) {
        if ((value = DateTimeValue.parse(strVal.toString())) == null) {
          // if not dateTimeValue, it is stringvalue
          value = strVal;
        }
      }
      pUriStr.set(uriStr);
      return value;
    } catch (IllegalArgumentException e) {
      // non string like value
      if ((value = IntegerValue.parse(uriStr)) != null
          || (value = RealValue.parse(uriStr)) != null
          || (value = BooleanValue.parse(uriStr)) != null
          || (value = CharValue.parse(uriStr)) != null) {
        pUriStr.set(uriStr);
        return value;
      }
      String msg = "Failed to parse untyped value!\n" + uriStr.markPosition();
      throw new IllegalArgumentException(msg);
    }
  }
Example #2
0
 private static Value parseTypedDateTime(URIString pUriStr) throws IllegalArgumentException {
   Value strVal;
   try {
     strVal = StringValue.parse(pUriStr);
   } catch (IllegalArgumentException e) {
     String msg =
         "Failed to retrieve typed datetime string!\n"
             + pUriStr.markPosition()
             + "Nested message is:\n"
             + e.getMessage();
     throw new IllegalArgumentException(msg);
   }
   return DateTimeValue.parse(strVal.toString(), true);
 }