[overlord-commits] Overlord SVN: r85 - in trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model: actions and 1 other directory.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Mon Jun 30 12:54:52 EDT 2008


Author: objectiser
Date: 2008-06-30 12:54:52 -0400 (Mon, 30 Jun 2008)
New Revision: 85

Added:
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/Messages.properties
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/GetVariableAction.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SetVariableAction.java
Modified:
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBAction.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/UnsupportedAction.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/CreateSessionAction.java
   trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties
Log:
Added support for Get/Set Variable action, with validation of the variable name against the specified session class. Also added other validation related to existence of session property. Need to also validate that session is consistent within service descriptors interconnected for the same service - with the exception of 'performed' service descriptors.

Modified: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBAction.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBAction.java	2008-06-30 10:55:52 UTC (rev 84)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBAction.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -29,7 +29,7 @@
 public abstract class ESBAction extends ModelObject {
 
 	private static final String ACTION_ELEMENT = "action";
-	private static final String SERVICE_ELEMENT = "service";
+	//private static final String SERVICE_ELEMENT = "service";
 	private static final String VALUE_ATTR = "value";
 	private static final String NAME_ATTR = "name";
 	private static final String PROPERTY_ELEMENT = "property";
@@ -56,7 +56,7 @@
 		m_action = action;
 		
 		// Find positional information
-		int servCount=getServicePosition();
+		int servCount=m_service.getServicePosition();
 		int actionCount=getActionPosition();
 		
 		String str=m_service.getModel().getContents();
@@ -160,6 +160,16 @@
 	}
 	
 	/**
+	 * This method determines whether the action is related to a behavioural
+	 * session.
+	 * 
+	 * @return Whether the action is session based
+	 */
+	public boolean isSessionBased() {
+		return(true);
+	}
+	
+	/**
 	 * This method returns the action's class name.
 	 * 
 	 * @return The action's class name
@@ -256,35 +266,6 @@
 					ConversionContext context);
 		
 	/**
-	 * This method returns the position of the service node within the
-	 * ESB configuration.
-	 * 
-	 * @return The service node position
-	 */
-	protected int getServicePosition() {
-		org.w3c.dom.Element service=(org.w3c.dom.Element)
-					getAction().getParentNode().getParentNode();
-
-		org.w3c.dom.Node services=service.getParentNode();
-		int servCount=0;
-		boolean f_end=false;
-		
-		for (int i=0; f_end == false &&
-				i < services.getChildNodes().getLength(); i++) {
-			org.w3c.dom.Node serv=services.getChildNodes().item(i);
-			
-			if (serv.getNodeName().equals(SERVICE_ELEMENT)) {
-				servCount++;
-				if (serv == service) {
-					f_end = true;
-				}
-			}
-		}
-		
-		return(servCount);
-	}
-		
-	/**
 	 * This method returns the node position of the action configuration
 	 * within the service descriptor.
 	 * 

Modified: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java	2008-06-30 10:55:52 UTC (rev 84)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBLanguageModel.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -248,7 +248,10 @@
 		java.util.Iterator<ESBService> iter=m_services.values().iterator();
 		
 		while (iter.hasNext()) {
-			iter.next().validate(l);
+			ESBService service=iter.next();
+			
+System.out.println("VALID SERVICE="+service);			
+			service.validate(l);
 		}
 	}
 	

Modified: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java	2008-06-30 10:55:52 UTC (rev 84)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/ESBService.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -38,10 +38,12 @@
  */
 public class ESBService extends ModelObject {
 
+	private static final String SERVICE_ELEMENT = "service";
 	private static final String SERVICE_NAME_PROPERTY = "serviceName";
 	private static final String ROOT_PROPERTY = "root";
 	private static final String BUSINESS_OBJECT_TYPE_PROPERTY = "session";
 	private static final String CONVERSATION_TYPE_PROPERTY = "conversationType";
+	private static final String ACTION_PACKAGE = "org.jboss.soa.overlord.jbossesb.actions.";
 	private static final String CREATE_SESSION_ACTION_CLASS = "org.jboss.soa.overlord.jbossesb.actions.CreateSessionAction";
 	private static final String RETRIEVE_SESSION_ACTION_CLASS = "org.jboss.soa.overlord.jbossesb.actions.RetrieveSessionAction";
 	private static final String ACTION_ELEMENT = "action";
@@ -80,6 +82,31 @@
 				}
 			}
 		}
