Author: objectiser
Date: 2008-09-29 10:57:24 -0400 (Mon, 29 Sep 2008)
New Revision: 352
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/AbstractESBModelChangeRule.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ConversationInteractionModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/IfModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ParallelModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/RunModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/SpawnModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhileModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/test/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRuleTest.java
Log:
Refactor model change rules to derive from ESB specific abstract class. Modify
'when' model change insertion to cater for insertion in any position - and define
appropriate tests.
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/AbstractESBModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/AbstractESBModelChangeRule.java
(rev 0)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/AbstractESBModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -0,0 +1,101 @@
+/*
+ * 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.tools.overlord.cdl.jbossesb.model.change;
+
+import org.jboss.tools.overlord.cdl.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.jbossesb.model.actions.*;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+
+/**
+ * This is the abstract ESB model change rule.
+ */
+public abstract class AbstractESBModelChangeRule extends AbstractModelChangeRule {
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context) and inserted
+ * model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param mobj The model object being inserted
+ * @param ref The optional reference model object
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ public boolean isInsertSupported(ModelChangeContext context,
+ Model model, ModelObject mobj, ModelObject ref) {
+ boolean ret=false;
+
+ if ((context.getParent() instanceof ESBService ||
+ (ref != null && ref.getSource().getObject()
+ instanceof AbstractESBAction &&
+ ((AbstractESBAction)ref.getSource().getObject()).getService() != null)) &&
+ model instanceof ESBLanguageModel) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the ESB service associated with the
+ * optional model object reference or the context.
+ *
+ * @param context The context
+ * @param ref The optional model object
+ * @return The ESB service, or null if not found
+ */
+ protected ESBService getESBService(ModelChangeContext context,
+ ModelObject ref) {
+ ESBService ret=(ESBService)context.getParent();
+
+ if (ref != null && ref.getSource().getObject() instanceof AbstractESBAction) {
+ ret = ((AbstractESBAction)ref.getSource().getObject()).getService();
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method determines whether an 'initiator' action,
+ * inserted at the defined position in the specified
+ * service, should actually be placed in a new scheduled
+ * service.
+ *
+ * @param service The current service
+ * @param pos The insertion position in that service
+ * @return Whether a new service needs to be scheduled to
+ * accommodate the initiator action
+ */
+ protected boolean shouldScheduleNewService(ESBService service,
+ int pos) {
+ boolean ret=false;
+
+ for (int i=0; ret == false && i < pos; i++) {
+ ESBAction action=service.getActions().get(i);
+
+ if (action.isSessionBased() && !action.isCreateSession()) {
+ ret = true;
+ }
+ }
+
+ return(ret);
+ }
+}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ConversationInteractionModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ConversationInteractionModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ConversationInteractionModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -31,7 +31,7 @@
* This is the model change rule for the Conversation Interaction.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class ConversationInteractionModelChangeRule extends AbstractModelChangeRule {
+public class ConversationInteractionModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -51,11 +51,7 @@
boolean ret=false;
if (mobj instanceof ConversationInteraction &&
- (context.getParent() instanceof ESBService ||
- (ref != null && ref.getSource().getObject()
- instanceof AbstractESBAction &&
- ((AbstractESBAction)ref.getSource().getObject()).getService() != null)) &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
@@ -253,17 +249,6 @@
}
}
- protected ESBService getESBService(ModelChangeContext context,
- ModelObject ref) {
- ESBService ret=(ESBService)context.getParent();
-
- if (ref != null && ref.getSource().getObject() instanceof AbstractESBAction) {
- ret = ((AbstractESBAction)ref.getSource().getObject()).getService();
- }
-
- return(ret);
- }
-
protected void insertReceive(ModelChangeContext context,
ESBLanguageModel esbModel, ConversationInteraction interaction,
ModelObject ref) {
@@ -372,8 +357,6 @@
// Check if existing actions need to be moved
if (pos != -1 && service != endService) {
for (int i=pos+1; i < service.getActions().size();) {
- //ESBService extraService=(ESBService)context.getParent();
-
ESBAction act=service.getActions().get(i);
service.getActions().remove(i);
@@ -427,21 +410,6 @@
}
}
- protected boolean shouldScheduleNewService(ESBService service,
- int pos) {
- boolean ret=false;
-
- for (int i=0; ret == false && i < pos; i++) {
- ESBAction action=service.getActions().get(i);
-
- if (action.isSessionBased() && !action.isCreateSession()) {
- ret = true;
- }
- }
-
- return(ret);
- }
-
/**
* This method determines whether the rule is appropriate
* for the supplied type of model, parent (in the context)
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/IfModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/IfModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/IfModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -33,7 +33,7 @@
* This is the model change rule for the If grouping construct.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class IfModelChangeRule extends AbstractModelChangeRule {
+public class IfModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -52,8 +52,7 @@
boolean ret=false;
if (mobj instanceof If &&
- context.getParent() instanceof ESBService &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ParallelModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ParallelModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/ParallelModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -32,7 +32,7 @@
* This is the model change rule for the Parallel grouping construct.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class ParallelModelChangeRule extends AbstractModelChangeRule {
+public class ParallelModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -51,8 +51,7 @@
boolean ret=false;
if (mobj instanceof Parallel &&
- context.getParent() instanceof ESBService &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/RunModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/RunModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/RunModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -32,7 +32,7 @@
* This is the model change rule for the Run composition construct.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class RunModelChangeRule extends AbstractModelChangeRule {
+public class RunModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -51,8 +51,7 @@
boolean ret=false;
if (mobj instanceof Run &&
- context.getParent() instanceof ESBService &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/SpawnModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/SpawnModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/SpawnModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -31,7 +31,7 @@
* This is the model change rule for the Spawn composition construct.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class SpawnModelChangeRule extends AbstractModelChangeRule {
+public class SpawnModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -50,8 +50,7 @@
boolean ret=false;
if (mobj instanceof Spawn &&
- context.getParent() instanceof ESBService &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -32,7 +32,7 @@
* This is the model change rule for the When grouping construct.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class WhenModelChangeRule extends AbstractModelChangeRule {
+public class WhenModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -51,8 +51,7 @@
boolean ret=false;
if (mobj instanceof When &&
- context.getParent() instanceof ESBService &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
@@ -90,9 +89,19 @@
public boolean insert(ModelChangeContext context,
Model model, ModelObject mobj, ModelObject ref) {
ESBLanguageModel esbModel=(ESBLanguageModel)model;
- ESBService service=(ESBService)context.getParent();
+ ESBService service=getESBService(context, ref);
When when=(When)mobj;
+ int pos=-1;
+
+ // Check if reference model object provided, and if so,
+ // if it has a position within the service
+ if (ref != null && ref.getSource().getObject() instanceof ESBAction) {
+ pos = service.getActions().indexOf((ESBAction)
+ ref.getSource().getObject());
+ }
+
+ // Create join service
ESBService joinService=
esbModel.createService(service.getCategory(),
esbModel.getUniqueServiceName(service.getCategory(),
@@ -102,158 +111,218 @@
// Check if context role is decision maker
if (when.getRoles().contains(context.getRole())) {
- WhenAction action=new WhenAction(service);
- service.addAction(action, -1);
-
- for (int i=0; i < when.getConditionalBlocks().size(); i++) {
- ConditionalBlock b=when.getConditionalBlocks().get(i);
+ insertWhen(context, model, service,
+ when, joinService, pos);
+ } else {
+ insertSwitch(context, model, service,
+ when, joinService, pos);
+ }
+
+ context.setParent(joinService);
+
+ // If reference provided, then move subsequent activities
+ // to the 'join service'
+ if (pos != -1) {
+ for (int i=pos+1; i < service.getActions().size();) {
+ ESBAction act=service.getActions().get(i);
+ service.getActions().remove(i);
- ESBService subService=
- esbModel.createService(service.getCategory(),
- esbModel.getUniqueServiceName(service.getCategory(),
- service.getName()));
-
- esbModel.addService(subService);
+ joinService.addAction(act, -1);
+ }
+ }
+
+ return(true);
+ }
- context.setParent(subService);
-
- for (int j=0; j < b.getContents().size(); j++) {
- context.insert(model, b.getContents().get(j), null);
- }
-
- ScheduleStateAction schedule=
- new ScheduleStateAction((ESBService)context.getParent());
-
- schedule.setDestination(joinService.getCategory(),
- joinService.getName(), true);
-
- ((ESBService)context.getParent()).addAction(schedule, -1);
+ protected void insertWhen(ModelChangeContext context,
+ Model model, ESBService service,
+ When when, ESBService joinService, int pos) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+
+ WhenAction action=new WhenAction(service);
+
+ service.addAction(action, pos);
+
+ for (int i=0; i < when.getConditionalBlocks().size(); i++) {
+ ConditionalBlock b=when.getConditionalBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
- if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
- when.getEnclosingDefinition() instanceof Conversation) {
- schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
- ((Conversation)when.getEnclosingDefinition())));
- }
+ context.setParent(subService);
+
+ for (int j=0; j < b.getContents().size(); j++) {
+ context.insert(model, b.getContents().get(j), null);
+ }
- action.addPath(subService.getCategory(),
- subService.getName(), i);
- }
+ ScheduleStateAction schedule=
+ new ScheduleStateAction((ESBService)context.getParent());
- if (service.getFirstSessionBasedAction() == action &&
+ schedule.setDestination(joinService.getCategory(),
+ joinService.getName(), true);
+
+ ((ESBService)context.getParent()).addAction(schedule, -1);
+
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
when.getEnclosingDefinition() instanceof Conversation) {
- action.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
((Conversation)when.getEnclosingDefinition())));
}
- } else {
+
+ action.addPath(subService.getCategory(),
+ subService.getName(), i);
+ }
+
+ if (service.getFirstSessionBasedAction() == action &&
+ when.getEnclosingDefinition() instanceof Conversation) {
+ action.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)when.getEnclosingDefinition())));
+ }
+ }
+
+ protected void insertSwitch(ModelChangeContext context,
+ Model model, ESBService service,
+ When when, ESBService joinService, int pos) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+
+ // Check if receive needs to be placed in new service
+ // descriptor - i.e. if insert at end, but current service
+ // already has service based actions, or reference object
+ // provided, but is not first position
+ if (shouldScheduleNewService(service, (pos == -1 ?
+ service.getActions().size() : pos))) {
- // Switch action, as role is a decision observer
- SwitchAction switchAction=new SwitchAction(service);
+ // Already has activities, so need to separate
+ // into another service descriptor
+ ESBService switchService=esbModel.createService(
+ service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(switchService);
- // Get lookahead analyser
- LookaheadAnalyser la=(LookaheadAnalyser)
- RegistryFactory.getRegistry().getExtension(
- LookaheadAnalyser.class, null);
+ // Add schedule action
+ ScheduleStateAction schedule=
+ new ScheduleStateAction(service);
- if (la == null) {
- logger.severe("Failed to find lookahead analyser");
- }
+ schedule.setDestination(switchService.getCategory(),
+ switchService.getName(), false);
- service.addAction(switchAction, -1);
+ service.addAction(schedule, pos);
+
+ context.setParent(switchService);
- java.util.List<MessageSignature> messageTypes=
- new java.util.Vector<MessageSignature>();
+ service = switchService;
+ pos = -1;
+ }
- for (int i=0; i < when.getConditionalBlocks().size(); i++) {
- ConditionalBlock cb=when.getConditionalBlocks().get(i);
-
- ESBService subService=
- esbModel.createService(service.getCategory(),
- esbModel.getUniqueServiceName(service.getCategory(),
- service.getName()));
+ // Switch action, as role is a decision observer
+ SwitchAction switchAction=new SwitchAction(service);
+
+ // Get lookahead analyser
+ LookaheadAnalyser la=(LookaheadAnalyser)
+ RegistryFactory.getRegistry().getExtension(
+ LookaheadAnalyser.class, null);
+
+ if (la == null) {
+ logger.severe("Failed to find lookahead analyser");
+ }
+
+ service.addAction(switchAction, pos);
+
+ java.util.List<MessageSignature> messageTypes=
+ new java.util.Vector<MessageSignature>();
- esbModel.addService(subService);
+ for (int i=0; i < when.getConditionalBlocks().size(); i++) {
+ ConditionalBlock cb=when.getConditionalBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
- context.setParent(subService);
-
- for (int j=0; j < cb.getContents().size(); j++) {
- context.insert(model, cb.getContents().get(j), null);
- }
+ esbModel.addService(subService);
- java.util.Set<Interaction> interactions=null;
-
- if (la != null) {
- interactions = la.getInteractions(cb);
- }
-
- switchAction.addCase(subService.getCategory(),
- subService.getName(), interactions, i);
+ context.setParent(subService);
+
+ for (int j=0; j < cb.getContents().size(); j++) {
+ context.insert(model, cb.getContents().get(j), null);
+ }
- ScheduleStateAction schedule=
- new ScheduleStateAction((ESBService)context.getParent());
-
- schedule.setDestination(joinService.getCategory(),
- joinService.getName(), true);
-
- ((ESBService)context.getParent()).addAction(schedule, -1);
+ java.util.Set<Interaction> interactions=null;
+
+ if (la != null) {
+ interactions = la.getInteractions(cb);
+ }
+
+ switchAction.addCase(subService.getCategory(),
+ subService.getName(), interactions, i);
- if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
- when.getEnclosingDefinition() instanceof Conversation) {
- schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
- ((Conversation)when.getEnclosingDefinition())));
- }
+ ScheduleStateAction schedule=
+ new ScheduleStateAction((ESBService)context.getParent());
+
+ schedule.setDestination(joinService.getCategory(),
+ joinService.getName(), true);
+
+ ((ESBService)context.getParent()).addAction(schedule, -1);
- if (interactions != null) {
- java.util.Iterator<Interaction> iter=interactions.iterator();
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
+ when.getEnclosingDefinition() instanceof Conversation) {
+ schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)when.getEnclosingDefinition())));
+ }
+
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
+
+ while (iter.hasNext()) {
+ Interaction interaction=iter.next();
- while (iter.hasNext()) {
- Interaction interaction=iter.next();
-
- //TODO: Only deals with single type for now
- // If a receive and not a response, then
- // add to the gateway
- if (InteractionUtil.isSend(interaction) == false &&
- interaction.getReplyToLabel() == null &&
- interaction.getMessageSignature().getTypes().size()==1) {
-
- messageTypes.add(interaction.getMessageSignature());
- }
+ //TODO: Only deals with single type for now
+ // If a receive and not a response, then
+ // add to the gateway
+ if (InteractionUtil.isSend(interaction) == false &&
+ interaction.getReplyToLabel() == null &&
+ interaction.getMessageSignature().getTypes().size()==1) {
+
+ messageTypes.add(interaction.getMessageSignature());
}
}
}
+ }
- // Only record message router 'routes' if the switch
- // receives request interactions, and it is the first
- // session based action in the service
- if (messageTypes.size() > 0 &&
- service.getFirstSessionBasedAction() == switchAction) {
- ESBService gwService=
- esbModel.getGatewayService();
+ // Only record message router 'routes' if the switch
+ // receives request interactions, and it is the first
+ // session based action in the service
+ if (messageTypes.size() > 0 &&
+ service.getFirstSessionBasedAction() == switchAction) {
+ ESBService gwService=
+ esbModel.getGatewayService();
+
+ if (gwService != null) {
+ ESBAction gwAction=gwService.getGatewayAction();
- if (gwService != null) {
- ESBAction gwAction=gwService.getGatewayAction();
+ if (gwAction instanceof MessageRouterAction) {
+ MessageRouterAction mra=(MessageRouterAction)
+ gwAction;
- if (gwAction instanceof MessageRouterAction) {
- MessageRouterAction mra=(MessageRouterAction)
- gwAction;
-
- mra.addRoute(service.getCategory(),
- service.getName(),
- false, messageTypes);
- }
- }
- }
-
- if (service.getFirstSessionBasedAction() == switchAction &&
- when.getEnclosingDefinition() instanceof Conversation) {
- switchAction.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
- ((Conversation)when.getEnclosingDefinition())));
- }
+ mra.addRoute(service.getCategory(),
+ service.getName(),
+ false, messageTypes);
+ }
+ }
}
-
- context.setParent(joinService);
-
- return(true);
+
+ if (service.getFirstSessionBasedAction() == switchAction &&
+ when.getEnclosingDefinition() instanceof Conversation) {
+ switchAction.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)when.getEnclosingDefinition())));
+ }
}
private static Logger logger =
Logger.getLogger("org.jboss.tools.overlord.cdl.jbossesb.model.change");
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhileModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhileModelChangeRule.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhileModelChangeRule.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -32,7 +32,7 @@
* This is the model change rule for the While repetition construct.
*/
@RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
-public class WhileModelChangeRule extends AbstractModelChangeRule {
+public class WhileModelChangeRule extends AbstractESBModelChangeRule {
/**
* This method determines whether the rule is appropriate
@@ -51,8 +51,7 @@
boolean ret=false;
if (mobj instanceof While &&
- context.getParent() instanceof ESBService &&
- model instanceof ESBLanguageModel) {
+ super.isInsertSupported(context, model, mobj, ref)) {
ret = true;
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/test/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRuleTest.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/test/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRuleTest.java 2008-09-28
17:38:27 UTC (rev 351)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/test/org/jboss/tools/overlord/cdl/jbossesb/model/change/WhenModelChangeRuleTest.java 2008-09-29
14:57:24 UTC (rev 352)
@@ -226,6 +226,194 @@
}
}
+ public void testInsertWhenActionWithSubsequentActions() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestESBAction act1=new TestESBAction();
+ service.addAction(act1, -1);
+
+ ModelObject ref=new ModelObject() {};
+ ref.getSource().setObject(act1);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ context.setRole(role);
+
+ When mobj=new When();
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ ConditionalBlock cb2=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb2);
+
+ ConditionalBlock cb3=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb3);
+
+ mobj.getRoles().add(role);
+
+ if (rule.insert(context, model, mobj, ref) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 actions: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof WhenAction) == false) {
+ fail("Action was not WhenAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 5) {
+ fail("Five services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ ESBService s3=null;
+ ESBService join=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null ||
+ s3 == null || join == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ join = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__2")) {
+ s2 = serv;
+ }
+ if (serv.getName().endsWith("__3")) {
+ s3 = serv;
+ }
+ }
+
+ if (join.getActions().size() != 1) {
+ fail("Join service does not have 1 action: "+join.getActions().size());
+ }
+
+ if (join.getActions().get(0) != act1) {
+ fail("Join action is not test ESB action");
+ }
+ }
+
+
+ public void testInsertWhenActionWithPrecedingActions() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestESBAction act1=new TestESBAction();
+ service.addAction(act1, -1);
+
+ TestESBAction act2=new TestESBAction();
+ service.addAction(act2, -1);
+
+ ModelObject ref=new ModelObject() {};
+ ref.getSource().setObject(act2);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ context.setRole(role);
+
+ When mobj=new When();
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ ConditionalBlock cb2=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb2);
+
+ ConditionalBlock cb3=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb3);
+
+ mobj.getRoles().add(role);
+
+ if (rule.insert(context, model, mobj, ref) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 2) {
+ fail("Expecting 2 actions: "+service.getActions().size());
+ }
+
+ if (service.getActions().get(0) != act1) {
+ fail("Action 1 was not test ESB action");
+ }
+
+ if ((service.getActions().get(1) instanceof WhenAction) == false) {
+ fail("Action 2 was not WhenAction: "+service.getActions().get(1));
+ }
+
+ if (model.getServices().size() != 5) {
+ fail("Five services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ ESBService s3=null;
+ ESBService join=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null ||
+ s3 == null || join == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ join = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__2")) {
+ s2 = serv;
+ }
+ if (serv.getName().endsWith("__3")) {
+ s3 = serv;
+ }
+ }
+
+ if (join.getActions().size() != 1) {
+ fail("Join service does not have 1 action: "+join.getActions().size());
+ }
+
+ if (join.getActions().get(0) != act2) {
+ fail("Join action is not test ESB action 2");
+ }
+ }
+
public void testInsertSwitchAction() {
WhenModelChangeRule rule=new WhenModelChangeRule();
@@ -510,4 +698,206 @@
schedule.getPropertyValue(ScheduleStateAction.SERVICE_NAME));
}
}
+
+ public void testInsertSwitchActionWithSubsequentActions() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestESBAction act1=new TestESBAction();
+ service.addAction(act1, -1);
+
+ ModelObject ref=new ModelObject() {};
+ ref.getSource().setObject(act1);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role1=new Role();
+ role1.setName("role1");
+
+ Role role2=new Role();
+ role2.setName("role2");
+
+ context.setRole(role1);
+
+ When mobj=new When();
+
+ mobj.getRoles().add(role2);
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ ConditionalBlock cb2=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb2);
+
+ ConditionalBlock cb3=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb3);
+
+ if (rule.insert(context, model, mobj, ref) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof SwitchAction) == false) {
+ fail("Action was not SwitchAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 5) {
+ fail("Five services expected: "+model.getServices().size());
+ }
+
+ ESBService join=null;
+ ESBService caseService1=null;
+ ESBService caseService2=null;
+ ESBService caseService3=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((caseService1 == null || caseService2 == null ||
+ caseService3 == null || join == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ join = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ caseService1 = serv;
+ }
+ if (serv.getName().endsWith("__2")) {
+ caseService2 = serv;
+ }
+ if (serv.getName().endsWith("__3")) {
+ caseService3 = serv;
+ }
+ }
+
+ if (join.getActions().size() != 1) {
+ fail("Join service does not have 1 action: "+join.getActions().size());
+ }
+
+ if (join.getActions().get(0) != act1) {
+ fail("Join action is not test ESB action");
+ }
+ }
+
+ public void testInsertSwitchActionWithPrecedingActions() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestESBAction act1=new TestESBAction();
+ act1.setInitiator(true);
+ act1.setSessionBased(true);
+ service.addAction(act1, -1);
+
+ TestESBAction act2=new TestESBAction();
+ service.addAction(act2, -1);
+
+ ModelObject ref=new ModelObject() {};
+ ref.getSource().setObject(act2);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role1=new Role();
+ role1.setName("role1");
+
+ Role role2=new Role();
+ role2.setName("role2");
+
+ context.setRole(role1);
+
+ When mobj=new When();
+
+ mobj.getRoles().add(role2);
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ ConditionalBlock cb2=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb2);
+
+ ConditionalBlock cb3=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb3);
+
+ if (rule.insert(context, model, mobj, ref) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 2) {
+ fail("Expecting 2 action: "+service.getActions().size());
+ }
+
+ if (service.getActions().get(0) != act1) {
+ fail("First action not test ESB action");
+ }
+
+ if ((service.getActions().get(1) instanceof ScheduleStateAction) == false) {
+ fail("Action was not ScheduleStateAction: "+service.getActions().get(1));
+ }
+
+ ScheduleStateAction schedule=(ScheduleStateAction)service.getActions().get(1);
+
+ ESBService addedService=model.getService(
+ schedule.getPropertyValue(ScheduleStateAction.SERVICE_CATEGORY),
+ schedule.getPropertyValue(ScheduleStateAction.SERVICE_NAME));
+
+ if (addedService == null) {
+ fail("Failed to find service '"+
+ schedule.getPropertyValue(ScheduleStateAction.SERVICE_CATEGORY)+"'
'"+
+ schedule.getPropertyValue(ScheduleStateAction.SERVICE_NAME)+"'");
+ }
+
+ if (addedService.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((addedService.getActions().get(0) instanceof SwitchAction) == false) {
+ fail("Action was not SwitchAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 6) {
+ fail("Five services expected: "+model.getServices().size());
+ }
+
+ ESBService join=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while (join == null && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ join = serv;
+ }
+ }
+
+ if (join.getActions().size() != 1) {
+ fail("Join service does not have 1 action: "+join.getActions().size());
+ }
+
+ if (join.getActions().get(0) != act2) {
+ fail("Join action is not test ESB action");
+ }
+ }
}