Search in sources :

Example 1 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class XStreamMarshaller method marshal.

@Override
public String marshal(Object o) {
    try (Writer writer = new StringWriter();
        CustomStaxWriter hsWriter = (CustomStaxWriter) staxDriver.createWriter(writer)) {
        XStream xStream = newXStream();
        if (o instanceof DMNModelInstrumentedBase) {
            KieDMNModelInstrumentedBase base = (KieDMNModelInstrumentedBase) o;
            String dmnPrefix = base.getNsContext().entrySet().stream().filter(kv -> KieDMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())).findFirst().map(Map.Entry::getKey).orElse("");
            hsWriter.getQNameMap().setDefaultPrefix(dmnPrefix);
        }
        extensionRegisters.forEach(r -> r.beforeMarshal(o, hsWriter.getQNameMap()));
        xStream.marshal(o, hsWriter);
        hsWriter.flush();
        return writer.toString();
    } catch (Exception e) {
        logger.error("Error marshalling DMN model to XML.", e);
    }
    return null;
}
Also used : Transformer(javax.xml.transform.Transformer) XStream(com.thoughtworks.xstream.XStream) TImportedValues(org.kie.dmn.model.v1_1.TImportedValues) TInputClause(org.kie.dmn.model.v1_1.TInputClause) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) StreamResult(javax.xml.transform.stream.StreamResult) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) TFunctionDefinition(org.kie.dmn.model.v1_1.TFunctionDefinition) LoggerFactory(org.slf4j.LoggerFactory) TypeHierarchyPermission(com.thoughtworks.xstream.security.TypeHierarchyPermission) TKnowledgeSource(org.kie.dmn.model.v1_1.TKnowledgeSource) TImport(org.kie.dmn.model.v1_1.TImport) TInformationItem(org.kie.dmn.model.v1_1.TInformationItem) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamReader(javax.xml.stream.XMLStreamReader) XStreamUtils(org.kie.utll.xml.XStreamUtils) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) TElementCollection(org.kie.dmn.model.v1_1.TElementCollection) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) TDMNElementReference(org.kie.dmn.model.v1_1.TDMNElementReference) TDecisionTable(org.kie.dmn.model.v1_1.TDecisionTable) TDecisionRule(org.kie.dmn.model.v1_1.TDecisionRule) TTextAnnotation(org.kie.dmn.model.v1_1.TTextAnnotation) DMNXStream(org.kie.dmn.backend.marshalling.v1x.DMNXStream) TDecisionService(org.kie.dmn.model.v1_1.TDecisionService) TNamedElement(org.kie.dmn.model.v1_1.TNamedElement) Reader(java.io.Reader) AbstractPullReader(com.thoughtworks.xstream.io.xml.AbstractPullReader) TOrganizationUnit(org.kie.dmn.model.v1_1.TOrganizationUnit) TInformationRequirement(org.kie.dmn.model.v1_1.TInformationRequirement) List(java.util.List) TExpression(org.kie.dmn.model.v1_1.TExpression) StaxWriter(com.thoughtworks.xstream.io.xml.StaxWriter) TBinding(org.kie.dmn.model.v1_1.TBinding) TBusinessContextElement(org.kie.dmn.model.v1_1.TBusinessContextElement) TOutputClause(org.kie.dmn.model.v1_1.TOutputClause) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) Writer(java.io.Writer) TRelation(org.kie.dmn.model.v1_1.TRelation) QName(javax.xml.namespace.QName) TBusinessKnowledgeModel(org.kie.dmn.model.v1_1.TBusinessKnowledgeModel) TAssociation(org.kie.dmn.model.v1_1.TAssociation) CustomStaxReader(org.kie.dmn.backend.marshalling.CustomStaxReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TKnowledgeRequirement(org.kie.dmn.model.v1_1.TKnowledgeRequirement) TLiteralExpression(org.kie.dmn.model.v1_1.TLiteralExpression) DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) Source(javax.xml.transform.Source) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) TContextEntry(org.kie.dmn.model.v1_1.TContextEntry) TDecision(org.kie.dmn.model.v1_1.TDecision) OutputStreamWriter(java.io.OutputStreamWriter) XMLConstants(javax.xml.XMLConstants) OutputStream(java.io.OutputStream) TArtifact(org.kie.dmn.model.v1_1.TArtifact) InputSource(org.xml.sax.InputSource) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) TInvocation(org.kie.dmn.model.v1_1.TInvocation) TPerformanceIndicator(org.kie.dmn.model.v1_1.TPerformanceIndicator) TDMNElement(org.kie.dmn.model.v1_1.TDMNElement) OutputKeys(javax.xml.transform.OutputKeys) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) DMNExtensionRegister(org.kie.dmn.api.marshalling.DMNExtensionRegister) TContext(org.kie.dmn.model.v1_1.TContext) TAuthorityRequirement(org.kie.dmn.model.v1_1.TAuthorityRequirement) SAXSource(javax.xml.transform.sax.SAXSource) StringReader(java.io.StringReader) TInputData(org.kie.dmn.model.v1_1.TInputData) TUnaryTests(org.kie.dmn.model.v1_1.TUnaryTests) TransformerFactory(javax.xml.transform.TransformerFactory) StringWriter(java.io.StringWriter) CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) XStream(com.thoughtworks.xstream.XStream) DMNXStream(org.kie.dmn.backend.marshalling.v1x.DMNXStream) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) Map(java.util.Map) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StaxWriter(com.thoughtworks.xstream.io.xml.StaxWriter) Writer(java.io.Writer) CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 2 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class ExtensionElementsConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    if (extensionRegisters.size() == 0) {
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            // skipping nodeName
            reader.moveUp();
        }
    } else {
        // do as default behavior, but in case cannot unmarshall an extension element child, just skip it.
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            try {
                Object object = readItem(reader, context, null);
                if (object instanceof DMNModelInstrumentedBase) {
                    ((KieDMNModelInstrumentedBase) object).setParent(obj);
                    ((KieDMNModelInstrumentedBase) obj).addChildren((KieDMNModelInstrumentedBase) object);
                }
                assignChildElement(obj, nodeName, object);
            } catch (CannotResolveClassException e) {
                // do nothing; I tried to convert the extension element child with the converters, but no converter is registered for this child.
                LOG.debug("Tried to convert the extension element child {}, but no converter is registered for this child.", nodeName);
            }
            reader.moveUp();
        }
    }
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

