Search in sources :

Example 1 with JBPMBpmn2Resource

use of org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2Resource in project kie-wb-common by kiegroup.

the class BaseDirectDiagramMarshaller method parseDefinitions.

private static DefinitionsHandler parseDefinitions(final InputStream inputStream) throws IOException {
    DroolsPackageImpl.init();
    BpsimPackageImpl.init();
    final ResourceSet resourceSet = new ResourceSetImpl();
    Resource.Factory.Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
    resourceFactoryRegistry.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactory());
    EPackage.Registry packageRegistry = resourceSet.getPackageRegistry();
    packageRegistry.put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
    packageRegistry.put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE);
    final JBPMBpmn2Resource resource = (JBPMBpmn2Resource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    resource.getDefaultLoadOptions().put(JBPMBpmn2Resource.OPTION_ENCODING, "UTF-8");
    resource.setEncoding("UTF-8");
    final Map<String, Object> options = new HashMap<>();
    options.put(JBPMBpmn2Resource.OPTION_ENCODING, "UTF-8");
    options.put(JBPMBpmn2Resource.OPTION_DEFER_IDREF_RESOLUTION, true);
    options.put(JBPMBpmn2Resource.OPTION_DISABLE_NOTIFY, true);
    options.put(JBPMBpmn2Resource.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2Resource.OPTION_PROCESS_DANGLING_HREF_RECORD);
    try {
        resource.load(inputStream, options);
    } finally {
        inputStream.close();
    }
    final DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
    return new DefinitionsHandler(root);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) LoggerFactory(org.slf4j.LoggerFactory) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.ConverterFactory) PropertyWriterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriterFactory) BaseConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory) JBPMBpmn2ResourceFactory(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2ResourceFactory) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EPackage(org.eclipse.emf.ecore.EPackage) JBPMBpmn2Resource(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2Resource) JBPMBpmn2ResourceFactory(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2ResourceFactory)

Aggregations

HashMap (java.util.HashMap)1 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 ConverterFactory (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.ConverterFactory)1 PropertyWriterFactory (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriterFactory)1 BaseConverterFactory (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory)1 JBPMBpmn2Resource (org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2Resource)1 JBPMBpmn2ResourceFactory (org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2ResourceFactory)1 GraphCommandFactory (org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory)1 LoggerFactory (org.slf4j.LoggerFactory)1