Author: objectiser
Date: 2009-01-24 18:36:19 -0500 (Sat, 24 Jan 2009)
New Revision: 469
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/ConversationInteractionModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/IfModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/LanguageToConversationModelChangeRule.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/META-INF/MANIFEST.MF
Log:
Add some initial model change rules for the stateless model.
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/META-INF/MANIFEST.MF
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/META-INF/MANIFEST.MF 2009-01-24
23:02:09 UTC (rev 468)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/META-INF/MANIFEST.MF 2009-01-24
23:36:19 UTC (rev 469)
@@ -24,6 +24,10 @@
org.jboss.tools.overlord.cdl.runtime.jbossesb.editor.JBossESBConfigEditorManager,
org.jboss.tools.overlord.cdl.runtime.jbossesb.validation.ESBLanguageModelValidationRule,
org.jboss.tools.overlord.cdl.runtime.jbossesb.export.ESBLanguageModelStreamExportRule,
+
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateless.LanguageToConversationModelChangeRule,
+
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateless.ConversationModelChangeRule,
+
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateless.ConversationInteractionModelChangeRule,
+
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateless.IfModelChangeRule,
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateful.LanguageToConversationModelChangeRule,
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateful.ConversationModelChangeRule,
org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateful.ConversationInteractionModelChangeRule,
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/ConversationInteractionModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/ConversationInteractionModelChangeRule.java
(rev 0)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/ConversationInteractionModelChangeRule.java 2009-01-24
23:36:19 UTC (rev 469)
@@ -0,0 +1,559 @@
+/*
+ * 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.runtime.jbossesb.model.change.stateless;
+
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.actions.stateless.*;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.util.ConversationUtil;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.util.IdentityUtil;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.util.InteractionUtil;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.RegistryInfo;
+
+/**
+ * This is the model change rule for the Conversation Interaction.
+ */
+(a)RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class ConversationInteractionModelChangeRule extends
AbstractStatelessESBModelChangeRule {
+
+ /**
+ * 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 (mobj instanceof ConversationInteraction &&
+ super.isInsertSupported(context, model, mobj, ref)) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.<p>
+ * <p>
+ * If a reference model object is supplied, then the
+ * insertion will occur relative to it. If the reference
+ * object is a block, then it means that the insertion
+ * should occur at the end of the block. Otherwise the
+ * new model object should be inserted before the
+ * reference object, within the containing block.<p>
+ * <p>
+ * If the reference object is not supplied, then the
+ * new model object should be inserted at the end of
+ * the behaviour associated with the parent in the model
+ * change context.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param ref The optional reference model object
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, ModelObject ref) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+ ConversationInteraction interaction=(ConversationInteraction)mobj;
+
+ // Check if send or receive
+ if (InteractionUtil.isSend(interaction)) {
+
+ // Send
+ insertSend(context, esbModel, interaction, ref);
+
+ } else {
+ // Receive
+ insertReceive(context, esbModel, interaction, ref);
+ }
+
+ return(true);
+ }
+
+ protected void insertSend(ModelChangeContext context,
+ ESBLanguageModel esbModel, ConversationInteraction interaction,
+ ModelObject ref) {
+ ESBService service=getESBService(context, ref);
+
+ SendMessageAction action=
+ new SendMessageAction(service);
+
+ if (interaction.getMessageSignature().getOperation() != null) {
+ action.setOperation(interaction.getMessageSignature().getOperation());
+ }
+
+ setMessageType(action, interaction);
+
+ boolean f_subsequentInitiator=false;
+ boolean f_moveActions=false;
+
+ // Check if reference model object provided, and if so,
+ // if it has a position within the service
+ int pos=getPosition(service, ref);
+
+ // Check if subsequent action(s) are initiators
+ if (pos != -1) {
+ for (int i=pos; f_subsequentInitiator == false &&
+ i < service.getActions().size(); i++) {
+ f_subsequentInitiator =
+ service.getActions().get(i).isInitiator();
+ }
+ }
+
+ // Move actions if a subsequent initiator has been found
+ f_moveActions = f_subsequentInitiator;
+
+ service.addAction(action, pos);
+
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == action
&&
+ interaction.getEnclosingDefinition() instanceof Conversation) {
+ action.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)interaction.getEnclosingDefinition())));
+ }
+
+ /* IS REQUIRED??
+ if (interaction.getRequestLabel() != null) {
+
+ // Create new ESB service
+ ESBService respService=esbModel.createService(
+ service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(respService);
+
+ action.setResponseDestination(respService.getCategory(),
+ respService.getName());
+
+ context.setParent(respService);
+
+ // Clear the sub-sequent initiator flag, as
+ // subsequent actions will be moved to new service
+ // anyway
+ f_subsequentInitiator = false;
+
+ } else if (interaction.getReplyToLabel() != null) {
+
+ if (interaction.getToRole() != null) {
+ action.setClientEPR(interaction.getToRole().getName());
+ } else {
+ action.setClientEPR("client");
+ }
+ }
+
+ // Check if subsequent initiator found, requiring
+ // a new service
+ if (f_subsequentInitiator) {
+
+ ESBService extraService=esbModel.createService(
+ service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(extraService);
+
+ // Add schedule action
+ ScheduleStateAction schedule=
+ new ScheduleStateAction(service);
+
+ schedule.setDestination(extraService.getCategory(),
+ extraService.getName(), false);
+
+ service.addAction(schedule, pos+1);
+
+ // Move pointer on, as now additional 'schedule' action
+ pos++;
+
+ context.setParent(extraService);
+ }
+
+ // Check if existing actions need to be moved
+ if (f_moveActions) {
+ for (int i=pos+1; i < service.getActions().size();) {
+ ESBService extraService=(ESBService)context.getParent();
+
+ ESBAction act=service.getActions().get(i);
+ service.getActions().remove(i);
+
+ extraService.addAction(act, -1);
+ }
+ }
+
+ // If not reply, then include the target service
+ // details
+ if (interaction.getReplyToLabel() == null &&
+ interaction.getToRole() != null &&
+ interaction.getToRole().getName() != null &&
+ interaction.getToRole().getName().length() > 0) {
+ String roleName=Character.toLowerCase(
+ interaction.getToRole().getName().charAt(0))+
+ interaction.getToRole().getName().substring(1);
+
+ action.setDestinationExpression(
+ InteractionUtil.getRoleServiceCategoryProperty(roleName),
+ InteractionUtil.getRoleServiceNameProperty(roleName));
+ }
+
+ if (interaction.getEnclosingDefinition() instanceof Conversation &&
+ interaction.getEnclosingDefinition().getModel()
+ instanceof ConversationModel) {
+
+ java.util.List<Identity> ids=((Conversation)
+ interaction.getEnclosingDefinition()).getIdentities();
+
+ java.util.List<IdentityLocator> locators=
+ ((ConversationModel)interaction.getEnclosingDefinition().
+ getModel()).getIdentityLocators();
+
+ IdentityUtil.defineIdentities(action.getPropertyElement(
+ SendMessageAction.IDENTITIES),
+ interaction.getMessageSignature(), ids, locators);
+ }
+ */
+ }
+
+ protected void insertReceive(ModelChangeContext context,
+ ESBLanguageModel esbModel, ConversationInteraction interaction,
+ ModelObject ref) {
+ ESBService service=getESBService(context, ref);
+ ESBService endService=service;
+
+ int endPos=-1;
+ boolean f_subsequentInitiator=false;
+
+ // Check if reference model object provided, and if so,
+ // if it has a position within the service
+ int pos=getPosition(service, ref);
+
+ // Check if subsequent action(s) are initiators
+ if (pos != -1) {
+ for (int i=pos; f_subsequentInitiator == false &&
+ i < service.getActions().size(); i++) {
+ f_subsequentInitiator =
+ service.getActions().get(i).isInitiator();
+ }
+ }
+
+ endPos = pos;
+
+ // 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
+
+ /* IS THIS REQUIRED??
+ if (shouldScheduleNewService(service, (pos == -1 ?
+ service.getActions().size() : pos))) {
+
+ // Already has activities, so need to separate
+ // into another service descriptor
+ ESBService recvService=esbModel.createService(
+ service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(recvService);
+
+ // Add schedule action
+ ScheduleStateAction schedule=
+ new ScheduleStateAction(service);
+
+ schedule.setDestination(recvService.getCategory(),
+ recvService.getName(), false);
+
+ service.addAction(schedule, pos);
+
+ context.setParent(recvService);
+
+ endService = recvService;
+ endPos = 0;
+ }
+ */
+
+ ReceiveMessageAction action=
+ new ReceiveMessageAction(endService);
+
+ if (interaction.getMessageSignature().getOperation() != null) {
+ action.setOperation(interaction.getMessageSignature().getOperation());
+ }
+
+ setMessageType(action, interaction);
+
+ endService.addAction(action, endPos);
+
+ if (endService.getFirstSessionBasedAction() == action &&
+ interaction.getEnclosingDefinition() instanceof Conversation) {
+ action.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)interaction.getEnclosingDefinition())));
+ }
+
+ // Check if subsequent initiator found, requiring
+ // a new service
+ /* IS STILL REQUIRED?
+ if (f_subsequentInitiator) {
+
+ ESBService extraService=esbModel.createService(
+ service.getCategory(),
+ esbModel.getUniqueServiceName(endService.getCategory(),
+ endService.getName()));
+
+ esbModel.addService(extraService);
+
+ // Add schedule action
+ ScheduleStateAction schedule=
+ new ScheduleStateAction(endService);
+
+ schedule.setDestination(extraService.getCategory(),
+ extraService.getName(), false);
+
+ endService.addAction(schedule, endPos+1);
+
+ // Move pointer on, as now additional 'schedule' action
+ pos++;
+
+ context.setParent(extraService);
+
+ endService = extraService;
+ endPos = -1;
+ }
+
+ // Check if existing actions need to be moved
+ if (pos != -1 && service != endService) {
+ for (int i=pos+1; i < service.getActions().size();) {
+ ESBAction act=service.getActions().get(i);
+ service.getActions().remove(i);
+
+ endService.addAction(act, -1);
+ }
+ }
+
+ // If not a response, then add to the gateway
+ if (interaction.getReplyToLabel() == null) {
+ ESBService gwService=esbModel.getGatewayService();
+
+ if (gwService != null) {
+ ESBAction gwAction=gwService.getGatewayAction();
+
+ if (gwAction instanceof MessageRouterAction) {
+ MessageRouterAction mra=(MessageRouterAction)
+ gwAction;
+
+ java.util.List<MessageSignature> mtypes=
+ new java.util.Vector<MessageSignature>();
+ mtypes.add(interaction.getMessageSignature());
+
+ mra.addRoute(endService.getCategory(),
+ endService.getName(),
+ service.isRoot(), mtypes);
+ }
+ }
+
+ // Set client EPR
+ if (interaction.getFromRole() != null) {
+ action.setClientEPR(interaction.getFromRole().getName());
+ } else {
+ action.setClientEPR("client");
+ }
+ }
+
+ if (interaction.getEnclosingDefinition() instanceof Conversation &&
+ interaction.getEnclosingDefinition().getModel()
+ instanceof ConversationModel) {
+
+ java.util.List<Identity> ids=((Conversation)
+ interaction.getEnclosingDefinition()).getIdentities();
+
+ java.util.List<IdentityLocator> locators=
+ ((ConversationModel)interaction.getEnclosingDefinition().
+ getModel()).getIdentityLocators();
+
+ IdentityUtil.defineIdentities(action.getPropertyElement(
+ SendMessageAction.IDENTITIES),
+ interaction.getMessageSignature(), ids, locators);
+ }
+ */
+ }
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context)
+ * and modified model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param fromObj The source model object
+ * @param toObj The model object to be updated
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ public boolean isUpdateSupported(ModelChangeContext context,
+ Model model, ModelObject fromObj, ModelObject toObj) {
+ boolean ret=false;
+
+ if (fromObj instanceof ConversationInteraction &&
+ toObj instanceof ConversationInteraction &&
+ super.isUpdateSupported(context, model, fromObj, toObj)) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method modifies an existing model object, within a
+ * parent model object, with the details supplied in
+ * another model object.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param fromObj The source model object
+ * @param toObj The model object to be updated
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean update(ModelChangeContext context,
+ Model model, ModelObject fromObj, ModelObject toObj) {
+ boolean ret=false;
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+ ConversationInteraction fromInteraction=(ConversationInteraction)fromObj;
+ ConversationInteraction toInteraction=(ConversationInteraction)toObj;
+ ESBService service=(ESBService)context.getParent();
+
+ // Get action from 'toInteraction'
+ if (toInteraction.getSource().getObject() instanceof
+ AbstractInteractionMessageAction) {
+ AbstractInteractionMessageAction ma=
+ (AbstractInteractionMessageAction)
+ toInteraction.getSource().getObject();
+
+ String origMesgType=ma.getMessageType();
+
+ // Set message type
+ setMessageType(ma, fromInteraction);
+
+ // Update message type in router if appropriate
+ if (InteractionUtil.isSend(fromInteraction) == false &&
+ fromInteraction.getReplyToLabel() == null) {
+ updateRouterMessageType(esbModel, service,
+ origMesgType, ma);
+ }
+
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ protected void updateRouterMessageType(ESBLanguageModel esbModel,
+ ESBService service, String origMesgType,
+ AbstractInteractionMessageAction ma) {
+ ESBService gwService=esbModel.getGatewayService();
+
+ if (gwService != null) {
+ ESBAction gwAction=gwService.getGatewayAction();
+
+ if (gwAction instanceof MessageRouterAction) {
+ MessageRouterAction mra=(MessageRouterAction)
+ gwAction;
+
+ org.w3c.dom.Element route=
+ mra.getRouteElement(service.getCategory(),
+ service.getName());
+
+ if (route != null) {
+ org.w3c.dom.NodeList nl=
+ route.getElementsByTagName(MessageRouterAction.MESSAGE_ELEMENT);
+
+ for (int i=0; i < nl.getLength(); i++) {
+ if (nl.item(i) instanceof org.w3c.dom.Element) {
+ org.w3c.dom.Element mesg=
+ (org.w3c.dom.Element)nl.item(i);
+
+ if (mesg.getAttribute(MessageRouterAction.TYPE_ATTR).
+ equals(origMesgType)) {
+ mesg.setAttribute(MessageRouterAction.TYPE_ATTR,
+ ma.getMessageType());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected void setMessageType(AbstractInteractionMessageAction action,
+ ConversationInteraction interaction) {
+
+ if (interaction.getMessageSignature().getTypes().size() == 1) {
+ TypeReference ref=interaction.getMessageSignature().getTypes().get(0);
+
+ // TODO: Search for an implementation associated with
+ // the type reference, so that the type can be
+ // abstract - possibly have the required message type
+ // notation as part of the context, so that if multiple
+ // implementations found, then can select e.g. XML or
+ // Java as message type representation.
+ String mtype=InteractionUtil.getTypeString(ref);
+
+ action.setMessageType(mtype);
+ }
+ }
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context)
+ * and deleted model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param mobj The model object to be removed
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ public boolean isDeleteSupported(ModelChangeContext context,
+ Model model, ModelObject mobj) {
+ boolean ret=false;
+
+ if (mobj instanceof ConversationInteraction &&
+ super.isDeleteSupported(context, model, mobj)) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+}
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/IfModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/IfModelChangeRule.java
(rev 0)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/IfModelChangeRule.java 2009-01-24
23:36:19 UTC (rev 469)
@@ -0,0 +1,431 @@
+/*
+ * 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.runtime.jbossesb.model.change.stateless;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.actions.stateless.*;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.util.ConversationUtil;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.util.InteractionUtil;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.model.analysis.*;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.*;
+
+/**
+ * This is the model change rule for the If grouping construct.
+ */
+(a)RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class IfModelChangeRule extends AbstractStatelessESBModelChangeRule {
+
+ /**
+ * 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 (mobj instanceof If &&
+ super.isInsertSupported(context, model, mobj, ref)) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.<p>
+ * <p>
+ * If a reference model object is supplied, then the
+ * insertion will occur relative to it. If the reference
+ * object is a block, then it means that the insertion
+ * should occur at the end of the block. Otherwise the
+ * new model object should be inserted before the
+ * reference object, within the containing block.<p>
+ * <p>
+ * If the reference object is not supplied, then the
+ * new model object should be inserted at the end of
+ * the behaviour associated with the parent in the model
+ * change context.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param ref The optional reference model object
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, ModelObject ref) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+ ESBService service=getESBService(context, ref);
+ If ifElem=(If)mobj;
+
+ int pos=getPosition(service, ref);
+
+ ESBService joinService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(joinService);
+
+ // Check if should be an 'if' or a 'switch' action
+ if (ifElem.getRoles().contains(context.getRole())) {
+
+ insertIf(context, model, service, ifElem, joinService, pos);
+ } else {
+ insertSwitch(context, model, service, ifElem, 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);
+
+ joinService.addAction(act, -1);
+ }
+ }
+
+ return(true);
+ }
+
+ protected void insertIf(ModelChangeContext context,
+ Model model, ESBService service,
+ If ifElem, ESBService joinService, int pos) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+
+ // If action, because the role is a decision maker
+ IfAction ifAction=new IfAction(service);
+
+ service.addAction(ifAction, pos);
+
+ for (int i=0; i < ifElem.getConditionalBlocks().size(); i++) {
+ ConditionalBlock cb=ifElem.getConditionalBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < cb.getContents().size(); j++) {
+ context.insert(model, cb.getContents().get(j), null);
+ }
+
+ boolean immediate=false;
+
+ ifAction.addPath((i==0 ? IfAction.IF : IfAction.ELSEIF),
+ subService.getCategory(), subService.getName(),
+ immediate, null, i);
+
+ /* REQUIRED?
+ ScheduleStateAction schedule=
+ new ScheduleStateAction((ESBService)context.getParent());
+
+ schedule.setDestination(joinService.getCategory(),
+ joinService.getName(), true);
+ ((ESBService)context.getParent()).addAction(schedule, -1);
+
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
+ ifElem.getEnclosingDefinition() instanceof Conversation) {
+ schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)ifElem.getEnclosingDefinition())));
+ }
+ */
+ }
+
+ if (ifElem.getElseBlock() != null) {
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < ifElem.getElseBlock().getContents().size(); j++) {
+ context.insert(model,
+ ifElem.getElseBlock().getContents().get(j), null);
+ }
+
+ boolean immediate=false;
+
+ ifAction.addPath(IfAction.ELSE,
+ subService.getCategory(), subService.getName(),
+ immediate, null, -1);
+
+ /* REQUIRED?
+ ScheduleStateAction schedule=
+ new ScheduleStateAction((ESBService)context.getParent());
+
+ schedule.setDestination(joinService.getCategory(),
+ joinService.getName(), true);
+ ((ESBService)context.getParent()).addAction(schedule, -1);
+
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
+ ifElem.getEnclosingDefinition() instanceof Conversation) {
+ schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)ifElem.getEnclosingDefinition())));
+ }
+ */
+ }
+
+ /*
+ if (service.getFirstSessionBasedAction() == ifAction &&
+ ifElem.getEnclosingDefinition() instanceof Conversation) {
+ ifAction.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)ifElem.getEnclosingDefinition())));
+ }
+ */
+ }
+
+ protected void insertSwitch(ModelChangeContext context,
+ Model model, ESBService service,
+ If ifElem, ESBService joinService, int pos) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+
+ // Check if 'when' 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
+
+ /* IS THIS REQUIRED???
+ if (shouldScheduleNewService(service, (pos == -1 ?
+ service.getActions().size() : pos))) {
+
+ // 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);
+
+ // Add schedule action
+ ScheduleStateAction schedule=
+ new ScheduleStateAction(service);
+
+ schedule.setDestination(switchService.getCategory(),
+ switchService.getName(), false);
+
+ service.addAction(schedule, pos);
+
+ context.setParent(switchService);
+
+ service = switchService;
+ pos = -1;
+ }
+ */
+
+ // 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>();
+
+ for (int i=0; i < ifElem.getConditionalBlocks().size(); i++) {
+ ConditionalBlock cb=ifElem.getConditionalBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < cb.getContents().size(); j++) {
+ context.insert(model, cb.getContents().get(j), null);
+ }
+
+ java.util.Set<Interaction> interactions=null;
+
+ if (la != null) {
+ interactions = la.getInteractions(cb);
+ }
+
+ switchAction.addCase(subService.getCategory(),
+ subService.getName(), interactions, i);
+
+ /* REQUIRED?
+ ScheduleStateAction schedule=
+ new ScheduleStateAction((ESBService)context.getParent());
+
+ schedule.setDestination(joinService.getCategory(),
+ joinService.getName(), true);
+ ((ESBService)context.getParent()).addAction(schedule, -1);
+
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
+ ifElem.getEnclosingDefinition() instanceof Conversation) {
+ schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)ifElem.getEnclosingDefinition())));
+ }
+
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
+
+ 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());
+ }
+ }
+ }
+ */
+ }
+
+ if (ifElem.getElseBlock() != null) {
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < ifElem.getElseBlock().getContents().size(); j++) {
+ context.insert(model,
+ ifElem.getElseBlock().getContents().get(j), null);
+ }
+
+ java.util.Set<Interaction> interactions=null;
+
+ if (la != null) {
+ interactions = la.getInteractions(ifElem.getElseBlock());
+ }
+
+ switchAction.addCase(subService.getCategory(),
+ subService.getName(), interactions, -1);
+
+ /*
+ ScheduleStateAction schedule=
+ new ScheduleStateAction((ESBService)context.getParent());
+
+ schedule.setDestination(joinService.getCategory(),
+ joinService.getName(), true);
+ ((ESBService)context.getParent()).addAction(schedule, -1);
+
+ if (((ESBService)context.getParent()).getFirstSessionBasedAction() == schedule
&&
+ ifElem.getEnclosingDefinition() instanceof Conversation) {
+ schedule.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)ifElem.getEnclosingDefinition())));
+ }
+
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
+
+ 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());
+ }
+ }
+ }
+ */
+ }
+
+ // 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 (gwAction instanceof MessageRouterAction) {
+ MessageRouterAction mra=(MessageRouterAction)
+ gwAction;
+
+ mra.addRoute(service.getCategory(),
+ service.getName(),
+ false, messageTypes);
+ }
+ }
+ }
+
+ /*
+ if (service.getFirstSessionBasedAction() == switchAction &&
+ ifElem.getEnclosingDefinition() instanceof Conversation) {
+ switchAction.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)ifElem.getEnclosingDefinition())));
+ }
+ */
+ }
+
+ private static Logger logger =
Logger.getLogger("org.jboss.tools.overlord.cdl.runtime.jbossesb.model.change.stateless");
+}
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/LanguageToConversationModelChangeRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/LanguageToConversationModelChangeRule.java
(rev 0)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.runtime.jbossesb/src/java/org/jboss/tools/overlord/cdl/runtime/jbossesb/model/change/stateless/LanguageToConversationModelChangeRule.java 2009-01-24
23:36:19 UTC (rev 469)
@@ -0,0 +1,98 @@
+/*
+ * 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.runtime.jbossesb.model.change.stateless;
+
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.runtime.jbossesb.model.actions.stateful.*;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.RegistryInfo;
+
+/**
+ * This is the model change rule for the Language Model to
+ * Conversation Model.
+ */
+(a)RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class LanguageToConversationModelChangeRule 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 (mobj instanceof ConversationModel &&
+ model instanceof ESBLanguageModel &&
+ ((ESBLanguageModel)model).isStateless()) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.<p>
+ * <p>
+ * If a reference model object is supplied, then the
+ * insertion will occur relative to it. If the reference
+ * object is a block, then it means that the insertion
+ * should occur at the end of the block. Otherwise the
+ * new model object should be inserted before the
+ * reference object, within the containing block.<p>
+ * <p>
+ * If the reference object is not supplied, then the
+ * new model object should be inserted at the end of
+ * the behaviour associated with the parent in the model
+ * change context.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param ref The optional reference model object
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, ModelObject ref) {
+ ConversationModel cm=(ConversationModel)mobj;
+
+ if (cm.getConversation() != null) {
+ context.insert(model, cm.getConversation(), null);
+ }
+
+ return(true);
+ }
+
+}