Search in sources :

Example 16 with KieDMNModelInstrumentedBase

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

the class DMNModelInstrumentedBaseConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    KieDMNModelInstrumentedBase mib = (KieDMNModelInstrumentedBase) parent;
    CustomStaxWriter staxWriter = ((CustomStaxWriter) writer.underlyingWriter());
    for (Entry<String, String> kv : mib.getNsContext().entrySet()) {
        try {
            if (KieDMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())) {
            // skip as that is the default namespace xmlns<:prefix>=DMN is handled by the stax driver.
            } else {
                staxWriter.writeNamespace(kv.getKey(), kv.getValue());
            }
        } catch (Exception e) {
            LOG.warn("The XML driver writer failed to manage writing namespace, namespaces prefixes could be wrong in the resulting file.", e);
        }
    }
    for (Entry<QName, String> kv : mib.getAdditionalAttributes().entrySet()) {
        staxWriter.addAttribute(kv.getKey().getPrefix() + ":" + kv.getKey().getLocalPart(), kv.getValue());
    }
}
Also used : CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) QName(javax.xml.namespace.QName) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase)

Example 17 with KieDMNModelInstrumentedBase

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

the class DecisionServiceConverter method parseElements.

@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        Object object = null;
        String nodeName = reader.getNodeName();
        if (nodeName.equals(INPUT_DATA)) {
            // Patch because the tag name inputData is used in both decision services and as a DRG Element
            DMNElementReference ref = new TDMNElementReference();
            ref.setHref(reader.getAttribute("href"));
            object = ref;
        } else {
            // Default behaviour
            object = readItem(reader, context, null);
        }
        if (object instanceof DMNModelInstrumentedBase) {
            ((KieDMNModelInstrumentedBase) object).setParent((KieDMNModelInstrumentedBase) parent);
            ((KieDMNModelInstrumentedBase) parent).addChildren((KieDMNModelInstrumentedBase) object);
        }
        reader.moveUp();
        assignChildElement(parent, nodeName, object);
    }
}
Also used : DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_1.TDMNElementReference) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) TDMNElementReference(org.kie.dmn.model.v1_1.TDMNElementReference) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase)

Example 18 with KieDMNModelInstrumentedBase

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

the class DMNModelInstrumentedBaseConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    KieDMNModelInstrumentedBase mib = (KieDMNModelInstrumentedBase) parent;
    CustomStaxWriter staxWriter = ((CustomStaxWriter) writer.underlyingWriter());
    for (Entry<String, String> kv : mib.getNsContext().entrySet()) {
        try {
            if (KieDMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())) {
            // skip as that is the default namespace xmlns<:prefix>=DMN is handled by the stax driver.
            } else {
                staxWriter.writeNamespace(kv.getKey(), kv.getValue());
            }
        } catch (Exception e) {
            LOG.warn("The XML driver writer failed to manage writing namespace, namespaces prefixes could be wrong in the resulting file.", e);
        }
    }
    for (Entry<QName, String> kv : mib.getAdditionalAttributes().entrySet()) {
        staxWriter.addAttribute(kv.getKey().getPrefix() + ":" + kv.getKey().getLocalPart(), kv.getValue());
    }
    if (parent instanceof TDefinitions) {
        TDefinitions tDefinitions = (TDefinitions) parent;
        String dmndiPrefix = tDefinitions.getPrefixForNamespaceURI(KieDMNModelInstrumentedBase.URI_DMNDI).orElse("dmndi");
        String diPrefix = tDefinitions.getPrefixForNamespaceURI(KieDMNModelInstrumentedBase.URI_DI).orElse("di");
        String dcPrefix = tDefinitions.getPrefixForNamespaceURI(KieDMNModelInstrumentedBase.URI_DC).orElse("dc");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNDI", dmndiPrefix), "DMNDI");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNDiagram", dmndiPrefix), "DMNDiagram");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNStyle", dmndiPrefix), "style");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNStyle", dmndiPrefix), "DMNStyle");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNShape", dmndiPrefix), "DMNShape");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNEdge", dmndiPrefix), "DMNEdge");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNDecisionServiceDividerLine", dmndiPrefix), "DMNDecisionServiceDividerLine");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNLabel", dmndiPrefix), "DMNLabel");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, DMNLabelConverter.TEXT, dmndiPrefix), DMNLabelConverter.TEXT);
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "Size", dmndiPrefix), "Size");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "FillColor", dmndiPrefix), "FillColor");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "StrokeColor", dmndiPrefix), "StrokeColor");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "FontColor", dmndiPrefix), "FontColor");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DI, "waypoint", diPrefix), "waypoint");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DI, "extension", diPrefix), "extension");
        staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DC, "Bounds", dcPrefix), "Bounds");
    }
}
Also used : CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) QName(javax.xml.namespace.QName) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) TDefinitions(org.kie.dmn.model.v1_2.TDefinitions)

Example 19 with KieDMNModelInstrumentedBase

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

the class DMNModelInstrumentedBaseConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    KieDMNModelInstrumentedBase mib = (KieDMNModelInstrumentedBase) 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 : CustomStaxReader(org.kie.dmn.backend.marshalling.CustomStaxReader) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase)

Example 20 with KieDMNModelInstrumentedBase

