You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by az...@apache.org on 2008/10/09 12:55:47 UTC
svn commit: r703130 - in /webservices/axis2/trunk/java/modules:
clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
kernel/conf/axis2.xml
Author: azeez
Date: Thu Oct 9 03:55:47 2008
New Revision: 703130
URL: http://svn.apache.org/viewvc?rev=703130&view=rev
Log:
Setting MembershipListener properties using reflection
Modified:
webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java?rev=703130&r1=703129&r2=703130&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java Thu Oct 9 03:55:47 2008
@@ -20,6 +20,7 @@
package org.apache.axis2.clustering.tribes;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
import org.apache.axis2.AxisFault;
import org.apache.axis2.clustering.ClusterManager;
import org.apache.axis2.clustering.ClusteringConstants;
@@ -56,6 +57,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.xml.namespace.QName;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -63,6 +65,9 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Iterator;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
/**
* The main ClusterManager class for the Tribes based clustering implementation
@@ -225,10 +230,10 @@
}
}
Parameter isActiveParam = getParameter(ClusteringConstants.Parameters.IS_ACTIVE);
- if(isActiveParam != null){
+ if (isActiveParam != null) {
System.out.println("##### isActive=" + isActiveParam.getValue());
memberInfo.setProperty(ClusteringConstants.Parameters.IS_ACTIVE,
- (String)isActiveParam.getValue());
+ (String) isActiveParam.getValue());
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
@@ -369,8 +374,10 @@
throws ClusteringFault {
MembershipListener membershipListener = null;
Parameter parameter = getParameter(ClusteringConstants.Parameters.MEMBERSHIP_LISTENER);
- if(parameter != null){
- String clazz = ((String) parameter.getValue()).trim();
+ if (parameter != null) {
+ OMElement paramEle = parameter.getParameterElement();
+ String clazz =
+ paramEle.getFirstChildWithName(new QName("class")).getText().trim();
try {
membershipListener = (MembershipListener) Class.forName(clazz).newInstance();
} catch (Exception e) {
@@ -378,6 +385,17 @@
log.error(msg, e);
throw new ClusteringFault(msg, e);
}
+ OMElement propsEle = paramEle.getFirstChildWithName(new QName("properties"));
+ if (propsEle != null) {
+ for (Iterator iter = propsEle.getChildElements(); iter.hasNext();) {
+ OMElement propEle = (OMElement) iter.next();
+ OMAttribute nameAttrib = propEle.getAttribute(new QName("name"));
+ if (nameAttrib != null) {
+ String name = nameAttrib.getAttributeValue();
+ setInstanceProperty(name, propEle.getText().trim(), membershipListener);
+ }
+ }
+ }
}
String scheme = getMembershipScheme();
@@ -401,6 +419,86 @@
}
/**
+ * Find and invoke the setter method with the name of form setXXX passing in the value given
+ * on the POJO object
+ * @param name name of the setter field
+ * @param val value to be set
+ * @param obj POJO instance
+ * @throws ClusteringFault If an error occurs while setting the property
+ */
+ public void setInstanceProperty(String name, Object val, Object obj) throws ClusteringFault {
+
+ String mName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
+ Method method;
+ try {
+ Method[] methods = obj.getClass().getMethods();
+ boolean invoked = false;
+ for (Method method1 : methods) {
+ if (mName.equals(method1.getName())) {
+ Class[] params = method1.getParameterTypes();
+ 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");
+ } else if (val instanceof String) {
+ String value = (String) val;
+ if (params[0].equals(String.class)) {
+ method = obj.getClass().getMethod(mName, String.class);
+ method.invoke(obj, new String[]{value});
+ } else if (params[0].equals(int.class)) {
+ method = obj.getClass().getMethod(mName, int.class);
+ method.invoke(obj, new Integer[]{new Integer(value)});
+ } else if (params[0].equals(long.class)) {
+ method = obj.getClass().getMethod(mName, long.class);
+ method.invoke(obj, new Long[]{new Long(value)});
+ } else if (params[0].equals(float.class)) {
+ method = obj.getClass().getMethod(mName, float.class);
+ method.invoke(obj, new Float[]{new Float(value)});
+ } else if (params[0].equals(double.class)) {
+ method = obj.getClass().getMethod(mName, double.class);
+ method.invoke(obj, new Double[]{new Double(value)});
+ } else if (params[0].equals(boolean.class)) {
+ method = obj.getClass().getMethod(mName, boolean.class);
+ method.invoke(obj, new Boolean[]{Boolean.valueOf(value)});
+ } else {
+ handleException("Did not find a setter method named : " + mName +
+ "() that takes a single String, int, long, float, double " +
+ "or boolean parameter");
+ }
+ } else {
+ if (params[0].equals(OMElement.class)) {
+ method = obj.getClass().getMethod(mName, OMElement.class);
+ method.invoke(obj, new OMElement[]{(OMElement) val});
+ }
+ }
+ invoked = true;
+ }
+ }
+
+ if (!invoked) {
+ handleException("Did not find a setter method named : " + mName +
+ "() that takes a single String, int, long, float, double " +
+ "or boolean parameter");
+ }
+
+ } catch (Exception e) {
+ handleException("Error invoking setter method named : " + mName +
+ "() that takes a single String, int, long, float, double " +
+ "or boolean parameter", e);
+ }
+ }
+
+ private void handleException(String msg, Exception e) throws ClusteringFault {
+ log.error(msg, e);
+ throw new ClusteringFault(msg, e);
+ }
+
+ private void handleException(String msg) throws ClusteringFault {
+ log.error(msg);
+ throw new ClusteringFault(msg);
+ }
+
+ /**
* Get some information from a neighbour. This information will be used by this node to
* initialize itself
* <p/>
Modified: webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml?rev=703130&r1=703129&r2=703130&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml Thu Oct 9 03:55:47 2008
@@ -69,7 +69,6 @@
<!--<parameter name="ModulesDirectory">modules</parameter>-->
-
<!--Following params will set the proper context paths for invocations. All the endpoints will have a commons context-->
<!--root which can configured using the following contextRoot parameter-->
<!--<parameter name="contextRoot">axis2</parameter>-->
@@ -88,8 +87,10 @@
<!--POJO deployer , this will alow users to drop .class file and make that into a service-->
<deployer extension=".class" directory="pojo" class="org.apache.axis2.deployment.POJODeployer"/>
- <deployer extension=".jar" directory="servicejars" class="org.apache.axis2.jaxws.framework.JAXWSDeployer"/>
- <deployer extension=".jar" directory="transports" class="org.apache.axis2.deployment.TransportDeployer"/>
+ <deployer extension=".jar" directory="servicejars"
+ class="org.apache.axis2.jaxws.framework.JAXWSDeployer"/>
+ <deployer extension=".jar" directory="transports"
+ class="org.apache.axis2.deployment.TransportDeployer"/>
<!--CORBA deployer , this will alow users to invoke remote CORBA services through Axis2-->
<!--<deployer extension=".xml" directory="corba" class="org.apache.axis2.corba.deployer.CorbaDeployer"/>-->
@@ -111,7 +112,8 @@
<!-- </listener>-->
<threadContextMigrators>
- <threadContextMigrator listId="JAXWS-ThreadContextMigrator-List" class="org.apache.axis2.jaxws.addressing.migrator.EndpointContextMapMigrator"/>
+ <threadContextMigrator listId="JAXWS-ThreadContextMigrator-List"
+ class="org.apache.axis2.jaxws.addressing.migrator.EndpointContextMapMigrator"/>
</threadContextMigrators>
<!-- ================================================= -->
@@ -121,7 +123,7 @@
<!--all the other MEP implement it and add the correct entry to here , so that you can refer from-->
<!--any operation -->
<!--Note : You can override this for a particular service by adding the same element with your requirement-->
- <messageReceivers>
+ <messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
@@ -131,7 +133,7 @@
<messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-out"
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
<messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
- class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
+ class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
<messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</messageReceivers>
@@ -143,15 +145,15 @@
<!--format serialization in Axis2. These message formats are expected to be resolved based on the content type. -->
<messageFormatters>
<messageFormatter contentType="application/x-www-form-urlencoded"
- class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
+ class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
<messageFormatter contentType="multipart/form-data"
- class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
+ class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
<messageFormatter contentType="application/xml"
- class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
<messageFormatter contentType="text/xml"
- class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
+ class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
<messageFormatter contentType="application/soap+xml"
- class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
+ class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
</messageFormatters>
<!-- ================================================= -->
@@ -161,13 +163,13 @@
<!--formats in Axis2. These message formats are expected to be resolved based on the content type. -->
<messageBuilders>
<messageBuilder contentType="application/xml"
- class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
+ class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
<messageBuilder contentType="application/xml"
- class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
+ class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
<messageBuilder contentType="application/x-www-form-urlencoded"
- class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
+ class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
<messageBuilder contentType="multipart/form-data"
- class="org.apache.axis2.builder.MultipartFormDataBuilder"/>
+ class="org.apache.axis2.builder.MultipartFormDataBuilder"/>
</messageBuilders>
<!-- ================================================= -->
@@ -204,9 +206,9 @@
<!--transportReceiver name="tcp"
class="org.apache.axis2.transport.tcp.TCPServer">
<parameter name="port">6060</parameter-->>
- <!--If you want to give your own host address for EPR generation-->
- <!--uncomment the following paramter , and set it as you required.-->
- <!--<parameter name="hostname">tcp://myApp.com/ws</parameter>-->
+ <!--If you want to give your own host address for EPR generation-->
+ <!--uncomment the following paramter , and set it as you required.-->
+ <!--<parameter name="hostname">tcp://myApp.com/ws</parameter>-->
<!-- /transportReceiver -->
<!-- ================================================= -->
@@ -276,9 +278,14 @@
which will be called on membership changes
-->
<!--
- <parameter name="membershipListener">org.apache.axis2.clustering.MembershipListenerImpl</parameter>
- -->
-
+ <parameter name="membershipListener">
+ <class>org.apache.axis2.clustering.MembershipListenerImpl</class>
+ <properties>
+ <property name="foo">bar</property>
+ </properties>
+ </parameter>
+ -->
+
<!--
The membership scheme used in this setup. The only values supported at the moment are
"multicast" and "wka"
@@ -387,10 +394,12 @@
The "enable" attribute indicates whether Configuration management has been enabled
-->
- <configurationManager class="org.apache.axis2.clustering.configuration.DefaultConfigurationManager"
- enable="true">
- <listener class="org.apache.axis2.clustering.configuration.DefaultConfigurationManagerListener"/>
- </configurationManager>
+ <configurationManager
+ class="org.apache.axis2.clustering.configuration.DefaultConfigurationManager"
+ enable="true">
+ <listener
+ class="org.apache.axis2.clustering.configuration.DefaultConfigurationManagerListener"/>
+ </configurationManager>
<!--
This interface is responsible for handling context replication. The property changes in
@@ -403,7 +412,7 @@
The "enable" attribute indicates whether context replication has been enabled
-->
<contextManager class="org.apache.axis2.clustering.context.DefaultContextManager"
- enable="true">
+ enable="true">
<listener class="org.apache.axis2.clustering.context.DefaultContextManagerListener"/>
<replication>
<defaults>
@@ -440,9 +449,9 @@
</handler>
</phase>
<phase name="Addressing">
- <handler name="AddressingBasedDispatcher"
+ <handler name="AddressingBasedDispatcher"
class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
- <order phase="Addressing"/>
+ <order phase="Addressing"/>
</handler>
</phase>
<phase name="Security"/>
@@ -487,9 +496,9 @@
</phaseOrder>
<phaseOrder type="InFaultFlow">
<phase name="Addressing">
- <handler name="AddressingBasedDispatcher"
+ <handler name="AddressingBasedDispatcher"
class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
- <order phase="Addressing"/>
+ <order phase="Addressing"/>
</handler>
</phase>
<phase name="Security"/>