_idMap.put(resourceId, baseElt);
// baseElt.setId(resourceId); commented out as bpmn2 seems to create
// duplicate ids right now.
applyProperties(baseElt, properties, preProcessingData);
if (baseElt instanceof Definitions) {
Process rootLevelProcess = null;
if(childElements == null || childElements.size() < 1) {
if (rootLevelProcess == null) {
rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
// set the properties and item definitions first
if(properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
String[] vardefs = properties.get("vardefs").split( ",\\s*" );
for(String vardef : vardefs) {
Property prop = Bpmn2Factory.eINSTANCE.createProperty();
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
// check if we define a structure ref in the definition
if(vardef.contains(":")) {
String[] vardefParts = vardef.split( ":\\s*" );
prop.setId(vardefParts[0]);
itemdef.setId("_" + prop.getId() + "Item");
itemdef.setStructureRef(vardefParts[1]);
} else {
prop.setId(vardef);
itemdef.setId("_" + prop.getId() + "Item");
}
prop.setItemSubjectRef(itemdef);
rootLevelProcess.getProperties().add(prop);
((Definitions) baseElt).getRootElements().add(itemdef);
}
}
if(properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature(
"http://www.jboss.org/drools", "adHoc", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute,
properties.get("adhocprocess"));
rootLevelProcess.getAnyAttribute().add(extensionEntry);
}
if(properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
MetaDataType metadata = DroolsFactory.eINSTANCE.createMetaDataType();
metadata.setName("customDescription");
metadata.setMetaValue(wrapInCDATABlock(properties.get("customdescription")));
if(rootLevelProcess.getExtensionValues() == null || rootLevelProcess.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
rootLevelProcess.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry(
(Internal) DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, metadata);
rootLevelProcess.getExtensionValues().get(0).getValue().add(extensionElementEntry);
}
rootLevelProcess.setId(properties.get("id"));
applyProcessProperties(rootLevelProcess, properties);
((Definitions) baseElt).getRootElements().add(rootLevelProcess);
}
} else {
for (BaseElement child : childElements) {
// tasks are only permitted under processes.
// a process should be created implicitly for tasks at the root
// level.
// process designer doesn't make a difference between tasks and
// global tasks.
// if a task has sequence edges it is considered a task,
// otherwise it is considered a global task.
// if (child instanceof Task && _outgoingFlows.get(child).isEmpty() && !_sequenceFlowTargets.contains(_objMap.get(child))) {
// // no edges on a task at the top level! We replace it with a
// // global task.
// GlobalTask task = null;
// if (child instanceof ScriptTask) {
// task = Bpmn2Factory.eINSTANCE.createGlobalScriptTask();
// ((GlobalScriptTask) task).setScript(((ScriptTask) child).getScript());
// ((GlobalScriptTask) task).setScriptLanguage(((ScriptTask) child).getScriptFormat());
// // TODO scriptLanguage missing on scriptTask
// } else if (child instanceof UserTask) {
// task = Bpmn2Factory.eINSTANCE.createGlobalUserTask();
// } else if (child instanceof ServiceTask) {
// // we don't have a global service task! Fallback on a
// // normal global task
// task = Bpmn2Factory.eINSTANCE.createGlobalTask();
// } else if (child instanceof BusinessRuleTask) {
// task = Bpmn2Factory.eINSTANCE.createGlobalBusinessRuleTask();
// } else if (child instanceof ManualTask) {
// task = Bpmn2Factory.eINSTANCE.createGlobalManualTask();
// } else {
// task = Bpmn2Factory.eINSTANCE.createGlobalTask();
// }
//
// task.setName(((Task) child).getName());
// task.setIoSpecification(((Task) child).getIoSpecification());
// task.getDocumentation().addAll(((Task) child).getDocumentation());
// ((Definitions) baseElt).getRootElements().add(task);
// continue;
// } else {
if (child instanceof SequenceFlow) {
// for some reason sequence flows are placed as root elements.
// find if the target has a container, and if we can use it:
List<String> ids = _outgoingFlows.get(child);
FlowElementsContainer container = null;
for (String id : ids) { // yes, we iterate, but we'll take the first in the list that will work.
Object obj = _idMap.get(id);
if (obj instanceof EObject && ((EObject) obj).eContainer() instanceof FlowElementsContainer) {
container = (FlowElementsContainer) ((EObject) obj).eContainer();
break;
}
}
if (container != null) {
container.getFlowElements().add((SequenceFlow) child);
continue;
}
}
if (child instanceof Task || child instanceof SequenceFlow
|| child instanceof Gateway || child instanceof Event
|| child instanceof Artifact || child instanceof DataObject || child instanceof SubProcess
|| child instanceof Lane || child instanceof CallActivity) {
if (rootLevelProcess == null) {
rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
// set the properties and item definitions first
if(properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
String[] vardefs = properties.get("vardefs").split( ",\\s*" );
for(String vardef : vardefs) {
Property prop = Bpmn2Factory.eINSTANCE.createProperty();
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
// check if we define a structure ref in the definition
if(vardef.contains(":")) {
String[] vardefParts = vardef.split( ":\\s*" );
prop.setId(vardefParts[0]);
itemdef.setId("_" + prop.getId() + "Item");
itemdef.setStructureRef(vardefParts[1]);
} else {
prop.setId(vardef);
itemdef.setId("_" + prop.getId() + "Item");
}
prop.setItemSubjectRef(itemdef);
rootLevelProcess.getProperties().add(prop);
((Definitions) baseElt).getRootElements().add(itemdef);
}
}
if(properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature(
"http://www.jboss.org/drools", "adHoc", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute,
properties.get("adhocprocess"));
rootLevelProcess.getAnyAttribute().add(extensionEntry);
}
if(properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
MetaDataType metadata = DroolsFactory.eINSTANCE.createMetaDataType();
metadata.setName("customDescription");
metadata.setMetaValue(wrapInCDATABlock(properties.get("customdescription")));
if(rootLevelProcess.getExtensionValues() == null || rootLevelProcess.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
rootLevelProcess.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry(
(Internal) DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, metadata);
rootLevelProcess.getExtensionValues().get(0).getValue().add(extensionElementEntry);
}
rootLevelProcess.setId(properties.get("id"));
applyProcessProperties(rootLevelProcess, properties);
((Definitions) baseElt).getRootElements().add(rootLevelProcess);
}
}
if (child instanceof Task) {
rootLevelProcess.getFlowElements().add((Task) child);
} else if (child instanceof CallActivity) {
rootLevelProcess.getFlowElements().add((CallActivity) child);
} else if (child instanceof RootElement) {
((Definitions) baseElt).getRootElements().add((RootElement) child);
} else if (child instanceof SequenceFlow) {
rootLevelProcess.getFlowElements().add((SequenceFlow) child);
} else if (child instanceof Gateway) {
rootLevelProcess.getFlowElements().add((Gateway) child);
} else if (child instanceof Event) {
rootLevelProcess.getFlowElements().add((Event) child);
} else if (child instanceof Artifact) {
rootLevelProcess.getArtifacts().add((Artifact) child);
} else if (child instanceof DataObject) {
// bubble up data objects
//rootLevelProcess.getFlowElements().add(0, (DataObject) child);
rootLevelProcess.getFlowElements().add((DataObject) child);
// ItemDefinition def = ((DataObject) child).getItemSubjectRef();
// if (def != null) {
// if (def.eResource() == null) {
// ((Definitions) rootLevelProcess.eContainer()).getRootElements().add(0, def);
// }
// Import imported = def.getImport();
// if (imported != null && imported.eResource() == null) {
// ((Definitions) rootLevelProcess.eContainer()).getImports().add(0, imported);
// }
// }
} else if(child instanceof SubProcess) {
rootLevelProcess.getFlowElements().add((SubProcess) child);
} else if(child instanceof Lane) {
// lanes handled later
} else {
_logger.error("Don't know what to do of " + child);
}