[overlord-commits] Overlord SVN: r202 - in cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb: META-INF and 6 other directories.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Mon Jul 28 13:31:20 EDT 2008


Author: objectiser
Date: 2008-07-28 13:31:19 -0400 (Mon, 28 Jul 2008)
New Revision: 202

Added:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/actions/
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/actions/GenerateAction.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRule.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java
Modified:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/META-INF/MANIFEST.MF
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/plugin.xml
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBLanguageModel.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBService.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBActionFactory.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/AbstractESBAction.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ReceiveMessageAction.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java
Log:
Initial generation of services and start of actions.

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/META-INF/MANIFEST.MF
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/META-INF/MANIFEST.MF	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/META-INF/MANIFEST.MF	2008-07-28 17:31:19 UTC (rev 202)
@@ -16,5 +16,7 @@
  org.scribble.core
 Scribble-Extensions: org.jboss.tools.overlord.jbossesb.parser.JBossESBParser,
   org.jboss.tools.overlord.jbossesb.parser.JBossESBNotation,
-  org.jboss.tools.overlord.jbossesb.validation.ESBLanguageModelValidationRule
+  org.jboss.tools.overlord.jbossesb.validation.ESBLanguageModelValidationRule,
+  org.jboss.tools.overlord.jbossesb.model.change.ConversationModelChangeRule,
+  org.jboss.tools.overlord.jbossesb.model.change.ConversationInteractionModelChangeRule
 Bundle-ActivationPolicy: lazy

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/plugin.xml
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/plugin.xml	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/plugin.xml	2008-07-28 17:31:19 UTC (rev 202)
@@ -7,4 +7,31 @@
          point="org.scribble.extension">
    </extension>
 
