[jboss-svn-commits] JBL Code SVN: r12142 - labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 25 12:50:03 EDT 2007
Author: tfennelly
Date: 2007-05-25 12:50:03 -0400 (Fri, 25 May 2007)
New Revision: 12142
Added:
labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java
Log:
ooop... missed adding this
Added: labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java (rev 0)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java 2007-05-25 16:50:03 UTC (rev 12142)
@@ -0,0 +1,122 @@
+package org.jboss.soa.esb.services.soapui;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Comment;
+import org.jboss.soa.esb.dom.YADOMUtil;
+
+import java.util.Map;
+
+import ognl.Ognl;
+import ognl.OgnlException;
+
+/**
+ * OGNL Utilities for SOAP message processing.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class OGNLUtils {
+
+ private static Logger logger = Logger.getLogger(OGNLUtils.class);
+ public static final String JBOSSESB_SOAP_NS = "http://jbossesb.jboss.org/soap";
+ public static final String JBOSSESB_SOAP_NS_PREFIX = "jbossesb-soap:";
+ public static final String OGNL_ATTRIB = "ognl";
+ public static final String IS_COLLECTION_ATTRIB = "is-collection";
+
+ public static Object getParameter(String ognl, Map params) {
+ Object param;
+
+ // Try getting the parameter from the params Map using the
+ // raw OGNL expression as the key...
+ param = params.get(ognl);
+ if(param == null) {
+ // And if that didn't work, try using the OGNL expression to extract the param
+ // from an Object Graph using the OGNL toolkit...
+ try {
+ param = Ognl.getValue(ognl, params);
+ } catch (OgnlException e) {
+ if(logger.isDebugEnabled()) {
+ logger.debug("OGNL Error.", e);
+ }
+ }
+ }
+
+ return (param != null?param:"");
+ }
+
+ public static String getOGNLExpression(Element element) {
+ StringBuffer ognlExpression = new StringBuffer();
+ Node parent = element.getParentNode();
+ boolean isInBody = false;
+
+ ognlExpression.append(getOGNLToken(element));
+
+ while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
+ Element parentElement = (Element) parent;
+ String parentName = YADOMUtil.getName(parentElement);
+
+ if (parentName.equalsIgnoreCase("body") &&
+ parent.getNamespaceURI().equalsIgnoreCase("http://schemas.xmlsoap.org/soap/envelope/")) {
+ isInBody = true;
+ break;
+ }
+
+ String preassignedOgnl = parentElement.getAttributeNS(JBOSSESB_SOAP_NS, OGNL_ATTRIB);
+ if(preassignedOgnl != null && !preassignedOgnl.equals("")) {
+ ognlExpression.insert(0, "." + preassignedOgnl);
+ isInBody = true;
+ break;
+ } else {
+ ognlExpression.insert(0, getOGNLToken(parentElement));
+ }
+ parent = parent.getParentNode();
+ }
+
+ if(!isInBody) {
+ return "";
+ }
+
+ // Remove the leading '.'
+ ognlExpression.deleteCharAt(0);
+
+ return ognlExpression.toString();
+ }
+
+ public static String getOGNLToken(Element element) {
+ String localName = element.getLocalName();
+ String ognlToken;
+
+ if (assertIsParentCollection(element)) {
+ int count = YADOMUtil.countElementsBefore(element, element.getTagName());
+ ognlToken = "[" + count + "]";
+ } else {
+ ognlToken = "." + localName;
+ }
+
+ return ognlToken;
+ }
+
+ private static boolean assertIsCollection(Element element) {
+ if(element.getAttributeNS(JBOSSESB_SOAP_NS, IS_COLLECTION_ATTRIB).equals("true")) {
+ // It's already been attributed... no need to check for the soapui comment...
+ return true;
+ }
+
+ Comment firstComment = (Comment) YADOMUtil.getFirstChildByType(element, Node.COMMENT_NODE);
+
+ // TODO: Get Ole (soapUI) to add an attribute to the collection element - better than looking for this comment.
+ if(firstComment != null && firstComment.getTextContent().indexOf("1 or more repetitions") != -1) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private static boolean assertIsParentCollection(Element element) {
+ Node parent = element.getParentNode();
+ if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE && assertIsCollection((Element)parent)) {
+ return true;
+ }
+ return false;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list