Search in sources :

Example 1 with DocumentRoot

use of org.eclipse.bpmn2.DocumentRoot in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshaller method parseDefinitions.

private static Definitions 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 JBPMBpmn2ResourceFactoryImpl());
    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 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();
}
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) LoggerFactory(org.slf4j.LoggerFactory) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.ConverterFactory) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JBPMBpmn2ResourceFactoryImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl) EPackage(org.eclipse.emf.ecore.EPackage)

Example 2 with DocumentRoot

use of org.eclipse.bpmn2.DocumentRoot in project kie-wb-common by kiegroup.

the class BPMFinderServiceImpl method parse.

protected Optional<Definitions> parse(FileUtils.ScanResult process) {
    org.uberfire.java.nio.file.Path formPath = process.getFile();
    try {
        ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl());
        resourceSet.getPackageRegistry().put(DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE);
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
        resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
        XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
        outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
        outResource.setEncoding("UTF-8");
        Map<String, Object> options = new HashMap<String, Object>();
        options.put(XMLResource.OPTION_ENCODING, "UTF-8");
        outResource.load(ioService.newInputStream(formPath), options);
        DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
        return Optional.of(root.getDefinitions());
    } catch (Exception ex) {
        logger.warn("Error reading process '" + process.getFile().getFileName(), ex);
    }
    return Optional.empty();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) DroolsResourceFactoryImpl(org.jboss.drools.util.DroolsResourceFactoryImpl) Bpmn2ResourceFactoryImpl(org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl)

Example 3 with DocumentRoot

use of org.eclipse.bpmn2.DocumentRoot 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;
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) Bpmn2ResourceFactoryImpl(org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 4 with DocumentRoot

use of org.eclipse.bpmn2.DocumentRoot 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;
}
Also used : Bpmn2Factory(org.eclipse.bpmn2.Bpmn2Factory) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) Definitions(org.eclipse.bpmn2.Definitions) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 5 with DocumentRoot

use of org.eclipse.bpmn2.DocumentRoot in project kie-wb-common by kiegroup.

the class BPMFinderServiceImpl method toDefinitions.

private Definitions toDefinitions(final InputStream in) {
    try {
        ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl());
        resourceSet.getPackageRegistry().put(DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE);
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
        resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
        XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
        outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
        outResource.setEncoding("UTF-8");
        Map<String, Object> options = new HashMap<String, Object>();
        options.put(XMLResource.OPTION_ENCODING, "UTF-8");
        outResource.load(in, options);
        DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
        return root.getDefinitions();
    } catch (Exception ex) {
        logger.warn("Cannot parse definitions due to", ex);
    }
    return null;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) DroolsResourceFactoryImpl(org.jboss.drools.util.DroolsResourceFactoryImpl) Bpmn2ResourceFactoryImpl(org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

DocumentRoot (org.eclipse.bpmn2.DocumentRoot)9 HashMap (java.util.HashMap)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)6 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)6 Definitions (org.eclipse.bpmn2.Definitions)3 Bpmn2ResourceFactoryImpl (org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Bpmn2Factory (org.eclipse.bpmn2.Bpmn2Factory)2 EPackage (org.eclipse.emf.ecore.EPackage)2 DroolsResourceFactoryImpl (org.jboss.drools.util.DroolsResourceFactoryImpl)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 GraphCommandFactory (org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory)2 LoggerFactory (org.slf4j.LoggerFactory)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1