use of org.kie.api.runtime.process.DataTransformer in project jbpm by kiegroup.
the class CallActivityHandler method readDataOutputAssociation.
protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, SubProcessNode subProcessNode, Map<String, String> dataOutputs) {
// sourceRef
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
String from = subNode.getTextContent();
// targetRef
subNode = subNode.getNextSibling();
String to = subNode.getTextContent();
// transformation
Transformation transformation = null;
subNode = subNode.getNextSibling();
if (subNode != null && "transformation".equals(subNode.getNodeName())) {
String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
String expression = subNode.getTextContent();
DataTransformer transformer = transformerRegistry.find(lang);
if (transformer == null) {
throw new IllegalArgumentException("No transformer registered for language " + lang);
}
transformation = new Transformation(lang, expression, from);
subNode = subNode.getNextSibling();
}
subProcessNode.addOutMapping(dataOutputs.get(from), to, transformation);
}
use of org.kie.api.runtime.process.DataTransformer in project jbpm by kiegroup.
the class CallActivityHandler method readDataInputAssociation.
protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, SubProcessNode subProcessNode, Map<String, String> dataInputs) {
// sourceRef
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
if ("sourceRef".equals(subNode.getNodeName())) {
String from = subNode.getTextContent();
// targetRef
subNode = subNode.getNextSibling();
String to = subNode.getTextContent();
// transformation
Transformation transformation = null;
subNode = subNode.getNextSibling();
if (subNode != null && "transformation".equals(subNode.getNodeName())) {
String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
String expression = subNode.getTextContent();
DataTransformer transformer = transformerRegistry.find(lang);
if (transformer == null) {
throw new IllegalArgumentException("No transformer registered for language " + lang);
}
transformation = new Transformation(lang, expression);
subNode = subNode.getNextSibling();
}
subProcessNode.addInMapping(dataInputs.get(to), from, transformation);
} else {
// targetRef
String to = subNode.getTextContent();
// assignment
subNode = subNode.getNextSibling();
if (subNode != null) {
org.w3c.dom.Node subSubNode = subNode.getFirstChild();
NodeList nl = subSubNode.getChildNodes();
if (nl.getLength() > 1) {
// not supported ?
subProcessNode.addInMapping(dataInputs.get(to), subSubNode.getTextContent());
return;
} else if (nl.getLength() == 0) {
return;
}
Object result = null;
Object from = nl.item(0);
if (from instanceof Text) {
result = ((Text) from).getTextContent();
} else {
result = nl.item(0);
}
subProcessNode.addInMapping(dataInputs.get(to), result.toString());
}
}
}
use of org.kie.api.runtime.process.DataTransformer in project jbpm by kiegroup.
the class StartEventHandler method readDataOutputAssociation.
protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, StartNode startNode) {
// sourceRef
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
if (!"sourceRef".equals(subNode.getNodeName())) {
throw new IllegalArgumentException("No sourceRef found in dataOutputAssociation in startEvent");
}
String source = subNode.getTextContent();
if (dataOutputs.get(source) == null) {
throw new IllegalArgumentException("No dataOutput could be found for the dataOutputAssociation.");
}
// targetRef
subNode = subNode.getNextSibling();
if (!"targetRef".equals(subNode.getNodeName())) {
throw new IllegalArgumentException("No targetRef found in dataOutputAssociation in startEvent");
}
String target = subNode.getTextContent();
startNode.setMetaData("TriggerMapping", target);
// transformation
Transformation transformation = null;
subNode = subNode.getNextSibling();
if (subNode != null && "transformation".equals(subNode.getNodeName())) {
String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
String expression = subNode.getTextContent();
DataTransformer transformer = transformerRegistry.find(lang);
if (transformer == null) {
throw new IllegalArgumentException("No transformer registered for language " + lang);
}
transformation = new Transformation(lang, expression, dataOutputs.get(source));
startNode.setMetaData("Transformation", transformation);
startNode.setEventTransformer(new EventTransformerImpl(transformation));
subNode = subNode.getNextSibling();
}
if (subNode != null) {
// no support for assignments
throw new UnsupportedOperationException(subNode.getNodeName() + " elements in dataOutputAssociations are not yet supported.");
}
startNode.addOutMapping(target, dataOutputs.get(source));
}
use of org.kie.api.runtime.process.DataTransformer in project jbpm by kiegroup.
the class TaskHandler method readDataOutputAssociation.
protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, WorkItemNode workItemNode, Map<String, String> dataOutputs) {
// sourceRef
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
String source = subNode.getTextContent();
// targetRef
subNode = subNode.getNextSibling();
String target = subNode.getTextContent();
// transformation
Transformation transformation = null;
subNode = subNode.getNextSibling();
if (subNode != null && "transformation".equals(subNode.getNodeName())) {
String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
String expression = subNode.getTextContent();
DataTransformer transformer = transformerRegistry.find(lang);
if (transformer == null) {
throw new IllegalArgumentException("No transformer registered for language " + lang);
}
transformation = new Transformation(lang, expression, source);
// transformation.setCompiledExpression(transformer.compile(expression));
subNode = subNode.getNextSibling();
}
// assignments
List<Assignment> assignments = new LinkedList<Assignment>();
while (subNode != null) {
org.w3c.dom.Node ssubNode = subNode.getFirstChild();
String from = ssubNode.getTextContent();
String to = ssubNode.getNextSibling().getTextContent();
assignments.add(new Assignment("XPath", from, to));
subNode = subNode.getNextSibling();
}
workItemNode.addOutAssociation(new DataAssociation(dataOutputs.get(source), target, assignments, transformation));
}
use of org.kie.api.runtime.process.DataTransformer in project jbpm by kiegroup.
the class TransformerJSONandXMLTest method testJAXBTransformer.
@Test
public void testJAXBTransformer() {
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><person><age>34</age><name>john</name></person>";
DataTransformer transformer = DataTransformerRegistry.get().find("http://www.mvel.org/2.0");
String expressionR = "java.io.StringReader result = new java.io.StringReader(xml);" + "return javax.xml.bind.JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(result);";
String expressionW = "java.io.StringWriter result = new java.io.StringWriter();" + "javax.xml.bind.JAXBContext.newInstance(classes).createMarshaller().marshal(employee, result);" + "return result.toString();";
Object compiled = transformer.compile(expressionW, new HashMap<String, Object>());
Map<String, Object> parameters = new HashMap<String, Object>();
Person person = new Person();
person.setAge(34);
person.setName("john");
parameters.put("employee", person);
parameters.put("classes", Person.class);
Object result = transformer.transform(compiled, parameters);
System.out.println(result);
assertEquals(expectedXml, result);
Object compiledR = transformer.compile(expressionR, new HashMap<String, Object>());
parameters.clear();
parameters.put("classes", Person.class);
parameters.put("xml", result);
Object resultr = transformer.transform(compiledR, parameters);
System.out.println(resultr);
assertNotNull(resultr);
assertTrue(resultr instanceof Person);
assertEquals("john", ((Person) resultr).getName());
assertEquals(34, ((Person) resultr).getAge().intValue());
}
Aggregations