You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2008/11/16 16:59:01 UTC

svn commit: r718051 - in /synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/config/xml/ utils/src/main/java/org/apache/synapse/commons/util/ utils/src/main/java/org/apache/synapse/commons/util/datasource/ utils/src/main/java/org/apache/...

Author: indika
Date: Sun Nov 16 07:59:00 2008
New Revision: 718051

URL: http://svn.apache.org/viewvc?rev=718051&view=rev
Log:
fix an issue with JNDI ...after refactoring datasource code

Added:
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java
Removed:
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceManager.java
Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
    synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java Sun Nov 16 07:59:00 2008
@@ -26,8 +26,9 @@
 import org.apache.synapse.mediators.db.Statement;
 import org.apache.synapse.commons.util.MBeanRepository;
 import org.apache.synapse.commons.util.datasource.DBPoolView;
-import org.apache.synapse.commons.util.datasource.DataSourceManager;
 import org.apache.synapse.commons.util.datasource.DatasourceMBeanRepository;
+import org.apache.synapse.commons.util.datasource.RepositoryBasedDataSourceFinder;
+import org.apache.synapse.commons.util.datasource.DataSourceFinder;
 import org.apache.synapse.util.xpath.SynapseXPath;
 import org.apache.synapse.security.secret.SecretManager;
 import org.jaxen.JaxenException;
@@ -142,7 +143,11 @@
 
         String dsName = getValue(pool, DSNAME_Q);
         mediator.addDataSourceProperty(DSNAME_Q, dsName);
