* @param doc
* @return
* @throws Exception
*/
private BPELProcessDefinition readProcessDefinition(URL doc, Monitor monitor) throws Exception {
BPELProcessDefinition processDefinition = factory.createBPELProcessDefinition();
processDefinition.setUnresolved(true);
processDefinition.setLocation(doc.toString());
InputStream is = doc.openStream();
XMLStreamReader reader = null;
try {
reader = inputFactory.createXMLStreamReader(is);
/*
* The principle here is to look for partnerLink elements, which
* form either services or references. A partnerLink can be EITHER -
* the algorithm for deciding is:
* 1) Explicit marking with sca:reference or sca:service attribute
* 2) "first use" of the partnerLink by specific BPEL activity elements:
* <onEvent../>, <receive../> or <pick../> elements imply a service
* <invoke../> implies a reference
*/
// TODO - need to handle <scope../> elements as kind of "nested" processes
// - and scopes introduce the possibility of partnerLinks with the
// same name at different levels of scope.... (yuk!!)
boolean completed = false;
while (!completed) {
switch (reader.next()) {
case START_ELEMENT:
QName qname = reader.getName();
if (BPELProcessorConstants.PROCESS_ELEMENT.equals(qname) || BPELProcessorConstants.PROCESS_ELEMENT_20.equals(qname)) {
QName processName = new QName(getString(reader, BPELProcessorConstants.TARGET_NAMESPACE), getString(reader, BPELProcessorConstants.NAME_ELEMENT));
processDefinition.setName(processName);
} else if (BPELProcessorConstants.PARTNERLINK_ELEMENT.equals(qname) || BPELProcessorConstants.PARTNERLINK_ELEMENT_20.equals(qname)) {
processDefinition.getPartnerLinks().add(processPartnerLinkElement(reader, monitor));
} else if (BPELProcessorConstants.ONEVENT_ELEMENT.equals(qname) || BPELProcessorConstants.RECEIVE_ELEMENT.equals(qname) || BPELProcessorConstants.ONMESSAGE_ELEMENT.equals(qname) ||
BPELProcessorConstants.ONEVENT_ELEMENT_20.equals(qname) || BPELProcessorConstants.RECEIVE_ELEMENT_20.equals(qname) || BPELProcessorConstants.ONMESSAGE_ELEMENT_20.equals(qname)) {
processPartnerLinkAsService(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks(), monitor);
} else if (BPELProcessorConstants.INVOKE_ELEMENT.equals(qname) || BPELProcessorConstants.INVOKE_ELEMENT_20.equals(qname)) {
processPartnerLinkAsReference(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks(), monitor);
} else if (BPELProcessorConstants.IMPORT_ELEMENT.equals(qname) || BPELProcessorConstants.IMPORT_ELEMENT_20.equals(qname)) {
processDefinition.getImports().add(processImportElement(reader));
} else if (BPELProcessorConstants.VARIABLE_ELEMENT.equals(qname) || BPELProcessorConstants.VARIABLE_ELEMENT_20.equals(qname)) {
// deal with variables that are SCA properties through the presence of a sca-bpel:property="yes" attribute
Property aProperty = processVariableElement(reader);
if( aProperty != null ) {
processDefinition.getProperties().add( aProperty );
} // end if
} // end if
break;
case END_ELEMENT:
qname = reader.getName();