Author: indika Date: Fri Nov 14 02:23:19 2008 New Revision: 23917 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=23917
Log: some code changes in data source code remove initializing of properties , data sources from configurationn builder so that configuration builder only build configuration Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapsePropertiesLoader.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryHelper.java Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java branches/synapse/1.2.wso2v1/src/main/assembly/bin.xml Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Fri Nov 14 02:23:19 2008 @@ -38,7 +38,6 @@ import org.apache.synapse.task.TaskDescriptionRepository; import org.apache.synapse.task.TaskDescriptionRepositoryFactory; import org.apache.synapse.util.RMIRegistryController; -import org.apache.synapse.util.datasource.DataSourceInformationRepository; import org.apache.synapse.util.datasource.InMemoryDataSourceRepository; import org.apache.synapse.util.datasource.JNDIBasedDataSourceRepository; @@ -104,8 +103,6 @@ TaskDescriptionRepositoryFactory.getTaskDescriptionRepository( SynapseConstants.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY); - private DataSourceInformationRepository dataSourceInformationRepository; - /** * Save the path to the configuration file loaded, to save it later if * required @@ -920,12 +917,4 @@ public TaskDescriptionRepository getTaskDescriptionRepository() { return repository; } - - public DataSourceInformationRepository getDataSourceInformationRepository() { - return dataSourceInformationRepository; - } - - public void setDataSourceInformationRepository(DataSourceInformationRepository dataSourceInformationRepository) { - this.dataSourceInformationRepository = dataSourceInformationRepository; - } } Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java Fri Nov 14 02:23:19 2008 @@ -27,14 +27,10 @@ import org.apache.synapse.mediators.base.SequenceMediator; import org.apache.synapse.mediators.builtin.DropMediator; import org.apache.synapse.mediators.builtin.LogMediator; -import org.apache.synapse.util.datasource.DataSourceInformationRepository; -import org.apache.synapse.util.datasource.factory.DataSourceInformationRepositoryFactory; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.Properties; /** * Builds a Synapse Configuration model with a given input @@ -75,15 +71,10 @@ // build the Synapse configuration parsing the XML config file try { - Properties synapseProperties = loadSynapseProperties(); - DataSourceInformationRepository repository = - DataSourceInformationRepositoryFactory.createDataSourceInformationRepository(synapseProperties); SynapseConfiguration synCfg = XMLConfigurationBuilder.getConfiguration(new FileInputStream(configFile)); log.info("Loaded Synapse configuration from : " + configFile); synCfg.setPathToConfigFile(new File(configFile).getAbsolutePath()); - synCfg.setProperties(synapseProperties); - synCfg.setDataSourceInformationRepository(repository); return synCfg; } catch (FileNotFoundException fnf) { @@ -94,50 +85,6 @@ return null; } - private static Properties loadSynapseProperties() { - - try { - Properties properties = new Properties(); - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - - if (log.isDebugEnabled()) { - log.debug("synapse.properties file is loading from classpath"); - } - - InputStream in = cl.getResourceAsStream(SynapseConstants.SYNAPSE_PROPERTIES); - if (in == null) { - if (log.isDebugEnabled()) { - log.debug("Unable to load synapse.propeties file"); - } - - String path = SynapseConstants.CONF_DIRECTORY + - File.separatorChar + SynapseConstants.SYNAPSE_PROPERTIES; - if (log.isDebugEnabled()) { - log.debug("synapse.properties file is loading from classpath" + - " with resource path '" + path + " '"); - } - - in = cl.getResourceAsStream(path); - if (in == null) { - if (log.isDebugEnabled()) { - log.debug("Unable to load the synapse.properties file from classpath" + - " with resource name '" + path + " '"); - } - } - } - - if (in != null) { - properties.load(in); - } - - return properties; - - } catch (Exception e) { - log.info("Using the default tuning parameters for Synapse"); - } - return new Properties(); - } - private static void handleException(String msg, Exception e) { log.error(msg, e); throw new SynapseException(msg, e); Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapsePropertiesLoader.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapsePropertiesLoader.java?pathrev=23917 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapsePropertiesLoader.java Fri Nov 14 02:23:19 2008 @@ -0,0 +1,83 @@ +/* +* 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; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.synapse.SynapseConstants; +import org.apache.synapse.util.MiscellaneousUtil; + +import java.util.Properties; + +/** + * Provides a Factory method load synapse properties. + * Cache the properties to make sure properties loading only is occurred onetime + */ +public class SynapsePropertiesLoader { + + private static Log log = LogFactory.getLog(SynapsePropertiesLoader.class); + + private SynapsePropertiesLoader() { + } + + private static Properties cacheProperties; + + /** + * Loads the properties + * This happen only cached properties are null. + * + * @return Synapse Properties + */ + public static Properties loadSynapseProperties() { + + if (cacheProperties == null) { + + if (log.isDebugEnabled()) { + log.debug("Loading synapse properties from a property file"); + } + + cacheProperties = MiscellaneousUtil.loadProperties( + SynapseConstants.SYNAPSE_PROPERTIES); + + } else { + + if (log.isDebugEnabled()) { + log.debug("Retrieving synapse properties from the cache"); + } + } + + // Original properties needed to be preserved + Properties tempProperties = new Properties(); + tempProperties.putAll(cacheProperties); + return tempProperties; + } + + /** + * Reloading properties from file + * + * @return Reloaded properties + */ + public static Properties reloadSynapseProperties() { + if (log.isDebugEnabled()) { + log.debug("Reloading synapse properties"); + } + cacheProperties = null; + return loadSynapseProperties(); + } +} Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java Fri Nov 14 02:23:19 2008 @@ -30,19 +30,22 @@ import org.apache.log4j.MDC; import org.apache.neethi.Assertion; import org.apache.neethi.Policy; +import org.apache.synapse.ServerManager; import org.apache.synapse.SynapseConstants; import org.apache.synapse.SynapseException; -import org.apache.synapse.ServerManager; -import org.apache.synapse.format.PlainTextBuilder; -import org.apache.synapse.format.BinaryBuilder; import org.apache.synapse.config.SynapseConfiguration; import org.apache.synapse.config.SynapseConfigurationBuilder; +import org.apache.synapse.config.SynapsePropertiesLoader; +import org.apache.synapse.format.BinaryBuilder; +import org.apache.synapse.format.PlainTextBuilder; +import org.apache.synapse.util.datasource.DataSourceInformationRepositoryHelper; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Properties; /** * This is the Synapse Module implementation class, which would initialize Synapse when it is @@ -160,14 +163,21 @@ String config = ServerManager.getInstance().getSynapseXMLPath(); + Properties synapseProperties = SynapsePropertiesLoader.loadSynapseProperties(); + + DataSourceInformationRepositoryHelper. + initializeDataSourceInformationRepository(axisConfiguration, synapseProperties); + if (config != null) { synapseConfiguration = SynapseConfigurationBuilder.getConfiguration(config); } else { log.warn("System property or init-parameter '" + SynapseConstants.SYNAPSE_XML + - "' is not specified. Using default configuration.."); + "' is not specified. Using default configuration.."); synapseConfiguration = SynapseConfigurationBuilder.getDefaultConfiguration(); } + synapseConfiguration.setProperties(synapseProperties); + // Set the Axis2 ConfigurationContext to the SynapseConfiguration synapseConfiguration.setAxisConfiguration(cfgCtx.getAxisConfiguration()); Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java Fri Nov 14 02:23:19 2008 @@ -67,7 +67,7 @@ public static final String PROP_PROVIDER_PORT = "providerPort"; public final static String PROP_REGISTRY = "registry"; public final static String PROP_REGISTRY_MEMORY = "memory"; - public final static String PROP_REGISTRY_JNDI = "JNDI"; + public final static String PROP_REGISTRY_JNDI = "JNDI"; public static final String PROP_ICFACTORY = "icFactory"; public static final String PROP_PROVIDER_URL = "providerUrl"; public static final String DOT_STRING = "."; @@ -76,9 +76,10 @@ public static final String PROP_TYPE = "type"; public static final String PROP_BASIC_DATA_SOURCE = "BasicDataSource"; public static final String PROP_CLASS_NAME = "className"; - public static final String PROP_CPDSADAPTER_DRIVER + public static final String PROP_CPDSADAPTER_DRIVER = "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"; public static final String PROP_FACTORY = "factory"; public static final String PROP_NAME = "name"; + public static final String DATASOURCE_INFORMATION_REPOSITORY = "DataSourceInformationRepository"; } Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java Fri Nov 14 02:23:19 2008 @@ -18,6 +18,10 @@ */ package org.apache.synapse.util.datasource; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.synapse.SynapseException; + import java.util.*; /** @@ -25,47 +29,78 @@ */ public class DataSourceInformationRepository { + private static final Log log = LogFactory.getLog(DataSourceInformationRepository.class); + private final Map<String, DataSourceInformation> dataSourceInformationMap = new HashMap<String, DataSourceInformation>(); + private final List<DataSourceInformationRepositoryListener> listeners = new ArrayList<DataSourceInformationRepositoryListener>(); public void setConfigurationProperties(Properties congurationProperties) { + for (DataSourceInformationRepositoryListener listener : listeners) { - if (listener != null) { - listener.reConfigure(congurationProperties); - } + listener.reConfigure(congurationProperties); } } public void addDataSourceInformation(DataSourceInformation dataSourceInformation) { + + assertNull(dataSourceInformation, "DataSource information is null"); + dataSourceInformationMap.put(dataSourceInformation.getAlias(), dataSourceInformation); for (DataSourceInformationRepositoryListener listener : listeners) { - if (listener != null) { - listener.addDataSourceInformation(dataSourceInformation); - } + listener.addDataSourceInformation(dataSourceInformation); } } public DataSourceInformation getDataSourceInformation(String name) { + + assertNull(name, "Name of the datasource information instance to be returned is null"); + return dataSourceInformationMap.get(name); } public DataSourceInformation removeDataSourceInformation(String name) { + + assertNull(name, "Name of the datasource information instance to be removed is null"); + DataSourceInformation information = dataSourceInformationMap.remove(name); + + assertNull(information, "There is no datasource information instance for given name :" + name); + for (DataSourceInformationRepositoryListener listener : listeners) { - if (listener != null) { - listener.removeDataSourceInformation(information); - } + listener.removeDataSourceInformation(information); } return information; } public Iterator<DataSourceInformation> getAllDataSourceInformation() { + return dataSourceInformationMap.values().iterator(); } public void registerDataSourceInformationRepositoryListener(DataSourceInformationRepositoryListener listener) { + + assertNull(listener, "Provided 'DataSourceInformationRepositoryListener' instance is null"); + listeners.add(listener); } + + private static void handleException(String msg) { + log.error(msg); + throw new SynapseException(msg); + } + + private void assertNull(String name, String msg) { + if (name == null || "".equals(name)) { + handleException(msg); + } + } + + private void assertNull(Object object, String msg) { + if (object == null) { + handleException(msg); + } + } } \ No newline at end of file Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryHelper.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryHelper.java?pathrev=23917 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryHelper.java Fri Nov 14 02:23:19 2008 @@ -0,0 +1,78 @@ +/* + * 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.util.datasource; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.synapse.SynapseException; +import org.apache.synapse.util.datasource.factory.DataSourceInformationRepositoryFactory; + +import java.util.Properties; + +/** + * + */ +public class DataSourceInformationRepositoryHelper { + + private static final Log log = LogFactory.getLog(DataSourceInformationRepositoryHelper.class); + + public static void initializeDataSourceInformationRepository(AxisConfiguration axisConfiguration, Properties properties) { + initializeDataSourceInformationRepository(axisConfiguration, properties, DataSourceManager.getInstance()); + } + + public static void initializeDataSourceInformationRepository(AxisConfiguration axisConfiguration, Properties properties, DataSourceInformationRepositoryListener listener) { + + DataSourceInformationRepository repository = + DataSourceInformationRepositoryFactory.createDataSourceInformationRepository(properties, listener); + Parameter parameter = new Parameter(DataSourceConfigurationConstants.DATASOURCE_INFORMATION_REPOSITORY, repository); + try { + axisConfiguration.addParameter(parameter); + } catch (AxisFault axisFault) { + handleException("Error setting 'DataSourceInformationRepository' as" + + " a parameter to axis2 configuration ", axisFault); + } + } + + public static DataSourceInformationRepository getDataSourceInformationRepository(AxisConfiguration axisConfiguration) { + + Parameter parameter = axisConfiguration.getParameter(DataSourceConfigurationConstants.DATASOURCE_INFORMATION_REPOSITORY); + if (parameter != null) { + Object result = parameter.getValue(); + if (!(result instanceof DataSourceInformationRepository)) { + handleException("Invalid type '" + result.getClass().getName() + + "' , expected : 'DataSourceInformationRepository'"); + } + return (DataSourceInformationRepository) result; + } + return null; + } + + private static void handleException(String msg, Throwable error) { + log.error(msg, error); + throw new SynapseException(msg, error); + } + + private static void handleException(String msg) { + log.error(msg); + throw new SynapseException(msg); + } +} Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java Fri Nov 14 02:23:19 2008 @@ -65,7 +65,7 @@ return result; } if (JNDI_REPOSITORY.isInitialized()) { - return IN_MEMORY_REPOSITORY.lookUp(name); + return JNDI_REPOSITORY.lookUp(name); } return null; } @@ -80,7 +80,6 @@ public DataSource find(String dsName, Properties jndiEnv) { try { - Context context = new InitialContext(jndiEnv); return find(dsName, context); @@ -122,6 +121,7 @@ if (dataSourceInformation == null) { return; } + String repositoryType = dataSourceInformation.getRepositoryType(); if (DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) { JNDI_REPOSITORY.register(dataSourceInformation); @@ -131,7 +131,9 @@ } public void removeDataSourceInformation(DataSourceInformation dataSourceInformation) { + String repositoryType = dataSourceInformation.getRepositoryType(); + if (DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) { JNDI_REPOSITORY.unRegister(dataSourceInformation.getDatasourceName()); } else { @@ -140,6 +142,7 @@ } public void reConfigure(Properties confProperties) { + JNDI_REPOSITORY.init(confProperties); IN_MEMORY_REPOSITORY.init(confProperties); } Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java Fri Nov 14 02:23:19 2008 @@ -47,8 +47,12 @@ * @param information DataSourceInformation instance */ void register(DataSourceInformation information); - + /** + * Removing datasource + * + * @param name name of the datasource to be removed + */ void unRegister(String name); /** Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java Fri Nov 14 02:23:19 2008 @@ -31,7 +31,8 @@ * */ public class DatasourceMBeanRepository implements MBeanRepository { - private final static Log log = LogFactory.getLog(DataSourceInformationRepository.class); + + private final static Log log = LogFactory.getLog(DatasourceMBeanRepository.class); private final static Map<String, DBPoolView> dataSourcesMBeans = new HashMap<String, DBPoolView>(); private final static DatasourceMBeanRepository DATASOURCE_M_BEAN_REPOSITORY = new DatasourceMBeanRepository(); @@ -45,6 +46,7 @@ } public void addMBean(String name, Object mBean) { + assertNull(name, "DataSorce MBean name cannot be found."); assertNull(mBean, "DataSorce MBean cannot be found."); assertFalse(mBean instanceof DBPoolView, "Given MBean instance is not matched " + @@ -55,16 +57,19 @@ } public Object getMBean(String name) { + assertNull(name, "DataSorce MBean name cannot be found."); return dataSourcesMBeans.get(name); } public void removeMBean(String name) { + dataSourcesMBeans.remove(name); MBeanRegistrar.getInstance().unRegisterMBean(MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, name); } public void clear() { + if (!dataSourcesMBeans.isEmpty()) { log.info("UnRegistering DBPool MBeans"); for (DBPoolView dbPoolView : dataSourcesMBeans.values()) { Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java Fri Nov 14 02:23:19 2008 @@ -83,10 +83,8 @@ } public void unRegister(String name) { - - if (name == null || "".equals(name)) { - return; - } + + assertNull(name,"Name of the datasource to be removed is empty or null"); dataSources.remove(name); REPOSITORY.removeMBean(name); } @@ -130,5 +128,4 @@ handleException(msg); } } - } Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java Fri Nov 14 02:23:19 2008 @@ -57,12 +57,14 @@ initialized = true; if (jndiEnv == null || jndiEnv.isEmpty()) { - log.warn(""); + log.warn("Provided global JNDI environment properties is empty or null."); return; } - jndiProperties = createJNDIEnvironment(jndiEnv, null); - initialContext = createInitialContext(jndiEnv); + if (isValid(jndiEnv)) { + jndiProperties = createJNDIEnvironment(jndiEnv, null); + initialContext = createInitialContext(jndiEnv); + } } private JNDIBasedDataSourceRepository() { @@ -210,8 +212,8 @@ try { context.unbind(name); } catch (NamingException e) { - handleException("Error removing a Datasource with name : "+ - name + " from the JNDI context : "+initialContext,e); + handleException("Error removing a Datasource with name : " + + name + " from the JNDI context : " + initialContext, e); } } @@ -498,4 +500,17 @@ } return null; } + + private boolean isValid(Properties dsProperties) { + + String dataSources = MiscellaneousUtil.getProperty(dsProperties, + DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES, null); + + if (dataSources != null && !"".equals(dataSources)) { + String[] dataSourcesNames = dataSources.split(","); + return !(dataSourcesNames == null || dataSourcesNames.length == 0); + } + + return false; + } } Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java Fri Nov 14 02:23:19 2008 @@ -98,7 +98,7 @@ information.setDatasourceName(dataSourceName); String dsType = (String) MiscellaneousUtil.getProperty( - properties, prefix + DataSourceConfigurationConstants.PROP_TYPE, + properties, prefix + DataSourceConfigurationConstants.PROP_TYPE, DataSourceConfigurationConstants.PROP_BASIC_DATA_SOURCE, String.class); information.setType(dsType); @@ -108,7 +108,7 @@ DataSourceConfigurationConstants.PROP_REGISTRY_MEMORY, String.class); information.setRepositoryType(repositoryType); - + Integer maxActive = (Integer) MiscellaneousUtil.getProperty( properties, prefix + DataSourceConfigurationConstants.PROP_MAXACTIVE, GenericObjectPool.DEFAULT_MAX_ACTIVE, Integer.class); Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java Fri Nov 14 02:23:19 2008 @@ -20,6 +20,7 @@ import org.apache.synapse.util.datasource.DataSourceInformation; import org.apache.synapse.util.datasource.DataSourceInformationRepository; +import org.apache.synapse.util.datasource.DataSourceInformationRepositoryListener; import org.apache.synapse.util.datasource.DataSourceManager; import java.util.List; @@ -31,10 +32,16 @@ public class DataSourceInformationRepositoryFactory { public static DataSourceInformationRepository createDataSourceInformationRepository(Properties properties) { + + return createDataSourceInformationRepository(properties, DataSourceManager.getInstance()); + } + + public static DataSourceInformationRepository createDataSourceInformationRepository(Properties properties, DataSourceInformationRepositoryListener listener) { + List<DataSourceInformation> dataSourceInformations = DataSourceInformationListFactory.createDataSourceInformationList(properties); DataSourceInformationRepository repository = new DataSourceInformationRepository(); + repository.registerDataSourceInformationRepositoryListener(listener); repository.setConfigurationProperties(properties); - repository.registerDataSourceInformationRepositoryListener(DataSourceManager.getInstance()); for (DataSourceInformation information : dataSourceInformations) { if (information != null) { repository.addDataSourceInformation(information); Modified: branches/synapse/1.2.wso2v1/src/main/assembly/bin.xml URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/src/main/assembly/bin.xml?rev=23917&r1=23916&r2=23917&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/src/main/assembly/bin.xml (original) +++ branches/synapse/1.2.wso2v1/src/main/assembly/bin.xml Fri Nov 14 02:23:19 2008 @@ -110,7 +110,7 @@ </includes> </fileSet> <fileSet> - <directory>modules/core/target</directory> + <directory>modules/mar/target</directory> <outputDirectory>synapse-${synapse.version}/repository/modules</outputDirectory> <includes> <include>synapse-${synapse.version}.mar</include> _______________________________________________ Esb-java-dev mailing list [email protected] http://mailman.wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
