You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by pz...@apache.org on 2006/06/01 11:28:27 UTC
svn commit: r410809 [3/10] - in /incubator/synapse/tags/M2: ./ bin/ etc/
modules/ modules/core/ modules/core/conf/ modules/core/src/
modules/core/src/org/ modules/core/src/org/apache/
modules/core/src/org/apache/synapse/ modules/core/src/org/apache/syn...
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/MessageContext.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/MessageContext.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/MessageContext.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/MessageContext.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.RelatesTo;
+
+import java.util.Iterator;
+import java.util.Set;
+
+
+/**
+ * The Synapse Message Context is available to all mediators through which it flows. It
+ * allows one to call to the underlying SynapseEnvironment (i.e. the SOAP engine
+ * - such as Axis2) where required. It also allows one to access the current
+ * SynapseConfiguration. Additionally it holds per message properties (i.e. local
+ * properties valid for the lifetime of the message), and the current SOAPEnvelope
+ */
+public interface MessageContext {
+
+ /**
+ * Get a reference to the current SynapseConfiguration
+ *
+ * @return the current synapse configuration
+ */
+ public SynapseConfiguration getConfiguration();
+
+ /**
+ * Set or replace the Synapse Configuration instance to be used. May be used to
+ * programatically change the configuration at runtime etc.
+ *
+ * @param cfg The new synapse configuration instance
+ */
+ public void setConfiguration(SynapseConfiguration cfg);
+
+ /**
+ * Returns a reference to the host Synapse Environment
+ * @return the Synapse Environment
+ */
+ public SynapseEnvironment getEnvironment();
+
+ /**
+ * Sets the SynapseEnvironment reference to this context
+ * @param se the reference to the Synapse Environment
+ */
+ public void setEnvironment(SynapseEnvironment se);
+
+ /**
+ * Get the value of a custom (local) property set on the message instance
+ * @param key key to look up property
+ * @return value for the given key
+ */
+ public Object getProperty(String key);
+
+ /**
+ * Set a custom (local) property with the given name on the message instance
+ * @param key key to be used
+ * @param value value to be saved
+ */
+ public void setProperty(String key, Object value);
+
+ /**
+ * Returns the Set of keys over the properties on this message context
+ * @return a Set of keys over message properties
+ */
+ public Set getPropertyKeySet();
+
+ /**
+ * Get the SOAP envelope of this message
+ * @return the SOAP envelope of the message
+ */
+ public SOAPEnvelope getEnvelope();
+
+ /**
+ * Sets the given envelope as the current SOAPEnvelope for this message
+ * @param envelope the envelope to be set
+ * @throws org.apache.axis2.AxisFault on exception
+ */
+ public void setEnvelope(SOAPEnvelope envelope) throws AxisFault;
+
+ // --- SOAP Message related methods ------
+ /** Get the faultTo EPR if available */
+ public EndpointReference getFaultTo();
+
+ /** Set the faultTo EPR */
+ public void setFaultTo(EndpointReference reference);
+
+ /** Get the from EPR if available */
+ public EndpointReference getFrom();
+
+ /** Set the from EPR */
+ public void setFrom(EndpointReference reference);
+
+ /** Get the message id if available */
+ public String getMessageID();
+
+ /** Set the message id */
+ public void setMessageID(String string);
+
+ /** Get the relatesTo of this message */
+ public RelatesTo getRelatesTo();
+
+ /**
+ * Sets the relatesTo references for this message
+ * @param reference the relatesTo references array
+ */
+ public void setRelatesTo(RelatesTo[] reference);
+
+ /** Set the replyTo EPR */
+ public EndpointReference getReplyTo();
+
+ /** Get the replyTo EPR if available */
+ public void setReplyTo(EndpointReference reference);
+
+ /** Get the To EPR */
+ public EndpointReference getTo();
+
+ /**
+ * Set the To EPR
+ * @param reference the To EPR
+ */
+ public void setTo(EndpointReference reference);
+
+ /**
+ * Sets the WSAAction
+ * @param actionURI the WSAAction
+ */
+ public void setWSAAction(String actionURI);
+
+ /**
+ * Returns the WSAAction
+ * @return the WSAAction
+ */
+ public String getWSAAction();
+
+ /**
+ * Returns the SOAPAction of the message
+ * @return the SOAPAction
+ */
+ public String getSoapAction();
+
+ /**
+ * Set the SOAPAction
+ * @param string the SOAP Action
+ */
+ public void setSoapAction(String string);
+
+ /**
+ * Set the message if
+ * @param messageID
+ */
+ public void setMessageId(String messageID);
+
+ /**
+ * Gets the message id
+ * @return the message id
+ */
+ public String getMessageId();
+
+ /**
+ * If this message using MTOM?
+ * @return true if using MTOM
+ */
+ public boolean isDoingMTOM();
+
+ /**
+ * Marks as using MTOM
+ * @param b true to mark as using MTOM
+ */
+ public void setDoingMTOM(boolean b);
+
+ /**
+ * Is this message over REST?
+ * @return true if over REST
+ */
+ public boolean isDoingREST();
+
+ /**
+ * Marks this message as over REST
+ * @param b true to mark as REST
+ */
+ public void setDoingREST(boolean b);
+
+ /**
+ * Is this message a SOAP 1.1 message?
+ * @return true if this is a SOAP 1.1 message
+ */
+ public boolean isSOAP11();
+
+ /**
+ * Mark this message as a response or not.
+ * @see org.apache.synapse.MessageContext#isResponse()
+ * @param b true to set this as a response
+ */
+ public void setResponse(boolean b);
+
+ /**
+ * Is this message a response to a synchronous message sent out through Synapse?
+ * @return true if this message is a response message
+ */
+ public boolean isResponse();
+
+ /**
+ * Marks this message as a fault response
+ * @see org.apache.synapse.MessageContext#isFaultResponse()
+ * @param b true to mark this as a fault response
+ */
+ public void setFaultResponse(boolean b);
+
+ /**
+ * Is this message a response to a fault message?
+ * @return true if this is a response to a fault message
+ */
+ public boolean isFaultResponse();
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/SynapseException.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/SynapseException.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/SynapseException.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/SynapseException.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+/**
+ * <p>Runtime exception for Synapse code to throw
+ */
+public class SynapseException extends RuntimeException {
+
+ private static final long serialVersionUID = -7244032125641596311L;
+
+ public SynapseException(String string) {
+ super(string);
+ }
+
+ public SynapseException(String msg, Throwable e) {
+ super(msg, e);
+ }
+
+ public SynapseException(Throwable t) {
+ super(t);
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/Util.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/Util.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/Util.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/Util.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,138 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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;
+
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.impl.llom.OMElementImpl;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+import org.apache.synapse.mediators.GetPropertyFunction;
+import org.jaxen.JaxenException;
+import org.jaxen.SimpleFunctionContext;
+import org.jaxen.XPathFunctionContext;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Holds utility methods used by Synapse
+ */
+public class Util {
+
+ private static final Log log = LogFactory.getLog(Util.class);
+
+ /**
+ * Evaluates the given XPath expression against the SOAPEnvelope of the
+ * current message and returns a String representation of the result
+ * @param xpath the expression to evaluate
+ * @param synCtx the source message which holds the SOAP envelope
+ * @return a String representation of the result of evaluation
+ */
+ public static String getStringValue(AXIOMXPath xpath, MessageContext synCtx) {
+
+ if (xpath != null) {
+ try {
+ // create an instance of a synapse:get-property() function and set it to the xpath
+ GetPropertyFunction getPropertyFunc = new GetPropertyFunction();
+ getPropertyFunc.setSynCtx(synCtx);
+
+ // set function context into XPath
+ SimpleFunctionContext fc = new XPathFunctionContext();
+ fc.registerFunction(Constants.SYNAPSE_NAMESPACE, "get-property", getPropertyFunc);
+ xpath.setFunctionContext(fc);
+
+ // register namespace for XPath extension function
+ xpath.addNamespace("synapse", Constants.SYNAPSE_NAMESPACE);
+
+ } catch (JaxenException je) {
+ String msg = "Error setting up the Synapse XPath extension function for XPath : " + xpath;
+ log.error(msg, je);
+ throw new SynapseException(msg, je);
+ }
+ }
+
+ try {
+ Object result = xpath.evaluate(synCtx.getEnvelope());
+ StringBuffer textValue = new StringBuffer();
+
+ if (result instanceof List) {
+ Iterator iter = ((List) result).iterator();
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof OMTextImpl) {
+ textValue.append(((OMTextImpl) o).getText());
+ } else if (o instanceof OMElementImpl) {
+ textValue.append(((OMElementImpl) o).getText());
+ }
+ }
+ } else {
+ textValue.append(result.toString());
+ }
+ return textValue.toString();
+
+ } catch (JaxenException je) {
+ String msg = "Evaluation of the XPath expression " + xpath.toString() + " resulted in an error";
+ log.error(msg, je);
+ throw new SynapseException(msg, je);
+ }
+ }
+
+ /**
+ * Return the namespace with the given prefix, using the given element
+ * @param prefix the prefix looked up
+ * @param elem the source element to use
+ * @return the namespace which maps to the prefix or null
+ */
+ public static String getNameSpaceWithPrefix(String prefix, OMElement elem) {
+ if (prefix == null || elem == null) {
+ log.warn("Searching for null NS prefix and/or using null OMElement");
+ return null;
+ }
+
+ Iterator iter = elem.getAllDeclaredNamespaces();
+ while (iter.hasNext()) {
+ OMNamespace ns = (OMNamespace) iter.next();
+ if (prefix.equals(ns.getPrefix())) {
+ return ns.getName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Add xmlns NS declarations of element 'elem' into XPath expression
+ * @param xpath
+ * @param elem
+ * @param log
+ */
+ public static void addNameSpaces(AXIOMXPath xpath, OMElement elem, Log log) {
+ try {
+ Iterator it = elem.getAllDeclaredNamespaces();
+ while (it.hasNext()) {
+ OMNamespace n = (OMNamespace) it.next();
+ xpath.addNamespace(n.getPrefix(), n.getName());
+ }
+ } catch (JaxenException je) {
+ String msg = "Error adding declared name spaces of " + elem + " to the XPath : " + xpath;
+ log.error(msg);
+ throw new SynapseException(msg, je);
+ }
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/FilterMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/FilterMediator.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/FilterMediator.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/FilterMediator.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,20 @@
+package org.apache.synapse.api;
+
+import org.apache.synapse.MessageContext;
+
+/**
+ * The filter mediator is a list mediator, which executes the given (sub) list of mediators
+ * if the specified condition is satisfied
+ *
+ * @see FilterMediator#test(org.apache.synapse.MessageContext)
+ */
+public interface FilterMediator extends ListMediator {
+
+ /**
+ * Should return true if the sub/child mediators should execute. i.e. if the filter
+ * condition is satisfied
+ * @param synCtx
+ * @return true if the configured filter condition evaluates to true
+ */
+ public boolean test(MessageContext synCtx);
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/ListMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/ListMediator.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/ListMediator.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/ListMediator.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,66 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.api;
+
+import java.util.List;
+
+/**
+ * The List mediator executes a given sequence/list of child mediators
+ */
+public interface ListMediator extends Mediator {
+
+ /**
+ * Appends the specified mediator to the end of this mediator's (children) list
+ * @param m the mediator to be added
+ * @return true (as per the general contract of the Collection.add method)
+ */
+ public boolean addChild(Mediator m);
+
+ /**
+ * Appends all of the mediators in the specified collection to the end of this mediator's (children)
+ * list, in the order that they are returned by the specified collection's iterator
+ * @param c the list of mediators to be added
+ * @return true if this list changed as a result of the call
+ */
+ public boolean addAll(List c);
+
+ /**
+ * Returns the mediator at the specified position
+ * @param pos index of mediator to return
+ * @return the mediator at the specified position in this list
+ */
+ public Mediator getChild(int pos);
+
+ /**
+ * Removes the first occurrence in this list of the specified mediator
+ * @param m mediator to be removed from this list, if present
+ * @return true if this list contained the specified mediator
+ */
+ public boolean removeChild(Mediator m);
+
+ /**
+ * Removes the mediator at the specified position in this list
+ * @param pos the index of the mediator to remove
+ * @return the mediator previously at the specified position
+ */
+ public Mediator removeChild(int pos);
+
+ /**
+ * Return the list of mediators of this List mediator instance
+ * @return the child/sub mediator list
+ */
+ public List getList();
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/Mediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/Mediator.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/Mediator.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/api/Mediator.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.api;
+
+import org.apache.synapse.MessageContext;
+
+/**
+ * All Synapse mediators must implement this Mediator interface. As a message passes
+ * through the synapse system, each mediator's mediate() method is invoked in the
+ * sequence/order defined in the SynapseConfiguration.
+ */
+public interface Mediator {
+
+ /**
+ * Invokes the mediator passing the current message for mediation. Each
+ * mediator performs its mediation action, and returns true if mediation
+ * should continue, or false if further mediation should be aborted.
+ *
+ * @param synCtx the current message for mediation
+ * @return true if further mediation should continue
+ */
+ public boolean mediate(MessageContext synCtx);
+
+ /**
+ * This is used for debugging purposes and exposes the type of the current
+ * mediator for logging and debugging purposes
+ * @return a String representation of the mediator type
+ */
+ public String getType();
+}
\ No newline at end of file
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Endpoint.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Endpoint.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Endpoint.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,83 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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;
+
+import java.net.URL;
+
+/**
+ * An endpoint can be used to give a logical name to an endpoint address, and possibly reused.
+ * If the address is not just a simple URL, then extensibility elements may be used to indicate
+ * the address. (i.e. an endpoint always will "resolve" into an absolute endpoint address.
+ *
+ * In future registry lookups etc may be used to resolve a named endpoint into its absolute address
+ */
+public class Endpoint {
+
+ /** The name of this endpoint instance */
+ private String name = null;
+ /** The simple address this endpoint resolves to - if explicitly specified */
+ private URL address = null;
+ /** The name of the actual endpoint to which this instance refers to */
+ private String ref = null;
+
+ /**
+ * Return the name of the endpoint
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the name of this named endpoint
+ * @param name the name to be set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * This should return the absolute EPR address referenced by the named endpoint. This may be possibly computed.
+ * @return an absolute address to be used to reference the named endpoint
+ */
+ public URL getAddress() {
+ return address;
+ }
+
+ /**
+ * Set an absolute URL as the address for this named endpoint
+ * @param address the absolute address to be used
+ */
+ public void setAddress(URL address) {
+ this.address = address;
+ }
+
+ /**
+ * Get the name of the Endpoint to which this instance refers to
+ * @return the name of the referenced endpoint
+ */
+ public String getRef() {
+ return ref;
+ }
+
+ /**
+ * Set the name of an Endpoint as the referenced endpoint of this instance
+ * @param ref the name of the Endpoint referenced
+ */
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Extension.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Extension.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Extension.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/Extension.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,34 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * An Extension allows the Synapse configuration to be extended. The Spring
+ * configuration support is implemented as such an extension, so that the
+ * Synapse core will not be dependent on Spring classes. An extension
+ * <b>must</b> specify the following methods to set and get its name.
+ */
+public interface Extension {
+
+ public String getName();
+
+ public void setName(String name);
+
+}
+
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfiguration.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,115 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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;
+
+import org.apache.synapse.api.Mediator;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The SynapseConfiguration holds the global configuration for a Synapse
+ * instance. It:
+ * - contains the model of the definitions & rules to execute
+ * - contains named global properties and their values
+ * - contains named endpoint definitions
+ */
+public class SynapseConfiguration {
+ /** Holds named sequences of mediators for reuse */
+ private Map namedSequences = new HashMap();
+
+ /** Holds named endpoints (which results into absolute EPRs) for reuse */
+ private Map namedEndpoints = new HashMap();
+
+ /** Holds global (system-wide) properties that apply to the synapse instance and every message */
+ private Map globalProps = new HashMap();
+
+ /** This is the "main" (or default) synapse mediator which mediates each and every message */
+ private Mediator mainMediator = null;
+
+ /**
+ * Add a named mediator into this configuration
+ * @param name the name for the sequence
+ * @param m the mediator to be reffered to by the name
+ */
+ public void addNamedMediator(String name, Mediator m) {
+ namedSequences.put(name, m);
+ }
+
+ /**
+ * Return the mediator named with the given name
+ * @param name the name being looked up
+ * @return the mediator referenced by the name
+ */
+ public Mediator getNamedMediator(String name) {
+ return (Mediator) namedSequences.get(name);
+ }
+
+ /**
+ * Return the "main" (or default) mediator of synapse. The main mediator mediates each and every
+ * message flowing through the system. In an XML based configuration, this is specified within the
+ * <rules> section of the configuration
+ * @return the main mediator to be used
+ */
+ public Mediator getMainMediator() {
+ return mainMediator;
+ }
+
+ /**
+ * Sets the main mediator for this instance
+ * @param mainMediator the mediator to be used as the main mediator
+ */
+ public void setMainMediator(Mediator mainMediator) {
+ this.mainMediator = mainMediator;
+ }
+
+ /**
+ * Add a global (system-wide) property.
+ * @param name the name of the property
+ * @param value its value
+ */
+ public void addProperty(String name, Object value) {
+ globalProps.put(name, value);
+ }
+
+ /**
+ * Get the value of the named property
+ * @param name key of the property being looked up
+ * @return its value
+ */
+ public Object getProperty(String name) {
+ return globalProps.get(name);
+ }
+
+ /**
+ * Define a named endpoint with the given name
+ * @param name the name of the endpoint
+ * @param endpoint the endpoint definition
+ */
+ public void addNamedEndpoint(String name, Endpoint endpoint) {
+ namedEndpoints.put(name, endpoint);
+ }
+
+ /**
+ * 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);
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfigurationBuilder.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfigurationBuilder.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/SynapseConfigurationBuilder.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,80 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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;
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.base.SynapseMediator;
+import org.apache.synapse.mediators.builtin.SendMediator;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.config.xml.XMLConfigurationBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ * Builds a Synapse Configuration model with a given input (e.g. XML, programmatic creation, default etc)
+ */
+public class SynapseConfigurationBuilder implements Constants {
+
+ private static Log log = LogFactory.getLog(SynapseConfigurationBuilder.class);
+
+ /**
+ * Return the default Synapse Configuration
+ * @return the default configuration to be used
+ */
+ public static SynapseConfiguration getDefaultConfiguration() {
+ // programatically create an empty configuration which just sends messages to thier implicit destinations
+ SynapseConfiguration config = new SynapseConfiguration();
+ SynapseMediator mainmediator = new SynapseMediator();
+ mainmediator.addChild(new SendMediator());
+ config.setMainMediator(mainmediator);
+ return config;
+ }
+
+ /**
+ * Build a Synapse configuration from a given XML configuration file
+ *
+ * @param configFile the XML configuration
+ * @return the Synapse configuration model
+ */
+ public static SynapseConfiguration getConfiguration(String configFile) {
+
+ // build the Synapse configuration parsing the XML config file
+ XMLConfigurationBuilder xmlBuilder = null;
+ try {
+ xmlBuilder = new XMLConfigurationBuilder();
+ SynapseConfiguration synCfg = xmlBuilder.getConfiguration(new FileInputStream(configFile));
+ log.info("Loaded Synapse configuration from : " + configFile);
+ return synCfg;
+
+ } catch (FileNotFoundException fnf) {
+ handleException("Cannot load Synapse configuration from : " + configFile, fnf);
+ } catch (Exception e) {
+ handleException("Could not initialize Synapse : " + e.getMessage(), e);
+ }
+ return null;
+ }
+
+ private static void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractListMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractListMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractListMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractListMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 java.util.Iterator;
+
+
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.api.ListMediator;
+import org.apache.synapse.api.Mediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This implements the basic logic to build a list mediator from a given XML
+ * configuration. It recursively builds the child mediators of the list.
+ */
+public abstract class AbstractListMediatorFactory extends AbstractMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(AbstractListMediatorFactory.class);
+
+ public void addChildren(OMElement el, ListMediator m)
+ {
+ Iterator it = el.getChildElements();
+ while (it.hasNext()) {
+ OMElement child = (OMElement) it.next();
+ Mediator med = MediatorFactoryFinder.getInstance().getMediator(child);
+ if (med != null) {
+ m.addChild(med);
+ } else {
+ String msg = "Unknown mediator : " + child.getLocalName();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ }
+ }
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/AbstractMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.jaxen.JaxenException;
+
+import java.util.Iterator;
+
+/**
+ * Is the abstract superclass of MediatorFactory's
+ */
+public abstract class AbstractMediatorFactory implements MediatorFactory {
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 javax.xml.namespace.QName;
+
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.ext.ClassMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+
+/**
+ * Creates an instance of a Class mediator using XML configuration specified
+ *
+ * <pre>
+ * <class name="class-name">
+ * <property name="string" (value="literal" | expression="xpath")/>*
+ * </class>
+ * </pre>
+ */
+public class ClassMediatorFactory extends AbstractMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
+
+ private static final QName CLASS_Q = new QName(Constants.SYNAPSE_NAMESPACE, "class");
+
+ public Mediator createMediator(OMElement elem) {
+
+ ClassMediator classMediator = new ClassMediator();
+
+ OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+ if (name == null) {
+ String msg = "The name of the actual mediator class is a required attribute";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ try {
+ Class clazz = getClass().getClassLoader().loadClass(name.getAttributeValue());
+ classMediator.setClazz(clazz);
+ } catch (ClassNotFoundException e) {
+ String msg = "Cannot find class : " + name.getAttributeValue();
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+
+ classMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
+
+ return classMediator;
+ }
+
+
+ public QName getTagQName() {
+ return CLASS_Q;
+ }
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/Constants.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/Constants.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/Constants.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/Constants.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 javax.xml.namespace.QName;
+
+/**
+ * Constants used in the XML processing
+ */
+public interface Constants {
+ public static final QName DEFINITIONS_ELT = new QName(Constants.SYNAPSE_NAMESPACE, "definitions");
+ public static final QName SEQUENCE_ELT = new QName(Constants.SYNAPSE_NAMESPACE, "sequence");
+ public static final QName ENDPOINT_ELT = new QName(Constants.SYNAPSE_NAMESPACE, "endpoint");
+ public static final QName PROPERTY_ELT = new QName(Constants.SYNAPSE_NAMESPACE, "set-property");
+ public static final QName RULES_ELT = new QName(Constants.SYNAPSE_NAMESPACE, "rules");
+
+ public static final String SYNAPSE_NAMESPACE = org.apache.synapse.Constants.SYNAPSE_NAMESPACE;
+ public static final String NULL_NAMESPACE = "";
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/DropMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/DropMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/DropMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/DropMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.builtin.DropMediator;
+import org.apache.axiom.om.OMElement;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This creates a drop mediator instance
+ *
+ * <pre>
+ * <drop/>
+ * </pre>
+ */
+public class DropMediatorFactory extends AbstractMediatorFactory {
+
+ private static final QName DROP_Q = new QName(Constants.SYNAPSE_NAMESPACE, "drop");
+
+ public Mediator createMediator(OMElement el) {
+ return new DropMediator();
+ }
+
+ public QName getTagQName() {
+ return DROP_Q;
+ }
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,43 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.synapse.config.Extension;
+import org.apache.axiom.om.OMElement;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * A extension factory that is capable of creating an instance of a
+ * named extension, through a given XML, should implement this interface
+ */
+
+public interface ExtensionFactory {
+ /**
+ * Creates an instance of a named extension using the OMElement
+ * @param elem
+ * @return the created named extension
+ */
+ public Extension createExtension(OMElement elem);
+
+ /**
+ * The QName of the extension element in the XML config
+ * @return QName of the extension element
+ */
+ public QName getTagQName();
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,123 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.config.Extension;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import sun.misc.Service;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This class loads available ConfigurationFactory implementations from the
+ * classpath and makes them available to the Synapse configuration builder.
+ *
+ * This class is based on J2SE Service Provider model
+ * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
+ */
+
+public class ExtensionFactoryFinder {
+
+ private static Map factoryMap = new HashMap();
+ private static final Log log = LogFactory.getLog(ExtensionFactoryFinder.class);
+ private static ExtensionFactoryFinder instance = null;
+
+ public static synchronized ExtensionFactoryFinder getInstance() {
+ if (instance == null) {
+ instance = new ExtensionFactoryFinder();
+ }
+ return instance;
+ }
+
+ /**
+ * Force re initialization next time
+ */
+ public synchronized void reset() {
+ factoryMap.clear();
+ instance = null;
+ }
+
+ private ExtensionFactoryFinder() {
+ factoryMap = new HashMap();
+ // now iterate through the available pluggable mediator factories
+ registerExtensions();
+ }
+
+ /**
+ * Register pluggable Configuration factories from the classpath
+ *
+ * This looks for JAR files containing a META-INF/services that adheres to the following
+ * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
+ */
+ private void registerExtensions() {
+
+ log.debug("Registering extensions found in the classpath : " +
+ System.getProperty("java.class.path"));
+
+ // register ExtensionFactory extensions
+ Iterator it = Service.providers(ExtensionFactory.class);
+ while (it.hasNext()) {
+ ExtensionFactory ef = (ExtensionFactory) it.next();
+ factoryMap.put(ef.getTagQName(), ef.getClass());
+ log.debug("Added extension factory " + ef.getClass() +
+ " to handle '" + ef.getTagQName() + "' extension elements");
+ }
+ }
+
+ /**
+ * This method returns an Extension instance of the correct type given an OMElement.
+ *
+ * @param elem an OMElement defining extension
+ * @return a correct Extension instance
+ */
+ public Extension getExtension(OMElement elem) {
+
+ QName qName = new QName(elem.getNamespace().getName(), elem.getLocalName());
+ log.debug("getConfiguration(" + qName + ")");
+
+ Class cls = (Class) factoryMap.get(qName);
+
+ if (cls == null) {
+ String msg = "Unknown extension factory referenced by element : " + qName;
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ try {
+ ExtensionFactory ef = (ExtensionFactory) cls.newInstance();
+ return ef.createExtension(elem);
+
+ } catch (InstantiationException e) {
+ String msg = "Error initializing extension factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+
+ } catch (IllegalAccessException e) {
+ String msg = "Error initializing extension factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+ }
+ }
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 javax.xml.namespace.QName;
+
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.transform.FaultMediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * Creates a fault mediator instance
+ *
+ * <pre>
+ * <makefault [version="soap11|soap12"]>
+ * <code (value="literal" | expression="xpath")/>
+ * <reason (value="literal" | expression="xpath")>
+ * <node>?
+ * <role>?
+ * <detail>?
+ * </makefault>
+ * </pre>
+ */
+public class FaultMediatorFactory extends AbstractMediatorFactory {
+
+ private static final QName HEADER_Q = new QName(Constants.SYNAPSE_NAMESPACE, "makefault");
+
+ private static final QName ATT_VERSION_Q = new QName(Constants.NULL_NAMESPACE, "version");
+ private static final QName CODE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "code");
+ private static final QName REASON_Q = new QName(Constants.SYNAPSE_NAMESPACE, "reason");
+ private static final QName NODE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "node");
+ private static final QName ROLE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "role");
+ private static final QName DETAIL_Q = new QName(Constants.SYNAPSE_NAMESPACE, "detail");
+
+ private static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
+ private static final QName ATT_EXPR_Q = new QName(Constants.NULL_NAMESPACE, "expression");
+
+ private static final String SOAP11 = "soap11";
+ private static final String SOAP12 = "soap12";
+
+ private static final Log log = LogFactory.getLog(FaultMediatorFactory.class);
+
+ public Mediator createMediator(OMElement elem) {
+
+ FaultMediator faultMediator = new FaultMediator();
+
+ OMAttribute version = elem.getAttribute(ATT_VERSION_Q);
+ if (version != null) {
+ if (SOAP11.equals(version.getAttributeValue())) {
+ faultMediator.setSoapVersion(FaultMediator.SOAP11);
+ } else if (SOAP12.equals(version.getAttributeValue())) {
+ faultMediator.setSoapVersion(FaultMediator.SOAP12);
+ }
+ }
+
+ OMElement code = elem.getFirstChildWithName(CODE_Q);
+ if (code != null) {
+ OMAttribute value = code.getAttribute(ATT_VALUE_Q);
+ OMAttribute expression = code.getAttribute(ATT_EXPR_Q);
+
+ if (value != null) {
+ String strValue = value.getAttributeValue();
+ String prefix, name;
+ if (strValue.indexOf(":") != -1) {
+ prefix = strValue.substring(0, strValue.indexOf(":"));
+ name = strValue.substring(strValue.indexOf(":")+1);
+ } else {
+ String msg = "A QName is expected for fault code as prefix:name";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ faultMediator.setFaultCodeValue(
+ new QName(Util.getNameSpaceWithPrefix(prefix, code), name));
+
+ } else if (expression != null) {
+ try {
+ AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
+ Util.addNameSpaces(xp, code, log);
+ faultMediator.setFaultCodeExpr(xp);
+ } catch (JaxenException je) {
+ String msg = "Invalid fault code expression : " + je.getMessage();
+ log.error(msg);
+ throw new SynapseException(msg, je);
+ }
+ } else {
+ String msg = "A 'value' or 'expression' attribute must specify the fault code";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ } else {
+ String msg = "The fault code is a required attribute for the makefault mediator";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ OMElement reason = elem.getFirstChildWithName(REASON_Q);
+ if (reason != null) {
+ OMAttribute value = reason.getAttribute(ATT_VALUE_Q);
+ OMAttribute expression = reason.getAttribute(ATT_EXPR_Q);
+
+ if (value != null) {
+ faultMediator.setFaultReasonValue(value.getAttributeValue());
+ } else if (expression != null) {
+ try {
+ AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
+ Util.addNameSpaces(xp, reason, log);
+ faultMediator.setFaultReasonExpr(xp);
+
+ } catch (JaxenException je) {
+ String msg = "Invalid fault reason expression : " + je.getMessage();
+ log.error(msg);
+ throw new SynapseException(msg, je);
+ }
+ } else {
+ String msg = "A 'value' or 'expression' attribute must specify the fault code";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ }else {
+ String msg = "The fault reason is a required attribute for the makefault mediator";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ OMElement node = elem.getFirstChildWithName(NODE_Q);
+ if (node != null && node.getText() != null) {
+ try {
+ faultMediator.setFaultNode(new URI(node.getText()));
+ } catch (URISyntaxException e) {
+ String msg = "Invalid URI specified for fault node : " + node.getText();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ }
+
+ OMElement role = elem.getFirstChildWithName(ROLE_Q);
+ if (role != null && role.getText() != null) {
+ try {
+ faultMediator.setFaultRole(new URI(role.getText()));
+ } catch (URISyntaxException e) {
+ String msg = "Invalid URI specified for fault role : " + role.getText();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ }
+
+ OMElement detail = elem.getFirstChildWithName(DETAIL_Q);
+ if (detail != null && detail.getText() != null) {
+ faultMediator.setFaultDetail(detail.getText());
+ }
+
+ return faultMediator;
+ }
+
+ public QName getTagQName() {
+ return HEADER_Q;
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FilterMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FilterMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FilterMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/FilterMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,114 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.synapse.mediators.filters.FilterMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import java.util.Iterator;
+
+/**
+ * Creates a filter mediator instance
+ *
+ * <pre>
+ * <filter (source="xpath" regex="string") | xpath="xpath">
+ * mediator+
+ * </filter>
+ * </pre>
+ */
+public class FilterMediatorFactory extends AbstractListMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(FaultMediatorFactory.class);
+
+ private static final QName FILTER_Q = new QName(Constants.SYNAPSE_NAMESPACE, "filter");
+
+ public Mediator createMediator(OMElement elem) {
+ FilterMediator filter = new FilterMediator();
+ super.addChildren(elem, filter);
+
+ OMAttribute attXpath = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "xpath"));
+ OMAttribute attSource = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "source"));
+ OMAttribute attRegex = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "regex"));
+
+ if (attXpath != null) {
+ if (attXpath.getAttributeValue() != null && attXpath.getAttributeValue().trim().length() == 0) {
+ String msg = "Invalid attribute value specified for xpath";
+ log.error(msg);
+ throw new SynapseException(msg);
+
+ } else {
+ try {
+ filter.setXpath(new AXIOMXPath(attXpath.getAttributeValue()));
+ } catch (JaxenException e) {
+ String msg = "Invalid XPath expression for attribute xpath : " + attXpath.getAttributeValue();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ }
+ Util.addNameSpaces(filter.getXpath(), elem, log);
+
+ } else if (attSource != null && attRegex != null) {
+
+ if (
+ (attSource.getAttributeValue() != null && attSource.getAttributeValue().trim().length() == 0) ||
+ (attRegex.getAttributeValue() != null && attRegex.getAttributeValue().trim().length() == 0) ){
+ String msg = "Invalid attribute values for source and/or regex specified";
+ log.error(msg);
+ throw new SynapseException(msg);
+
+ } else {
+ try {
+ filter.setSource(new AXIOMXPath(attSource.getAttributeValue()));
+ } catch (JaxenException e) {
+ String msg = "Invalid XPath expression for attribute source : " + attSource.getAttributeValue();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ try {
+ filter.setRegex(Pattern.compile(attRegex.getAttributeValue()));
+ } catch (PatternSyntaxException pse) {
+ String msg = "Invalid Regular Expression for attribute regex : " + attRegex.getAttributeValue();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ }
+ Util.addNameSpaces(filter.getSource(), elem, log);
+
+ } else {
+ String msg = "An xpath or (source, regex) attributes are required for a filter";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ return filter;
+ }
+
+ public QName getTagQName() {
+ return FILTER_Q;
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 javax.xml.namespace.QName;
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.transform.HeaderMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+/**
+ * This builds a Header Mediator parsing the XML configuration supplied
+ *
+ * Set header
+ * <pre>
+ * <header name="qname" (value="literal" | expression="xpath")/>
+ * </pre>
+ *
+ * Remove header
+ * <pre>
+ * <header name="qname" action="remove"/>
+ * </pre>
+ */
+public class HeaderMediatorFactory extends AbstractMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(HeaderMediatorFactory.class);
+
+ private static final QName HEADER_Q = new QName(Constants.SYNAPSE_NAMESPACE, "header");
+
+ public Mediator createMediator(OMElement elem) {
+
+ HeaderMediator headerMediator = new HeaderMediator();
+ OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+ OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
+ OMAttribute exprn = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));
+ OMAttribute action = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "action"));
+
+ if (name == null || name.getAttributeValue() == null) {
+ String msg = "A valid name attribute is required for the header mediator";
+ log.error(msg);
+ throw new SynapseException(msg);
+ } else {
+ headerMediator.setName(name.getAttributeValue());
+ }
+
+ // The action attribute is optional, if provided and equals to 'remove' the
+ // header mediator will act as a header remove mediator
+ if (action != null && "remove".equals(action.getAttributeValue())) {
+ headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
+ }
+
+ if (value == null && exprn == null) {
+ String msg = "A 'value' or 'expression' attribute is required for a header mediator";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ if (value != null && value.getAttributeValue() != null) {
+ headerMediator.setValue(value.getAttributeValue());
+
+ } else if (exprn != null && exprn.getAttributeValue() != null) {
+ try {
+ AXIOMXPath xp = new AXIOMXPath(exprn.getAttributeValue());
+ Util.addNameSpaces(xp, elem, log);
+ headerMediator.setExpression(xp);
+ } catch (JaxenException je) {
+ String msg = "Invalid XPath expression : " + exprn.getAttributeValue();
+ log.error(msg);
+ throw new SynapseException(msg, je);
+ }
+
+ } else {
+ String msg = "Invalid attribute value for the attribute 'expression' or 'value'";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ return headerMediator;
+ }
+
+ public QName getTagQName() {
+ return HEADER_Q;
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/InMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/InMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/InMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/InMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,47 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.api.Mediator;
+import org.apache.synapse.mediators.filters.InMediator;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Creates an In mediator instance
+ *
+ * <pre>
+ * <in>
+ * mediator+
+ * </in>
+ * </pre>
+ */
+public class InMediatorFactory extends AbstractListMediatorFactory {
+
+ private static final QName IN_Q = new QName(Constants.SYNAPSE_NAMESPACE, "in");
+
+ public Mediator createMediator(OMElement elem) {
+ InMediator filter = new InMediator();
+ super.addChildren(elem, filter);
+ return filter;
+ }
+
+ public QName getTagQName() {
+ return IN_Q;
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 javax.xml.namespace.QName;
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.builtin.LogMediator;
+import org.apache.synapse.mediators.MediatorProperty;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created a Log mediator that logs messages using commons-logging.
+ *
+ * <pre>
+ * <log [level="simple|headers|full|custom"]>
+ * <property> *
+ * </log>
+ * </pre>
+ */
+public class LogMediatorFactory extends AbstractMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
+
+ private static final QName LOG_Q = new QName(Constants.SYNAPSE_NAMESPACE, "log");
+ private static final String SIMPLE = "simple";
+ private static final String HEADERS = "headers";
+ private static final String FULL = "full";
+ private static final String CUSTOM = "custom";
+
+ public QName getTagQName() {
+ return LOG_Q;
+ }
+
+ public Mediator createMediator(OMElement elem) {
+
+ LogMediator logMediator = new LogMediator();
+
+ // Set the high level set of properties to be logged (i.e. log level)
+ OMAttribute level = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "level"));
+ if (level != null) {
+ String levelstr = level.getAttributeValue();
+ if (SIMPLE.equals(levelstr)) {
+ logMediator.setLogLevel(LogMediator.SIMPLE);
+ } else if (HEADERS.equals(levelstr)) {
+ logMediator.setLogLevel(LogMediator.HEADERS);
+ } else if (FULL.equals(levelstr)) {
+ logMediator.setLogLevel(LogMediator.FULL);
+ } else if (CUSTOM.equals(levelstr)) {
+ logMediator.setLogLevel(LogMediator.CUSTOM);
+ }
+ }
+
+ // check if a custom seperator has been supplied, if so use it
+ OMAttribute seperator = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "seperator"));
+ if (seperator != null) {
+ logMediator.setSeperator(seperator.getAttributeValue());
+ }
+
+ logMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
+
+ return logMediator;
+ }
+
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 javax.xml.namespace.QName;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.axiom.om.OMElement;
+
+/**
+ * A mediator factory capable of creating an instance of a mediator through a given
+ * XML should implement this interface
+ */
+public interface MediatorFactory {
+ /**
+ * Creates an instance of the mediator using the OMElement
+ * @param elem
+ * @return the created mediator
+ */
+ public Mediator createMediator(OMElement elem);
+
+ /**
+ * The QName of this mediator element in the XML config
+ * @return QName of the mediator element
+ */
+ public QName getTagQName();
+}
Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java Thu Jun 1 02:28:13 2006
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.MediatorFactory;
+import org.apache.synapse.api.Mediator;
+import org.apache.axiom.om.OMElement;
+
+import sun.misc.Service;
+
+/**
+ *
+ *
+ * This class is based on J2SE Service Provider model
+ * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
+ */
+
+public class MediatorFactoryFinder {
+
+ private static Map factoryMap = new HashMap();
+ private static final Log log = LogFactory.getLog(MediatorFactoryFinder.class);
+
+ private static final Class[] mediatorFactories = {
+ SequenceMediatorFactory.class,
+ LogMediatorFactory.class,
+ SendMediatorFactory.class,
+ FilterMediatorFactory.class,
+ SynapseMediatorFactory.class,
+ DropMediatorFactory.class,
+ HeaderMediatorFactory.class,
+ FaultMediatorFactory.class,
+ PropertyMediatorFactory.class,
+ SwitchMediatorFactory.class,
+ SwitchCaseMediatorFactory.class,
+ SwitchCaseDefaultMediatorFactory.class,
+ InMediatorFactory.class,
+ OutMediatorFactory.class
+ };
+
+ private static MediatorFactoryFinder instance = null;
+
+ public static synchronized MediatorFactoryFinder getInstance() {
+ if (instance == null) {
+ instance = new MediatorFactoryFinder();
+ }
+ return instance;
+ }
+
+ /**
+ * Force re initialization next time
+ */
+ public synchronized void reset() {
+ factoryMap.clear();
+ instance = null;
+ }
+
+ private MediatorFactoryFinder() {
+
+ factoryMap = new HashMap();
+ for (int i = 0; i < mediatorFactories.length; i++) {
+ Class c = mediatorFactories[i];
+ try {
+ factoryMap.put(((MediatorFactory) c.newInstance()).getTagQName(), c);
+ } catch (Exception e) {
+ throw new SynapseException("Error instantiating " + c.getName(), e);
+ }
+ }
+ // now iterate through the available pluggable mediator factories
+ registerExtensions();
+ }
+
+ /**
+ * Register pluggable mediator factories from the classpath
+ *
+ * This looks for JAR files containing a META-INF/services that adheres to the following
+ * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
+ */
+ private void registerExtensions() {
+
+ log.debug("Registering mediator extensions found in the classpath : " + System.getProperty("java.class.path"));
+
+ // register MediatorFactory extensions
+ Iterator it = Service.providers(MediatorFactory.class);
+ while (it.hasNext()) {
+ MediatorFactory mf = (MediatorFactory) it.next();
+ QName tag = mf.getTagQName();
+ factoryMap.put(tag, mf.getClass());
+ log.debug("Added MediatorFactory " + mf.getClass() + " to handle " + tag);
+ }
+ }
+
+ /**
+ * This method returns a Processor given an OMElement. This will be used
+ * recursively by the elements which contain processor elements themselves
+ * (e.g. rules)
+ *
+ * @param element
+ * @return Processor
+ */
+ public Mediator getMediator(OMElement element) {
+
+ QName qName = new QName(element.getNamespace().getName(), element.getLocalName());
+ log.debug("getMediator(" + qName + ")");
+ Class cls = (Class) factoryMap.get(qName);
+
+ if (cls == null) {
+ String msg = "Unknown mediator referenced by configuration element : " + qName;
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ try {
+ MediatorFactory mf = (MediatorFactory) cls.newInstance();
+ return mf.createMediator(element);
+
+ } catch (InstantiationException e) {
+ String msg = "Error initializing mediator factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+
+ } catch (IllegalAccessException e) {
+ String msg = "Error initializing mediator factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org