+  <extension point="org.eclipse.ui.popupMenus"> 
+	<objectContribution 
+      id="org.jboss.tools.overlord.jbossesb.object.contribution"
+   			objectClass="org.eclipse.core.resources.IFile"
+   				nameFilter="*.cdm">
+	  <menu
+         id="org.jboss.tools.overlord.menu"
+         label="Overlord"
+         path="additions">
+      	<separator name="group1"/>
+      </menu>
+	  <menu
+         id="jbossesb.menu"
+         label="JBossESB"
+         path="org.jboss.tools.overlord.menu/additions">
+      	<separator name="group2"/>
+      </menu>
+      <action
+           label="Generate"
+           class="org.jboss.tools.overlord.jbossesb.actions.GenerateAction"
+           menubarPath="org.jboss.tools.overlord.menu/jbossesb.menu/group2"
+           enablesFor="1"
+           id="org.jboss.tools.overlord.jbossesb.actions.GenerateAction">
+     </action> 
+    </objectContribution>
+  </extension>
+  
 </plugin>

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/actions/GenerateAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/actions/GenerateAction.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/actions/GenerateAction.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -0,0 +1,316 @@
+/*
+ * 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.jbossesb.actions;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+import org.scribble.conversation.model.ConversationModel;
+import org.scribble.extensions.RegistryFactory;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.w3c.dom.Node;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+
+/**
+ * This class implements the action to generate the choreography
+ * as a JBossESB ESB configuration.
+ */
+public class GenerateAction implements IObjectActionDelegate {
+
+	public GenerateAction() {
+	}
+
+	/**
+	 * This method implements the action's run method.
+	 * 
+	 * @param action The action
+	 */
+	public void run(IAction action) {
+		if (m_selection instanceof StructuredSelection) {
+			StructuredSelection sel=(StructuredSelection)m_selection;
+			
+			IResource res=(IResource)sel.getFirstElement();
+			
+			if (res instanceof IFile) {
+				generate((IFile)res);
+			}
+		}
+	}
+	
+	protected void generate(IFile res) {
+		ModelReference ref=
+			org.scribble.osgi.model.OSGIModelRepository.createReference(res);
+		
+		if (ref != null) {
+			ModelRepository mrep=(ModelRepository)
+					RegistryFactory.getRegistry().getExtension(
+						ModelRepository.class, null);
+
+			if (mrep != null) {
+				Model model=mrep.getModel(ref,
+								new DefaultModelListener());
+				
+				if (model instanceof ConversationModel) {
+					ConversationModel cm=(ConversationModel)model;
+					
+					java.util.List<Role> roles=cm.getRoles();
+					
+					for (int i=0; i < roles.size(); i++) {
+						
+						generateRole(cm, roles.get(i));
+					}
+				}
+			}
+		}
+	}
+	
+	protected void generateRole(ConversationModel cm, Role role) {
+		
+		if (logger.isLoggable(Level.FINEST)) {
+			logger.finest("Generate role '"+role+"' for: "+cm);
+		}
+		
+		// Project to role
+		org.scribble.projector.Projector projector=
+			(org.scribble.projector.Projector)
+			RegistryFactory.getRegistry().getExtension(
+					org.scribble.projector.Projector.class, null);
+
+		if (projector != null) {
+			Model localModel=projector.project(cm,
+					role, new DefaultModelListener());
+			
+			if (localModel instanceof ConversationModel &&
+					((ConversationModel)localModel).getConversation() != null) {
+				ConversationModel lcm=(ConversationModel)localModel;
+				
+				ModelReference targetRef=
+					new ModelReference(ESBLanguageModel.JBOSSESB_NOTATION);
+				
+				DefaultESBLanguageModel target=
+					new DefaultESBLanguageModel(targetRef);
+				
+				ModelChangeContext context=
+					new DefaultModelChangeContext(targetRef);
+				
+				context.insert(target, target,
+							lcm.getConversation(), -1);
+				
+				try {
+					System.out.println("------------------------------");
+					System.out.println("ROLE="+role.getName());
+					System.out.println("ESB Configuration:\r\n"+
+						getText(target.getESBConfiguration()));
+				} catch(Exception e) {
+					e.printStackTrace();
+				}
+			}
+		}
+	}
+	
+	/**
+	 * This class converts a DOM representation node to
+	 * text.
+	 * 
+	 * @param node The DOM node
+	 * @return The text
+	 * @throws Exception Failed to convert
+	 */
+	protected String getText(Node node) throws Exception {
+		String ret=null;
+			
+		try {
+			// Transform the DOM represent to text
+			java.io.ByteArrayOutputStream xmlstr=
+					new java.io.ByteArrayOutputStream();
+				
+			DOMSource source=new DOMSource();
+			source.setNode(node);
+			
+			StreamResult result=new StreamResult(xmlstr);
+			
+			Transformer trans=
+					TransformerFactory.newInstance().newTransformer();
+			trans.transform(source, result);
+			
+			xmlstr.close();
+			
+			ret = new String(xmlstr.toByteArray());
+			
+			if ((node instanceof org.w3c.dom.Document) == false) {
+				
+				// Strip off any <?xml> header
+				int index=ret.indexOf("<?xml");
+				if (index != -1) {
+					index = ret.indexOf("<", 1);
+					
+					if (index != -1) {
+						ret = ret.substring(index);
+					} else {
+						index = ret.indexOf("?>");
+						
+						if (index != -1) {
+							index += 2;
+							
+							// Remove any trailing whitespaces
+							// after XML header
+							while (index < ret.length() &&
+									Character.isWhitespace(ret.charAt(index))) {
+								index++;
+							}
+							
+							ret = ret.substring(index);
+						}
+					}
+				}
+			}
+
+		} catch(Exception e) {
+			throw new Exception("Failed to transform " +
+					"DOM representation into text", e);
+		}
+		
+		int pos=0;
+		int prevpos=0;
+		StringBuffer buf=new StringBuffer();
+		int level=0;
+		
+		while ((pos=ret.indexOf('<', prevpos)) != -1) {
+			
+			if (prevpos < pos &&
+					ret.substring(prevpos, pos).trim().length() > 0 &&
+					ret.charAt(prevpos-1) != '?') {
+				
+				if (ret.charAt(prevpos) == '\r' &&
+						ret.charAt(prevpos+1) == '\n') {
+					prevpos += 2;
+				}
+				for (int i=0; i < level; i++) {
+					buf.append("    ");
+				}
+				
+				buf.append(ret.substring(prevpos, pos).trim());
+				buf.append("\r\n");
+			}
+			
+			int endpos=ret.indexOf('>', pos);
+		
+			if (endpos > 0) {
+				boolean noreturn=false;
+				
+				if (pos > 0 && ret.charAt(pos+1) == '/') {
+					level--;
+				}
+				
+				for (int i=0; i < level; i++) {
+					buf.append("    ");
+				}
+				buf.append(ret.substring(pos, endpos+1));
+				
+				if (ret.charAt(endpos-1)== '?') {
+					//noreturn = true;
+					
+				} else if (ret.charAt(endpos-1) == '/') {
+					// Ignore
+				} else if (pos > 0 && ret.charAt(pos+1) == '/') {
+					// Ignore
+					
+				} else if (pos > 0 && ret.charAt(pos+1) == '!') {
+					// Ignore
+					
+				} else {
+					level++;
+				}
+							
+				if (noreturn == false) {
+					buf.append("\r\n");
+				}
+				
+				pos = endpos+1;
+			}
+			
+			prevpos = pos;
+		}
+		
+		if (prevpos != -1 &&
+				ret.substring(prevpos).trim().length() > 0) {
+			buf.append(ret.substring(prevpos));
+		}
+		
+		ret = buf.toString();
+		
+		return(ret);
+	}
+
+	/**
+	 * This method indicates that the selection has changed.
+	 * 
+	 * @param action The action
+	 * @param selection The selection
+	 */
+	public void selectionChanged(IAction action,
+            ISelection selection) {
+		m_selection = selection;
+	}
+
+	/**
+	 * This method sets the currently active workbench part.
+	 * 
+	 * @param action The action
+	 * @param targetPart The active workbench part
+	 */
+	public void setActivePart(IAction action,
+            IWorkbenchPart targetPart) {
+		m_targetPart = targetPart;
+	}
+	
+	/**
+	 * This method is used to report a warning.
+	 * 
+	 * @param mesg The warning message
+	 */
+	public void warn(String mesg) {
+		
+		MessageBox mbox=new MessageBox(m_targetPart.getSite().getShell(),
+				SWT.ICON_WARNING|SWT.OK);
+		mbox.setMessage(mesg);
+		mbox.open();
+	}
+
+	private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.actions");
+	
+	private ISelection m_selection=null;
+    private IWorkbenchPart m_targetPart=null;
+}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBLanguageModel.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBLanguageModel.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBLanguageModel.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -184,13 +184,8 @@
 				ESBService service=serviter.next();
 				
 				if (service.isRoot()) {
-					Conversation conv=new Conversation();
 					
-					ModelName modelName=new ModelName();
-					modelName.setName(service.getServiceName());
-					
-					conv.setModelName(modelName);
-					
+					/*
 					String convType=service.getConversationType();
 					String role=null;
 					
@@ -239,22 +234,19 @@
 					} else {
 						logger.warning("No conversation type specified");
 					}
-					
-					// TODO: Associate a conformance reference for the
-					// conversation type - when using Scribble dependency
-					// management, this will ensure appropriate validation
-					// when either the dependent conversation is changed, or
-					// the ESB config file changed.
-					//ConformanceReference confRef=new ConformanceReference();
-					
-					//conv.getConformsTo().add(confRef);
-								
+													
 					conv.setBlock(new Block());
 					
 					service.convert(conv.getBlock().getContents(),
 									new DefaultConversionContext(role));
 					
-					getConversations().add(conv);
+					*/
+					
+					Conversation conv=service.convert(null);
+					
+					if (conv != null) {
+						getConversations().add(conv);
+					}
 				}
 				
 				//Add session class to list
