Skip to content

Commit

Permalink
Remove unnecessary try-catch block.
Browse files Browse the repository at this point in the history
  • Loading branch information
baldimir committed Oct 9, 2024
1 parent 372744f commit e8a1908
Showing 1 changed file with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,40 +305,36 @@ private Object parseType(ValueType value, DMNType dmnType) {
} else if (val != null && !(val.getValue() instanceof Node) && !isDateTimeOrDuration(val.getValue())) {
return ((JAXBElement<?>) val).getValue();
} else {
try {
Object dateTimeOrDurationValue = (val != null) ? val.getValue() : null;
if (dateTimeOrDurationValue instanceof Duration || dateTimeOrDurationValue instanceof XMLGregorianCalendar) {
if (!isDMNAny(dmnType)) {
// need to convert to java.time.* equivalent
text = dateTimeOrDurationValue.toString();
return text != null ? recurseSimpleDMNTypeToFindBuiltInFEELType((BaseDMNTypeImpl) dmnType).fromString(text) : null;
Object dateTimeOrDurationValue = (val != null) ? val.getValue() : null;
if (dateTimeOrDurationValue instanceof Duration || dateTimeOrDurationValue instanceof XMLGregorianCalendar) {
if (!isDMNAny(dmnType)) {
// need to convert to java.time.* equivalent
text = dateTimeOrDurationValue.toString();
return text != null ? recurseSimpleDMNTypeToFindBuiltInFEELType((BaseDMNTypeImpl) dmnType).fromString(text) : null;
} else {
// no DMN type information from the DMN model
if (dateTimeOrDurationValue instanceof Duration) {
try {
return java.time.Duration.parse(dateTimeOrDurationValue.toString());
} catch (DateTimeParseException e) {
return ComparablePeriod.parse(dateTimeOrDurationValue.toString());
}
} else {
// no DMN type information from the DMN model
if (dateTimeOrDurationValue instanceof Duration) {
try {
return java.time.Duration.parse(dateTimeOrDurationValue.toString());
} catch (DateTimeParseException e) {
return ComparablePeriod.parse(dateTimeOrDurationValue.toString());
}
} else {
XMLGregorianCalendar xmlCal = (XMLGregorianCalendar) dateTimeOrDurationValue;
if (xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && xmlCal.getXMLSchemaType() == DatatypeConstants.DATETIME) {
return ZonedDateTime.parse(xmlCal.toXMLFormat());
} else if (xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && xmlCal.getXMLSchemaType() == DatatypeConstants.TIME) {
return OffsetTime.parse(xmlCal.toXMLFormat());
} else if (xmlCal.getXMLSchemaType() == DatatypeConstants.DATETIME) {
return LocalDateTime.of(LocalDate.of(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay()), LocalTime.of(xmlCal.getHour(), xmlCal.getMinute(), xmlCal.getSecond()));
} else if (xmlCal.getXMLSchemaType() == DatatypeConstants.DATE) {
return LocalDate.of(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay());
} else if (xmlCal.getXMLSchemaType() == DatatypeConstants.TIME) {
return LocalTime.parse(xmlCal.toXMLFormat());
}
return xmlCal.toGregorianCalendar();
XMLGregorianCalendar xmlCal = (XMLGregorianCalendar) dateTimeOrDurationValue;
if (xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && xmlCal.getXMLSchemaType() == DatatypeConstants.DATETIME) {
return ZonedDateTime.parse(xmlCal.toXMLFormat());
} else if (xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && xmlCal.getXMLSchemaType() == DatatypeConstants.TIME) {
return OffsetTime.parse(xmlCal.toXMLFormat());
} else if (xmlCal.getXMLSchemaType() == DatatypeConstants.DATETIME) {
return LocalDateTime.of(LocalDate.of(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay()), LocalTime.of(xmlCal.getHour(), xmlCal.getMinute(), xmlCal.getSecond()));
} else if (xmlCal.getXMLSchemaType() == DatatypeConstants.DATE) {
return LocalDate.of(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay());
} else if (xmlCal.getXMLSchemaType() == DatatypeConstants.TIME) {
return LocalTime.parse(xmlCal.toXMLFormat());
}
return xmlCal.toGregorianCalendar();
}
}
} catch (Exception e) {
LOGGER.error("Error trying to coerce JAXB type {} with value '{}': {}", val.getClass().getName(), val, e.getMessage());
}
return val;
}
Expand Down

0 comments on commit e8a1908

Please sign in to comment.