+
+		// Find positional information
+		int servCount=getServicePosition();
+		
+		String str=getModel().getContents();
+
+		int startPosition=str.indexOf("<service ");
+		int endPosition=-1;
+		
+		while (startPosition != -1 && servCount > 0) {
+			servCount--;
+			
+			endPosition = str.indexOf("</service>", startPosition);
+			
+			if (servCount > 0) {
+				startPosition=str.indexOf("<service ", endPosition);
+			}
+		}
+		
+		if (startPosition != -1) {
+			endPosition = str.indexOf("</service>", startPosition);
+				
+			getSource().setStartPosition(startPosition);
+			getSource().setEndPosition(endPosition);
+		}
 	}
 	
 	/**
@@ -102,6 +129,15 @@
 	 */
 	public void validate(ModelListener l) {
 		
+		// Check that the service specifies a session
+		if (isSessionBased() && getSessionClass() == null) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.Messages"),
+						"_NOT_SPECIFIED_SESSION_CLASS",
+						new String[]{}), null);
+		}
+		
 		for (int i=0; i < m_actions.size(); i++) {
 			m_actions.get(i).validate(l);
 		}
@@ -137,6 +173,15 @@
 	}
 	
 	/**
+	 * This method returns the XML configuration representation of the service.
+	 * 
+	 * @return The XML configuration for the service
+	 */
+	public org.w3c.dom.Element getService() {
+		return(m_service);
+	}
+	
+	/**
 	 * This method returns the list of ESB actions.
 	 * 
 	 * @return The ESB actions
@@ -173,7 +218,8 @@
 			}
 			
 		} catch(Exception e) {
-			e.printStackTrace();
+			logger.log(java.util.logging.Level.SEVERE,
+					"Failed to get session class '"+session+"'", e);
 		}
 		
 		return(ret);
@@ -188,9 +234,17 @@
 	public boolean isLoop() {
 		boolean ret=false;
 		
-		if (m_actions.size() > 0) {
-			ESBAction action=(ESBAction)m_actions.get(0);
+		ESBAction action=null;
+		
+		for (int i=0; action == null && i < m_actions.size(); i++) {
+			action=m_actions.get(i);
 			
+			if (action.isSessionBased() == false) {
+				action = null;
+			}
+		}
+		
+		if (action != null) {
 			ret = action.isLoop();
 		}
 		
@@ -205,10 +259,17 @@
 	 */
 	public boolean isRoot() {
 		boolean ret=false;
+		ESBAction action=null;
 		
-		if (m_actions.size() > 0) {
-			ESBAction action=(ESBAction)m_actions.get(0);
+		for (int i=0; action == null && i < m_actions.size(); i++) {
+			action=m_actions.get(i);
 			
+			if (action.isSessionBased() == false) {
+				action = null;
+			}
+		}
+		
+		if (action != null) {
 			if (action.getActionClass().equals(CREATE_SESSION_ACTION_CLASS)) {
 				String bool=action.getPropertyValue(ROOT_PROPERTY);
 				if (bool != null) {
@@ -249,10 +310,17 @@
 	 */
 	public String getServiceName() {
 		String ret=null;
+		ESBAction action=null;
 		
-		if (m_actions.size() > 0) {
-			ESBAction action=(ESBAction)m_actions.get(0);
+		for (int i=0; action == null && i < m_actions.size(); i++) {
+			action=m_actions.get(i);
 			
+			if (action.isSessionBased() == false) {
+				action = null;
+			}
+		}
+		
+		if (action != null) {			
 			if (action.getActionClass().equals(CREATE_SESSION_ACTION_CLASS) ||
 					action.getActionClass().equals(RETRIEVE_SESSION_ACTION_CLASS)) {
 				ret = action.getPropertyValue(SERVICE_NAME_PROPERTY);
@@ -293,10 +361,17 @@
 	 */
 	public String getConversationType() {
 		String ret=null;
+		ESBAction action=null;
 		
-		if (m_actions.size() > 0) {
-			ESBAction action=(ESBAction)m_actions.get(0);
+		for (int i=0; action == null && i < m_actions.size(); i++) {
+			action=m_actions.get(i);
 			
+			if (action.isSessionBased() == false) {
+				action = null;
+			}
+		}
+		
+		if (action != null) {
 			if (action.getActionClass().equals(CREATE_SESSION_ACTION_CLASS)) {
 				ret = action.getPropertyValue(CONVERSATION_TYPE_PROPERTY);
 				
@@ -327,8 +402,63 @@
 		
 		return(ret);
 	}
+	
+	/**
+	 * This method returns the session class associated with the service
+	 * descriptor.
+	 * 
+	 * @return The session class
+	 */
+	public Class<?> getSessionClass() {
+		Class<?> ret=null;
+		ESBAction action=null;
+		
+		for (int i=0; action == null && i < m_actions.size(); i++) {
+			action=m_actions.get(i);
+			
+			if (action.isSessionBased() == false) {
+				action = null;
+			}
+		}
+		
+		if (action != null) {
+			if (action.getActionClass().startsWith(ACTION_PACKAGE)) {
+				String session=action.getPropertyValue(BUSINESS_OBJECT_TYPE_PROPERTY);
+				
+				if (session != null) {
+					try {
+						ClassLoader cl=getProjectLoader();
+						
+						ret = Class.forName(session, true, cl);
+						
+					} catch(Exception e) {
+						logger.log(java.util.logging.Level.SEVERE,
+								"Failed to get session class '"+session+"'", e);
+					}
+				}
+			}
+		}
+		
+		return(ret);
+	}
 
 	/**
+	 * This method determines whether the service is related to a behavioural
+	 * session.
+	 * 
+	 * @return Whether the service is session based
+	 */
+	public boolean isSessionBased() {
+		boolean ret=false;
+		
+		for (int i=0; ret == false && i < m_actions.size(); i++) {
+			ret = m_actions.get(i).isSessionBased();
+		}
+		
+		return(ret);
+	}
+	
+	/**
 	 * This method converts the actions associated with the ESB service into
 	 * activities that can be checked for conformance against a conversation
 	 * type.
@@ -350,6 +480,32 @@
 	}
 
 	/**
+	 * This method returns the position of the service node within the
+	 * ESB configuration.
+	 * 
+	 * @return The service node position
+	 */
+	protected int getServicePosition() {
+		org.w3c.dom.Node services=m_service.getParentNode();
+		int servCount=0;
+		boolean f_end=false;
+		
+		for (int i=0; f_end == false &&
+				i < services.getChildNodes().getLength(); i++) {
+			org.w3c.dom.Node serv=services.getChildNodes().item(i);
+			
+			if (serv.getNodeName().equals(SERVICE_ELEMENT)) {
+				servCount++;
+				if (serv == m_service) {
+					f_end = true;
+				}
+			}
+		}
+		
+		return(servCount);
+	}
+		
+	/**
 	 * This method returns a custom classloader that uses the project's
 	 * classpath to locate classes referenced by the ESB config file.
 	 * 
@@ -425,6 +581,10 @@
 		return(ret);
 	}
 	
+	public String toString() {
+		return("ESBService: "+getCategory()+"/"+getName()+"["+getSource()+"]");
+	}
+	
 	private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model");
 
 	private ESBLanguageModel m_model=null;

Added: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/Messages.properties
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/Messages.properties	                        (rev 0)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/Messages.properties	2008-06-30 16:54:52 UTC (rev 85)
@@ -0,0 +1,19 @@
+# /*
+#  * 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.
+#  */
+
+_NOT_SPECIFIED_SESSION_CLASS=First conversation action must specify a valid session class

Modified: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/UnsupportedAction.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/UnsupportedAction.java	2008-06-30 10:55:52 UTC (rev 84)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/UnsupportedAction.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -28,6 +28,16 @@
 public class UnsupportedAction extends ESBAction {
 
 	/**
+	 * This method determines whether the action is related to a behavioural
+	 * session.
+	 * 
+	 * @return Whether the action is session based
+	 */
+	public boolean isSessionBased() {
+		return(false);
+	}
+	
+	/**
 	 * This method converts the ESB action into an equivalent
 	 * behavioural description for conformance checking.
 	 * 

Modified: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/CreateSessionAction.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/CreateSessionAction.java	2008-06-30 10:55:52 UTC (rev 84)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/CreateSessionAction.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -19,7 +19,6 @@
 
 import org.jboss.tools.overlord.jbossesb.model.ConversionContext;
 import org.jboss.tools.overlord.jbossesb.model.ESBAction;
-import org.jboss.tools.overlord.jbossesb.model.ESBService;
 import org.scribble.model.*;
 
 /**

Added: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/GetVariableAction.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/GetVariableAction.java	                        (rev 0)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/GetVariableAction.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -0,0 +1,104 @@
+/*
+ * 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.actions;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.overlord.jbossesb.model.ConversionContext;
+import org.jboss.tools.overlord.jbossesb.model.ESBAction;
+import org.scribble.model.*;
+
+/**
+ * The model component for the 'GetVariableAction'. 
+ *  
+ * @author gary
+ */
+public class GetVariableAction extends ESBAction {
+
+	private static final String VARIABLE = "variable";
+
+	/**
+	 * This method validates the ESB action and reports warnings or
+	 * errors to the supplied model listener.
+	 * 
+	 * @param l The model listener
+	 */
+	@Override
+	public void validate(ModelListener l) {
+		super.validate(l);
+		
+		String variable=getPropertyValue(VARIABLE);
+		
+		if (variable == null) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_NOT_SPECIFIED_VARIABLE",
+						new String[]{}), null);
+		} else {
+			
+			// Check that variable defined on session class
+			Class<?> cls=getService().getSessionClass();
+			
+			if (cls != null) {
+				try {
+					java.beans.BeanInfo bi=java.beans.Introspector.getBeanInfo(cls);
+					
+					boolean f_found=false;
+					
+					java.beans.PropertyDescriptor[] pds=bi.getPropertyDescriptors();
+					
+					for (int i=0; f_found==false && pds != null &&
+								i < pds.length; i++) {
+						if (pds[i].getName().equals(variable)) {
+							f_found = true;
+						}
+					}
+					
+					if (f_found == false) {
+						l.error(this, org.scribble.util.MessageUtil.format(
+								java.util.PropertyResourceBundle.getBundle(
+								"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+									"_NOT_FOUND_VARIABLE",
+									new String[]{variable, cls.getName()}), null);					
+					}
+				} catch(Exception e) {
+					logger.log(java.util.logging.Level.SEVERE,
+							"Failed to check if variable '"+
+							variable+"' exists on session class '"+
+							cls+"'", e);
+				}
+			}
+		}
+	}
+		
+	/**
+	 * This method converts the ESB action into an equivalent
+	 * behavioural description for conformance checking.
+	 * 
+	 * @param activities The list of activities that will contain
+	 * 				the converted action(s)
+	 * @param context The conversion context
+	 */
+	@Override
+	public void convert(java.util.List<Activity> activities,
+			ConversionContext context) {
+	}
+	
+	private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model.actions");
+}

Added: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java	                        (rev 0)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -0,0 +1,161 @@
+/*
+ * 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.actions;
+
+import org.jboss.tools.overlord.jbossesb.model.ConversionContext;
+import org.jboss.tools.overlord.jbossesb.model.ESBAction;
+import org.jboss.tools.overlord.jbossesb.model.ESBLink;
+import org.jboss.tools.overlord.jbossesb.model.ESBService;
+import org.scribble.model.*;
+
+/**
+ * The model component for the 'MessageRouterAction'. Although
+ * not an integral part of the behaviour of a service, it provides
+ * a behavioural gateway to ensure that messages sent to a
+ * specific endpoint reference are routed to the appropriate
+ * ESB service descriptor. Therefore the routing configuration
+ * needs to be synchronized with the definition of the service
+ * descriptors representing the various behavioural states associated
+ * with a service.
+ *  
+ * @author gary
+ */
+public class MessageRouterAction extends ESBAction {
+
+	private static final String INITIATE = "initiate";
+	private static final String SERVICE_NAME = "service-name";
+	private static final String SERVICE_CATEGORY = "service-category";
+	private static final String ROUTE = "route";
+	private static final String PATHS = "paths";
+
+	/**
+	 * This method initializes the links with the ESB service descriptors
+	 * identified in each path of the action.
+	 */
+	@Override
+	protected void initializeLinks() {
+		super.initializeLinks();
+		
+		org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
+		
+		for (int i=0; i < nl.getLength(); i++) {
+			
+			org.w3c.dom.Node n=nl.item(i);
+			
+			if (n instanceof org.w3c.dom.Element) {
+				if (n.getNodeName().equals(ROUTE)) {
+					String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+					String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+					String initiate=((org.w3c.dom.Element)n).getAttribute(INITIATE);
+
+					// Lookup service associated with category and name
+					ESBService service=getService().getModel().getService(category, name);
+				
+					// Initialize link, even if service is null - this will be
+					// reported as a validation error later
+					getLinks().add(new ESBLink(category, name, service, true));
+					
+					if (service != null) {
+						if (initiate != null && initiate.equalsIgnoreCase("true")) {
+							m_initiateServices.add(service);
+						} else {
+							m_services.add(service);
+						}
+					}
+				}
+			}
+		}
+	}
+	
+	/**
+	 * This method determines whether the action is related to a behavioural
+	 * session.
+	 * 
+	 * @return Whether the action is session based
+	 */
+	public boolean isSessionBased() {
+		return(false);
+	}
+	
+	/**
+	 * This method validates the ESB action and reports warnings or
+	 * errors to the supplied model listener.
+	 * 
+	 * @param l The model listener
+	 */
+	@Override
+	public void validate(ModelListener l) {
+		super.validate(l);
+		
+		// Check that message router has no other session based
+		// ESB actions in the same service descriptor
+		if (getService().isSessionBased()) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_CANNOT_SESSION_BASED_ACTIONS_WITH_ROUTER",
+						new String[]{}), null);
+		}
+		
+		// Check that 'initate' services have a 'CreateSessionAction' and
+		// represent the root behaviour
+		for (int i=0; i < m_initiateServices.size(); i++) {
+			ESBService service=m_initiateServices.get(i);
+			
+			if (service.isRoot() == false) {
+				l.error(this, org.scribble.util.MessageUtil.format(
+						java.util.PropertyResourceBundle.getBundle(
+						"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+							"_CANNOT_INITIATE_NON_ROOT",
+							new String[]{service.getCategory(), 
+									service.getName()}), null);
+			}
+		}
+		
+		// Check that non-'initate' services don't have a 'CreateSessionAction' and
+		// represent the root behaviour
+		for (int i=0; i < m_services.size(); i++) {
+			ESBService service=m_services.get(i);
+			
+			if (service.isRoot()) {
+				l.error(this, org.scribble.util.MessageUtil.format(
+						java.util.PropertyResourceBundle.getBundle(
+						"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+							"_MUST_INITIATE_ROOT",
+							new String[]{service.getCategory(), 
+									service.getName()}), null);
+			}
+		}
+	}
+
+	/**
+	 * This method converts the ESB action into an equivalent
+	 * behavioural description for conformance checking.
+	 * 
+	 * @param activities The list of activities that will contain
+	 * 				the converted action(s)
+	 * @param context The conversion context
+	 */
+	@Override
+	public void convert(java.util.List<Activity> activities,
+			ConversionContext context) {
+	}
+	
+	private java.util.List<ESBService> m_initiateServices=new java.util.Vector<ESBService>();
+	private java.util.List<ESBService> m_services=new java.util.Vector<ESBService>();
+}

Modified: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties	2008-06-30 10:55:52 UTC (rev 84)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties	2008-06-30 16:54:52 UTC (rev 85)
@@ -16,7 +16,12 @@
 #  * MA  02110-1301, USA.
 #  */
 
+_CANNOT_INITIATE_NON_ROOT=Cannot 'initiate' non-root service descriptor for category '{0}' and name '{1}'
+_CANNOT_SESSION_BASED_ACTIONS_WITH_ROUTER=Cannot define MessageRouterAction with session based actions in service descriptor
+_MUST_INITIATE_ROOT=Must 'initiate' root service descriptor for category '{0}' and name '{1}'
 _NOT_FOUND_BUSINESS_OBJECT_TYPE=Business object type '{0}' could not be found
+_NOT_FOUND_VARIABLE=Variable '{0}' could not be found on session type '{1}'
 _NOT_FOUND_PERFORM_CREATE_SESSION=Perform action can only invoke a service descriptor that starts with a CreateSessionAction
 _NOT_FOUND_SERVICE_DESCRIPTOR=Service descriptor for category '{0}' and name '{1}' not found
+_NOT_SPECIFIED_VARIABLE=Variable name has not been specified
 _MUST_BE_FIRST_ACTION='{0}' action must be first in the service descriptor
\ No newline at end of file

Added: trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SetVariableAction.java
===================================================================
--- trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SetVariableAction.java	                        (rev 0)
+++ trunk/cdl/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SetVariableAction.java	2008-06-30 16:54:52 UTC (rev 85)
@@ -0,0 +1,104 @@
+/*
+ * 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.actions;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.overlord.jbossesb.model.ConversionContext;
+import org.jboss.tools.overlord.jbossesb.model.ESBAction;
+import org.scribble.model.*;
+
+/**
+ * The model component for the 'SetVariableAction'. 
+ *  
+ * @author gary
+ */
+public class SetVariableAction extends ESBAction {
+
+	private static final String VARIABLE = "variable";
+
+	/**
+	 * This method validates the ESB action and reports warnings or
+	 * errors to the supplied model listener.
+	 * 
+	 * @param l The model listener
+	 */
+	@Override
+	public void validate(ModelListener l) {
+		super.validate(l);
+		
+		String variable=getPropertyValue(VARIABLE);
+		
+		if (variable == null) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_NOT_SPECIFIED_VARIABLE",
+						new String[]{}), null);
+		} else {
+			
+			// Check that variable defined on session class
+			Class<?> cls=getService().getSessionClass();
+			
+			if (cls != null) {
+				try {
+					java.beans.BeanInfo bi=java.beans.Introspector.getBeanInfo(cls);
+					
+					boolean f_found=false;
+					
+					java.beans.PropertyDescriptor[] pds=bi.getPropertyDescriptors();
+					
+					for (int i=0; f_found==false && pds != null &&
+								i < pds.length; i++) {
+						if (pds[i].getName().equals(variable)) {
+							f_found = true;
+						}
+					}
+					
+					if (f_found == false) {
+						l.error(this, org.scribble.util.MessageUtil.format(
+								java.util.PropertyResourceBundle.getBundle(
+								"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+									"_NOT_FOUND_VARIABLE",
+									new String[]{variable, cls.getName()}), null);					
+					}
+				} catch(Exception e) {
+					logger.log(java.util.logging.Level.SEVERE,
+							"Failed to check if variable '"+
+							variable+"' exists on session class '"+
+							cls+"'", e);
+				}
+			}
+		}
+	}
+		
+	/**
+	 * This method converts the ESB action into an equivalent
+	 * behavioural description for conformance checking.
+	 * 
+	 * @param activities The list of activities that will contain
+	 * 				the converted action(s)
+	 * @param context The conversion context
+	 */
+	@Override
+	public void convert(java.util.List<Activity> activities,
+			ConversionContext context) {
+	}
+	
+	private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model.actions");
+}




More information about the overlord-commits mailing list