[jboss-svn-commits] JBL Code SVN: r7191 - labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/persistence

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Oct 29 09:52:40 EST 2006


Author: daniel.brum at jboss.com
Date: 2006-10-29 09:52:39 -0500 (Sun, 29 Oct 2006)
New Revision: 7191

Added:
   labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java
Log:


Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java	2006-10-29 14:52:37 UTC (rev 7190)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java	2006-10-29 14:52:39 UTC (rev 7191)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+
+package org.jboss.internal.soa.esb.persistence.format;
+
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+
+import org.jboss.internal.soa.esb.persistence.format.db.DBMessageStorePlugin;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.services.persistence.MessageStoreFactory;
+
+public class MessageStoreFactoryImpl extends MessageStoreFactory {
+	
+	private final Hashtable<URI, MessageStorePlugin> messageStoreFormats = new Hashtable<URI, MessageStorePlugin>();
+
+	
+	public MessageStoreFactoryImpl() {
+		reset();
+	}
+	
+	public MessageStore getMessageStore() {
+		return ((MessageStorePlugin) messageStoreFormats.get(MessageStoreType.DEFAULT_TYPE)).getMessageStore();
+	}
+	
+	public MessageStore getMessageStore(URI type) {
+		if (type == null)
+			throw new IllegalArgumentException();
+
+		MessageStorePlugin plugin = messageStoreFormats.get(type);
+
+		if (plugin != null)
+			return plugin.getMessageStore();
+		else
+			return null;
+	}
+	
+	public void reset ()
+	{
+		messageStoreFormats.clear();
+		/*
+		 * Go through the properties loaded from the property file. Anything
+		 * starting with MessageStorePlugin.MESSAGE_STORE_PLUGIN is assumed to be a plugin
+		 * that we load and add to the list.
+		 */		
+		
+		Properties properties = System.getProperties();
+		
+		if (properties != null)
+		{
+			Enumeration names = properties.propertyNames();
+
+			while (names.hasMoreElements())
+			{
+				String attrName = (String) names.nextElement();
+				
+				if (attrName.startsWith(MessageStorePlugin. MESSAGE_STORE_PLUGIN))
+				{
+					try
+					{
+						String pluginName = properties.getProperty(attrName);
+						Class c = Class.forName(pluginName);
+						MessageStorePlugin thePlugin = (MessageStorePlugin) c.newInstance();
+
+						messageStoreFormats.put(thePlugin.getType(), thePlugin);
+					}
+					catch (ClassNotFoundException ex)
+					{
+						ex.printStackTrace();
+					}
+					catch (IllegalAccessException ex)
+					{
+						ex.printStackTrace();
+					}
+					catch (InstantiationException ex)
+					{
+						ex.printStackTrace();
+					}
+				}
+			}
+		}
+	         
+		/*
+		 * Now add the default(s).
+		 */		
+		messageStoreFormats.put(MessageStoreType.DATABASE, new DBMessageStorePlugin());		
+	}
+
+}




More information about the jboss-svn-commits mailing list