Search in sources :

Example 16 with Resource

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;
}
Also used : XmlExtendedMetadata(org.eclipse.bpmn2.util.XmlExtendedMetadata) ElementHandlerImpl(org.eclipse.emf.ecore.xmi.impl.ElementHandlerImpl) OnlyContainmentTypeInfo(org.eclipse.bpmn2.util.OnlyContainmentTypeInfo) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData)

Example 17 with Resource

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"));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Process(org.eclipse.bpmn2.Process) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 18 with Resource

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;
}
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 19 with 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;
}
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)

Example 20 with Resource

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

the class JBPMBpmn2ResourceFactory 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)

Aggregations

Definitions (org.eclipse.bpmn2.Definitions)9 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)6 Test (org.junit.Test)6 JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)6 Process (org.eclipse.bpmn2.Process)5 HashMap (java.util.HashMap)4 Bpmn2Resource (org.eclipse.bpmn2.util.Bpmn2Resource)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)4 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 Resource (io.opencensus.proto.resource.v1.Resource)3 ArrayList (java.util.ArrayList)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 URI (java.net.URI)2 LinkedHashMap (java.util.LinkedHashMap)2 DefaultValue (javax.ws.rs.DefaultValue)2