Search in sources :

Example 21 with KieDMNModelInstrumentedBase

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

Example 22 with KieDMNModelInstrumentedBase

use of org.kie.dmn.model.v1_2.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_3.TDMNElementReference) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase) TDMNElementReference(org.kie.dmn.model.v1_3.TDMNElementReference) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase)

Example 23 with KieDMNModelInstrumentedBase

use of org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase 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_3.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

Aggregations

DMNModelInstrumentedBase (org.kie.dmn.model.api.DMNModelInstrumentedBase)14 QName (javax.xml.namespace.QName)9 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 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 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