-        DataSource dataSource = DataSourceManager.getInstance().find(dsName);
+         DataSource dataSource = null;
+        RepositoryBasedDataSourceFinder finder = RepositoryBasedDataSourceFinder.getInstance();
+        if (finder.isInitialized()) {
+            dataSource = RepositoryBasedDataSourceFinder.getInstance().find(dsName);
+        }
         if (dataSource != null) {
             MBeanRepository mBeanRepository = DatasourceMBeanRepository.getInstance();
             Object mBean = mBeanRepository.getMBean(dsName);
@@ -158,7 +163,7 @@
         props.put(Context.SECURITY_CREDENTIALS, getValue(pool, PASS_Q));
         props.put(Context.PROVIDER_URL, getValue(pool, URL_Q));
 
-        dataSource = DataSourceManager.getInstance().find(dsName, props);
+        dataSource = DataSourceFinder.find(dsName, props);
         if (dataSource == null) {
             handleException("Cannot find a DataSource for given properties :" + props);
         }

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java Sun Nov 16 07:59:00 2008
@@ -34,9 +34,6 @@
      */
     public void createLocalRegistry(int port) {
         try {
-            if (log.isDebugEnabled()) {
-                log.debug("Creating a RMI registry with port :" + port);
-            }
             localRegistry = LocateRegistry.createRegistry(port);
         } catch (RemoteException e) {
             String msg = "Couldn't create a local registry(RMI) : port " + port +
@@ -53,9 +50,8 @@
             try {
                 log.info("Removing the RMI registy instance from the RMI runtime ");
                 UnicastRemoteObject.unexportObject(localRegistry, true);
-                this.localRegistry = null;
             } catch (NoSuchObjectException e) {
-                String msg = "Error when stoping localregistry(RMI)";
+                String msg = "Error when stopping localregistry(RMI)";
                 handleException(msg, e);
             }
         }

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java Sun Nov 16 07:59:00 2008
@@ -18,22 +18,22 @@
  */
 package org.apache.synapse.commons.util.datasource;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.util.SynapseUtilException;
+
 import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.sql.DataSource;
 import java.util.Properties;
 
 /**
- * Finds a DataSource based on various criteria
+ *
  */
-public interface DataSourceFinder {
-
-    /**
-     * Find a DataSource using given name
-     *
-     * @param name Name of the DataSource to be found
-     * @return DataSource if found , otherwise null
-     */
-    DataSource find(String name);
+public class DataSourceFinder {
+    
+    private static Log log = LogFactory.getLog(DataSourceFinder.class);
 
     /**
      * Find a DataSource using the given name and JNDI environment properties
@@ -42,7 +42,18 @@
      * @param jndiEnv JNDI environment properties
      * @return DataSource if found , otherwise null
      */
-    DataSource find(String dsName, Properties jndiEnv);
+    public static DataSource find(String dsName, Properties jndiEnv) {
+
+        try {
+            Context context = new InitialContext(jndiEnv);
+            return find(dsName, context);
+
+        } catch (NamingException e) {
+            handleException("Error looking up DataSource : " + dsName +
+                    " using JNDI properties : " + jndiEnv, e);
+        }
+        return null;
+    }
 
     /**
      * Find a DataSource using the given name and naming context
@@ -51,6 +62,43 @@
      * @param context Naming Context
      * @return DataSource if found , otherwise null
      */
-    DataSource find(String dsName, Context context);
+    public static DataSource find(String dsName, Context context) {
+
+        try {
+            Object dataSourceO = context.lookup(dsName);
+            if (dataSourceO != null && dataSourceO instanceof DataSource) {
+                return (DataSource) dataSourceO;
+            } else {
+                handleException("DataSource : " + dsName + " not found when looking up" +
+                        " using JNDI properties : " + context.getEnvironment());
+            }
+
+        } catch (NamingException e) {
+            handleException(new StringBuilder().append("Error looking up DataSource : ")
+                    .append(dsName).append(" using JNDI properties : ").
+                    append(context).toString(), e);
+        }
+        return null;
+    }
 
+    /**
+     * Helper methods for handle errors.
+     *
+     * @param msg The error message
+     */
+    private static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseUtilException(msg);
+    }
+
+    /**
+     * Helper methods for handle errors.
+     *
+     * @param msg The error message
+     * @param e   The exception
+     */
+    private static void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseUtilException(msg, e);
+    }
 }

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java Sun Nov 16 07:59:00 2008
@@ -22,7 +22,10 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.commons.util.SynapseUtilException;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
 
 /**
  *
@@ -34,12 +37,10 @@
     private final Map<String, DataSourceInformation> dataSourceInformationMap =
             new HashMap<String, DataSourceInformation>();
 
-    private final List<DataSourceInformationRepositoryListener> listeners =
-            new ArrayList<DataSourceInformationRepositoryListener>();
+    private DataSourceInformationRepositoryListener listener;
 
     public void setConfigurationProperties(Properties congurationProperties) {
-
-        for (DataSourceInformationRepositoryListener listener : listeners) {
+        if (listener != null) {
             listener.reConfigure(congurationProperties);
         }
     }
@@ -49,7 +50,7 @@
         assertNull(dataSourceInformation, "DataSource information is null");
 
         dataSourceInformationMap.put(dataSourceInformation.getAlias(), dataSourceInformation);
-        for (DataSourceInformationRepositoryListener listener : listeners) {
+        if (assertListerNotNull()) {
             listener.addDataSourceInformation(dataSourceInformation);
         }
     }
@@ -69,7 +70,7 @@
 
         assertNull(information, "There is no datasource information instance for given name :" + name);
 
-        for (DataSourceInformationRepositoryListener listener : listeners) {
+        if (assertListerNotNull()) {
             listener.removeDataSourceInformation(information);
         }
         return information;
@@ -80,11 +81,35 @@
         return dataSourceInformationMap.values().iterator();
     }
 
-    public void registerDataSourceInformationRepositoryListener(DataSourceInformationRepositoryListener listener) {
+    public void setRepositoryListener(DataSourceInformationRepositoryListener listener) {
 
         assertNull(listener, "Provided 'DataSourceInformationRepositoryListener' instance is null");
 
-        listeners.add(listener);
+        if (this.listener != null) {
+            handleException("There is a 'DataSourceInformationRepositoryListener' associated with 'DataSourceInformationRepository'");
+        }
+        this.listener = listener;
+    }
+
+    public void removeRepositoryListener() {
+        this.listener = null;
+    }
+
+    public DataSourceInformationRepositoryListener getRepositoryListener() {
+        return this.listener;
+    }
+
+    private boolean assertListerNotNull() {
+        if (listener == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Cannot find a 'DataSourceInformationRepositoryListener'.");
+            }
+            return false;
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("Using 'DataSourceInformationRepositoryListener' as :" + listener);
+        }
+        return true;
     }
 
     private static void handleException(String msg) {
@@ -103,4 +128,4 @@
             handleException(msg);
         }
     }
-}
\ No newline at end of file
+}

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java Sun Nov 16 07:59:00 2008
@@ -36,7 +36,10 @@
     private static final Log log = LogFactory.getLog(DataSourceInformationRepositoryHelper.class);
 
     public static void initializeDataSourceInformationRepository(AxisConfiguration axisConfiguration, Properties properties) {
-        initializeDataSourceInformationRepository(axisConfiguration, properties, DataSourceManager.getInstance());
+        DataSourceRepositoryManager listener = DataSourceRepositoryManager.getInstance();
+        RepositoryBasedDataSourceFinder finder = RepositoryBasedDataSourceFinder.getInstance();
+        finder.init(listener);
+        initializeDataSourceInformationRepository(axisConfiguration, properties, listener);
     }
 
     public static void initializeDataSourceInformationRepository(AxisConfiguration axisConfiguration, Properties properties, DataSourceInformationRepositoryListener listener) {

Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java?rev=718051&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java Sun Nov 16 07:59:00 2008
@@ -0,0 +1,116 @@
+/*
+*  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.commons.util.datasource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.util.SynapseUtilException;
+
+import javax.sql.DataSource;
+import java.util.Properties;
+
+/**
+ * Utility class to handle data source registration
+ */
+public class DataSourceRepositoryManager implements DataSourceInformationRepositoryListener {
+
+    private static final Log log = LogFactory.getLog(DataSourceRepositoryManager.class);
+
+    private static final DataSourceRepositoryManager DATA_SOURCE_REPOSITORY_MANAGER = new DataSourceRepositoryManager();
+
+    private static final DataSourceRepository IN_MEMORY_REPOSITORY = InMemoryDataSourceRepository.getInstance();
+    private static final DataSourceRepository JNDI_REPOSITORY = JNDIBasedDataSourceRepository.getInstance();
+
+    public DataSourceRepositoryManager() {
+    }
+
+    public static DataSourceRepositoryManager getInstance() {
+        return DATA_SOURCE_REPOSITORY_MANAGER;
+    }
+
+    /**
+     * Find a DataSource using given name
+     *
+     * @param name Name of the DataSource to be found
+     * @return DataSource if found , otherwise null
+     */
+    public DataSource getDataSource(String name) {
+
+        if (name == null || "".equals(name)) {
+            handleException("DataSource name cannot be found.");
+        }
+
+        DataSource result = IN_MEMORY_REPOSITORY.lookUp(name);
+
+        if (result != null) {
+            return result;
+        }
+        if (JNDI_REPOSITORY.isInitialized()) {
+            return JNDI_REPOSITORY.lookUp(name);
+        }
+        return null;
+    }
+
+    public void addDataSourceInformation(DataSourceInformation dataSourceInformation) {
+
+        if (dataSourceInformation == null) {
+            return;
+        }
+
+        String repositoryType = dataSourceInformation.getRepositoryType();
+        if (DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
+            JNDI_REPOSITORY.register(dataSourceInformation);
+        } else {
+            IN_MEMORY_REPOSITORY.register(dataSourceInformation);
+        }
+    }
+
+    public void removeDataSourceInformation(DataSourceInformation dataSourceInformation) {
+
+        String repositoryType = dataSourceInformation.getRepositoryType();
+
+        if (DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
+            JNDI_REPOSITORY.unRegister(dataSourceInformation.getDatasourceName());
+        } else {
+            IN_MEMORY_REPOSITORY.unRegister(dataSourceInformation.getDatasourceName());
+        }
+    }
+
+    public void reConfigure(Properties confProperties) {
+
+        JNDI_REPOSITORY.init(confProperties);
+        IN_MEMORY_REPOSITORY.init(confProperties);
+    }
+
+    public void clear() {
+        IN_MEMORY_REPOSITORY.clear();
+        JNDI_REPOSITORY.clear();
+    }
+
+    /**
+     * Helper methods for handle errors.
+     *
+     * @param msg The error message
+     */
+    private static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseUtilException(msg);
+    }
+
+}

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java Sun Nov 16 07:59:00 2008
@@ -44,7 +44,7 @@
 
     private static final JNDIBasedDataSourceRepository ourInstance =
             new JNDIBasedDataSourceRepository();
