Search in sources :

Example 6 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)

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

Example 8 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_4.KieDMNModelInstrumentedBase)

Example 9 with DMNModelInstrumentedBase

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

Example 10 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_4.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_4.KieDMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

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