You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by su...@apache.org on 2011/03/15 10:46:44 UTC
svn commit: r1081702 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
config/SynapseConfiguration.java
config/xml/SynapseXMLConfigurationSerializer.java
config/xml/XMLToTemplateMapper.java endpoints/TemplateEndpoint.java
Author: supun
Date: Tue Mar 15 09:46:44 2011
New Revision: 1081702
URL: http://svn.apache.org/viewvc?rev=1081702&view=rev
Log:
improving the endpoint templates to use the registry
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLToTemplateMapper.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/TemplateEndpoint.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=1081702&r1=1081701&r2=1081702&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Tue Mar 15 09:46:44 2011
@@ -19,13 +19,15 @@
package org.apache.synapse.config;
+import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.*;
+import org.apache.synapse.config.xml.XMLToTemplateMapper;
+import org.apache.synapse.config.xml.endpoints.TemplateFactory;
import org.apache.synapse.endpoints.Template;
-import org.apache.synapse.endpoints.TemplateEndpoint;
import org.apache.synapse.message.processors.MessageProcessor;
import org.apache.synapse.message.store.MessageStore;
import org.apache.synapse.deployers.SynapseArtifactDeploymentStore;
@@ -144,11 +146,6 @@ public class SynapseConfiguration implem
private Map<String, Template> endpointTemplates = new ConcurrentHashMap<String, Template>();
/**
- * Endpoints map for holding the endpoints references
- */
- private Map<String, TemplateEndpoint> endpointGroups = new ConcurrentHashMap<String, TemplateEndpoint>();
-
- /**
* Description/documentation of the configuration
*/
private String description = null;
@@ -1408,23 +1405,62 @@ public class SynapseConfiguration implem
}
}
- public void addEndpointGroup(String name, TemplateEndpoint group) {
- endpointGroups.put(name, group);
+ public void addEndpointTemplate(String name, Template template) {
+ assertAlreadyExists(name, SEQUENCE);
+ localRegistry.put(name, template);
}
- public Map<String, TemplateEndpoint> getEndpointGroups() {
- return endpointGroups;
- }
+ public Template getEndpointTemplate(String key) {
+ Object o = getEntry(key);
+ if (o instanceof Mediator) {
+ return (Template) o;
+ }
- public void addEndpointTemplate(String name, Template template) {
- endpointTemplates.put(name, template);
- }
+ Entry entry = null;
+ if (o == null) {
+ entry = new Entry(key);
+ entry.setType(Entry.REMOTE_ENTRY);
+ } else {
+ Object object = localRegistry.get(key);
+ if (object instanceof Entry) {
+ entry = (Entry) object;
+ }
+ }
- public Map<String, Template> getEndpointTemplates() {
- return endpointTemplates;
- }
+ assertEntryNull(entry, key);
+
+ //noinspection ConstantConditions
+ if (entry.getMapper() == null) {
+ entry.setMapper(new XMLToTemplateMapper());
+ }
+
+ if (entry.getType() == Entry.REMOTE_ENTRY) {
+ if (registry != null) {
+ o = registry.getResource(entry, getProperties());
+ if (o != null && o instanceof Template) {
+ localRegistry.put(key, entry);
+ return (Template) o;
+ } else if (o instanceof OMNode) {
+ Template m = new TemplateFactory().createEndpointTemplate(
+ (OMElement) o, properties);
+ if (m != null) {
+ entry.setValue(m);
+ return m;
+ }
+ }
+ }
+ } else {
+ Object value = entry.getValue();
+ if (value instanceof OMNode) {
+ Object object = entry.getMapper().getObjectFromOMNode(
+ (OMNode) value, getProperties());
+ if (object instanceof Template) {
+ entry.setValue(object);
+ return (Template) object;
+ }
+ }
+ }
- public Template getEndpointTemplate(String name) {
- return endpointTemplates.get(name);
+ return null;
}
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java?rev=1081702&r1=1081701&r2=1081702&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java Tue Mar 15 09:46:44 2011
@@ -99,6 +99,7 @@ public class SynapseXMLConfigurationSeri
Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
Map<String, SequenceMediator> sequences = new HashMap<String, SequenceMediator>();
Map<String, TemplateMediator> templates = new HashMap<String, TemplateMediator>();
+ Map<String, Template> endpointTemplates = new HashMap<String, Template>();
itr = synCfg.getLocalRegistry().keySet().iterator();
while (itr.hasNext()) {
@@ -113,6 +114,8 @@ public class SynapseXMLConfigurationSeri
sequences.put(key.toString(), (SequenceMediator) o);
} else if (o instanceof Endpoint) {
endpoints.put(key.toString(), (Endpoint) o);
+ } else if (o instanceof Template) {
+ endpointTemplates.put(key.toString(), (Template) o);
} else if (o instanceof Entry) {
entries.put(key.toString(), (Entry) o);
} else {
@@ -134,7 +137,7 @@ public class SynapseXMLConfigurationSeri
serializeMediatorTemplates(definitions, templates);
// serialize the endpoint templates
- serializeEndpointTemplates(definitions, synCfg.getEndpointTemplates());
+ serializeEndpointTemplates(definitions, endpointTemplates);
// handle startups
serializeStartups(definitions, synCfg.getStartups());
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLToTemplateMapper.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLToTemplateMapper.java?rev=1081702&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLToTemplateMapper.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLToTemplateMapper.java Tue Mar 15 09:46:44 2011
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.XMLToObjectMapper;
+import org.apache.synapse.config.xml.endpoints.TemplateFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Properties;
+
+public class XMLToTemplateMapper implements XMLToObjectMapper {
+ public Object getObjectFromOMNode(OMNode om, Properties properties) {
+ if (!(om instanceof OMElement)) {
+ throw new SynapseException("Configuration is not in proper format.");
+ }
+
+ OMElement elem = (OMElement) om;
+ OMElement element = elem.getFirstChildWithName(
+ new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
+ if (element != null) {
+ return MediatorFactoryFinder.getInstance().getMediator(elem, properties);
+ }
+
+ element = elem.getFirstChildWithName(
+ new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
+ if (element != null) {
+ TemplateFactory templateFactory = new TemplateFactory();
+ return templateFactory.createEndpointTemplate(elem, properties);
+ }
+ return null;
+ }
+}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/TemplateEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/TemplateEndpoint.java?rev=1081702&r1=1081701&r2=1081702&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/TemplateEndpoint.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/TemplateEndpoint.java Tue Mar 15 09:46:44 2011
@@ -87,7 +87,7 @@ public class TemplateEndpoint extends Ab
super.init(synapseEnvironment);
Template endpointTemplate = synapseEnvironment.getSynapseConfiguration().
- getEndpointTemplates().get(template);
+ getEndpointTemplate(template);
if (endpointTemplate == null) {
handleException("Template " + template +
@@ -122,7 +122,7 @@ public class TemplateEndpoint extends Ab
log.debug("Loading template endpoint with key : " + template);
}
- Template eprTemplate = synCfg.getEndpointTemplates().get(template);
+ Template eprTemplate = synCfg.getEndpointTemplate(template);
if (eprTemplate != null) {
realEndpoint = eprTemplate.create(this, synCfg.getProperties());