Author: objectiser
Date: 2009-06-22 19:10:42 -0400 (Mon, 22 Jun 2009)
New Revision: 649
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Scope.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/ParserTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/testmodels/LoanApprovalService(a)Service.bpel
Log:
Handle situations where fault handlers defined with multiple invokes, so faults need to be
associated with each invoke, as not clear which one they belong to.
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java 2009-06-20
23:25:56 UTC (rev 648)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java 2009-06-22
23:10:42 UTC (rev 649)
@@ -120,7 +120,63 @@
convertRequest(activities, context);
+ // Check if invoke is contained within a scope that defines
+ // fault handlers. If so, then generate choice to throw
+ // fault exceptions.
+ Scope scope=null;
+ org.w3c.dom.Element cur=getDOMElement();
+
+ while (cur != null && cur.getParentNode() instanceof org.w3c.dom.Element
&&
+ scope == null) {
+ cur = (org.w3c.dom.Element)cur.getParentNode();
+
+ if (cur != null) {
+ BPELElement elem=BPELElementFactory.createBPELElement(getModel(),
+ cur);
+
+ if (elem instanceof Scope) {
+ scope = (Scope)elem;
+ }
+ }
+ }
+
+ if (scope != null && scope.getFaultHandlers() != null &&
+ (scope.getFaultHandlers().getCatchPaths().size() > 0 ||
+ scope.getFaultHandlers().getCatchAll() != null)) {
+ org.scribble.conversation.model.If te=
+ new org.scribble.conversation.model.If();
+
+ activities.add(te);
+
+ org.scribble.conversation.model.ConditionalBlock cb=
+ new org.scribble.conversation.model.ConditionalBlock();
+ te.getConditionalBlocks().add(cb);
+
+ activities = cb.getContents();
+
+ for (int i=0; i < scope.getFaultHandlers().getCatchPaths().size(); i++) {
+ Catch catchBlock=scope.getFaultHandlers().getCatchPaths().get(i);
+
+ org.scribble.conversation.model.ConditionalBlock fcb=
+ new org.scribble.conversation.model.ConditionalBlock();
+
+ convertFaultResponse(fcb.getContents(), catchBlock.getFaultVariable(), context);
+
+ org.scribble.conversation.model.Raise raise=
+ new org.scribble.conversation.model.Raise();
+
+ TypeReference tref=new TypeReference();
+ tref.setAlias(catchBlock.getFaultName());
+ raise.setType(tref);
+
+ fcb.getContents().add(raise);
+
+ te.getConditionalBlocks().add(fcb);
+ }
+ }
+
if (getOutputVariable() != null) {
+
convertResponse(activities, context);
}
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Scope.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Scope.java 2009-06-20
23:25:56 UTC (rev 648)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Scope.java 2009-06-22
23:10:42 UTC (rev 649)
@@ -534,12 +534,16 @@
context.addVariable(m_variables.get(i));
}
+ // TODO: Count number of invoke activities
+ int invokeCount=countInvokes(getActivity().getDOMElement());
+
// Check whether scope has been defined to represent
// an interaction with one or more fault responses and
// no event handlers
Invoke invoke=null;
- if (m_faultHandlers != null && (m_faultHandlers.getCatchPaths().size() > 0
||
+ if (invokeCount == 1 &&
+ m_faultHandlers != null && (m_faultHandlers.getCatchPaths().size() > 0 ||
m_faultHandlers.getCatchAll() != null) &&
(m_eventHandlers == null || (m_eventHandlers.getOnEvents().size() == 0 &&
m_eventHandlers.getOnAlarms().size() == 0)) &&
@@ -584,9 +588,34 @@
// added
java.util.List<Activity> acts=activities;
- // TODO: Check if try/catch block is required
+ // Check if try/catch block is required
+ if (getFaultHandlers() != null &&
+ (getFaultHandlers().getCatchPaths().size() > 0 ||
+ getFaultHandlers().getCatchAll() != null)) {
+ org.scribble.conversation.model.TryEscape te=
+ new org.scribble.conversation.model.TryEscape();
+
+ acts.add(te);
+
+ acts = te.getBlock().getContents();
+
+ for (int i=0; i < getFaultHandlers().getCatchPaths().size(); i++) {
+ org.scribble.conversation.model.CatchBlock cb=
+ new org.scribble.conversation.model.CatchBlock();
+
+ TypeReference tref=new TypeReference();
+ tref.setAlias(getFaultHandlers().getCatchPaths().get(i).getFaultName());
+ cb.setType(tref);
+
+ if (getFaultHandlers().getCatchPaths().get(i).getActivity() != null) {
+ getFaultHandlers().getCatchPaths().get(i).getActivity().
+ convert(cb.getContents(), context);
+ }
+
+ te.getEscapeBlocks().add(cb);
+ }
+ }
-
// Convert normal activities in scope
if (getActivity() != null) {
getActivity().convert(acts, context);
@@ -607,6 +636,31 @@
return(ret);
}
+
+ /**
+ * This method recursively counts the number of 'invoke' activities
+ * contained within a DOM element.
+ *
+ * @param elem The current element
+ * @return The number of invokes contained within the element
+ */
+ protected int countInvokes(org.w3c.dom.Element elem) {
+ int ret=0;
+
+ if (elem.getLocalName().equals("invoke")) {
+ ret = 1;
+ } else {
+ org.w3c.dom.NodeList nl=elem.getChildNodes();
+
+ for (int i=0; i < nl.getLength(); i++) {
+ if (nl.item(i) instanceof org.w3c.dom.Element) {
+ ret += countInvokes((org.w3c.dom.Element)nl.item(i));
+ }
+ }
+ }
+
+ return(ret);
+ }
private org.w3c.dom.Element m_partnerLinksElem=null;
private org.w3c.dom.Element m_variablesElem=null;
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/ParserTest.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/ParserTest.java 2009-06-20
23:25:56 UTC (rev 648)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/ParserTest.java 2009-06-22
23:10:42 UTC (rev 649)
@@ -44,7 +44,7 @@
suite.addTest(new BPELToConversationTest("ReqRespFault@Buyer"));
suite.addTest(new BPELToConversationTest("ReqRespFault@Seller"));
suite.addTest(new
BPELToConversationTest("LoanApprovalService@Service"));
-
+
return suite;
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/testmodels/LoanApprovalService(a)Service.bpel
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/testmodels/LoanApprovalService(a)Service.bpel 2009-06-20
23:25:56 UTC (rev 648)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/plugintest/org/jboss/tools/overlord/cdl/bpel/parser/testmodels/LoanApprovalService(a)Service.bpel 2009-06-22
23:10:42 UTC (rev 649)
@@ -1,4 +1,4 @@
-<process name="loanApprovalProcess"
xmlns:ns0="http://www.scribble.org/conversation"
ns0:conversationType="LoanApprovalService@Service"
+<process name="loanApprovalProcess"
targetNamespace="http://example.com/loan-approval/"
xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
xmlns:lns="http://example.com/loan-approval/wsdl/"