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;
}
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());
}
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;
}
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;
}
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");
}
}
Aggregations