@@ -393,6 +385,11 @@
 		m_services.put(getKey(service.getCategory(), service.getName()),
 				service);
 		
+		// Add service
+		if (service.getService() != null) {
+			m_servicesElem.appendChild(service.getService());
+		}
+		
 		// Add provider information
 		String busId=service.getJMSBusIdRef();
 		

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBService.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBService.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/DefaultESBService.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -26,6 +26,7 @@
 import org.eclipse.jdt.internal.core.*;
 
 import org.scribble.model.*;
+import org.scribble.conversation.model.*;
 import org.scribble.osgi.model.*;
 
 /**
@@ -93,27 +94,11 @@
 		m_service.setAttribute(CATEGORY_ATTR, category);
 		m_service.setAttribute(NAME_ATTR, name);
 		
-		/* Create jms listener and bus id when added to model
-		org.w3c.dom.Element listeners=m_service.getOwnerDocument().createElement(LISTENERS_ELEMENT);
-		m_service.appendChild(listeners);
-		
-		m_jmsListenerElem = m_service.getOwnerDocument().createElement(JMS_LISTENER_ELEMENT);
-		listeners.appendChild(m_jmsListenerElem);
-		
-		m_jmsListenerElem.setAttribute(BUSIDREF_ATTR, getBusId(category,name));
-		*/
+		m_actionsElem = m_model.getESBConfiguration().
+				getOwnerDocument().createElement(ACTIONS_ELEMENT);
+		m_service.appendChild(m_actionsElem);
 	}
 	
