You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2006/07/31 08:25:11 UTC
svn commit: r427027 - in
/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config:
SynapseConfiguration.java xml/EndpointFactory.java
xml/XMLConfigurationBuilder.java
Author: asankha
Date: Sun Jul 30 23:25:10 2006
New Revision: 427027
URL: http://svn.apache.org/viewvc?rev=427027&view=rev
Log:
Add support for dynamic main mediator (rules element)
and dynamic endpoints
Modified:
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointFactory.java
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java?rev=427027&r1=427026&r2=427027&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java Sun Jul 30 23:25:10 2006
@@ -50,8 +50,11 @@
/** Hold referenced to the declared registries */
private Map registryMap = new HashMap();
- /** This is the "main" (or default) synapse mediator which mediates each and every message */
- private Mediator mainMediator = null;
+ /**
+ * This is the "main" (or default) synapse mediator which mediates each and every message
+ * It could/would hold a Mediator object or a DynamicProperty (if loaded from a registry)
+ */
+ private Object mainMediator = null;
/**
* Add a named mediator into this configuration
@@ -83,7 +86,7 @@
DynamicProperty dp = (DynamicProperty) o;
o = getRegistry(dp.getRegistryName()).getProperty(dp);
if (o == null) {
- handleException("Invalid DynamicSequence for name : " + name);
+ handleException("Invalid DynamicSequence for name : " + name + " from registry");
}
}
return (Mediator) o;
@@ -96,7 +99,15 @@
* @return the main mediator to be used
*/
public Mediator getMainMediator() {
- return mainMediator;
+ Object o = mainMediator;
+ if (o != null && o instanceof DynamicProperty) {
+ DynamicProperty dp = (DynamicProperty) o;
+ o = getRegistry(dp.getRegistryName()).getProperty(dp);
+ if (o == null) {
+ handleException("Invalid Synapse Mainmediator from registry");
+ }
+ }
+ return (Mediator) o;
}
/**
@@ -107,6 +118,10 @@
this.mainMediator = mainMediator;
}
+ public void setMainMediator(DynamicProperty dp) {
+ this.mainMediator = dp;
+ }
+
/**
* Add a global (system-wide) property.
* @param name the name of the property
@@ -159,12 +174,29 @@
}
/**
+ * Support DynamicEndpoints
+ * @param name name of Dynamic Endpoint
+ * @param dp the DynamicProperty referencing the endpoint
+ */
+ public void addNamedEndpoint(String name, DynamicProperty dp) {
+ namedEndpoints.put(name, dp);
+ }
+
+ /**
* Get the definition of a named endpoint
* @param name the name being looked up
* @return the endpoint definition which will resolve into an absolute address
*/
public Endpoint getNamedEndpoint(String name) {
- return (Endpoint) namedEndpoints.get(name);
+ Object o = namedEndpoints.get(name);
+ if (o != null && o instanceof DynamicProperty) {
+ DynamicProperty dp = (DynamicProperty) o;
+ o = getRegistry(dp.getRegistryName()).getProperty(dp);
+ if (o == null) {
+ handleException("Invalid DynamicEndpoint for name : " + name + " from registry");
+ }
+ }
+ return (Endpoint) o;
}
/**
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointFactory.java?rev=427027&r1=427026&r2=427027&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointFactory.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointFactory.java Sun Jul 30 23:25:10 2006
@@ -16,9 +16,11 @@
package org.apache.synapse.config.xml;
import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.XMLToObjectMapper;
import org.apache.synapse.SynapseException;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -50,10 +52,14 @@
*
* </endpoint>
*/
-public class EndpointFactory {
+public class EndpointFactory implements XMLToObjectMapper {
private static Log log = LogFactory.getLog(EndpointFactory.class);
+ private static final EndpointFactory instance = new EndpointFactory();
+
+ private EndpointFactory() {}
+
public static Endpoint createEndpoint(OMElement elem) {
OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
@@ -119,4 +125,16 @@
throw new SynapseException(msg, e);
}
+ public Object getObjectFromOMNode(OMNode om) {
+ if (om instanceof OMElement) {
+ return createEndpoint((OMElement) om);
+ } else {
+ handleException("Invalid XML configuration for an Endpoint. OMElement expected");
+ }
+ return null;
+ }
+
+ public static EndpointFactory getInstance() {
+ return instance;
+ }
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java?rev=427027&r1=427026&r2=427027&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java Sun Jul 30 23:25:10 2006
@@ -97,14 +97,23 @@
}
OMElement rules = root.getFirstChildWithName(Constants.RULES_ELT);
+
if (rules == null) {
handleException("A valid Synapse configuration MUST specify the main mediator using the <rules> element");
} else {
- SynapseMediator sm = (SynapseMediator) MediatorFactoryFinder.getInstance().getMediator(rules);
- if (sm.getList().isEmpty()) {
- handleException("Invalid configuration, the main mediator specified by the <rules> element is empty");
+ OMAttribute key = rules.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
+ if (key != null) {
+ DynamicProperty dp = new DynamicProperty(key.getAttributeValue());
+ dp.setMapper(MediatorFactoryFinder.getInstance());
+ config.setMainMediator(dp);
} else {
- config.setMainMediator(sm);
+ SynapseMediator sm = (SynapseMediator)
+ MediatorFactoryFinder.getInstance().getMediator(rules);
+ if (sm.getList().isEmpty()) {
+ handleException("Invalid configuration, the main mediator specified by the <rules> element is empty");
+ } else {
+ config.setMainMediator(sm);
+ }
}
}
@@ -212,7 +221,7 @@
* Create an endpoint definition digesting an XML fragment
*
* <pre>
- * <endpoint name="string" [address="url"]>
+ * <endpoint name="string" [key="string"] [address="url"]>
* .. extensibility ..
* </endpoint>
* </pre>
@@ -220,9 +229,17 @@
*/
public void defineEndpoint(SynapseConfiguration config, OMElement ele) {
- Endpoint endpoint = EndpointFactory.createEndpoint(ele);
- // add this endpoint to the configuration
- config.addNamedEndpoint(endpoint.getName(), endpoint);
+ OMAttribute name = ele.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+ OMAttribute key = ele.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
+ if (name != null && key != null) {
+ DynamicProperty dp = new DynamicProperty(key.getAttributeValue());
+ dp.setMapper(EndpointFactory.getInstance());
+ config.addNamedEndpoint(name.getAttributeValue(), dp);
+ } else {
+ Endpoint endpoint = EndpointFactory.createEndpoint(ele);
+ // add this endpoint to the configuration
+ config.addNamedEndpoint(endpoint.getName(), endpoint);
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org