[jbosscache-commits] JBoss Cache SVN: r6220 - in core/trunk/src: main/java/org/jboss/cache/config and 4 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Tue Jul 8 14:43:36 EDT 2008
Author: mircea.markus
Date: 2008-07-08 14:43:36 -0400 (Tue, 08 Jul 2008)
New Revision: 6220
Added:
core/trunk/src/main/java/org/jboss/cache/config/OldFileFormatException.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
Log:
fall back to the old configuration format
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-07-08 17:15:50 UTC (rev 6219)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-07-08 18:43:36 UTC (rev 6220)
@@ -8,8 +8,9 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.OldFileFormatException;
+import org.jboss.cache.config.parsing.XmlConfigurationParser;
import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
-import org.jboss.cache.config.parsing.XmlConfigurationParser;
import org.jboss.cache.factories.ComponentFactory;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.invocation.CacheInvocationDelegate;
@@ -64,7 +65,15 @@
public Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
{
XmlConfigurationParser parser = new XmlConfigurationParser();
- Configuration c = parser.parseFile(configFileName);
+ Configuration c = null;
+ try
+ {
+ c = parser.parseFile(configFileName);
+ } catch (OldFileFormatException e)
+ {
+ XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
+ c = oldParser.parseFile(configFileName);
+ }
return createCache(c, start);
}
@@ -142,9 +151,16 @@
public Cache<K, V> createCache(InputStream is) throws ConfigurationException
{
- //todo mmarkus also try to parse old file types.
XmlConfigurationParser parser = new XmlConfigurationParser();
- Configuration c = parser.parseStream(is);
+ Configuration c = null;
+ try
+ {
+ c = parser.parseStream(is);
+ } catch (OldFileFormatException e)
+ {
+ XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
+ c = oldParser.parseStream(is);
+ }
return createCache(c);
}
Added: core/trunk/src/main/java/org/jboss/cache/config/OldFileFormatException.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/OldFileFormatException.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/OldFileFormatException.java 2008-07-08 18:43:36 UTC (rev 6220)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.config;
+
+/**
+ * This exception indicates that an old configuration file is passed to a parser that only knows how to handle newer
+ * configuration file.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 3.0
+ */
+public class OldFileFormatException extends ConfigurationException
+{
+ public OldFileFormatException(String string)
+ {
+ super(string);
+ }
+
+ public OldFileFormatException()
+ {
+ this("The configuration file has an old format.");
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-07-08 17:15:50 UTC (rev 6219)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-07-08 18:43:36 UTC (rev 6220)
@@ -109,6 +109,7 @@
* Parses an XML file and returns a new configuration.
* For looking up the file, {@link org.jboss.cache.config.parsing.FileLookup} is used.
*
+ * @throws OldFileFormatException if the file has a 2.x format
* @see org.jboss.cache.config.parsing.FileLookup
*/
public Configuration parseFile(String filename)
@@ -123,6 +124,8 @@
/**
* Similar to {@link #parseFile(String)}, just that it does not create the input stream.
+ *
+ * @throws OldFileFormatException if the file has a 2.x format
*/
public Configuration parseStream(InputStream configStream)
{
@@ -132,6 +135,8 @@
/**
* Root should be the <b>jbosscache</b> element in the configuration file.
+ *
+ * @throws OldFileFormatException if the file has a 2.x format
*/
public Configuration parseElement(Element root)
{
@@ -147,6 +152,10 @@
private Configuration processElements()
{
+ if ("server".equalsIgnoreCase(root.getNodeName()))
+ {
+ throw new OldFileFormatException();
+ }
configureLocking(getSingleElement("locking"));
configureTransaction(getSingleElement("transaction"));
configureReplication(getSingleElement("replication"));
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-07-08 17:15:50 UTC (rev 6219)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-07-08 18:43:36 UTC (rev 6220)
@@ -25,11 +25,10 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.*;
import org.jboss.cache.config.*;
-import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.JGroupsStackParser;
import org.jboss.cache.config.parsing.element.BuddyElementParser;
-import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.CachePrinter;
import org.jgroups.Address;
Modified: core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2008-07-08 17:15:50 UTC (rev 6219)
+++ core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2008-07-08 18:43:36 UTC (rev 6220)
@@ -44,6 +44,12 @@
}
}
+ public void testLoadOldConfig()
+ {
+ cache = (CacheSPI) new DefaultCacheFactory().createCache("configs/conf2x/buddy-replication-cache.xml");
+ assert cache.getCacheStatus() == CacheStatus.STARTED : "Should have started";
+ }
+
public void testFromConfigFileStarted()
{
cache = (CacheSPI) new DefaultCacheFactory().createCache(configFile);
Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-07-08 17:15:50 UTC (rev 6219)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-07-08 18:43:36 UTC (rev 6220)
@@ -28,6 +28,19 @@
config = parser.parseFile("configs/parser-test.xml");
}
+ public void testParseOldConfigFile()
+ {
+ XmlConfigurationParser parser = new XmlConfigurationParser();
+ try
+ {
+ parser.parseFile("configs/conf2x/pess-local.xml");
+ assert false : "exception expected";
+ } catch (OldFileFormatException e)
+ {
+ //expectd
+ }
+ }
+
public void testTransactionManagerLookupClass()
{
assert config.getTransactionManagerLookupClass().equals("org.jboss.cache.transaction.GenericTransactionManagerLookup");
More information about the jbosscache-commits
mailing list