You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2009/07/23 14:07:57 UTC
svn commit: r797031 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config:
SynapseConfiguration.java xml/SynapseXMLConfigurationFactory.java
Author: hiranya
Date: Thu Jul 23 12:07:57 2009
New Revision: 797031
URL: http://svn.apache.org/viewvc?rev=797031&view=rev
Log:
* Added some validation to properly handle addition of proxy services, startups and event sources.
* Added some validation to properly hanlde removal of items from the configuration
* Updated the jabadocs to indicate that low level validation is performed by SynapseConfiguration class it self
* Removed redundent validation from the SynapseXMLConfigurationFactory
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/SynapseXMLConfigurationFactory.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=797031&r1=797030&r2=797031&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 Thu Jul 23 12:07:57 2009
@@ -120,7 +120,8 @@
/**
- * Add a named sequence into the local registry
+ * Add a named sequence into the local registry. If a sequence already exists by the specified
+ * key a runtime exception is thrown.
*
* @param key
* the name for the sequence
@@ -134,7 +135,8 @@
/**
* Allow a dynamic sequence to be cached and made available through the
- * local registry
+ * local registry. If a sequence already exists by the specified
+ * key a runtime exception is thrown.
*
* @param key
* the key to lookup the sequence from the remote registry
@@ -247,7 +249,12 @@
* of the sequence to be removed
*/
public void removeSequence(String key) {
- localRegistry.remove(key);
+ Object sequence = localRegistry.get(key);
+ if (sequence instanceof Mediator) {
+ localRegistry.remove(key);
+ } else {
+ handleException("No sequence exists by the key/name : " + key);
+ }
}
/**
@@ -274,7 +281,8 @@
* Define a resource to the local registry. All static resources (e.g. URL
* source) are loaded during this definition phase, and the inability to
* load such a resource will not allow the definition of the resource to the
- * local registry
+ * local registry. If an entry already exists by the specified key a runtime
+ * exception is thrown.
*
* @param key
* the key associated with the resource
@@ -408,7 +416,12 @@
* the key of the reference to be removed
*/
public void removeEntry(String key) {
- localRegistry.remove(key);
+ Object entry = localRegistry.get(key);
+ if (entry instanceof Entry) {
+ localRegistry.remove(key);
+ } else {
+ handleException("No entry exists by the key : " + key);
+ }
}
/**
@@ -441,7 +454,8 @@
}
/**
- * Define a named endpoint with the given key
+ * Define a named endpoint with the given key. If an endpoint already exists by the specified
+ * name a runtime exception is thrown.
*
* @param key
* the key for the endpoint
@@ -454,7 +468,8 @@
}
/**
- * Add a dynamic endpoint definition to the local registry
+ * Add a dynamic endpoint definition to the local registry. If an endpoint already exists by
+ * the specified name a runtime exception is thrown.
*
* @param key
* the key for the endpoint definition
@@ -539,17 +554,24 @@
}
/**
- * Deletes the endpoint with the given key
+ * Deletes the endpoint with the given key. If an endpoint does not exist by the specified
+ * key a runtime exception is thrown.
*
* @param key
* of the endpoint to be deleted
*/
public void removeEndpoint(String key) {
- localRegistry.remove(key);
+ Object endpoint = localRegistry.get(key);
+ if (endpoint instanceof Endpoint) {
+ localRegistry.remove(key);
+ } else {
+ handleException("No endpoint exists by the key/name : " + key);
+ }
}
/**
- * Add a Proxy service to the configuration
+ * Add a Proxy service to the configuration. If a proxy service already exists by the
+ * specified name a runtime exception is thrown.
*
* @param name
* the name of the Proxy service
@@ -557,7 +579,11 @@
* the Proxy service instance
*/
public void addProxyService(String name, ProxyService proxy) {
- proxyServices.put(name, proxy);
+ if (!proxyServices.containsKey(name)) {
+ proxyServices.put(name, proxy);
+ } else {
+ handleException("Duplicate proxy service by the name : " + name);
+ }
}
/**
@@ -572,7 +598,8 @@
}
/**
- * Deletes the Proxy Service named with the given name
+ * Deletes the Proxy Service named with the given name. If a proxy service does not exist by
+ * the specified name a runtime exception is thrown.
*
* @param name
* of the Proxy Service to be deleted
@@ -720,21 +747,31 @@
}
/**
- * Add a startup to the startups map in the configuration
+ * Add a startup to the startups map in the configuration. If a startup already exists by the
+ * specified name a runtime exception is thrown.
*
* @param startup - Startup object to be added
*/
public void addStartup(Startup startup) {
- startups.put(startup.getName(), startup);
+ if (!startups.containsKey(startup.getName())) {
+ startups.put(startup.getName(), startup);
+ } else {
+ handleException("Duplicate startup by the name : " + startup.getName());
+ }
}
/**
- * Removes the startup specified by the name
+ * Removes the startup specified by the name. If no startup exists by the specified name a
+ * runtime exception is thrown.
*
* @param name - name of the startup that needs to be removed
*/
public void removeStartup(String name) {
- startups.remove(name);
+ if (startups.containsKey(name)) {
+ startups.remove(name);
+ } else {
+ handleException("No startup exists by the name : " + name);
+ }
}
/**
@@ -947,16 +984,39 @@
return taskDescriptionRepository;
}
+ /**
+ * Add an event source to the configuration. If an event source already exists by the
+ * specified name a runtime exception is thrown.
+ *
+ * @param name
+ * name of the event source
+ * @param eventSource
+ * the event source to be added
+ */
public void addEventSource(String name, SynapseEventSource eventSource) {
- eventSources.put(name, eventSource);
+ if (!eventSources.containsKey(name)) {
+ eventSources.put(name, eventSource);
+ } else {
+ handleException("Duplicate event source by the name : " + name);
+ }
}
public SynapseEventSource getEventSource(String name) {
return eventSources.get(name);
}
+ /**
+ * Remove an event source from the configuration. If the specified event source does not
+ * exist a runtime exception is thrown.
+ *
+ * @param name name of the event source to be removed
+ */
public void removeEventSource(String name) {
- eventSources.remove(name);
+ if (eventSources.containsKey(name)) {
+ eventSources.remove(name);
+ } else {
+ handleException("No event source exists by the name : " + name);
+ }
}
public Collection<SynapseEventSource> getEventSources() {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java?rev=797031&r1=797030&r2=797031&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java Thu Jul 23 12:07:57 2009
@@ -153,38 +153,26 @@
public static Startup defineStartup(SynapseConfiguration config, OMElement elem) {
Startup startup = StartupFinder.getInstance().getStartup(elem);
- if (config.getStartup(startup.getName()) != null) {
- handleException("Duplicate startup with name : " + startup.getName());
- }
config.addStartup(startup);
return startup;
}
public static ProxyService defineProxy(SynapseConfiguration config, OMElement elem) {
ProxyService proxy = ProxyServiceFactory.createProxy(elem);
- if (config.getProxyService(proxy.getName()) != null) {
- handleException("Duplicate proxy service with name : " + proxy.getName());
- }
config.addProxyService(proxy.getName(), proxy);
return proxy;
}
public static Entry defineEntry(SynapseConfiguration config, OMElement elem) {
Entry entry = EntryFactory.createEntry(elem);
- if (config.getLocalRegistry().get(entry.getKey()) != null) {
- handleException("Duplicate registry entry definition for key : " + entry.getKey());
- }
config.addEntry(entry.getKey(), entry);
- return entry;
+ return entry;
}
public static Mediator defineSequence(SynapseConfiguration config, OMElement ele) {
String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
- if (config.getLocalRegistry().get(name) != null) {
- handleException("Duplicate sequence definition : " + name);
- }
Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(ele);
config.addSequence(name, mediator);
// mandatory sequence is treated as a speciall sequence because it will be fetched for
@@ -204,9 +192,6 @@
String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
- if (config.getLocalRegistry().get(name.trim()) != null) {
- handleException("Duplicate endpoint definition : " + name);
- }
Endpoint endpoint = EndpointFactory.getEndpointFromElement(ele, false);
config.addEndpoint(name.trim(), endpoint);
return endpoint;
@@ -218,9 +203,6 @@
public static SynapseEventSource defineEventSource(SynapseConfiguration config, OMElement elem) {
SynapseEventSource eventSource = EventSourceFactory.createEventSource(elem);
- if (config.getEventSource(eventSource.getName()) != null) {
- handleException("Duplicate event source with name : " + eventSource.getName());
- }
config.addEventSource(eventSource.getName(), eventSource);
return eventSource;
}