-	/*
-	protected String getBusId(String category, String name) {
-		String ret=category.replace('.', '_');
-		
-		ret += "_"+name;
-		
-		return(ret);
-	}
-	*/
-	
 	/**
 	 * This method initializes the service.
 	 */
@@ -123,6 +108,9 @@
 	
 		if (actions != null && actions.getLength() == 1 &&
 				actions.item(0) instanceof org.w3c.dom.Element) {
+			
+			m_actionsElem = (org.w3c.dom.Element)actions.item(0);
+			
 			org.w3c.dom.NodeList nl=((org.w3c.dom.Element)
 						actions.item(0)).getChildNodes();
 			
@@ -261,6 +249,32 @@
 		return(m_actions);
 	}
 	
+	/**
+	 * This method adds an action to the service.
+	 * 
+	 * @param action The action to be added
+	 * @param pos The position to add, or -1 if at the end
+	 */
+	public void addAction(ESBAction action, int pos) {
+		// If position specified, then find element at
+		// the position and insert after the previous
+		// element
+		
+		if (action.getAction() != null) {
+			m_actionsElem.appendChild(action.getAction());
+		}
+	}
+	
+	/**
+	 * This method removes an action from the service.
+	 * 
+	 * @param action The action to be removed
+	 * @return Whether the action was removed
+	 */
+	public boolean removeAction(ESBAction action) {
+		return(false);
+	}
+	
 	protected java.lang.annotation.Annotation getServiceAnnotation(String session) {
 		java.lang.annotation.Annotation ret=null;
 		
@@ -541,6 +555,98 @@
 	}
 	
 	/**
+	 * This method converts the ESB service into a Conversation, if
+	 * the service represents a conversation.
+	 * 
+	 * @param context The conversion context, or null if this is the
+	 * 					root conversation
+	 * @return The conversation
+	 */
+	public Conversation convert(ConversionContext context) {
+		Conversation ret=null;
+		
+		if (isCreateSession()) {
+			ret = new Conversation();
+		
+			ret.derivedFrom(this);
+			
+			ModelName modelName=new ModelName();
+			modelName.setName(getServiceName());
+			
+			ret.setModelName(modelName);
+			
+			String convType=getConversationType();
+			String role=null;
+			
+			if (convType != null) {
+				int index=convType.indexOf('@');
+			
+				if (index != -1) {
+					// TODO: Need to think whether this should be
+					// 'implements' reference. If so, then need to change
+					// Java Lang Model parser and also Lang Model conformance
+					// rule.
+					ImplementsReference iref=
+						new ImplementsReference(ConversationModel.CONVERSATION);
+				
+					role = convType.substring(index+1);
+					
+					iref.setLocatedRole(role);
+					
+					// Need to locate the model name
+					modelName.setLocatedRole(new Role(iref.getLocatedRole()));
+					
+					String mainpart=convType.substring(0, index);
+					
+					index = mainpart.lastIndexOf(".");
+					
+					if (index == -1) {
+						iref.setNamespace("");
+						iref.setLocalpart(mainpart);
+					} else {
+						iref.setNamespace(mainpart.substring(0, index));								
+						iref.setLocalpart(mainpart.substring(index+1));
+					}
+					
+					ret.getImplements().add(iref);
+					//ret.getConformsTo().add(iref);
+					
+					org.scribble.model.DependencyManager dm=
+						(org.scribble.model.DependencyManager)
+						org.scribble.extensions.RegistryFactory.getRegistry().getExtension(
+								org.scribble.model.DependencyManager.class, null);
+					
+					if (dm != null) {
+						dm.recordDependency(getModel().getModelReference(),
+								iref, DependencyType.Implements);
+					}
+
+				} else {
+					logger.warning("Conversation type does not " +
+							"contain '@' located role separator");
+				}
+			} else {
+				logger.warning("No conversation type specified");
+			}
+											
+			ret.setBlock(new Block());
+			
+			context = new DefaultConversionContext(role);
+					
+			context.processing(this);
+			
+			for (int i=0; i < m_actions.size(); i++) {
+				((ESBAction)m_actions.get(i)).convert(
+						ret.getBlock().getContents(), context);
+			}
+			
+			context.processed(this);
+		}
+		
+		return(ret);
+	}
+
+	/**
 	 * This method converts the actions associated with the ESB service into
 	 * activities that can be checked for conformance against a conversation
 	 * type.
@@ -550,12 +656,12 @@
 	 * @param context The conversion context
 	 */
 	public void convert(java.util.List<Activity> activities,
-			ConversionContext context) {
-		
+					ConversionContext context) {
 		context.processing(this);
 		
 		for (int i=0; i < m_actions.size(); i++) {
-			((ESBAction)m_actions.get(i)).convert(activities, context);
+			((ESBAction)m_actions.get(i)).convert(
+					activities, context);
 		}
 		
 		context.processed(this);
@@ -620,9 +726,10 @@
 				listeners = (org.w3c.dom.Element)nl.item(0);
 			} else {
 				listeners = m_service.getOwnerDocument().createElement(LISTENERS_ELEMENT);
+				
 				if (m_service.getFirstChild() != null) {
-					m_service.insertBefore(m_service.getFirstChild(),
-							listeners);
+					m_service.insertBefore(listeners,
+							m_service.getFirstChild());
 				} else {
 					m_service.appendChild(listeners);
 				}
@@ -675,5 +782,6 @@
 	private ESBLanguageModel m_model=null;
 	private org.w3c.dom.Element m_service=null;
 	private org.w3c.dom.Element m_jmsListenerElem=null;
+	private org.w3c.dom.Element m_actionsElem=null;
 	private java.util.List<ESBAction> m_actions=new java.util.Vector<ESBAction>();
 }

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBActionFactory.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBActionFactory.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBActionFactory.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -28,10 +28,10 @@
  */
 public class ESBActionFactory {
 
-	private static final String MODEL_ACTION_PACKAGE =
+	public static final String MODEL_ACTION_PACKAGE =
 						"org.jboss.tools.overlord.jbossesb.model.actions";
-	private static final String CLASS_ATTR = "class";
-	private static final String CONVERSATION_ACTION_PACKAGE = 
+	public static final String CLASS_ATTR = "class";
+	public static final String CONVERSATION_ACTION_PACKAGE = 
 						"org.jboss.soa.overlord.jbossesb.actions";
 
 	/**
@@ -79,6 +79,30 @@
 		
 		return(ret);
 	}
+	
+	/**
+	 * This method determines the runtime action class based on
+	 * the ESB model action class.
+	 * 
+	 * @param cls The ESB model action class
+	 * @return The conversation action class
+	 */
+	public static String getConversationAction(Class<?> cls) {
+		String actionType=cls.getName();
+		String ret=null;
+		
+		// Check that it is a conversation based ESB action
+		if (actionType.startsWith(MODEL_ACTION_PACKAGE)) {
+			int index=actionType.lastIndexOf('.');
+			if (index != -1) {
+				String actionName=actionType.substring(index+1);
+				
+				ret = CONVERSATION_ACTION_PACKAGE+"."+actionName;
+			}
+		}
+		
+		return(ret);
+	}
 
 	private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model");
 }

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -69,6 +69,20 @@
 	public String getOriginalContents();
 	
 	/**
+	 * This method adds a new service to the model.
+	 * 
+	 * @param service The service
+	 */
+	public void addService(ESBService service);
+	
+	/**
+	 * This method removes a service from the model.
+	 * 
+	 * @param service The service
+	 */
+	public void removeService(ESBService service);
+	
+	/**
 	 * This method returns the reference to the DOM
 	 * representation of the ESB configuration.
 	 * 

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -17,6 +17,7 @@
  */
 package org.jboss.tools.overlord.jbossesb.model;
 
