private static Value parseTypedReference(URIString pUriStr) throws IllegalArgumentException { Value strVal; int pos = pUriStr.getPos(); try { strVal = StringValue.parse(pUriStr); } catch (IllegalArgumentException e) { String msg = "Failed to retrieve typed reference string!\n" + pUriStr.markPosition() + "Nested message is:\n" + e.getMessage(); throw new IllegalArgumentException(msg); } URIString refUriStr = new URIString(strVal.toString()); try { URI ref = URI.parseRef(refUriStr, true); return new ReferenceValue(ref); } catch (IllegalArgumentException e) { String msg = "Failed to parse typed reference value!\n" + pUriStr.markPosition(pos) + "Nested message is:\n" + e.getMessage(); throw new IllegalArgumentException(msg); } }
private static Value parseTypedValue(URIString pUriStr) throws IllegalArgumentException { URIString uriStr = pUriStr.deepCopy(); int typeInfoPos = uriStr.getPos(); String typeInfo = parseTypeInfo(uriStr); if (typeInfo == null) { String msg = "typeInfo expected!\n" + uriStr.markPosition(); throw new IllegalArgumentException(msg); } int valuePos = uriStr.getPos(); Value val; try { if (typeInfo.equalsIgnoreCase(MOF.DT_STR)) { val = StringValue.parse(uriStr); } else if (typeInfo.equalsIgnoreCase(MOF.REFERENCE)) { val = parseTypedReference(uriStr); } else if (typeInfo.equalsIgnoreCase(MOF.DT_DATETIME)) { val = parseTypedDateTime(uriStr); } else if (typeInfo.equalsIgnoreCase(MOF.DT_CHAR16)) { val = CharValue.parse(uriStr); } else if (typeInfo.equalsIgnoreCase(MOF.DT_BOOL)) { val = BooleanValue.parse(uriStr); } else if (typeInfo.equalsIgnoreCase(MOF.DT_SINT8)) { val = IntegerValue.parseSigned(uriStr, 8); } else if (typeInfo.equalsIgnoreCase(MOF.DT_SINT16)) { val = IntegerValue.parseSigned(uriStr, 16); } else if (typeInfo.equalsIgnoreCase(MOF.DT_SINT32)) { val = IntegerValue.parseSigned(uriStr, 32); } else if (typeInfo.equalsIgnoreCase(MOF.DT_SINT64)) { val = IntegerValue.parseSigned(uriStr, 64); } else if (typeInfo.equalsIgnoreCase(MOF.DT_UINT8)) { val = IntegerValue.parseUnsigned(uriStr, 8); } else if (typeInfo.equalsIgnoreCase(MOF.DT_UINT16)) { val = IntegerValue.parseUnsigned(uriStr, 16); } else if (typeInfo.equalsIgnoreCase(MOF.DT_UINT32)) { val = IntegerValue.parseUnsigned(uriStr, 32); } else if (typeInfo.equalsIgnoreCase(MOF.DT_UINT64)) { val = IntegerValue.parseUnsigned(uriStr, 64); } else if (typeInfo.equalsIgnoreCase(MOF.DT_REAL32)) { val = RealValue.parseFloat(uriStr); } else if (typeInfo.equalsIgnoreCase(MOF.DT_REAL64)) { val = RealValue.parseDouble(uriStr); } else { val = null; } } catch (IllegalArgumentException e) { String msg = "Failed to parse " + typeInfo + " value!\n" + uriStr.markPosition(valuePos) + "Nested message:\n" + e.getMessage(); throw new IllegalArgumentException(msg); } if (val == null) { String msg = "Unknown type:" + typeInfo + "!\n" + uriStr.markPosition(typeInfoPos); throw new IllegalArgumentException(msg); } pUriStr.set(uriStr); return val; }