Search in sources :

Example 1 with DMNModelInstrumentedBase

use of org.kie.dmn.model.v1_1.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.v1_1.DMNModelInstrumentedBase)

Example 2 with DMNModelInstrumentedBase

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

the class DMNModelInstrumentedBaseConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    DMNModelInstrumentedBase mib = (DMNModelInstrumentedBase) parent;
    CustomStaxReader customStaxReader = (CustomStaxReader) reader.underlyingReader();
    Map<String, String> currentNSCtx = customStaxReader.getNsContext();
    mib.getNsContext().putAll(currentNSCtx);
    mib.setLocation(customStaxReader.getLocation());
    mib.setAdditionalAttributes(customStaxReader.getAdditionalAttributes());
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.v1_1.DMNModelInstrumentedBase) CustomStaxReader(org.kie.dmn.backend.marshalling.CustomStaxReader)

Example 3 with DMNModelInstrumentedBase

use of org.kie.dmn.model.v1_1.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) {
                    ((DMNModelInstrumentedBase) object).setParent(obj);
                    ((DMNModelInstrumentedBase) obj).addChildren((DMNModelInstrumentedBase) 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.
            }
            reader.moveUp();
        }
    }
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.v1_1.DMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

Example 4 with DMNModelInstrumentedBase

use of org.kie.dmn.model.v1_1.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) {
            DMNModelInstrumentedBase base = (DMNModelInstrumentedBase) o;
            String dmnPrefix = base.getNsContext().entrySet().stream().filter(kv -> DMNModelInstrumentedBase.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 : XStream(com.thoughtworks.xstream.XStream) KnowledgeSource(org.kie.dmn.model.v1_1.KnowledgeSource) Transformer(javax.xml.transform.Transformer) InformationItem(org.kie.dmn.model.v1_1.InformationItem) ContextEntry(org.kie.dmn.model.v1_1.ContextEntry) OutputClause(org.kie.dmn.model.v1_1.OutputClause) StreamResult(javax.xml.transform.stream.StreamResult) FunctionDefinition(org.kie.dmn.model.v1_1.FunctionDefinition) LoggerFactory(org.slf4j.LoggerFactory) TextAnnotation(org.kie.dmn.model.v1_1.TextAnnotation) LiteralExpression(org.kie.dmn.model.v1_1.LiteralExpression) InformationRequirement(org.kie.dmn.model.v1_1.InformationRequirement) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) Map(java.util.Map) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Binding(org.kie.dmn.model.v1_1.Binding) DMNModelInstrumentedBase(org.kie.dmn.model.v1_1.DMNModelInstrumentedBase) DecisionTable(org.kie.dmn.model.v1_1.DecisionTable) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Reader(java.io.Reader) AbstractPullReader(com.thoughtworks.xstream.io.xml.AbstractPullReader) Context(org.kie.dmn.model.v1_1.Context) List(java.util.List) Definitions(org.kie.dmn.model.v1_1.Definitions) StaxWriter(com.thoughtworks.xstream.io.xml.StaxWriter) BusinessContextElement(org.kie.dmn.model.v1_1.BusinessContextElement) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) DecisionService(org.kie.dmn.model.v1_1.DecisionService) Invocation(org.kie.dmn.model.v1_1.Invocation) Writer(java.io.Writer) DMNExtensionRegister(org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister) QName(javax.xml.namespace.QName) BusinessKnowledgeModel(org.kie.dmn.model.v1_1.BusinessKnowledgeModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) CustomStaxReader(org.kie.dmn.backend.marshalling.CustomStaxReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Association(org.kie.dmn.model.v1_1.Association) DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) Source(javax.xml.transform.Source) InputData(org.kie.dmn.model.v1_1.InputData) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) ArrayList(java.util.ArrayList) CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) Relation(org.kie.dmn.model.v1_1.Relation) DecisionRule(org.kie.dmn.model.v1_1.DecisionRule) UnaryTests(org.kie.dmn.model.v1_1.UnaryTests) OrganizationUnit(org.kie.dmn.model.v1_1.OrganizationUnit) Expression(org.kie.dmn.model.v1_1.Expression) OutputStreamWriter(java.io.OutputStreamWriter) KnowledgeRequirement(org.kie.dmn.model.v1_1.KnowledgeRequirement) OutputStream(java.io.OutputStream) InputSource(org.xml.sax.InputSource) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) OutputKeys(javax.xml.transform.OutputKeys) XStreamUtils.createTrustingXStream(org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) Artifact(org.kie.dmn.model.v1_1.Artifact) AuthorityRequirement(org.kie.dmn.model.v1_1.AuthorityRequirement) DMNElementReference(org.kie.dmn.model.v1_1.DMNElementReference) ImportedValues(org.kie.dmn.model.v1_1.ImportedValues) Decision(org.kie.dmn.model.v1_1.Decision) ElementCollection(org.kie.dmn.model.v1_1.ElementCollection) SAXSource(javax.xml.transform.sax.SAXSource) StringReader(java.io.StringReader) NamedElement(org.kie.dmn.model.v1_1.NamedElement) Import(org.kie.dmn.model.v1_1.Import) InputClause(org.kie.dmn.model.v1_1.InputClause) PerformanceIndicator(org.kie.dmn.model.v1_1.PerformanceIndicator) StringWriter(java.io.StringWriter) CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createTrustingXStream(org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream) DMNModelInstrumentedBase(org.kie.dmn.model.v1_1.DMNModelInstrumentedBase) 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 5 with DMNModelInstrumentedBase

use of org.kie.dmn.model.v1_1.DMNModelInstrumentedBase in project kie-wb-common by kiegroup.

the class DDExtensionsRegister method beforeMarshal.

@Override
public void beforeMarshal(Object o, QNameMap qmap) {
    if (o instanceof DMNModelInstrumentedBase) {
        DMNModelInstrumentedBase base = (DMNModelInstrumentedBase) o;
        String ddPrefix = base.getPrefixForNamespaceURI(DMNDiagram.DMNV11_DD).orElse("dd");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DD, "DMNDiagram", ddPrefix), "DMNDiagram");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DD, "DMNShape", ddPrefix), "DMNShape");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DD, "DMNFontStyle", ddPrefix), "DMNFontStyle");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DD, "BorderSize", ddPrefix), "BorderSize");
        String dcPrefix = base.getPrefixForNamespaceURI(DMNDiagram.DMNV11_DC).orElse("dc");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DC, "Bounds", dcPrefix), "Bounds");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DC, "BgColor", dcPrefix), "BgColor");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DC, "BorderColor", dcPrefix), "BorderColor");
        qmap.registerMapping(new QName(DMNDiagram.DMNV11_DC, "FontColor", dcPrefix), "FontColor");
    }
}
Also used : QName(javax.xml.namespace.QName) DMNModelInstrumentedBase(org.kie.dmn.model.v1_1.DMNModelInstrumentedBase)

Aggregations

DMNModelInstrumentedBase (org.kie.dmn.model.v1_1.DMNModelInstrumentedBase)7 QName (javax.xml.namespace.QName)4 CustomStaxReader (org.kie.dmn.backend.marshalling.CustomStaxReader)2 CustomStaxWriter (org.kie.dmn.backend.marshalling.CustomStaxWriter)2 XStream (com.thoughtworks.xstream.XStream)1 AbstractPullReader (com.thoughtworks.xstream.io.xml.AbstractPullReader)1 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)1 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)1 StaxWriter (com.thoughtworks.xstream.io.xml.StaxWriter)1 CannotResolveClassException (com.thoughtworks.xstream.mapper.CannotResolveClassException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1