+import org.scribble.conversation.model.Conversation;
 import org.scribble.model.*;
 
 /**
@@ -77,6 +78,22 @@
 	public java.util.List<ESBAction> getActions();
 	
 	/**
+	 * This method adds an action to the service.
+	 * 
+	 * @param action The action to be added
+	 * @param pos The position to add, or -1 if at the end
+	 */
+	public void addAction(ESBAction action, int pos);
+	
+	/**
+	 * This method removes an action from the service.
+	 * 
+	 * @param action The action to be removed
+	 * @return Whether the action was removed
+	 */
+	public boolean removeAction(ESBAction action);
+	
+	/**
 	 * This method determines whether the ESB service represents a
 	 * loop construct.
 	 * 
@@ -150,9 +167,19 @@
 	 * @param context The conversion context
 	 */
 	public void convert(java.util.List<Activity> activities,
-			ConversionContext context);
+					ConversionContext context);
 
 	/**
+	 * This method converts the ESB service into a Conversation, if
+	 * the service represents a conversation.
+	 * 
+	 * @param context The conversion context, or null if this is the
+	 * 					root conversation
+	 * @return The conversation
+	 */
+	public Conversation convert(ConversionContext context);
+	
+	/**
 	 * This method returns the position of the service node within the
 	 * ESB configuration.
 	 * 

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/AbstractESBAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/AbstractESBAction.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/AbstractESBAction.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -42,21 +42,47 @@
 	protected static final String BUSINESS_OBJECT_TYPE_PROPERTY = SESSION;
 
 	/**
-	 * The default constructor.
+	 * The constructor for initializing the action based on
+	 * an existing DOM element.
 	 */
 	protected AbstractESBAction(ESBService service,
 			org.w3c.dom.Element action) {
-		init(service, action);
+		initExistingAction(service, action);
 	}
 	
 	/**
+	 * The contructor for initializing a new action.
+	 */
+	protected AbstractESBAction(ESBService service,
+			String actionClass) {
+		initNewAction(service, actionClass);
+	}
+	
+	/**
 	 * This method initializes the action.
 	 * 
 	 * @param service The reference to the service in which
 	 * 				the action is contained
+	 * @param actionClass The action class
+	 */
+	protected void initNewAction(ESBService service,
+			String actionClass) {
+		m_service = service;
+		
+		m_action = service.getService().
+				getOwnerDocument().createElement(ACTION_ELEMENT);
+		
+		m_action.setAttribute(CLASS_PROPERTY, actionClass);
+	}
+	
+	/**
+	 * This method initializes the action.
+	 * 
+	 * @param service The reference to the service in which
+	 * 				the action is contained
 	 * @param action The XML configuration details for the action
 	 */
