use of org.omg.dmn.tck.marshaller._20160719.ValueType in project tck by dmn-tck.
the class DroolsTCKTest method parseType.
private Object parseType(ValueType value, DMNType dmnType) {
if (value.getList() != null && !value.getList().isNil()) {
List<Object> result = new ArrayList<>();
ValueType.List list = value.getList().getValue();
for (ValueType vt : list.getItem()) {
result.add(parseType(vt, dmnType));
}
return result;
} else if (!dmnType.isComposite()) {
String text = null;
Object val = value.getValue();
if (val != null && !value.getValue().isNil() && val instanceof JAXBElement<?> && ((JAXBElement<?>) val).getValue() instanceof Node && !isDateTimeOrDuration(((JAXBElement<?>) val).getValue())) {
Node nodeVal = (Node) ((JAXBElement<?>) val).getValue();
if (nodeVal.getFirstChild() != null) {
text = nodeVal.getFirstChild().getTextContent();
}
return text != null ? ((BuiltInType) ((BaseDMNTypeImpl) dmnType).getFeelType()).fromString(text) : null;
} else if (val instanceof JAXBElement<?> && !(((JAXBElement<?>) val).getValue() instanceof Node) && !isDateTimeOrDuration(((JAXBElement<?>) val).getValue())) {
return ((JAXBElement<?>) val).getValue();
} else {
try {
Object dateTimeOrDurationValue = (val != null) ? ((JAXBElement<?>) val).getValue() : null;
if (dateTimeOrDurationValue instanceof Duration || dateTimeOrDurationValue instanceof XMLGregorianCalendar) {
// need to convert to java.time.* equivalent
text = dateTimeOrDurationValue.toString();
return text != null ? ((BuiltInType) ((BaseDMNTypeImpl) dmnType).getFeelType()).fromString(text) : null;
}
} catch (Exception e) {
logger.error("Error trying to coerce JAXB type " + val.getClass().getName() + " with value '" + val.toString() + "': " + e.getMessage());
}
return val;
}
} else {
Map<String, Object> result = new HashMap<>();
for (ValueType.Component component : value.getComponent()) {
if (!dmnType.getFields().containsKey(component.getName())) {
throw new RuntimeException("Error parsing input: unknown field '" + component.getName() + "' for type '" + dmnType.getName() + "'");
}
DMNType fieldType = dmnType.getFields().get(component.getName());
if (fieldType == null) {
throw new RuntimeException("Error parsing input: unknown type for field '" + component.getName() + "' on type " + dmnType.getName() + "'");
}
Object fieldValue = parseType(component, fieldType);
result.put(component.getName(), fieldValue);
}
return result;
}
}
Aggregations