[overlord-commits] Overlord SVN: r35 - in trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord: jbossesb and 1 other directories.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Thu Jun 19 03:53:09 EDT 2008


Author: jeff.yuchang
Date: 2008-06-19 03:53:09 -0400 (Thu, 19 Jun 2008)
New Revision: 35

Added:
   trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/conversation/LogicalCourier.java
   trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/
   trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/MessageUtil.java
   trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/NameSpaceUtil.java
   trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/Test.java
   trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/XMLUtils.java
Log:
[SOAG-7]
* Remove the dependencies from pi4soa common libraries.


Added: trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/conversation/LogicalCourier.java
===================================================================
--- trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/conversation/LogicalCourier.java	                        (rev 0)
+++ trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/conversation/LogicalCourier.java	2008-06-19 07:53:09 UTC (rev 35)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., 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.
+ * 
+ * (C) 2008,
+ */
+package org.jboss.soa.overlord.conversation;
+
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.addressing.eprs.*;
+import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+
+/**
+ * This class providers the courier implementation associated
+ * with a LogicalEPR.
+ */
+public class LogicalCourier implements org.jboss.soa.esb.couriers.Courier {
+	
+	private ServiceInvoker serviceInvoker=null;
+	
+	/**
+	 * The constructor, supplied the logical EPR represented
+	 * by the courier.
+	 * 
+	 * @param epr The logical EPR
+	 * @throws MessageDeliverException
+	 */
+	public LogicalCourier(LogicalEPR epr)
+						throws MessageDeliverException {
+		serviceInvoker = epr.getServiceInvoker();
+	}
+	
+	/**
+	 * This method delivers the supplied message to the EPR
+	 * associated with the logical courier.
+	 * 
+	 * @param mesg The message
+	 */
+	public boolean deliver(Message mesg) throws CourierException,
+			MalformedEPRException {
+		
+		try {
+			serviceInvoker.deliverAsync(mesg);
+		} catch(MessageDeliverException e) {
+			throw new CourierException("Failed to deliver message", e);
+		}
+		
+		return(true);
+	}
+
+	/**
+	 * This method cleans up after the courier implementation
+	 * is no longer required.
+	 */
+	public void cleanup() {
+		serviceInvoker = null;
+	}
+
+}

Added: trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/MessageUtil.java
===================================================================
--- trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/MessageUtil.java	                        (rev 0)
+++ trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/MessageUtil.java	2008-06-19 07:53:09 UTC (rev 35)
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Change History:
+ * Mar 21, 2006 : Initial version created by gary
+ */
+package org.jboss.soa.overlord.jbossesb.util;
+
+import java.util.logging.Logger;
+
+import org.w3c.dom.Node;
+
+
+/**
+ * This class represents utility functions for processing
+ * messages.
+ *
+ */
+public class MessageUtil {
+	
+	private static Logger logger = Logger.getLogger(MessageUtil.class.getName());
+	
+	/**
+	 * This method returns the message type associated with the
+	 * supplied value.
+	 * 
+	 * @param value The value
+	 * @return The message type
+	 */
+	public static String getMessageType(Object value) {
+		String ret=null;
+		
+		if (value instanceof org.w3c.dom.Node) {
+			String namespace=((org.w3c.dom.Node)value).getNamespaceURI();
+			String localpart=((org.w3c.dom.Node)value).getLocalName();
+			
+			if (value instanceof org.w3c.dom.Element &&
+					((org.w3c.dom.Element)value).hasAttributeNS(
+							"http://www.w3.org/2001/XMLSchema-instance", "type")) {
+				String type=((org.w3c.dom.Element)value).getAttributeNS(
+						"http://www.w3.org/2001/XMLSchema-instance", "type");
+				
+				String prefix= XMLUtils.getPrefix(type);
+				
+				localpart = XMLUtils.getLocalname(type);
+
+				if (prefix == null) {
+					namespace = null;
+				} else {
+					namespace = ((org.w3c.dom.Element)value).
+							getAttribute("xmlns:"+prefix);
+					if (!NameSpaceUtil.isNotNull(namespace)) {
+						namespace = null;
+					}
+				}
+			}
+			
+			if (namespace == null) {
+				ret = localpart;
+			} else {
+				ret = NameSpaceUtil.getFullyQualifiedName(namespace,
+								localpart);
+			}
+		} else if (value instanceof String) {
+			ret = String.class.getName();
+			
+			try {
+				Node node=XMLUtils.getNode((String)value);
+				ret = getMessageType(node);
+			} catch(Exception e) {
+				logger.warning("Failed to obtain message type from value: "+value);
+			}
+			
+		} else {
+			ret = value.getClass().getName();
+		}
+		
+		return(ret);
+	}
+	
+}