Example 3 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class DMNBaseConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    parseElements(reader, context, obj);
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase)

Example 4 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class ExtensionElementsConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    if (extensionRegisters.size() == 0) {
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            // skipping nodeName
            reader.moveUp();
        }
    } else {
        // do as default behavior, but in case cannot unmarshall an extension element child, just skip it.
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            try {
                Object object = readItem(reader, context, null);
                if (object instanceof DMNModelInstrumentedBase) {
                    ((KieDMNModelInstrumentedBase) object).setParent(obj);
                    ((KieDMNModelInstrumentedBase) obj).addChildren((KieDMNModelInstrumentedBase) object);
                }
                assignChildElement(obj, nodeName, object);
            } catch (CannotResolveClassException e) {
                // do nothing; I tried to convert the extension element child with the converters, but no converter is registered for this child.
                LOG.debug("Tried to convert the extension element child {}, but no converter is registered for this child.", nodeName);
            }
            reader.moveUp();
        }
    }
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

Example 5 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class DMNBaseConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    parseElements(reader, context, obj);
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase)

Aggregations

DMNModelInstrumentedBase (org.kie.dmn.model.api.DMNModelInstrumentedBase)22 CannotResolveClassException (com.thoughtworks.xstream.mapper.CannotResolveClassException)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)6 Reader (java.io.Reader)5 StringReader (java.io.StringReader)5 List (java.util.List)5 Definitions (org.kie.dmn.model.api.Definitions)5 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 XStream (com.thoughtworks.xstream.XStream)4 AbstractPullReader (com.thoughtworks.xstream.io.xml.AbstractPullReader)4 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)4 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)4 StaxWriter (com.thoughtworks.xstream.io.xml.StaxWriter)4 TypeHierarchyPermission (com.thoughtworks.xstream.security.TypeHierarchyPermission)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 Map (java.util.Map)4