-    private static InitialContext initialContext;
+    private InitialContext initialContext;
     private Properties jndiProperties;
     private static final Map<String, InitialContext> perDataSourceICMap = new HashMap<String, InitialContext>();
     private boolean initialized = false;
@@ -60,11 +60,11 @@
             log.warn("Provided global JNDI environment properties is empty or null.");
             return;
         }
+
         if (isValid(jndiEnv)) {
             jndiProperties = createJNDIEnvironment(jndiEnv, null);
-            initialContext = createInitialContext(jndiEnv);
+            initialContext = createInitialContext(jndiProperties);
         }
-
     }
 
     private JNDIBasedDataSourceRepository() {
@@ -80,16 +80,30 @@
         validateInitialized();
         String dataSourceName = information.getDatasourceName();
         validateDSName(dataSourceName);
-        Properties jndiEvn = createJNDIEnvironment(information.getProperties(), information.getAlias());
-
-        InitialContext context = createInitialContext(jndiEvn);
+        Properties properties = information.getProperties();
+        
+        InitialContext context = null;
+        Properties jndiEvn = null;
+
+        if (properties != null && !properties.isEmpty()) {
+            jndiEvn = createJNDIEnvironment(properties, information.getAlias());
+            context = createInitialContext(jndiEvn);
+        }
         if (context == null) {
+
             validateInitialContext(initialContext);
             context = initialContext;
+
+            if (log.isDebugEnabled()) {
+                log.debug("Cannot create a name context with jndi properties : " + jndiEvn);
+                log.debug("Using system-wide jndi properties : " + jndiProperties);
+            }
+
             jndiEvn = jndiProperties;
         } else {
             perDataSourceICMap.put(dataSourceName, context);
         }
+
         String dsType = information.getType();
         String driver = information.getDriver();
         String url = information.getUrl();
@@ -174,7 +188,7 @@
 
             ref.add(new BinaryRefAddr(
                     DataSourceConfigurationConstants.PROP_JNDI_ENV,
-                    MiscellaneousUtil.serialize(jndiProperties)));
+                    MiscellaneousUtil.serialize(jndiEvn)));
             ref.add(new StringRefAddr(
                     DataSourceConfigurationConstants.PROP_DATA_SOURCE_NAME, name));
             ref.add(new StringRefAddr(
@@ -231,7 +245,7 @@
         }
 
         InitialContext context = getCachedInitialContext(dsName);
-        return DataSourceManager.getInstance().find(dsName, context);
+        return DataSourceFinder.find(dsName, context);
     }
 
     public void clear() {

Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java?rev=718051&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java Sun Nov 16 07:59:00 2008
@@ -0,0 +1,95 @@
+/*
+ *  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.commons.util.datasource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.util.SynapseUtilException;
+
+import javax.sql.DataSource;
+
+/**
+ * Finds a DataSource from  DataSourceRepositories
+ */
+public class RepositoryBasedDataSourceFinder {
+
+    private final static Log log = LogFactory.getLog(InMemoryDataSourceRepository.class);
+    private DataSourceRepositoryManager dataSourceRepositoryManager;
+    private boolean initialized;
+    private static final RepositoryBasedDataSourceFinder REPOSITORY_BASED_DATA_SOURCE_FINDER = new RepositoryBasedDataSourceFinder();
+
+    private RepositoryBasedDataSourceFinder() {
+    }
+
+    public static RepositoryBasedDataSourceFinder getInstance() {
+        return REPOSITORY_BASED_DATA_SOURCE_FINDER;
+    }
+
+    public void init(DataSourceRepositoryManager dataSourceRepositoryManager) {
+        this.dataSourceRepositoryManager = dataSourceRepositoryManager;
+        this.initialized = true;
+    }
+
+    /**
+     * Find a DataSource using given name
+     *
+     * @param name Name of the DataSource to be found
+     * @return DataSource if found , otherwise null
+     */
+    public DataSource find(String name) {
+        assertInitialized();
+        if (name == null || "".equals(name)) {
+            handleException("DataSource name cannot be found.");
+        }
+
+        return dataSourceRepositoryManager.getDataSource(name);
+    }
+
+
+    /**
+     * Helper methods for handle errors.
+     *
+     * @param msg The error message
+     */
+    private static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseUtilException(msg);
+    }
+
+    /**
+     * Helper methods for handle errors.
+     *
+     * @param msg The error message
+     * @param e   The exception
+     */
+    private static void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseUtilException(msg, e);
+    }
+
+    private void assertInitialized() {
+        if (!initialized) {
+            handleException("RepositoryBasedDataSourceFinder has not been initialized with a 'DataSourceRepositoryManager' instance ");
+        }
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+}

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java Sun Nov 16 07:59:00 2008
@@ -218,7 +218,6 @@
         information.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
         information.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
         information.setTestWhileIdle(testWhileIdle);
