Search in sources :

Example 1 with JBPMBpmn2ResourceFactoryImpl

use of org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl 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 JBPMBpmn2ResourceFactoryImpl

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

the class Bpmn2JsonUnmarshaller method unmarshall.

/**
 * NOTE: This method has been set protected for Stunner support. Stunner bpmn implementation provides a custom JsonParser that
 * is used instead of the one used in jbpm-designer-backend.
 * <p>
 * Start unmarshalling using the parser.
 * @param parser
 * @param preProcessingData
 * @return the root element of a bpmn2 document.
 * @throws JsonParseException
 * @throws IOException
 */
protected Bpmn2Resource unmarshall(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
    try {
        // open the object
        parser.nextToken();
        ResourceSet rSet = new ResourceSetImpl();
        rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
        Bpmn2Resource bpmn2 = (Bpmn2Resource) rSet.createResource(URI.createURI("virtual.bpmn2"));
        rSet.getResources().add(bpmn2);
        _currentResource = bpmn2;
        if (preProcessingData == null || preProcessingData.length() < 1) {
            preProcessingData = "ReadOnlyService";
        }
        // do the unmarshalling now:
        Definitions def = (Definitions) unmarshallItem(parser, preProcessingData);
        def.setExporter("jBPM Designer");
        def.setExporterVersion("6.2.0");
        revisitUserTasks(def);
        revisitServiceTasks(def);
        revisitMessages(def);
        revisitCatchEvents(def);
        revisitThrowEvents(def);
        revisitLanes(def);
        revisitSubProcessItemDefs(def);
        revisitArtifacts(def);
        revisitGroups(def);
        revisitTaskAssociations(def);
        revisitSendReceiveTasks(def);
        reconnectFlows();
        revisitGateways(def);
        revisitCatchEventsConvertToBoundary(def);
        revisitBoundaryEventsPositions(def);
        createDiagram(def);
        updateIDs(def);
        revisitDataObjects(def);
        revisitAssociationsIoSpec(def);
        revisitWsdlImports(def);
        revisitMultiInstanceTasks(def);
        addSimulation(def);
        revisitItemDefinitions(def);
        revisitProcessDoc(def);
        revisitDI(def);
        revisitSignalRef(def);
        orderDiagramElements(def);
        // return def;
        _currentResource.getContents().add(def);
        return _currentResource;
    } catch (Exception e) {
        _logger.error(e.getMessage());
        return _currentResource;
    } finally {
        parser.close();
        _objMap.clear();
        _idMap.clear();
        _outgoingFlows.clear();
        _sequenceFlowTargets.clear();
        _bounds.clear();
        _currentResource = null;
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Bpmn2Resource(org.eclipse.bpmn2.util.Bpmn2Resource) Definitions(org.eclipse.bpmn2.Definitions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JBPMBpmn2ResourceFactoryImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with JBPMBpmn2ResourceFactoryImpl

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

Example 4 with JBPMBpmn2ResourceFactoryImpl

use of org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl 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

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 JBPMBpmn2ResourceFactoryImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)2 Bpmn2Resource (org.eclipse.bpmn2.util.Bpmn2Resource)2 JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Definitions (org.eclipse.bpmn2.Definitions)1 EPackage (org.eclipse.emf.ecore.EPackage)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 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 LoggerFactory (org.slf4j.LoggerFactory)1