use of org.eclipse.emf.ecore.xmi.XMLResource in project jbpm by kiegroup.
the class BPMN2EmfExtTest method testOnExitScriptElement.
public void testOnExitScriptElement() throws Exception {
// write
XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
inResource.setEncoding("UTF-8");
DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
OnExitScriptType root = DroolsFactory.eINSTANCE.createOnExitScriptType();
root.setScript("script");
root.setScriptFormat("format");
documentRoot.setOnExitScript(root);
inResource.getContents().add(documentRoot);
StringWriter stringWriter = new StringWriter();
inResource.save(stringWriter, null);
assertNotNull(stringWriter.getBuffer().toString());
if (stringWriter.getBuffer().toString().length() < 1) {
fail("generated xml is empty");
}
// read
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");
InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
outResource.load(is, options);
DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
assertNotNull(outRoot.getOnExitScript());
OnExitScriptType scriptType = outRoot.getOnExitScript();
assertEquals("script", scriptType.getScript());
assertEquals("format", scriptType.getScriptFormat());
}
use of org.eclipse.emf.ecore.xmi.XMLResource in project jbpm by kiegroup.
the class BpsimTest method testBpsimData.
@SuppressWarnings("unchecked")
public void testBpsimData() throws Exception {
// write
XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
inResource.setEncoding("UTF-8");
DocumentRoot documentRoot = BpsimFactory.eINSTANCE.createDocumentRoot();
BPSimDataType bpsimData = BpsimFactory.eINSTANCE.createBPSimDataType();
Scenario defaultScenario = BpsimFactory.eINSTANCE.createScenario();
defaultScenario.setId("default");
defaultScenario.setName("Scenario");
ScenarioParameters scenarioParams = BpsimFactory.eINSTANCE.createScenarioParameters();
scenarioParams.setBaseTimeUnit(TimeUnit.S);
defaultScenario.setScenarioParameters(scenarioParams);
ElementParameters elementParams = BpsimFactory.eINSTANCE.createElementParameters();
TimeParameters elementTimeParams = BpsimFactory.eINSTANCE.createTimeParameters();
Parameter processingTimeParameter = BpsimFactory.eINSTANCE.createParameter();
UniformDistributionType uniformDistrobutionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
uniformDistrobutionType.setMin(180.0);
uniformDistrobutionType.setMax(600.0);
processingTimeParameter.getParameterValue().add(uniformDistrobutionType);
elementTimeParams.setProcessingTime(processingTimeParameter);
elementParams.setTimeParameters(elementTimeParams);
defaultScenario.getElementParameters().add(elementParams);
bpsimData.getScenario().add(defaultScenario);
documentRoot.setBPSimData(bpsimData);
inResource.getContents().add(documentRoot);
StringWriter stringWriter = new StringWriter();
inResource.save(stringWriter, null);
assertNotNull(stringWriter.getBuffer().toString());
if (stringWriter.getBuffer().toString().length() < 1) {
fail("generated xml is empty");
}
// read
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");
InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
outResource.load(is, options);
DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
assertNotNull(outRoot.getBPSimData());
BPSimDataType outAnalysisData = outRoot.getBPSimData();
assertEquals(outAnalysisData.getScenario().size(), 1);
Scenario outScenario = outAnalysisData.getScenario().get(0);
assertEquals(outScenario.getElementParameters().size(), 1);
assertEquals(outScenario.getId(), "default");
assertEquals(outScenario.getName(), "Scenario");
assertNotNull(outScenario.getScenarioParameters());
assertNotNull(outScenario.getElementParameters());
assertEquals(outScenario.getElementParameters().size(), 1);
ElementParameters outElementParamType = outScenario.getElementParameters().get(0);
assertNotNull(outElementParamType.getTimeParameters());
TimeParameters outTimeParams = outElementParamType.getTimeParameters();
assertNotNull(outTimeParams.getProcessingTime());
assertEquals(outTimeParams.getProcessingTime().getParameterValue().size(), 1);
UniformDistributionType outDistributionType = (UniformDistributionType) outTimeParams.getProcessingTime().getParameterValue().get(0);
assertEquals(outDistributionType.getMax(), 600.0);
assertEquals(outDistributionType.getMin(), 180.0);
}
use of org.eclipse.emf.ecore.xmi.XMLResource in project tesb-studio-se by Talend.
the class ServicesResourceFactoryImpl method createResource.
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
XMLResource result = new ServicesResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
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);
return result;
}
Aggregations