You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ru...@apache.org on 2007/12/14 05:45:36 UTC
svn commit: r604102 - in
/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
config/xml/ mediators/ext/
Author: ruwan
Date: Thu Dec 13 20:45:35 2007
New Revision: 604102
URL: http://svn.apache.org/viewvc?rev=604102&view=rev
Log:
POJOCommand mediator modifications with action
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java?rev=604102&r1=604101&r2=604102&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java Thu Dec 13 20:45:35 2007
@@ -22,12 +22,9 @@
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Mediator;
import org.apache.synapse.SynapseException;
import org.apache.synapse.mediators.ext.AnnotatedCommandMediator;
-import org.apache.synapse.mediators.ext.POJOCommandMediator;
import org.jaxen.JaxenException;
import javax.xml.namespace.QName;
@@ -89,7 +86,7 @@
xpath = new AXIOMXPath(
child.getAttribute(ATT_EXPRN).getAttributeValue());
OMElementUtils.addNameSpaces(xpath, child, log);
- pojoMediator.addDynamicSetterProperty(propName, xpath);
+ pojoMediator.addMessageSetterProperty(propName, xpath);
} catch (JaxenException e) {
handleException("Error instantiating XPath expression : " +
child.getAttribute(ATT_EXPRN), e);
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java?rev=604102&r1=604101&r2=604102&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java Thu Dec 13 20:45:35 2007
@@ -22,8 +22,6 @@
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Mediator;
import org.apache.synapse.SynapseException;
import org.apache.synapse.mediators.ext.POJOCommandMediator;
@@ -48,8 +46,17 @@
*/
public class POJOCommandMediatorFactory extends AbstractMediatorFactory {
- private static final QName POJO_COMMAND_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "pojoCommand");
- protected static final QName ATT_ACTION = new QName("action");
+ private static final QName POJO_COMMAND_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "pojoCommand");
+ protected static final QName ATT_ACTION = new QName("action");
+ protected static final QName ATT_CTXNAME = new QName("context-name");
+
+ protected static final String RM_ACTION = "ReadMessage";
+ protected static final String UM_ACTION = "UpdateMessage";
+ protected static final String RC_ACTION = "ReadContext";
+ protected static final String UC_ACTION = "UpdateContext";
+ protected static final String RAUM_ACTION = "ReadAndUpdateMessage";
+ protected static final String RAUC_ACTION = "ReadAndUpdateContext";
public Mediator createMediator(OMElement elem) {
@@ -79,69 +86,146 @@
OMElement child = (OMElement) it.next();
if("property".equals(child.getLocalName())) {
- String propName = child.getAttribute(ATT_NAME).getAttributeValue();
- if (propName == null) {
- handleException(
- "A POJO command mediator property must specify the name attribute");
+ OMAttribute nameAttr = child.getAttribute(ATT_NAME);
+ if (nameAttr != null && nameAttr.getAttributeValue() != null
+ && !"".equals(nameAttr.getAttributeValue())) {
+
+ handlePropertyAction(nameAttr.getAttributeValue(), child, pojoMediator);
} else {
- if (child.getAttribute(ATT_EXPRN) != null) {
- AXIOMXPath xpath = null;
+ handleException("A POJO command mediator " +
+ "property must specify the name attribute");
+ }
+ }
+ }
- try {
- xpath = new AXIOMXPath(child.getAttribute(ATT_EXPRN).getAttributeValue());
- OMElementUtils.addNameSpaces(xpath, child, log);
-
- if (child.getAttribute(ATT_ACTION) != null) {
-
- String action = child.getAttribute(ATT_ACTION).getAttributeValue();
- if ("get".equals(action)) {
- pojoMediator.addMessageGetterProperty(propName, xpath);
- } else if ("set".equals(action)) {
- pojoMediator.addDynamicSetterProperty(propName, xpath);
- } else {
- // if there is an action attribute and the value is not neigther get nor set
- handleException("Property action for the " +
- "POJOCommand mediator should be eigther 'get' or 'set'");
- }
- } else {
- // if no action is provided take it as a setter propperty
- pojoMediator.addDynamicSetterProperty(propName, xpath);
- }
-
- } catch (JaxenException e) {
- handleException("Error instantiating XPath expression : " +
- child.getAttribute(ATT_EXPRN), e);
- }
- } else {
- if (child.getAttribute(ATT_VALUE) != null) {
+ return pojoMediator;
+ }
- String value = child.getAttribute(ATT_VALUE).getAttributeValue();
- if (child.getAttribute(ATT_ACTION) != null) {
+ private void handlePropertyAction(String name, OMElement propElem, POJOCommandMediator m) {
- String action = child.getAttribute(ATT_ACTION).getAttributeValue();
- if ("get".equals(action)) {
- pojoMediator.addContextGetterProperty(propName, value);
- } else if ("set".equals(action)) {
- pojoMediator.addStaticSetterProperty(propName, value);
- } else {
- // if there is an action attribute and the value is not neigther get nor set
- handleException("Property action for the " +
- "POJOCommand mediator should be eigther 'get' or 'set'");
- }
- } else {
- // if no action is provided take it as a setter propperty
- pojoMediator.addStaticSetterProperty(propName, value);
- }
+ OMAttribute valueAttr = propElem.getAttribute(ATT_VALUE);
+ OMAttribute exprAttr = propElem.getAttribute(ATT_EXPRN);
+ OMAttribute ctxNameAttr = propElem.getAttribute(ATT_CTXNAME);
+ OMAttribute actionAttr = propElem.getAttribute(ATT_ACTION);
+
+ AXIOMXPath xpath = null;
+ try {
+ if (exprAttr != null) {
+ xpath = new AXIOMXPath(exprAttr.getAttributeValue());
+ OMElementUtils.addNameSpaces(xpath, propElem, log);
+ }
+ } catch (JaxenException e) {
+ handleException("Error in building the expression as an AXIOMXPath" + e);
+ }
+
+ // if there is a value attribute there is no action (action is implied as read value)
+ if (valueAttr != null) {
+ String value = valueAttr.getAttributeValue();
+ // all other three attributes can not co-exists
+ if (exprAttr != null && ctxNameAttr != null) {
+ handleException("Command properties can not contain all three 'value', " +
+ "'expression' and 'context-name' attributes. Only one or " +
+ "combination of two can be there.");
+ } else {
+ m.addStaticSetterProperty(name, value);
+ if (exprAttr != null) {
+ // action ==> ReadValueAndUpdateMesssage
+ m.addMessageGetterProperty(name, xpath);
+ } else if (ctxNameAttr != null) {
+ // action ==> ReadValueAndUpdateContext
+ m.addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
+ } // else the action ==> ReadValue
+ }
+ } else if (propElem.getFirstElement() != null) {
+ // all other two attributes can not co-exists
+ if (exprAttr != null && ctxNameAttr != null) {
+ handleException("Command properties can not contain all the " +
+ "'expression' and 'context-name' attributes with a child. Only one " +
+ "attribute of those can co-exists with a child");
+ } else {
+ m.addStaticSetterProperty(name, propElem.getFirstElement());
+ if (exprAttr != null) {
+ // action ==> ReadValueAndUpdateMesssage
+ m.addMessageGetterProperty(name, xpath);
+ } else if (ctxNameAttr != null) {
+ // action ==> ReadValueAndUpdateContext
+ m.addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
+ } // else the action ==> ReadValue
+ }
+ } else {
+ // if both context-name and expression is there
+ if (exprAttr != null && ctxNameAttr != null) {
+ if (actionAttr != null && actionAttr.getAttributeValue() != null) {
+ String action = actionAttr.getAttributeValue();
+ if (RM_ACTION.equals(action) || UC_ACTION.equals(action)) {
+ // action ==> ReadMessageAndUpdateContext
+ m.addMessageSetterProperty(name, xpath);
+ m.addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
+ } else if (RC_ACTION.equals(action) || UM_ACTION.equals(action)) {
+ // action ==> ReadContextAndUpdateMessage
+ m.addContextSetterProperty(name, ctxNameAttr.getAttributeValue());
+ m.addMessageGetterProperty(name, xpath);
+ } else {
+ handleException("Invalid action for " +
+ "the command property with the name " + name);
+ }
+ } else {
+ handleException("Action attribute " +
+ "is required for the command property with name " + name);
+ }
+ } else {
+ // only one of expression or context-name is present
+ if (actionAttr != null && actionAttr.getAttributeValue() != null) {
+ String action = actionAttr.getAttributeValue();
+ if (exprAttr != null) {
+ if (RM_ACTION.equals(action)) {
+ // action ==> ReadMessage
+ m.addMessageSetterProperty(name, xpath);
+ } else if (UM_ACTION.equals(action)) {
+ // action ==> UpdateMessage
+ m.addMessageGetterProperty(name, xpath);
+ } else if (RAUM_ACTION.equals(action)) {
+ // action ==> ReadAndUpdateMessage
+ m.addMessageSetterProperty(name, xpath);
+ m.addMessageGetterProperty(name, xpath);
+ } else {
+ handleException("Invalid action for " +
+ "the command property with the name " + name);
+ }
+ } else if (ctxNameAttr != null) {
+ String ctxName = ctxNameAttr.getAttributeValue();
+ if (RC_ACTION.equals(action)) {
+ // action ==> ReadContext
+ m.addContextSetterProperty(name, ctxName);
+ } else if (UC_ACTION.equals(action)) {
+ // action ==> UpdateContext
+ m.addContextGetterProperty(name, ctxName);
+ } else if (RAUC_ACTION.equals(action)) {
+ // action ==> ReadAndUpdateContext
+ m.addContextSetterProperty(name, ctxName);
+ m.addContextGetterProperty(name, ctxName);
} else {
- handleException("A POJO mediator property must specify either " +
- "name and expression attributes, or name and value attributes");
+ handleException("Invalid action for " +
+ "the command property with the name " + name);
}
+ } else {
+ handleException("Unrecognized command property with the name " + name);
+ }
+ } else {
+ // action ==> ReadAndUpdateMessage/Context
+ if (exprAttr != null) {
+ m.addMessageSetterProperty(name, xpath);
+ m.addMessageGetterProperty(name, xpath);
+ } else if (ctxNameAttr != null) {
+ String ctxName = ctxNameAttr.getAttributeValue();
+ m.addContextSetterProperty(name, ctxName);
+ m.addContextGetterProperty(name, ctxName);
+ } else {
+ handleException("Unrecognized command property with the name " + name);
}
}
}
}
-
- return pojoMediator;
}
public QName getTagQName() {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java?rev=604102&r1=604101&r2=604102&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java Thu Dec 13 20:45:35 2007
@@ -58,54 +58,118 @@
handleException("Invalid POJO Command mediator. The command class name is required");
}
- for (Iterator itr = mediator.getStaticSetterProperties().keySet().iterator(); itr.hasNext(); ) {
+ for (Iterator itr = mediator.
+ getStaticSetterProperties().keySet().iterator(); itr.hasNext(); ) {
+
String propName = (String) itr.next();
- String value = (String) mediator.getStaticSetterProperties().get(propName);
+ Object value = mediator.getStaticSetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
- prop.addAttribute(fac.createOMAttribute("value", nullNS, value));
- prop.addAttribute(fac.createOMAttribute("action", nullNS, "set"));
+
+ if (value instanceof String) {
+ prop.addAttribute(fac.createOMAttribute("value", nullNS, (String) value));
+ } else if (value instanceof OMElement) {
+ prop.addChild((OMElement) value);
+ } else {
+ handleException("Unable to serialize the command " +
+ "mediator property with the naem " + propName + " : Unknown type");
+ }
+
+ if (mediator.getContextGetterProperties().containsKey(propName)) {
+ prop.addAttribute(fac.createOMAttribute("context-name", nullNS,
+ mediator.getContextGetterProperties().get(propName)));
+ } else if (mediator.getMessageGetterProperties().containsKey(propName)) {
+ AXIOMXPath xpath = mediator.getMessageGetterProperties().get(propName);
+ prop.addAttribute(fac.createOMAttribute("expression", nullNS, xpath.toString()));
+ serializeNamespaces(prop, xpath);
+ }
pojoCommand.addChild(prop);
}
- for (Iterator itr = mediator.getDynamicSetterProperties().keySet().iterator(); itr.hasNext(); ) {
+ for (Iterator itr = mediator.
+ getMessageSetterProperties().keySet().iterator(); itr.hasNext(); ) {
+
String propName = (String) itr.next();
- AXIOMXPath exprn = (AXIOMXPath) mediator.getDynamicSetterProperties().get(propName);
+ AXIOMXPath exprn = mediator.getMessageSetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
- prop.addAttribute(fac.createOMAttribute("expression", nullNS,
- exprn.toString()));
+ prop.addAttribute(fac.createOMAttribute("expression", nullNS, exprn.toString()));
serializeNamespaces(prop, exprn);
- prop.addAttribute(fac.createOMAttribute("action", nullNS, "set"));
+
+ if (mediator.getMessageGetterProperties().containsKey(propName)) {
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadAndUpdateMessage"));
+ } else if (mediator.getContextGetterProperties().containsKey(propName)) {
+ prop.addAttribute(fac.createOMAttribute("context-name", nullNS,
+ mediator.getContextGetterProperties().get(propName)));
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadMessage"));
+ } else {
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadMessage"));
+ }
pojoCommand.addChild(prop);
}
- for (Iterator itr = mediator.getContextGetterProperties().keySet().iterator(); itr.hasNext(); ) {
+ for (Iterator itr = mediator.
+ getContextSetterProperties().keySet().iterator(); itr.hasNext(); ) {
+
String propName = (String) itr.next();
- String value = (String) mediator.getContextGetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
- prop.addAttribute(fac.createOMAttribute("value", nullNS, value));
- prop.addAttribute(fac.createOMAttribute("action", nullNS, "get"));
+ prop.addAttribute(fac.createOMAttribute("context-name", nullNS,
+ mediator.getContextSetterProperties().get(propName)));
+
+ if (mediator.getContextGetterProperties().containsKey(propName)) {
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadAndUpdateContext"));
+ } else if (mediator.getMessageGetterProperties().containsKey(propName)) {
+ AXIOMXPath exprn = mediator.getMessageGetterProperties().get(propName);
+ prop.addAttribute(fac.createOMAttribute("expression", nullNS, exprn.toString()));
+ serializeNamespaces(prop, exprn);
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadContext"));
+ } else {
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadContext"));
+ }
pojoCommand.addChild(prop);
}
- for (Iterator itr = mediator.getMessageGetterProperties().keySet().iterator(); itr.hasNext(); ) {
+ for (Iterator itr = mediator.
+ getContextGetterProperties().keySet().iterator(); itr.hasNext(); ) {
+
String propName = (String) itr.next();
- AXIOMXPath exprn = (AXIOMXPath) mediator.getMessageGetterProperties().get(propName);
- OMElement prop = fac.createOMElement(PROP_Q);
- prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
- prop.addAttribute(fac.createOMAttribute("expression", nullNS,
- exprn.toString()));
- serializeNamespaces(prop, exprn);
- prop.addAttribute(fac.createOMAttribute("action", nullNS, "get"));
- pojoCommand.addChild(prop);
+ if (!isSerialized(propName, mediator)) {
+ String value = mediator.getContextGetterProperties().get(propName);
+ OMElement prop = fac.createOMElement(PROP_Q);
+ prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
+ prop.addAttribute(fac.createOMAttribute("context-name", nullNS, value));
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "UpdateContext"));
+ pojoCommand.addChild(prop);
+ }
+ }
+
+ for (Iterator itr = mediator.
+ getMessageGetterProperties().keySet().iterator(); itr.hasNext(); ) {
+
+ String propName = (String) itr.next();
+ if (!isSerialized(propName, mediator)) {
+ AXIOMXPath exprn = mediator.getMessageGetterProperties().get(propName);
+ OMElement prop = fac.createOMElement(PROP_Q);
+ prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
+ prop.addAttribute(fac.createOMAttribute("expression", nullNS,
+ exprn.toString()));
+ serializeNamespaces(prop, exprn);
+ prop.addAttribute(fac.createOMAttribute("action", nullNS, "UpdateMessage"));
+ pojoCommand.addChild(prop);
+ }
}
if (parent != null) {
parent.addChild(pojoCommand);
}
return pojoCommand;
+ }
+
+ private boolean isSerialized(String propName, POJOCommandMediator m) {
+ return m.getContextSetterProperties().containsKey(propName) ||
+ m.getStaticSetterProperties().containsKey(propName) ||
+ m.getMessageSetterProperties().containsKey(propName);
}
public String getMediatorClassName() {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java?rev=604102&r1=604101&r2=604102&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java Thu Dec 13 20:45:35 2007
@@ -20,6 +20,7 @@
package org.apache.synapse.mediators.ext;
import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.synapse.Command;
@@ -55,25 +56,31 @@
* 'static' properties whose values are constant and does not depend
* on the current message (i.e. and XPath over it)
*/
- private Map staticSetterProperties = new HashMap();
+ private Map<String, Object> staticSetterProperties = new HashMap<String, Object>();
/**
* 'dynamic' properties whose values are dynamically evaluated before each
* invocation of the command, by evaluating an XPath against the current message
*/
- private Map dynamicSetterProperties = new HashMap();
+ private Map<String, AXIOMXPath> messageSetterProperties = new HashMap<String, AXIOMXPath>();
+
+ /**
+ * 'dynamic' properties whose values are dynamically evaluated before each
+ * invocation of the command, by getting a property from the message context
+ */
+ private Map<String, String> contextSetterProperties = new HashMap<String, String>();
/**
* 'context' properties whose values are set back to the message context as message
* context properties
*/
- private Map contextGetterProperties = new HashMap();
+ private Map<String, String> contextGetterProperties = new HashMap<String, String>();
/**
* 'messsage' properties whose values are set back to the current message, from the command
* and as specified by the XPATH
*/
- private Map messageGetterProperties = new HashMap();
+ private Map<String, AXIOMXPath> messageGetterProperties = new HashMap<String, AXIOMXPath>();
/**
* Implements the mediate method of the Mediator interface. This method will instantiate
@@ -116,15 +123,21 @@
// then set the static/constant properties first
for (Iterator iter = staticSetterProperties.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
- setInstanceProperty(name,
- (String) staticSetterProperties.get(name), commandObject, synCtx);
+ setInstanceProperty(name, staticSetterProperties.get(name), commandObject, synCtx);
+ }
+
+ // now set the any dynamic properties from the message context properties
+ for (Iterator iter = contextSetterProperties.keySet().iterator(); iter.hasNext(); ) {
+ String name = (String) iter.next();
+ setInstanceProperty(name, synCtx.getProperty(contextSetterProperties.get(name)),
+ commandObject, synCtx);
}
// now set the any dynamic properties evaluating XPath's on the current message
- for (Iterator iter = dynamicSetterProperties.keySet().iterator(); iter.hasNext(); ) {
+ for (Iterator iter = messageSetterProperties.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
- AXIOMXPath xpath = (AXIOMXPath) dynamicSetterProperties.get(name);
+ AXIOMXPath xpath = messageSetterProperties.get(name);
String value = Axis2MessageContext.getStringValue(xpath, synCtx);
setInstanceProperty(name, value, commandObject, synCtx);
@@ -161,7 +174,7 @@
// then set the context properties back to the messageContext from the command
for (Iterator iter = contextGetterProperties.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
- synCtx.setProperty((String) contextGetterProperties.get(name),
+ synCtx.setProperty(contextGetterProperties.get(name),
getInstanceProperty(name, commandObject, synCtx));
}
@@ -170,7 +183,7 @@
for (Iterator iter = messageGetterProperties.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
- AXIOMXPath xpath = (AXIOMXPath) messageGetterProperties.get(name);
+ AXIOMXPath xpath = messageGetterProperties.get(name);
Object resultValue = getInstanceProperty(name, commandObject, synCtx);
@@ -190,7 +203,8 @@
} else {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Unable to set the message property " + resultValue
- + "back to the message : Specified element by the xpath " + xpath + " can not be found");
+ + "back to the message : Specified element by the xpath "
+ + xpath + " can not be found");
}
}
} catch (JaxenException e) {
@@ -245,7 +259,8 @@
* @param obj POJO instance
* @param synCtx current message
*/
- protected void setInstanceProperty(String name, String value, Object obj, MessageContext synCtx) {
+ protected void setInstanceProperty(
+ String name, Object value, Object obj, MessageContext synCtx) {
String mName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
Method method = null;
@@ -260,31 +275,42 @@
if (params.length != 1) {
handleException("Did not find a setter method named : " + mName +
"() that takes a single String, int, long, float, double " +
- "or boolean parameter", synCtx);
- } else {
+ "or boolean or OMElement parameter", synCtx);
+ } else if (value instanceof String) {
if (params[0].equals(String.class)) {
method = obj.getClass().getMethod(mName, new Class[]{String.class});
- method.invoke(obj, new String[]{value});
+ method.invoke(obj, new String[]{(String) value});
} else if (params[0].equals(int.class)) {
method = obj.getClass().getMethod(mName, new Class[]{int.class});
- method.invoke(obj, new Integer[]{new Integer(value)});
+ method.invoke(obj, new Integer[]{new Integer((String) value)});
} else if (params[0].equals(long.class)) {
method = obj.getClass().getMethod(mName, new Class[]{long.class});
- method.invoke(obj, new Long[]{new Long(value)});
+ method.invoke(obj, new Long[]{new Long((String) value)});
} else if (params[0].equals(float.class)) {
method = obj.getClass().getMethod(mName, new Class[]{float.class});
- method.invoke(obj, new Float[]{new Float(value)});
+ method.invoke(obj, new Float[]{new Float((String) value)});
} else if (params[0].equals(double.class)) {
method = obj.getClass().getMethod(mName, new Class[]{double.class});
- method.invoke(obj, new Double[]{new Double(value)});
+ method.invoke(obj, new Double[]{new Double((String) value)});
} else if (params[0].equals(boolean.class)) {
method = obj.getClass().getMethod(mName, new Class[]{boolean.class});
- method.invoke(obj, new Boolean[]{new Boolean(value)});
+ method.invoke(obj, new Boolean[]{new Boolean((String) value)});
} else {
handleException("Did not find a setter method named : " + mName +
"() that takes a single String, int, long, float, double " +
"or boolean parameter", synCtx);
}
+ } else if (value instanceof OMElement) {
+ if (params[0].equals(OMElement.class)) {
+ method = obj.getClass().getMethod(mName, new Class[]{OMElement.class});
+ method.invoke(obj, new OMElement[]{(OMElement) value});
+ } else {
+ handleException("Did not find a setter method named : " + mName
+ + "() that takes an OMElement as the parameter", synCtx);
+ }
+ } else {
+ handleException("Can not handle the value type : "
+ + value.getClass(), synCtx);
}
invoked = true;
}
@@ -311,35 +337,43 @@
this.command = command;
}
- public void addStaticSetterProperty(String name, String value) {
+ public void addStaticSetterProperty(String name, Object value) {
this.staticSetterProperties.put(name, value);
}
- public void addDynamicSetterProperty(String name, Object value) {
- this.dynamicSetterProperties.put(name, value);
+ public void addMessageSetterProperty(String name, AXIOMXPath xpath) {
+ this.messageSetterProperties.put(name, xpath);
+ }
+
+ public void addContextSetterProperty(String name, String ctxName) {
+ this.contextSetterProperties.put(name, ctxName);
}
public void addContextGetterProperty(String name, String value) {
this.contextGetterProperties.put(name, value);
}
- public void addMessageGetterProperty(String name, Object value) {
- this.messageGetterProperties.put(name, value);
+ public void addMessageGetterProperty(String name, AXIOMXPath xpath) {
+ this.messageGetterProperties.put(name, xpath);
}
- public Map getStaticSetterProperties() {
+ public Map<String, Object> getStaticSetterProperties() {
return this.staticSetterProperties;
}
- public Map getDynamicSetterProperties() {
- return this.dynamicSetterProperties;
+ public Map<String, AXIOMXPath> getMessageSetterProperties() {
+ return this.messageSetterProperties;
+ }
+
+ public Map<String, String> getContextSetterProperties() {
+ return this.contextSetterProperties;
}
- public Map getContextGetterProperties() {
+ public Map<String, String> getContextGetterProperties() {
return this.contextGetterProperties;
}
- public Map getMessageGetterProperties() {
+ public Map<String, AXIOMXPath> getMessageGetterProperties() {
return this.messageGetterProperties;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org