use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class DefaultProfileImpl method getDefinitions.
private Definitions getDefinitions(String xml) {
try {
DroolsFactoryImpl.init();
BpsimFactoryImpl.init();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
Resource resource = resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
resource.load(is, Collections.EMPTY_MAP);
resource.load(Collections.EMPTY_MAP);
return ((DocumentRoot) resource.getContents().get(0)).getDefinitions();
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class JBPMBpmn2ResourceFactoryImpl method createAndInitResource.
/*
*
* Creates a new BpmnResourceImpl and initializes it.
*
* The method creates a DocumentRoot and a Definitions element, as both are
* mandatory.
*/
public Definitions createAndInitResource(URI uri) {
DroolsFactoryImpl.init();
BpsimFactoryImpl.init();
Resource resource = createResource(uri);
Bpmn2Factory factory = Bpmn2Factory.eINSTANCE;
Definitions definitions = factory.createDefinitions();
DocumentRoot docummentRoot = factory.createDocumentRoot();
docummentRoot.setDefinitions(definitions);
resource.getContents().add(docummentRoot);
return definitions;
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testMarshallProcessVariables.
@Test
public void testMarshallProcessVariables() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSVARIABLES);
JBPMBpmn2ResourceImpl resource = tested.marshallToBpmn2Resource(diagram);
String result = tested.marshall(diagram);
assertDiagram(result, 1, 7, 7);
Definitions definitions = (Definitions) resource.getContents().get(0);
assertNotNull(definitions);
List<RootElement> rootElements = definitions.getRootElements();
assertNotNull(rootElements);
assertNotNull(getItemDefinition(rootElements, "_employeeItem", "java.lang.String"));
assertNotNull(getItemDefinition(rootElements, "_reasonItem", "java.lang.String"));
assertNotNull(getItemDefinition(rootElements, "_performanceItem", "java.lang.String"));
Process process = getProcess(definitions);
assertNotNull(process);
List<Property> properties = process.getProperties();
assertNotNull(properties);
assertNotNull(getProcessProperty(properties, "employee", "_employeeItem"));
assertNotNull(getProcessProperty(properties, "reason", "_reasonItem"));
assertNotNull(getProcessProperty(properties, "performance", "_performanceItem"));
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testMarshallUserTaskAssignments.
@Test
public void testMarshallUserTaskAssignments() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_USERTASKASSIGNMENTS);
JBPMBpmn2ResourceImpl resource = tested.marshallToBpmn2Resource(diagram);
String result = tested.marshall(diagram);
assertDiagram(result, 1, 7, 7);
Definitions definitions = (Definitions) resource.getContents().get(0);
assertNotNull(definitions);
Process process = getProcess(definitions);
assertNotNull(process);
org.eclipse.bpmn2.UserTask userTask = (org.eclipse.bpmn2.UserTask) getNamedFlowElement(process, org.eclipse.bpmn2.UserTask.class, "Self Evaluation");
assertNotNull(userTask);
DataInput dataInput = (DataInput) getDataInput(userTask, "reason");
validateDataInputOrOutput(dataInput, "_reasonInputX", "com.test.Reason", "_reasonInputXItem");
DataOutput dataOutput = (DataOutput) getDataOutput(userTask, "performance");
validateDataInputOrOutput(dataOutput, "_performanceOutputX", "Object", "_performanceOutputXItem");
ItemAwareElement sourceRef = getDataInputAssociationSourceRef(userTask, "reason");
assertNotNull(sourceRef);
ItemAwareElement targetRef = getDataInputAssociationTargetRef(userTask, "_reasonInputX");
assertNotNull(targetRef);
sourceRef = getDataOutputAssociationSourceRef(userTask, "_performanceOutputX");
assertNotNull(sourceRef);
targetRef = getDataOutputAssociationTargetRef(userTask, "performance");
assertNotNull(targetRef);
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class DefaultProfileImpl method createMarshaller.
public IDiagramMarshaller createMarshaller() {
return new IDiagramMarshaller() {
public String parseModel(String jsonModel, String preProcessingData) {
Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
// Definitions def;
Resource res;
try {
res = unmarshaller.unmarshall(jsonModel, preProcessingData);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Map saveMap = new HashMap();
saveMap.put(XMLResource.OPTION_ENCODING, "UTF-8");
saveMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
saveMap.put(XMLResource.OPTION_DISABLE_NOTIFY, true);
saveMap.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
res.save(outputStream, saveMap);
return outputStream.toString();
} catch (JsonParseException e) {
_logger.error(e.getMessage(), e);
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
return "";
}
public Definitions getDefinitions(String jsonModel, String preProcessingData) {
try {
Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
JBPMBpmn2ResourceImpl res = (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
return (Definitions) res.getContents().get(0);
} catch (JsonParseException e) {
_logger.error(e.getMessage(), e);
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
return null;
}
public Resource getResource(String jsonModel, String preProcessingData) {
try {
Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
return (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
} catch (JsonParseException e) {
_logger.error(e.getMessage(), e);
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
return null;
}
};
}
Aggregations