Search in sources :

Example 6 with DocumentRoot

use of org.eclipse.bpmn2.DocumentRoot 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;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JBPMBpmn2ResourceFactoryImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl) IOException(java.io.IOException)

Aggregations

DocumentRoot (org.eclipse.bpmn2.DocumentRoot)6 HashMap (java.util.HashMap)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Definitions (org.eclipse.bpmn2.Definitions)2 Bpmn2ResourceFactoryImpl (org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 JBPMBpmn2ResourceFactoryImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl)2 JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Bpmn2Factory (org.eclipse.bpmn2.Bpmn2Factory)1 EPackage (org.eclipse.emf.ecore.EPackage)1 DroolsResourceFactoryImpl (org.jboss.drools.util.DroolsResourceFactoryImpl)1 ConverterFactory (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.ConverterFactory)1 GraphCommandFactory (org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory)1