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);
JBPMBpmn2ResourceImpl resource = (JBPMBpmn2ResourceImpl) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
resource.setEncoding("UTF-8");
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 );
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
resource.load(is, options);
if(!resource.getErrors().isEmpty()) {
String errorMessages = "";
for (Resource.Diagnostic error : resource.getErrors()) {
errorMessages += error.getMessage() + "\n";
}
notification.fire( new DesignerNotificationEvent( errorMessages, NotificationEvent.NotificationType.ERROR ) );
}
if(!resource.getWarnings().isEmpty()) {
String warningMessages = "";
for(Resource.Diagnostic warning : resource.getWarnings()) {
warningMessages += warning.getMessage() + "\n";
}
notification.fire( new DesignerNotificationEvent( warningMessages, NotificationEvent.NotificationType.WARNING ) );
}
EList<Diagnostic> warnings = resource.getWarnings();
if (warnings != null && !warnings.isEmpty()){
for (Diagnostic diagnostic : warnings) {
_logger.info("Warning: " + diagnostic.getMessage());
}
}
return ((DocumentRoot) resource.getContents().get(0)).getDefinitions();
} catch(Exception e) {
return getDefaultDefinitions();
}
}