[savara-commits] savara SVN: r70 - in tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src: java/org/jboss/savara/tools/bpel/model/component and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sat Oct 31 11:49:58 EDT 2009
Author: objectiser
Date: 2009-10-31 11:49:57 -0400 (Sat, 31 Oct 2009)
New Revision: 70
Added:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/util/InteractionUtilTest.java
Modified:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/component/Pick.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/util/InteractionUtil.java
Log:
Define 'createInstance' attribute on appropriate receive and pick constructs.
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java 2009-10-31 12:35:22 UTC (rev 69)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java 2009-10-31 15:49:57 UTC (rev 70)
@@ -238,6 +238,11 @@
if (varName != null) {
((Receive)act).setVariable(varName);
}
+
+ // Check if create instance
+ if (InteractionUtil.isFirstInteraction(interaction)) {
+ ((Receive)act).setCreateInstance(true);
+ }
}
}
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java 2009-10-31 12:35:22 UTC (rev 69)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java 2009-10-31 15:49:57 UTC (rev 70)
@@ -265,6 +265,11 @@
createVariable(varName, recv, bpelModel);
}
+ // Check if create instance
+ if (InteractionUtil.isFirstInteraction(recv)) {
+ act.setCreateInstance(true);
+ }
+
// Set details on interaction
onm.setPartnerLink(pl.getName());
onm.setPortType(portType);
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/component/Pick.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/component/Pick.java 2009-10-31 12:35:22 UTC (rev 69)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/component/Pick.java 2009-10-31 15:49:57 UTC (rev 70)
@@ -32,6 +32,7 @@
private static final long serialVersionUID = -2235972351406517577L;
public static final String PICK = "pick";
+ public static final String CREATE_INSTANCE = "createInstance";
/**
* The constructor for the activity.
@@ -72,6 +73,36 @@
}
/**
+ * This method sets the 'create instance'
+ * attribute.
+ *
+ * @param b Whether to create instance
+ */
+ public void setCreateInstance(boolean b) {
+ String create=(b?"yes":"no");
+
+ getDOMElement().setAttribute(CREATE_INSTANCE, create);
+ }
+
+ /**
+ * This method returns whether to create instance.
+ *
+ * @return Whether to create instance
+ */
+ public boolean getCreateInstance() {
+ boolean ret=false;
+ String create=
+ getDOMElement().getAttribute(CREATE_INSTANCE);
+
+ if (create != null &&
+ create.equals("yes")) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
* This method adds an 'onMessage' to the grouping construct.
*
* @param on The 'onMessage' to be added
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/util/InteractionUtil.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/util/InteractionUtil.java 2009-10-31 12:35:22 UTC (rev 69)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/util/InteractionUtil.java 2009-10-31 15:49:57 UTC (rev 70)
@@ -20,6 +20,7 @@
import org.jboss.savara.tools.bpel.model.component.BPELActivity;
import org.jboss.savara.tools.bpel.model.component.Invoke;
import org.jboss.savara.tools.bpel.model.component.Sequence;
+import org.scribble.conversation.model.If;
import org.scribble.model.*;
/**
@@ -91,6 +92,60 @@
}
/**
+ * This method determines whether this is the first interaction
+ * associated with the conversation.
+ *
+ * @param interaction The interaction
+ * @return Whether the interaction is the first in the conversation
+ */
+ public static boolean isFirstInteraction(Interaction interaction) {
+ boolean ret=false;
+
+ if (interaction.getParent() instanceof Block &&
+ interaction.getParent().getParent() != null) {
+ ModelObject parent=(ModelObject)interaction.getParent().getParent();
+
+ // Check that first interaction in block
+ Block block=(Block)interaction.getParent();
+ ret = true;
+
+ for (int i=0; ret && i < block.getContents().size(); i++) {
+ if (block.getContents().get(i) == interaction) {
+ break;
+ } else if (block.getContents().get(i) instanceof Interaction) {
+ ret = false;
+ }
+ }
+
+ // Check if definition
+ if (ret) {
+
+ if (parent instanceof If) {
+ if (parent.getParent() instanceof Block) {
+ parent = parent.getParent().getParent();
+ }
+ }
+
+ if (parent instanceof Definition) {
+
+ // Check if it is the top level definition
+ ret = (parent.getParent() instanceof Model);
+
+ // TODO: How do we know if this conversation is the
+ // top level, or has it been 'run' by the top level
+ // conversation? While the conversation used to
+ // generate the BPEL is produced as one definition,
+ // this should not be a problem.
+ } else {
+ ret = false;
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
* This method determines whether the supplied activity
* is either an invoke, or a sequence that has an
* invoke as its first element.
Added: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/util/InteractionUtilTest.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/util/InteractionUtilTest.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/util/InteractionUtilTest.java 2009-10-31 15:49:57 UTC (rev 70)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.bpel.util;
+
+import junit.framework.TestCase;
+
+import org.jboss.savara.tools.bpel.model.util.InteractionUtil;
+import org.scribble.conversation.model.*;
+import org.scribble.model.*;
+
+public class InteractionUtilTest extends TestCase {
+
+ public void testIsFirstInteractionSingleInteraction() {
+ ConversationModel cm=new ConversationModel();
+ Conversation c=new Conversation();
+ cm.setConversation(c);
+
+ Interaction i1=new Interaction();
+
+ c.getBlock().getContents().add(i1);
+
+ if (InteractionUtil.isFirstInteraction(i1) == false) {
+ fail("Interaction should be first in conversation");
+ }
+ }
+
+ public void testIsFirstInteractionSecondInteraction() {
+ ConversationModel cm=new ConversationModel();
+ Conversation c=new Conversation();
+ cm.setConversation(c);
+
+ Interaction i1=new Interaction();
+ Interaction i2=new Interaction();
+
+ c.getBlock().getContents().add(i1);
+ c.getBlock().getContents().add(i2);
+
+ if (InteractionUtil.isFirstInteraction(i2)) {
+ fail("Interaction should NOT be first in conversation");
+ }
+ }
+
+ public void testIsFirstInteractionIfElse() {
+ ConversationModel cm=new ConversationModel();
+ Conversation c=new Conversation();
+ cm.setConversation(c);
+
+ If choice=new If();
+ c.getBlock().getContents().add(choice);
+
+ Block b=choice.createNewPath();
+
+ Interaction i1=new Interaction();
+
+ b.getContents().add(i1);
+
+ Block b2=choice.createNewPath();
+
+ Interaction i2=new Interaction();
+ Interaction i3=new Interaction();
+
+ b2.getContents().add(i2);
+ b2.getContents().add(i3);
+
+ if (InteractionUtil.isFirstInteraction(i1) == false) {
+ fail("Interaction should be first in conversation");
+ }
+
+ if (InteractionUtil.isFirstInteraction(i2) == false) {
+ fail("Interaction should be first in conversation");
+ }
+
+ if (InteractionUtil.isFirstInteraction(i3)) {
+ fail("Interaction should NOT be first in conversation");
+ }
+ }
+}
More information about the savara-commits
mailing list