[overlord-commits] Overlord SVN: r328 - in cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb: src/java/org/jboss/tools/overlord/cdl/jbossesb and 2 other directories.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Sun Sep 14 16:21:18 EDT 2008


Author: objectiser
Date: 2008-09-14 16:21:17 -0400 (Sun, 14 Sep 2008)
New Revision: 328

Added:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/export/
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/export/ESBLanguageModelStreamExportRule.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/TypeReferenceModelChangeRule.java
Modified:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/META-INF/MANIFEST.MF
Log:
ESB specific rules to update the model.

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/META-INF/MANIFEST.MF
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/META-INF/MANIFEST.MF	2008-09-12 16:42:14 UTC (rev 327)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/META-INF/MANIFEST.MF	2008-09-14 20:21:17 UTC (rev 328)
@@ -21,9 +21,11 @@
   org.jboss.tools.overlord.cdl.jbossesb.parser.JBossESBNotation,
   org.jboss.tools.overlord.cdl.jbossesb.editor.JBossESBConfigEditorManager,
   org.jboss.tools.overlord.cdl.jbossesb.validation.ESBLanguageModelValidationRule,
+  org.jboss.tools.overlord.cdl.jbossesb.export.ESBLanguageModelStreamExportRule,
   org.jboss.tools.overlord.cdl.jbossesb.model.change.LanguageToConversationModelChangeRule,
   org.jboss.tools.overlord.cdl.jbossesb.model.change.ConversationModelChangeRule,
   org.jboss.tools.overlord.cdl.jbossesb.model.change.ConversationInteractionModelChangeRule,
+  org.jboss.tools.overlord.cdl.jbossesb.model.change.TypeReferenceModelChangeRule,
   org.jboss.tools.overlord.cdl.jbossesb.model.change.IfModelChangeRule,
   org.jboss.tools.overlord.cdl.jbossesb.model.change.ParallelModelChangeRule,
   org.jboss.tools.overlord.cdl.jbossesb.model.change.RunModelChangeRule,

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/export/ESBLanguageModelStreamExportRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/export/ESBLanguageModelStreamExportRule.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/export/ESBLanguageModelStreamExportRule.java	2008-09-14 20:21:17 UTC (rev 328)
@@ -0,0 +1,205 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.tools.overlord.cdl.jbossesb.export;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.jboss.tools.overlord.cdl.jbossesb.model.ESBLanguageModel;
+import org.scribble.export.*;
+import org.scribble.export.stream.*;
+import org.scribble.extensions.RegistryInfo;
+import org.scribble.model.*;
+import org.w3c.dom.Node;
+
+/**
+ * This class implements the stream based export rule for the
+ * ESBLanguageModel entity.
+ */
+ at RegistryInfo(extension=ExportRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class ESBLanguageModelStreamExportRule extends DefaultModelStreamExportRule {
+
+	/**
+	 * This method exports the model object.
+	 * 
+	 * @param modelObject The model object
+	 * @param context The context
+	 */
+	public boolean isSupported(ModelObject modelObject, String format) {
+		return(super.isSupported(modelObject, format) &&
+				ESBLanguageModel.class.isAssignableFrom(modelObject.getClass()));
+	}
+	
+	/**
+	 * This method determines whether the exporter rule is appropriate
+	 * for the supplied model object and format.
+	 * 
+	 * @param modelObject The model object
+	 * @param format The format
+	 * @throws IOException Failed to record export information
+	 */
+	public void export(ModelObject modelObject, ExporterContext context)
+							throws java.io.IOException {
+		ESBLanguageModel model=(ESBLanguageModel)modelObject;
+		
+		try {
+			String text=getText(model.getESBConfiguration());
+			
+			context.record(text.getBytes());
+			
+		} catch(Exception e) {
+			throw new java.io.IOException("Failed to get ESB configuration text");
+		}
+	}
+	
+	/**
+	 * 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);
+	}
+}

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/TypeReferenceModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/TypeReferenceModelChangeRule.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/change/TypeReferenceModelChangeRule.java	2008-09-14 20:21:17 UTC (rev 328)
@@ -0,0 +1,172 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.tools.overlord.cdl.jbossesb.model.change;
+
+import org.jboss.tools.overlord.cdl.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.jbossesb.model.actions.*;
+import org.jboss.tools.overlord.cdl.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 Type Reference.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class TypeReferenceModelChangeRule extends AbstractModelChangeRule {
+
+	/**
+	 * 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 TypeReference &&
+				toObj instanceof TypeReference &&
+				model instanceof ESBLanguageModel) {
+			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;
+		TypeReference fromTypeRef=(TypeReference)fromObj;
+		TypeReference toTypeRef=(TypeReference)toObj;
+		ConversationInteraction toInteraction=null;
+		ConversationInteraction fromInteraction=null;
+		
+		if (toTypeRef != null && toTypeRef.getParent() instanceof MessageSignature &&
+						toTypeRef.getParent().getParent() instanceof ConversationInteraction) {
+			toInteraction = (ConversationInteraction)toTypeRef.getParent().getParent();
+		}
+		
+		if (fromTypeRef != null && fromTypeRef.getParent() instanceof MessageSignature &&
+						fromTypeRef.getParent().getParent() instanceof ConversationInteraction) {
+			fromInteraction = (ConversationInteraction)fromTypeRef.getParent().getParent();
+		}
+		
+		// Get action from 'toInteraction'
+		if (toInteraction != null &&
+				toInteraction.getSource().getObject() instanceof
+							AbstractInteractionMessageAction) {
+			AbstractInteractionMessageAction ma=
+					(AbstractInteractionMessageAction)
+						toInteraction.getSource().getObject();
+			
+			ESBService service = ma.getService();
+				
+			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);
+		}
+	}
+}




More information about the overlord-commits mailing list