use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class JBPMBpmn2ResourceFactoryImpl method createResource.
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*/
@Override
public Resource createResource(URI uri) {
DroolsFactoryImpl.init();
BpsimFactoryImpl.init();
JBPMBpmn2ResourceImpl result = new JBPMBpmn2ResourceImpl(uri);
ExtendedMetaData extendedMetadata = new XmlExtendedMetadata();
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetadata);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetadata);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, new OnlyContainmentTypeInfo());
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_ELEMENT_HANDLER, new ElementHandlerImpl(true));
result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE, new ArrayList<Object>());
result.getDefaultSaveOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
result.getDefaultSaveOptions().put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
return result;
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest 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);
DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
Definitions definitions = definitionsConverter.toDefinitions();
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");
// this fails because of type
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 BPMNDiagramMarshallerTest method testMarshallProcessProperties.
@Test
public void testMarshallProcessProperties() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSPROPERTIES);
JBPMBpmn2ResourceImpl resource = tested.marshallToBpmn2Resource(diagram);
String result = tested.marshall(diagram);
assertDiagram(result, 1, 3, 2);
Definitions definitions = (Definitions) resource.getContents().get(0);
assertNotNull(definitions);
Process process = getProcess(definitions);
assertNotNull(process);
assertEquals("JDLProj.BPSimple", process.getId());
assertEquals("BPSimple", process.getName());
assertTrue(process.isIsExecutable());
assertEquals("true", getProcessPropertyValue(process, "adHoc"));
assertEquals("org.jbpm", getProcessPropertyValue(process, "packageName"));
assertEquals("1.0", getProcessPropertyValue(process, "version"));
assertNotNull(process.getDocumentation());
assertFalse(process.getDocumentation().isEmpty());
assertEquals("<![CDATA[This is a\nsimple\nprocess]]>", process.getDocumentation().get(0).getText());
assertEquals("<![CDATA[This is the\nProcess\nInstance\nDescription]]>", getProcessExtensionValue(process, "customDescription"));
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshaller method createBpmn2Resource.
private Bpmn2Resource createBpmn2Resource() {
DroolsFactoryImpl.init();
BpsimFactoryImpl.init();
ResourceSet rSet = new ResourceSetImpl();
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
Bpmn2Resource resource = (Bpmn2Resource) rSet.createResource(URI.createURI("virtual.bpmn2"));
rSet.getResources().add(resource);
return resource;
}
use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.
the class BaseDiagramMarshaller method parseDefinitions.
private Definitions parseDefinitions(final InputStream inputStream) throws IOException {
try {
DroolsPackageImpl.init();
BpsimPackageImpl.init();
final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactoryImpl());
resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
resourceSet.getPackageRegistry().put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE);
final JBPMBpmn2ResourceImpl resource = (JBPMBpmn2ResourceImpl) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
resource.setEncoding("UTF-8");
final Map<String, Object> options = new HashMap<String, Object>();
options.put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
options.put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true);
options.put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true);
options.put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD);
resource.load(inputStream, options);
final DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
return root.getDefinitions();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
inputStream.close();
}
}
return null;
}
Aggregations