jomarko commented on code in PR #6259:
URL:
https://github.com/apache/incubator-kie-drools/pull/6259#discussion_r1961502842
##########
kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/ConstraintsChecks.dmn:
##########
@@ -22,7 +22,7 @@
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/"
- xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/"
+ xmlns:feel="https://www.omg.org/spec/DMN/20230324/FEEL/"
Review Comment:
Hmm, this code change open a question in me, what should our tooling to do
if an inconsistent namespaces are present in opened file.
##########
kie-dmn/kie-dmn-backend/src/main/java/org/kie/dmn/backend/marshalling/v1x/XStreamMarshaller.java:
##########
@@ -91,42 +97,113 @@ public Definitions unmarshal(String xml) {
default:
result = xstream15.unmarshal(secondStringReader);
break;
-
}
return result;
- } catch ( Exception e ) {
- logger.error( "Error unmarshalling DMN model from reader.", e );
+ } catch (Exception e) {
+ logger.error("Error unmarshalling DMN model from reader.", e);
}
return null;
}
public enum DMN_VERSION {
- UNKNOWN, DMN_v1_1, DMN_v1_2, DMN_v1_3, DMN_v1_4, DMN_v1_5;
+ UNKNOWN(""),
+ DMN_v1_1("v1_1"),
+ DMN_v1_2("v1_2"),
+ DMN_v1_3("v1_3"),
+ DMN_v1_4("v1_4"),
+ DMN_v1_5("v1_5");
+ final String versionString;
+
+ DMN_VERSION(String versionString) {
+ this.versionString = versionString;
+ }
+
+ public String getVersionString() {
+ return versionString;
+ }
+ }
+
+ public enum URI_NAMESPACE {
+ URI_DMN("MODEL"),
+ URI_FEEL("FEEL"),
+ URI_DMNDI("DMNDI"),
+ URI_DI("DI"),
+ URI_DC("DC");
+
+ private final String identifier;
+
+ URI_NAMESPACE(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
}
- public static DMN_VERSION inferDMNVersion(Reader from) {
+ public static Collection<String> getNsContextValues(Reader from) {
+ Collection<String> toReturn = Collections.emptySet();
+ XMLStreamReader xmlReader = null;
+ CustomStaxReader customStaxReader = null;
try {
- XMLStreamReader xmlReader =
staxDriver.getInputFactory().createXMLStreamReader(from);
- CustomStaxReader customStaxReader = new CustomStaxReader(new
QNameMap(), xmlReader);
- DMN_VERSION result = DMN_VERSION.UNKNOWN;
- if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_5.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_5;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_4.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_4;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_3;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_2;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_1;
- }
- xmlReader.close();
- customStaxReader.close();
- return result;
+ xmlReader =
staxDriver.getInputFactory().createXMLStreamReader(from);
+ customStaxReader = new CustomStaxReader(new QNameMap(), xmlReader);
+ toReturn = customStaxReader.getNsContext().values();
} catch (Exception e) {
logger.error("Error unmarshalling DMN model from reader.", e);
+ } finally {
+ if (customStaxReader != null) {
+ customStaxReader.close();
+ }
+ if (xmlReader != null) {
+ try {
+ xmlReader.close();
Review Comment:
We could probably use `try with resources` to simplify the code? I think
`try with resources` closes the stream automatically and similar line don't
need to be written, what do you think?
##########
kie-dmn/kie-dmn-backend/src/main/java/org/kie/dmn/backend/marshalling/v1x/XStreamMarshaller.java:
##########
@@ -91,42 +97,113 @@ public Definitions unmarshal(String xml) {
default:
result = xstream15.unmarshal(secondStringReader);
break;
-
}
return result;
- } catch ( Exception e ) {
- logger.error( "Error unmarshalling DMN model from reader.", e );
+ } catch (Exception e) {
+ logger.error("Error unmarshalling DMN model from reader.", e);
}
return null;
}
public enum DMN_VERSION {
- UNKNOWN, DMN_v1_1, DMN_v1_2, DMN_v1_3, DMN_v1_4, DMN_v1_5;
+ UNKNOWN(""),
+ DMN_v1_1("v1_1"),
+ DMN_v1_2("v1_2"),
+ DMN_v1_3("v1_3"),
+ DMN_v1_4("v1_4"),
+ DMN_v1_5("v1_5");
+ final String versionString;
+
+ DMN_VERSION(String versionString) {
+ this.versionString = versionString;
+ }
+
+ public String getVersionString() {
+ return versionString;
+ }
+ }
+
+ public enum URI_NAMESPACE {
+ URI_DMN("MODEL"),
+ URI_FEEL("FEEL"),
+ URI_DMNDI("DMNDI"),
+ URI_DI("DI"),
+ URI_DC("DC");
+
+ private final String identifier;
+
+ URI_NAMESPACE(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
}
- public static DMN_VERSION inferDMNVersion(Reader from) {
+ public static Collection<String> getNsContextValues(Reader from) {
+ Collection<String> toReturn = Collections.emptySet();
+ XMLStreamReader xmlReader = null;
+ CustomStaxReader customStaxReader = null;
try {
- XMLStreamReader xmlReader =
staxDriver.getInputFactory().createXMLStreamReader(from);
- CustomStaxReader customStaxReader = new CustomStaxReader(new
QNameMap(), xmlReader);
- DMN_VERSION result = DMN_VERSION.UNKNOWN;
- if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_5.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_5;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_4.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_4;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_3;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_2;
- } else if
(customStaxReader.getNsContext().values().stream().anyMatch(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN::equals))
{
- result = DMN_VERSION.DMN_v1_1;
- }
- xmlReader.close();
- customStaxReader.close();
- return result;
+ xmlReader =
staxDriver.getInputFactory().createXMLStreamReader(from);
+ customStaxReader = new CustomStaxReader(new QNameMap(), xmlReader);
+ toReturn = customStaxReader.getNsContext().values();
} catch (Exception e) {
logger.error("Error unmarshalling DMN model from reader.", e);
+ } finally {
+ if (customStaxReader != null) {
+ customStaxReader.close();
Review Comment:
We could probably use `try with resources` to simplify the code? I think
`try with resources` closes the stream automatically and similar line don't
need to be written, what do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]