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/08/06 15:11:51 UTC
svn commit: r563126 - in
/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
config/xml/ClassMediatorFactory.java config/xml/PropertyHelper.java
core/axis2/Axis2SynapseEnvironment.java mediators/ext/ClassMediator.java
Author: ruwan
Date: Mon Aug 6 06:11:50 2007
New Revision: 563126
URL: http://svn.apache.org/viewvc?view=rev&rev=563126
Log:
Cleaning the code and adding the helper class to build the properties
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java?view=diff&rev=563126&r1=563125&r2=563126
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java Mon Aug 6 06:11:50 2007
@@ -45,7 +45,7 @@
*/
public class ClassMediatorFactory extends AbstractMediatorFactory {
- private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
+ private static final Log log = LogFactory.getLog(ClassMediatorFactory.class);
private static final QName CLASS_Q = new QName(Constants.SYNAPSE_NAMESPACE,
"class");
@@ -75,68 +75,8 @@
for (Iterator it = elem.getChildElements(); it.hasNext();) {
OMElement child = (OMElement) it.next();
- if (child.getLocalName().toLowerCase().equals("property")) {
-
- String propertyName = child
- .getAttributeValue(new QName("name"));
- String mName = "set"
- + Character.toUpperCase(propertyName.charAt(0))
- + propertyName.substring(1);
-
- // try to set String value first
- if (child.getAttributeValue(new QName("value")) != null) {
- String value = child.getAttributeValue(new QName("value"));
-
- try {
- Method method = m.getClass().getMethod(mName,
- new Class[]{String.class});
- if (log.isDebugEnabled()) {
- log.debug("Setting property :: invoking method "
- + mName + "(" + value + ")");
- }
- method.invoke(m, new Object[]{value});
-
- } catch (Exception e) {
- String msg = "Error setting property : " + propertyName
- + " as a String property into class"
- + " mediator : " + m.getClass() + " : "
- + e.getMessage();
- throw new SynapseException(msg, e);
-
- }
- } else if (child.getAttributeValue(new QName("expression")) != null) {
- // check whether there is an XPATH exp for the property value
- // todo:
- } else {
- // now try XML child
- OMElement value = child.getFirstElement();
- if (value != null) {
-
- try {
- Method method = m.getClass().getMethod(mName,
- new Class[]{OMElement.class});
- if (log.isDebugEnabled()) {
- log
- .debug("Setting property :: invoking method "
- + mName + "(" + value + ")");
- }
- method.invoke(m, new Object[]{value});
-
- } catch (Exception e) {
- String msg = "Error setting property : "
- + propertyName
- + " as an OMElement property into class"
- + " mediator : " + m.getClass() + " : "
- + e.getMessage();
- throw new SynapseException(msg, e);
-
- }
-
- }
-
- // classMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
-
- }
+ if(PropertyHelper.isStaticProperty(child)) {
+ PropertyHelper.setStaticProperty(child, m);
}
}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java?view=auto&rev=563126
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java Mon Aug 6 06:11:50 2007
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.MessageContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
+
+/**
+ * This class will be used as a Helper class to get the properties loaded while building the
+ * Synapse Configuration from the XML
+ */
+public class PropertyHelper {
+
+ /**
+ * Log variable for the logging purposes
+ */
+ private static final Log log = LogFactory.getLog(PropertyHelper.class);
+
+ /**
+ * This method will set the static property discribed in the OMElement to the specified object.
+ * This Object should have the setter method for the specified property name
+ *
+ * @param property - OMElement specifying the property to be built in to the object
+ * @param o - Object to which the specified property will be set.
+ */
+ public static void setStaticProperty(OMElement property, Object o) {
+
+ if (property.getLocalName().toLowerCase().equals("property")) {
+
+ String propertyName = property.getAttributeValue(new QName("name"));
+ String mName = "set"
+ + Character.toUpperCase(propertyName.charAt(0))
+ + propertyName.substring(1);
+
+ // try to set String value first
+ if (property.getAttributeValue(new QName("value")) != null) {
+ String value = property.getAttributeValue(new QName("value"));
+
+ try {
+ Method method = o.getClass().getMethod(mName,
+ new Class[]{String.class});
+ if (log.isDebugEnabled()) {
+ log.debug("Setting property :: invoking method "
+ + mName + "(" + value + ")");
+ }
+ method.invoke(o, new Object[]{value});
+
+ } catch (Exception e) {
+ String msg = "Error setting property : " + propertyName
+ + " as a String property into class"
+ + " mediator : " + o.getClass() + " : "
+ + e.getMessage();
+ throw new SynapseException(msg, e);
+
+ }
+
+ } else {
+ // now try XML child
+ OMElement value = property.getFirstElement();
+ if (value != null) {
+
+ try {
+ Method method = o.getClass().getMethod(mName,
+ new Class[]{OMElement.class});
+ if (log.isDebugEnabled()) {
+ log
+ .debug("Setting property :: invoking method "
+ + mName + "(" + value + ")");
+ }
+ method.invoke(o, new Object[]{value});
+
+ } catch (Exception e) {
+ String msg = "Error setting property : "
+ + propertyName
+ + " as an OMElement property into class"
+ + " mediator : " + o.getClass() + " : "
+ + e.getMessage();
+ throw new SynapseException(msg, e);
+
+ }
+
+ }
+
+ }
+ }
+ }
+
+ /**
+ * This method will be called in the mediation time to set the dynamic properties specified by
+ * XPATH functions over the message context to the specified object. In this case the setter
+ * method should be present for the specified property name
+ *
+ * @param property - OMElement specifying the property to get the XPATH expression
+ * @param o - Object to which the executed XPATH function value over the MC will be set
+ * @param synCtx - MessageContext containg the message over which the XPATH function will
+ * be executed
+ */
+ public static void setDynamicProperty(OMElement property, Object o, MessageContext synCtx) {
+
+ // todo: ruwan
+ }
+
+ /**
+ * This method will check the given OMElement represent either a static property or not
+ *
+ * @param property - OMElement to be checked for the static property
+ * @return boolean true id the elemet represents a static property element false otherwise
+ */
+ public static boolean isStaticProperty(OMElement property) {
+
+ return "property".equals(property.getLocalName().toLowerCase())
+ && (property.getAttributeValue(new QName("value")) != null);
+
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?view=diff&rev=563126&r1=563125&r2=563126
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java Mon Aug 6 06:11:50 2007
@@ -128,9 +128,14 @@
}
public MessageContext createMessageContext() {
- log.debug("Creating Message Context");
+
+ if (log.isDebugEnabled()) {
+ log.debug("Creating Message Context");
+ }
+
org.apache.axis2.context.MessageContext axis2MC
= new org.apache.axis2.context.MessageContext();
+ axis2MC.setConfigurationContext(this.configContext);
MessageContext mc = new Axis2MessageContext(axis2MC, synapseConfig, this);
try {
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java?view=diff&rev=563126&r1=563125&r2=563126
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java Mon Aug 6 06:11:50 2007
@@ -28,6 +28,12 @@
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.axiom.om.OMElement;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
/**
* The class mediator delegates the mediation to a new instance of a specified
@@ -43,7 +49,9 @@
private Mediator mediator = null;
- /**
+ private List properties = new ArrayList();
+
+ /**
* Don't use a new instance... do one instance of the object per instance of
* this mediator
*
@@ -67,7 +75,6 @@
if (mediator == null) {
if (log.isDebugEnabled()) {
log.debug("The instance of the specified mediator is null");
-
}
return true;
}
@@ -83,8 +90,6 @@
}
}
-
-
public void destroy() {
log.debug("destroy");
if (mediator instanceof ManagedLifecycle) {
@@ -112,4 +117,12 @@
public Mediator getMediator() {
return mediator;
}
+
+ public void addProperty(OMElement property) {
+ properties.add(property);
+ }
+
+ public List getProperties() {
+ return this.properties;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org