Author: indika
Date: Thu Aug  7 10:47:06 2008
New Revision: 683663

URL: http://svn.apache.org/viewvc?rev=683663&view=rev
Log:
Add some Logs and input parameter validation

Modified:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java?rev=683663&r1=683662&r2=683663&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
 Thu Aug  7 10:47:06 2008
@@ -21,6 +21,9 @@
  */
 package org.apache.synapse.util.datasource;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
 import org.apache.synapse.util.datasource.factory.DataSourceFactory;
 
 import javax.sql.DataSource;
@@ -32,6 +35,8 @@
  */
 public class InMemoryDataSourceRegistry implements DataSourceRegistry {
 
+    private final static Log log = 
LogFactory.getLog(InMemoryDataSourceRegistry.class);
+
     private static final InMemoryDataSourceRegistry ourInstance = new 
InMemoryDataSourceRegistry();
     private final static Map<String, DataSource> dataSources = new 
HashMap<String, DataSource>();
 
@@ -42,13 +47,52 @@
     private InMemoryDataSourceRegistry() {
     }
 
+    /**
+     * Keep DataSource in the Local store
+     *
+     * @see 
org.apache.synapse.util.datasource.DataSourceRegistry#register(DataSourceInformation)
+     */
     public void register(DataSourceInformation information) {
+
+        if (information == null) {
+            handleException("DataSourceInformation cannot be found.");
+        }
+
         DataSource dataSource = 
DataSourceFactory.createDataSource(information);
+
+        if (dataSource == null) {
+
+            if (log.isDebugEnabled()) {
+                log.debug("DataSource cannot be created or" +
+                        " found for DataSource Information " + information);
+            }
+            return;
+        }
+
         String name = information.getName();
+
+        if (log.isDebugEnabled()) {
+            log.debug("Registering a DatSource with name : " + name + " in 
Local Pool");
+        }
+
         dataSources.put(name, dataSource);
     }
 
+    /**
+     * Get a DataSource from Local store
+     *
+     * @see 
org.apache.synapse.util.datasource.DataSourceRegistry#lookUp(String)
+     */
     public DataSource lookUp(String name) {
+
+        if (name == null || "".equals(name)) {
+            handleException("DataSorce name cannot be found.");
+        }
         return dataSources.get(name);
     }
+
+    private static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
+    }
 }

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java?rev=683663&r1=683662&r2=683663&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
 Thu Aug  7 10:47:06 2008
@@ -47,10 +47,22 @@
 
         if (!initialize) {
 
+            if (jndiEnv == null) {
+                handleException("JNDI environment properties cannot be found");
+            }
+
             indiEnv.putAll(jndiEnv);
+
             try {
+
+                if (log.isDebugEnabled()) {
+                    log.debug("Initilating a Naming conext with JNDI " +
+                            "environment properties :  " + jndiEnv);
+                }
+
                 initialContext = new InitialContext(jndiEnv);
                 initialize = true;
+
             } catch (NamingException e) {
                 handleException("Error creating a InitialConext" +
                         " with JNDI env properties : " + jndiEnv);
@@ -62,6 +74,11 @@
     private JNDIBasedDataSourceRegistry() {
     }
 
+    /**
+     * Register a DataSource in the JNDI tree
+     *
+     * @see 
org.apache.synapse.util.datasource.DataSourceRegistry#register(DataSourceInformation)
+     */
     public void register(DataSourceInformation information) {
 
         String dsType = information.getType();
@@ -74,6 +91,11 @@
         String maxWait = String.valueOf(information.getMaxWait());
         String dataSourceName = information.getName();
 
+        if (dataSourceName == null || "".equals(dataSourceName)) {
+            handleException("Invalid DataSource configuration !! -" +
+                    "DataSource Name cannot be found ");
+        }
+
         //populates context tree
         populateContextTree(initialContext, dataSourceName);
 
@@ -94,8 +116,14 @@
             setBasicDataSourceParameters(ref, information);
             //set default properties for reference
             setCommonParameters(ref, information);
+
             try {
 
+                if (log.isDebugEnabled()) {
+                    log.debug("Registering a DataSource with name : " +
+                            dataSourceName + " in the JNDI tree with 
properties : " + indiEnv);
+                }
+
                 initialContext.rebind(dataSourceName, ref);
             } catch (NamingException e) {
                 String msg = " Error binding name ' " + dataSourceName + " ' 
to " +
@@ -154,6 +182,12 @@
             setCommonParameters(ref, information);
 
             try {
+
+                if (log.isDebugEnabled()) {
+                    log.debug("Registering a DataSource with name : " +
+                            dataSourceName + " in the JNDI tree with 
properties : " + indiEnv);
+                }
+
                 initialContext.rebind(dataSourceName, ref);
             } catch (NamingException e) {
                 String msg = "Error binding name ' " + dataSourceName + " ' to 
" +
@@ -166,7 +200,16 @@
         }
     }
 
+    /**
+     * Get a DatSource which has been registered in the JNDI tree
+     *
+     * @see 
org.apache.synapse.util.datasource.DataSourceRegistry#lookUp(String)
+     */
     public DataSource lookUp(String dsName) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Getting a DataSource with name : " + dsName + " from 
the JNDI tree.");
+        }
         return DataSourceFinder.find(dsName, initialContext);
     }
 
@@ -197,7 +240,9 @@
         reference.add(new StringRefAddr(
                 DataSourceInformationFactory.PROP_TESTWHILEIDLE,
                 String.valueOf(information.isTestWhileIdle())));
+
         String validationQuery = information.getValidationQuery();
+
         if (validationQuery != null && !"".equals(validationQuery)) {
             reference.add(new StringRefAddr(
                     DataSourceInformationFactory.PROP_VALIDATIONQUERY, 
validationQuery));


Reply via email to