-	protected void init(ESBService service,
+	protected void initExistingAction(ESBService service,
 					org.w3c.dom.Element action) {
 		m_service = service;
 		m_action = action;

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ReceiveMessageAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ReceiveMessageAction.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ReceiveMessageAction.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -44,6 +44,18 @@
 					org.w3c.dom.Element action) {
 		super(service, action);
 	}
+	
+	/**
+	 * This constructor initializes the DOM element for
+	 * the action.
+	 * 
+	 * @param service The reference to the service in which
+	 * 				the action will be contained
+	 */
+	public ReceiveMessageAction(ESBService service) {
+		super(service, ESBActionFactory.getConversationAction(
+				ReceiveMessageAction.class));
+	}
 
 	/**
 	 * This method returns the mandatory property names.

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRule.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRule.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -0,0 +1,108 @@
+/*
+ * 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.jbossesb.model.change;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+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.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class ConversationInteractionModelChangeRule extends AbstractModelChangeRule {
+
+	/**
+	 * This method determines whether the rule is appropriate
+	 * for the supplied type of model, parent and
+	 * model object.
+	 * 
+	 * @param model The model
+	 * @param parent The parent model object
+	 * @param mobj The model object causing the change
+	 * @return Whether the rule supports the supplied information
+	 */
+	@Override
+	protected boolean isChangeSupported(Model model, ModelObject parent,
+						ModelObject mobj) {
+		boolean ret=false;
+		
+		if (mobj instanceof ConversationInteraction &&
+				parent instanceof ESBService &&
+				model instanceof ESBLanguageModel) {
+			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.
+	 * 
+	 * @param context The context
+	 * @param model The model being changed
+	 * @param parent The parent model object
+	 * @param mobj The model object details to be inserted
+	 * @param position The position, where relevant
+	 * @return Whether the change has been applied
+	 */
+	@Override
+	public boolean insert(ModelChangeContext context,
+				Model model, ModelObject parent,
+					ModelObject mobj, int position) {
+		ESBLanguageModel esbModel=(ESBLanguageModel)model;
+		ESBService service=(ESBService)parent;
+		ConversationInteraction interaction=(ConversationInteraction)mobj;
+		
+		// Check if send or receive
+		if ((interaction.getFromRole() != null &&
+				interaction.getFromRole().getName().equals(
+						context.getRoleName())) ||
+			(interaction.getToRole() != null &&
+				interaction.getToRole().getName().equals(
+						context.getRoleName()) == false)) {
+			
+			// Send
+			
+		} else {
+			
+			// TODO: Create a new service to receive the
+			// message and add a schedule service to link
+			// to this new service - issue, how do we
+			// deal with request/response
+			
+			// Receive
+			ReceiveMessageAction action=
+					new ReceiveMessageAction(service);
+			
+			service.addAction(action, position);
+		}
+		
+		return(true);
+	}
+	
+}

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -0,0 +1,99 @@
+/*
+ * 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.jbossesb.model.change;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+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.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class ConversationModelChangeRule extends AbstractModelChangeRule {
+
+	/**
+	 * This method determines whether the rule is appropriate
+	 * for the supplied type of model, parent and
+	 * model object.
+	 * 
+	 * @param model The model
+	 * @param parent The parent model object
+	 * @param mobj The model object causing the change
+	 * @return Whether the rule supports the supplied information
+	 */
+	@Override
+	protected boolean isChangeSupported(Model model, ModelObject parent,
+						ModelObject mobj) {
+		boolean ret=false;
+		
+		if (mobj instanceof Conversation &&
+				model instanceof ESBLanguageModel) {
+			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.
+	 * 
+	 * @param context The context
+	 * @param model The model being changed
+	 * @param parent The parent model object
+	 * @param mobj The model object details to be inserted
+	 * @param position The position, where relevant
+	 * @return Whether the change has been applied
+	 */
+	@Override
+	public boolean insert(ModelChangeContext context,
+				Model model, ModelObject parent,
+					ModelObject mobj, int position) {
+		ESBLanguageModel esbModel=(ESBLanguageModel)model;
+		Conversation conv=(Conversation)mobj;
+		
+		String category=((Model)conv.getModel()).
+					getNamespace().getName();
+		String name=conv.getModelName().getName()+"-"+
+				conv.getModelName().getLocatedRole().getName();
+		
+		// Create new ESB service
+		DefaultESBService service=new DefaultESBService(
+					esbModel, category, name);
+
+		esbModel.addService(service);
+		
+		// Process the activities within the conversation
+		java.util.List<Activity> acts=conv.getBlock().getContents();
+		
+		for (int i=0; i < acts.size(); i++) {
+			context.insert(model, service, acts.get(i), i);
+		}
+		
+		return(true);
+	}
+	
+}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -54,6 +54,10 @@
 		m_services.put(service.getCategory()+":"+service.getName(), service);
 	}
 	
+	public void removeService(ESBService service) {
+		m_services.remove(service.getCategory()+":"+service.getName());
+	}
+	
 	public ESBService getService(String category, String name) {
 		return(m_services.get(category+":"+name));
 	}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java	2008-07-28 11:44:17 UTC (rev 201)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java	2008-07-28 17:31:19 UTC (rev 202)
@@ -22,6 +22,7 @@
 import org.jboss.tools.overlord.jbossesb.model.ConversionContext;
 import org.jboss.tools.overlord.jbossesb.model.ESBAction;
 import org.jboss.tools.overlord.jbossesb.model.ESBLanguageModel;
+import org.scribble.conversation.model.Conversation;
 import org.scribble.model.Activity;
 import org.scribble.model.ModelListener;
 import org.w3c.dom.Element;
@@ -32,6 +33,10 @@
 		activities.addAll(m_contents);
 	}
 	
+	public Conversation convert(ConversionContext context) {
+		return(null);
+	}
+	
 	public List<Activity> getContents() {
 		return(m_contents);
 	}
@@ -155,6 +160,16 @@
 		m_jmsBusIdRef = busId;
 	}
 
+	public void addAction(ESBAction action, int pos) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public boolean removeAction(ESBAction action) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
 	private String m_category=null;
 	private String m_name=null;
 	private ESBLanguageModel m_model=null;




More information about the overlord-commits mailing list