Added: trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/NameSpaceUtil.java
===================================================================
--- trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/NameSpaceUtil.java	                        (rev 0)
+++ trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/NameSpaceUtil.java	2008-06-19 07:53:09 UTC (rev 35)
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2005 Pi4 Technologies Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Change History:
+ * Jul 28, 2005 : Initial version created by gary
+ */
+package org.jboss.soa.overlord.jbossesb.util;
+
+/**
+ * This class provides helper functiions for manipulating fully
+ * qualified names (with local parts and namespaces).
+ */
+public class NameSpaceUtil {
+	
+	public static final String NAMESPACE_PREFIX="{";
+	public static final String NAMESPACE_SUFFIX="}";
+	
+	/**
+	 * This method checks whether the supplied name is a
+	 * fully qualified name, with the name space contained
+	 * in braces, followed by a localpart.
+	 * 
+	 * @param name The name
+	 * @return Whether the name is a fully qualified name
+	 */
+	public static boolean isFullyQualifiedName(String name) {
+		boolean ret=false;
+		int pos=0;
+		
+		if (name != null && name.startsWith("{") &&
+				(pos=name.indexOf('}')) != -1 &&
+				name.length() != pos+1) {
+			ret = true;
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the fully qualified name associated
+	 * with the supplied namespace and local part. If the namespace
+	 * is null, or an empty string, then only the local part
+	 * will be returned.
+	 * 
+	 * @param namespace The namespace
+	 * @param localpart The local part
+	 * @return The fully qualified name
+	 */
+	public static String getFullyQualifiedName(String namespace,
+					String localpart) {
+		String ret=null;
+
+		if (namespace != null && namespace.trim().length() > 0) {
+			ret = NAMESPACE_PREFIX+namespace+NAMESPACE_SUFFIX;
+		}
+		
+		if (localpart != null) {
+			if (ret == null) {
+				ret = localpart;
+			} else {
+				ret += localpart;
+			}
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the namespace component of a fully
+	 * qualified name. If the supplied name does not have the
+	 * namespace prefix, then a null will be returned. If the
+	 * supplied name does not have the suffix, then the contents
+	 * following the prefix, to the end of the name, will be
+	 * returned.
+	 * 
+	 * @param qname The fully qualified name
+	 * @return The namespace
+	 */
+	public static String getNamespace(String qname) {
+		String ret=null;
+		int index=0;
+		
+		if (qname != null &&
+				(index=qname.indexOf(NAMESPACE_PREFIX)) != -1) {
+			int endindex=qname.indexOf(NAMESPACE_SUFFIX);
+			
+			if (endindex == -1) {
+				endindex = qname.length();
+			}
+			
+			ret = qname.substring(index+1, endindex);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method extracts the local part from the supplied
+	 * fully qualified name. If the namespace suffix cannot
+	 * be found, then the fully supplied name will be
+	 * returned.
+	 * 
+	 * @param qname The fully qualified name
+	 * @return The local part
+	 */
+	public static String getLocalPart(String qname) {
+		String ret=null;
+		int index=0;
+		
+		if (qname != null &&
+				(index=qname.indexOf(NAMESPACE_SUFFIX)) != -1) {
+			ret = qname.substring(index+1);
+		} else {
+			ret = qname;
+		}
+		
+		return(ret);
+	}
+	
+	public static boolean isNotNull(String value) {
+		return(value != null && value.trim().length() > 0);		
+	}
+
+}

Added: trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/Test.java
===================================================================
--- trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/Test.java	                        (rev 0)
+++ trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/Test.java	2008-06-19 07:53:09 UTC (rev 35)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., 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.
+ * 
+ * (C) 2008,
+ */
+package org.jboss.soa.overlord.jbossesb.util;
+
+import org.w3c.dom.Element;
+
+/**
+ * @author jeffyu
+ *
+ */
+public class Test {
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) throws Exception{
+		String attr="myId";
+		String val="<order><orderId id=\""+3+"\" /></order>";
+		String expr="/order/orderId/@id";
+		
+		String value = XMLUtils.executeXpath(val, expr);
+		System.out.println(value);
+		
+		Element element = (Element) XMLUtils.getNode(val);
+		System.out.println(XMLUtils.executeXpath(element, expr));
+	}
+
+}

Added: trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/XMLUtils.java
===================================================================
--- trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/XMLUtils.java	                        (rev 0)
+++ trunk/samples/esb/purchasing/system/src/org/jboss/soa/overlord/jbossesb/util/XMLUtils.java	2008-06-19 07:53:09 UTC (rev 35)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., 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.
+ * 
+ * (C) 2008,
+ */
+package org.jboss.soa.overlord.jbossesb.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+public class XMLUtils {
+	
+	/**
+	 * This method converts the supplied text representation
+	 * of an XML document into a DOM Node.
+	 * 
+	 * @param text The text
+	 * @return The node
+	 * @throws XMLException Failed to convert the text
+	 */
+	public static Node getNode(String text) throws Exception {
+		Node ret=null;
+		
+		try {
+			// Transform the text representation to DOM
+			DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+			fact.setNamespaceAware(true);
+			
+			InputStream xmlstr= new ByteArrayInputStream(text.getBytes());
+
+			DocumentBuilder builder=fact.newDocumentBuilder();
+			org.w3c.dom.Document doc=builder.parse(xmlstr);
+			
+			ret = doc.getDocumentElement();
+			
+		} catch(Exception e) {
+			throw new Exception("Failed to transform text " +
+					"into DOM representation", e);
+		}
+
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the prefix part of the supplied
+	 * qualified name.
+	 * 
+	 * @param qname The qualified name
+	 * @return The prefix
+	 */
+	public static String getPrefix(String qname) {
+		String ret=null;
+		int pos=0;
+		
+		if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
+			ret = qname.substring(0, pos);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the localname part of the supplied
+	 * qualified name.
+	 * 
+	 * @param qname The qualified name
+	 * @return The localname part
+	 */
+	public static String getLocalname(String qname) {
+		String ret=qname;
+		int pos=0;
+		
+		if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
+			ret = qname.substring(pos+1);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * 
+	 * @param object
+	 * @param expression: xpath expression
+	 * @return
+	 * @throws Exception
+	 */
+	public static String executeXpath(Object object, String expression) throws Exception {
+		XPathFactory factory = XPathFactory.newInstance();
+		XPath theXpath = factory.newXPath();
+		
+		if (object instanceof String) {
+			String xmlMessage = (String)object;
+			Node node = getNode(xmlMessage);
+			return theXpath.evaluate(expression, node);
+		} else if (object instanceof Element) {
+			return theXpath.evaluate(expression, object);
+		}
+		
+		return null;
+	}
+	
+}
\ No newline at end of file




More information about the overlord-commits mailing list