use of org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase 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 : XStream(com.thoughtworks.xstream.XStream) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) TDecisionService(org.kie.dmn.model.v1_3.TDecisionService) TInputClause(org.kie.dmn.model.v1_3.TInputClause) LoggerFactory(org.slf4j.LoggerFactory) TInformationItem(org.kie.dmn.model.v1_3.TInformationItem) TPerformanceIndicator(org.kie.dmn.model.v1_3.TPerformanceIndicator) DMNDecisionServiceDividerLine(org.kie.dmn.model.v1_3.dmndi.DMNDecisionServiceDividerLine) TypeHierarchyPermission(com.thoughtworks.xstream.security.TypeHierarchyPermission) TDefinitions(org.kie.dmn.model.v1_3.TDefinitions) TElementCollection(org.kie.dmn.model.v1_3.TElementCollection) TAuthorityRequirement(org.kie.dmn.model.v1_3.TAuthorityRequirement) XMLStreamReader(javax.xml.stream.XMLStreamReader) Bounds(org.kie.dmn.model.v1_3.dmndi.Bounds) XStreamUtils(org.kie.utll.xml.XStreamUtils) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) TImport(org.kie.dmn.model.v1_3.TImport) TContext(org.kie.dmn.model.v1_3.TContext) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) TBusinessKnowledgeModel(org.kie.dmn.model.v1_3.TBusinessKnowledgeModel) TAssociation(org.kie.dmn.model.v1_3.TAssociation) Point(org.kie.dmn.model.v1_3.dmndi.Point) DMNXStream(org.kie.dmn.backend.marshalling.v1x.DMNXStream) TRuleAnnotation(org.kie.dmn.model.v1_3.TRuleAnnotation) Color(org.kie.dmn.model.v1_3.dmndi.Color) TDMNElementReference(org.kie.dmn.model.v1_3.TDMNElementReference) TKnowledgeRequirement(org.kie.dmn.model.v1_3.TKnowledgeRequirement) DMNEdge(org.kie.dmn.model.v1_3.dmndi.DMNEdge) Reader(java.io.Reader) TArtifact(org.kie.dmn.model.v1_3.TArtifact) TBusinessContextElement(org.kie.dmn.model.v1_3.TBusinessContextElement) AbstractPullReader(com.thoughtworks.xstream.io.xml.AbstractPullReader) TContextEntry(org.kie.dmn.model.v1_3.TContextEntry) List(java.util.List) DMNDI(org.kie.dmn.model.v1_3.dmndi.DMNDI) TDecision(org.kie.dmn.model.v1_3.TDecision) StaxWriter(com.thoughtworks.xstream.io.xml.StaxWriter) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) TImportedValues(org.kie.dmn.model.v1_3.TImportedValues) Writer(java.io.Writer) DiagramElement(org.kie.dmn.model.v1_3.dmndi.DiagramElement) QName(javax.xml.namespace.QName) TRuleAnnotationClause(org.kie.dmn.model.v1_3.TRuleAnnotationClause) TDecisionTable(org.kie.dmn.model.v1_3.TDecisionTable) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase) CustomStaxReader(org.kie.dmn.backend.marshalling.CustomStaxReader) Dimension(org.kie.dmn.model.v1_3.dmndi.Dimension) TLiteralExpression(org.kie.dmn.model.v1_3.TLiteralExpression) TUnaryTests(org.kie.dmn.model.v1_3.TUnaryTests) DMNShape(org.kie.dmn.model.v1_3.dmndi.DMNShape) TExpression(org.kie.dmn.model.v1_3.TExpression) TInformationRequirement(org.kie.dmn.model.v1_3.TInformationRequirement) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) CustomStaxWriter(org.kie.dmn.backend.marshalling.CustomStaxWriter) TFunctionDefinition(org.kie.dmn.model.v1_3.TFunctionDefinition) TInputData(org.kie.dmn.model.v1_3.TInputData) DMNStyle(org.kie.dmn.model.v1_3.dmndi.DMNStyle) Logger(org.slf4j.Logger) TFunctionItem(org.kie.dmn.model.v1_3.TFunctionItem) DMNDiagram(org.kie.dmn.model.v1_3.dmndi.DMNDiagram) TGroup(org.kie.dmn.model.v1_3.TGroup) StringWriter(java.io.StringWriter) TBinding(org.kie.dmn.model.v1_3.TBinding) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) DMNExtensionRegister(org.kie.dmn.api.marshalling.DMNExtensionRegister) TTextAnnotation(org.kie.dmn.model.v1_3.TTextAnnotation) TDMNElement(org.kie.dmn.model.v1_3.TDMNElement) TDecisionRule(org.kie.dmn.model.v1_3.TDecisionRule) TInvocation(org.kie.dmn.model.v1_3.TInvocation) TOutputClause(org.kie.dmn.model.v1_3.TOutputClause) TRelation(org.kie.dmn.model.v1_3.TRelation) TItemDefinition(org.kie.dmn.model.v1_3.TItemDefinition) DMNLabel(org.kie.dmn.model.v1_3.dmndi.DMNLabel) StringReader(java.io.StringReader) TOrganizationUnit(org.kie.dmn.model.v1_3.TOrganizationUnit) TKnowledgeSource(org.kie.dmn.model.v1_3.TKnowledgeSource) TNamedElement(org.kie.dmn.model.v1_3.TNamedElement) 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_3.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.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) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException)

Aggregations

DMNModelInstrumentedBase (org.kie.dmn.model.api.DMNModelInstrumentedBase)14 QName (javax.xml.namespace.QName)8 CustomStaxReader (org.kie.dmn.backend.marshalling.CustomStaxReader)8 CustomStaxWriter (org.kie.dmn.backend.marshalling.CustomStaxWriter)8 CannotResolveClassException (com.thoughtworks.xstream.mapper.CannotResolveClassException)6 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase)6 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase)6 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase)5 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_4.KieDMNModelInstrumentedBase)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 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 ArrayList (java.util.ArrayList)4