-        information.setValidationQuery(validationQuery);
         information.setMinIdle(minIdle);
         information.setDefaultTransactionIsolation(defaultTransactionIsolation);
         information.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
@@ -228,8 +227,14 @@
         information.setPoolPreparedStatements(poolPreparedStatements);
         information.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
         information.setInitialSize(initialSize);
-        information.setDefaultCatalog(defaultCatalog);
 
+        if (validationQuery != null && !"".equals(validationQuery)) {
+            information.setValidationQuery(validationQuery);
+        }
+
+        if (defaultCatalog != null && !"".equals(defaultCatalog)) {
+            information.setDefaultCatalog(defaultCatalog);
+        }
         return information;
     }
 

Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java?rev=718051&r1=718050&r2=718051&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java Sun Nov 16 07:59:00 2008
@@ -21,7 +21,7 @@
 import org.apache.synapse.commons.util.datasource.DataSourceInformation;
 import org.apache.synapse.commons.util.datasource.DataSourceInformationRepository;
 import org.apache.synapse.commons.util.datasource.DataSourceInformationRepositoryListener;
-import org.apache.synapse.commons.util.datasource.DataSourceManager;
+import org.apache.synapse.commons.util.datasource.DataSourceRepositoryManager;
 
 import java.util.List;
 import java.util.Properties;
@@ -33,16 +33,16 @@
 
     public static DataSourceInformationRepository createDataSourceInformationRepository(Properties properties) {
 
-        return createDataSourceInformationRepository(properties, DataSourceManager.getInstance());
+        return createDataSourceInformationRepository(properties, DataSourceRepositoryManager.getInstance());
     }
 
     public static DataSourceInformationRepository createDataSourceInformationRepository(Properties properties, DataSourceInformationRepositoryListener listener) {
 
-        List<DataSourceInformation> dataSourceInformations = DataSourceInformationListFactory.createDataSourceInformationList(properties);
+        List<DataSourceInformation> sourceInformationList = DataSourceInformationListFactory.createDataSourceInformationList(properties);
         DataSourceInformationRepository repository = new DataSourceInformationRepository();
-        repository.registerDataSourceInformationRepositoryListener(listener);
+        repository.setRepositoryListener(listener);
         repository.setConfigurationProperties(properties);
-        for (DataSourceInformation information : dataSourceInformations) {
+        for (DataSourceInformation information : sourceInformationList) {
             if (information != null) {
                 repository.addDataSourceInformation(information);
             }