Return-Path: Delivered-To: apmail-incubator-abdera-commits-archive@locus.apache.org Received: (qmail 58774 invoked from network); 6 Nov 2007 00:39:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Nov 2007 00:39:24 -0000 Received: (qmail 27831 invoked by uid 500); 6 Nov 2007 00:39:12 -0000 Delivered-To: apmail-incubator-abdera-commits-archive@incubator.apache.org Received: (qmail 27812 invoked by uid 500); 6 Nov 2007 00:39:12 -0000 Mailing-List: contact abdera-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-dev@incubator.apache.org Delivered-To: mailing list abdera-commits@incubator.apache.org Received: (qmail 27803 invoked by uid 99); 6 Nov 2007 00:39:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 16:39:12 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Nov 2007 00:39:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BB88D1A9832; Mon, 5 Nov 2007 16:38:59 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r592206 - in /incubator/abdera/java/trunk/core/src: main/java/org/apache/abdera/ main/java/org/apache/abdera/converter/ main/java/org/apache/abdera/util/ test/java/org/apache/abdera/test/core/ Date: Tue, 06 Nov 2007 00:38:59 -0000 To: abdera-commits@incubator.apache.org From: jmsnell@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071106003859.BB88D1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jmsnell Date: Mon Nov 5 16:38:58 2007 New Revision: 592206 URL: http://svn.apache.org/viewvc?rev=592206&view=rev Log: Part 2 of the AbderaConfiguration/Configuration refactoring. This encapsulates all of the configuration details into the implementation of the Configuration interface so that it can be fully replaced. Specifically, it removes the direct dependency that the Abdera class has on the ServiceUtil helper class so that alternative ways of instantiating the default classes can be used --- e.g. ways that don't involve crawling the classpath. Spring users can likely benefit from this immediately by creating a SpringConfiguration implementation that uses the spring framework to specify the various implementations to use. Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/DefaultConversionContext.java incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java?rev=592206&r1=592205&r2=592206&view=diff ============================================================================== --- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java (original) +++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java Mon Nov 5 16:38:58 2007 @@ -27,8 +27,6 @@ import org.apache.abdera.parser.ParserFactory; import org.apache.abdera.util.AbderaConfiguration; import org.apache.abdera.util.Configuration; -import org.apache.abdera.util.Messages; -import org.apache.abdera.util.ServiceUtil; import org.apache.abdera.writer.StreamWriter; import org.apache.abdera.writer.Writer; import org.apache.abdera.writer.WriterFactory; @@ -209,7 +207,7 @@ * @return A new factory instance */ private Factory newFactory() { - return ServiceUtil.newFactoryInstance(this); + return config.newFactoryInstance(this); } /** @@ -218,7 +216,7 @@ * @return A new parser instance */ private Parser newParser() { - return ServiceUtil.newParserInstance(this); + return config.newParserInstance(this); } /** @@ -227,11 +225,7 @@ * @return A new XPath instance */ private XPath newXPath() { - try { - return ServiceUtil.newXPathInstance(this); - } catch (NoClassDefFoundError n) { - throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","XPath"),n); - } + return config.newXPathInstance(this); } /** @@ -240,11 +234,7 @@ * @return A new ParserFactory instance */ private ParserFactory newParserFactory() { - try { - return ServiceUtil.newParserFactoryInstance(this); - } catch (NoClassDefFoundError n) { - throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","Parser"),n); - } + return config.newParserFactoryInstance(this); } /** @@ -253,11 +243,7 @@ * @return A new WriterFactory instance */ private WriterFactory newWriterFactory() { - try { - return ServiceUtil.newWriterFactoryInstance(this); - } catch (NoClassDefFoundError n) { - throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","WriterFactory"),n); - } + return config.newWriterFactoryInstance(this); } /** @@ -266,11 +252,7 @@ * @return A new default writer implementation instance */ private Writer newWriter() { - try { - return ServiceUtil.newWriterInstance(this); - } catch (NoClassDefFoundError n) { - throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","Writer"),n); - } + return config.newWriterInstance(this); } /** @@ -279,11 +261,7 @@ * @return A new default writer implementation instance */ public StreamWriter newStreamWriter() { - try { - return ServiceUtil.newStreamWriterInstance(this); - } catch (NoClassDefFoundError n) { - throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","StreamWriter"),n); - } + return config.newStreamWriterInstance(this); } // Static convenience methods // Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/DefaultConversionContext.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/DefaultConversionContext.java?rev=592206&r1=592205&r2=592206&view=diff ============================================================================== --- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/DefaultConversionContext.java (original) +++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/DefaultConversionContext.java Mon Nov 5 16:38:58 2007 @@ -17,7 +17,6 @@ */ package org.apache.abdera.converter; -import java.util.List; import java.util.Map; import org.apache.abdera.Abdera; @@ -38,7 +37,7 @@ } private void initConverters() { - List providers = + ConverterProvider[] providers = getAbdera().getConfiguration().getConverterProviders(); for (ConverterProvider provider : providers) { for (Map.Entry,Converter> entry : provider) { Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java?rev=592206&r1=592205&r2=592206&view=diff ============================================================================== --- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java (original) +++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java Mon Nov 5 16:38:58 2007 @@ -26,11 +26,18 @@ import java.util.Map; import java.util.ResourceBundle; +import org.apache.abdera.Abdera; import org.apache.abdera.converter.ConverterProvider; import org.apache.abdera.factory.ExtensionFactory; +import org.apache.abdera.factory.Factory; import org.apache.abdera.parser.NamedParser; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.parser.ParserFactory; import org.apache.abdera.writer.NamedWriter; import org.apache.abdera.writer.StreamWriter; +import org.apache.abdera.writer.Writer; +import org.apache.abdera.writer.WriterFactory; +import org.apache.abdera.xpath.XPath; /** * Provides the basic configuration for the Abdera default implementation. This @@ -73,13 +80,6 @@ } private final ResourceBundle bundle; - private final String xpath; - private final String parser; - private final String factory; - private final String parserFactory; - private final String writerFactory; - private final String writer; - private final String streamwriter; private final List factories; private final List providers; private final Map writers; @@ -95,13 +95,6 @@ AbderaConfiguration.getBundle( ServiceUtil.getClassLoader(), Locale.getDefault()); - xpath = getConfigurationOption(CONFIG_XPATH, DEFAULT_XPATH); - parser = getConfigurationOption(CONFIG_PARSER, DEFAULT_PARSER); - factory = getConfigurationOption(CONFIG_FACTORY, DEFAULT_FACTORY); - parserFactory = getConfigurationOption(CONFIG_PARSERFACTORY, DEFAULT_PARSERFACTORY); - writerFactory = getConfigurationOption(CONFIG_WRITERFACTORY, DEFAULT_WRITERFACTORY); - writer = getConfigurationOption(CONFIG_WRITER, DEFAULT_WRITER); - streamwriter = getConfigurationOption(CONFIG_STREAMWRITER, DEFAULT_STREAMWRITER); factories = ServiceUtil.loadExtensionFactories(); providers = ServiceUtil.loadConverterProviders(); writers = initNamedWriters(); @@ -140,55 +133,7 @@ return (value != null) ? value : _default; } - /** - * Returns the Java classname of the default Abdera XPath implementation - */ - public String getDefaultXPath() { - return xpath; - } - - /** - * Returns the Java classname of the default Abdera Parser implementation - */ - public String getDefaultParser() { - return parser; - } - - /** - * Returns the Java classname of the default Abdera Factory implementation - */ - public String getDefaultFactory() { - return factory; - } - - /** - * Returns the Java classname of the default ParserFactory implementation - */ - public String getDefaultParserFactory() { - return parserFactory; - } - - /** - * Returns the Java classname of the default WriterFactory implementation - */ - public String getDefaultWriterFactory() { - return writerFactory; - } - - /** - * Returns the Java classname of the default Writer implementation - */ - public String getDefaultWriter() { - return writer; - } - - /** - * Returns the Java classname of the default StreamWriter implementation - */ - public String getDefaultStreamWriter() { - return streamwriter; - } - + /** * Registers an ExtensionFactory implementation. */ @@ -208,8 +153,11 @@ /** * Returns the listing of registered ConverterProvider implementations */ - public List getConverterProviders() { - return providers; + public ConverterProvider[] getConverterProviders() { + return providers != null ? + providers.toArray( + new ConverterProvider[providers.size()]) : + new ConverterProvider[0]; } /** @@ -245,18 +193,24 @@ ServiceUtil._loadimpls(STREAM_WRITER,true); writers = Collections.synchronizedMap(new HashMap>()); for (Class writer : _writers) { - try { - Field field = writer.getField("NAME"); - if (Modifier.isStatic(field.getModifiers())) { - String name = (String)field.get(null); - if (name != null) - writers.put(name.toLowerCase(), writer); - } - } catch (Exception e) {} + String name = getName(writer); + if (name != null) + writers.put(name.toLowerCase(), writer); } return writers; } + private static String getName(Class sw) { + String name = null; + try { + Field field = sw.getField("NAME"); + if (Modifier.isStatic(field.getModifiers())) { + name = (String)field.get(null); + } + } catch (Exception e) {} + return name; + } + /** * Returns the collection of NamedWriters */ @@ -278,6 +232,13 @@ Map parsers = getNamedParsers(); parsers.put(parser.getName(), parser); } + + /** + * Registers a StreamWriter implementation + */ + public void addStreamWriter(Class sw) { + getStreamWriters().put(getName(sw), sw); + } /** * Registers NamedParser implementations using @@ -309,4 +270,88 @@ } } + + /** + * Return a new instance of org.apache.abdera.factory.Factory + * + * @return A new factory instance + */ + public Factory newFactoryInstance(Abdera abdera) { + return ServiceUtil.newFactoryInstance(abdera); + } + + /** + * Return a new instance of org.apache.abdera.parser.Parser + * + * @return A new parser instance + */ + public Parser newParserInstance(Abdera abdera) { + return ServiceUtil.newParserInstance(abdera); + } + + /** + * Return a new instance of org.apache.abdera.xpath.XPath + * + * @return A new XPath instance + */ + public XPath newXPathInstance(Abdera abdera) { + try { + return ServiceUtil.newXPathInstance(abdera); + } catch (NoClassDefFoundError n) { + throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","XPath"),n); + } + } + + /** + * Return a new instance of org.apache.abdera.parser.ParserFactory + * + * @return A new ParserFactory instance + */ + public ParserFactory newParserFactoryInstance(Abdera abdera) { + try { + return ServiceUtil.newParserFactoryInstance(abdera); + } catch (NoClassDefFoundError n) { + throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","Parser"),n); + } + } + + /** + * Return a new instance of org.apache.abdera.writer.WriterFactory + * + * @return A new WriterFactory instance + */ + public WriterFactory newWriterFactoryInstance(Abdera abdera) { + try { + return ServiceUtil.newWriterFactoryInstance(abdera); + } catch (NoClassDefFoundError n) { + throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","WriterFactory"),n); + } + } + + /** + * Return a new instance of the default org.apache.abdera.writer.Writer + * + * @return A new default writer implementation instance + */ + public Writer newWriterInstance(Abdera abdera) { + try { + return ServiceUtil.newWriterInstance(abdera); + } catch (NoClassDefFoundError n) { + throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","Writer"),n); + } + } + + /** + * Return a new instance of the default org.apache.abdera.writer.Writer + * + * @return A new default writer implementation instance + */ + public StreamWriter newStreamWriterInstance(Abdera abdera) { + try { + return ServiceUtil.newStreamWriterInstance(abdera); + } catch (NoClassDefFoundError n) { + throw new RuntimeException(Messages.format("IMPLEMENTATION.NOT.AVAILABLE","StreamWriter"),n); + } + } + } Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java?rev=592206&r1=592205&r2=592206&view=diff ============================================================================== --- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java (original) +++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java Mon Nov 5 16:38:58 2007 @@ -21,11 +21,18 @@ import java.util.List; import java.util.Map; +import org.apache.abdera.Abdera; import org.apache.abdera.converter.ConverterProvider; import org.apache.abdera.factory.ExtensionFactory; +import org.apache.abdera.factory.Factory; import org.apache.abdera.parser.NamedParser; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.parser.ParserFactory; import org.apache.abdera.writer.NamedWriter; import org.apache.abdera.writer.StreamWriter; +import org.apache.abdera.writer.Writer; +import org.apache.abdera.writer.WriterFactory; +import org.apache.abdera.xpath.XPath; public interface Configuration extends Cloneable, Serializable { @@ -42,82 +49,67 @@ * @return The configuration option value of _default */ public abstract String getConfigurationOption(String id, String _default); - - /** - * Returns the Java classname of the default Abdera XPath implementation - */ - public abstract String getDefaultXPath(); - - /** - * Returns the Java classname of the default Abdera Parser implementation - */ - public abstract String getDefaultParser(); - + /** - * Returns the Java classname of the default Abdera Factory implementation + * Get a new instance of the default Factory impl */ - public abstract String getDefaultFactory(); + public Factory newFactoryInstance(Abdera abdera); /** - * Returns the Java classname of the default ParserFactory implementation + * Get a new instance of the default Parser impl */ - public abstract String getDefaultParserFactory(); + public Parser newParserInstance(Abdera abdera); /** - * Returns the Java classname of the default WriterFactory implementation + * Get a new instance of the default XPath impl */ - public abstract String getDefaultWriterFactory(); + public XPath newXPathInstance(Abdera abdera); /** - * Returns the Java classname of the default Writer implementation + * Get a new instance of the default ParserFactory impl */ - public abstract String getDefaultWriter(); + public ParserFactory newParserFactoryInstance(Abdera abdera); /** - * Returns the Java classname of the default StreamWriter implementation + * Get a new instance of the default WriterFactory impl */ - public abstract String getDefaultStreamWriter(); + public WriterFactory newWriterFactoryInstance(Abdera abdera); /** - * Registers an ExtensionFactory implementation. + * Get a new instance of the default Writer impl */ - public abstract void addExtensionFactory(ExtensionFactory factory); + public Writer newWriterInstance(Abdera abdera); /** - * Returns the listing of registered ExtensionFactory implementations + * Get a new instance of the default StreamWriter impl */ - public abstract List getExtensionFactories(); + public StreamWriter newStreamWriterInstance(Abdera abdera); /** - * Returns the listing of registered ConverterProvider implementations + * Get a listing of ConverterProviders */ - public abstract List getConverterProviders(); + public ConverterProvider[] getConverterProviders(); /** - * Registers a NamedWriter implementation + * Get the collection of NamedParsers; */ - public abstract void addNamedWriter(NamedWriter writer); + public Map getNamedParsers(); /** - * Returns the collection of NamedWriters + * Get the collection of NamedWriters */ - public abstract Map getNamedWriters(); + public Map getNamedWriters(); /** - * Returns the collection of NamedWriters + * Get the collection of Named StreamWriters */ - public abstract Map> getStreamWriters(); + public Map> getStreamWriters(); /** - * Registers a NamedParser implementation + * Get the collection of ExtensionFactory impls */ - public abstract void addNamedParser(NamedParser parser); + public List getExtensionFactories(); - /** - * Returns the collection of Named Parsers - */ - public abstract Map getNamedParsers(); public abstract Object clone(); - } Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java?rev=592206&r1=592205&r2=592206&view=diff ============================================================================== --- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java (original) +++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java Mon Nov 5 16:38:58 2007 @@ -77,7 +77,7 @@ public static XPath newXPathInstance(Abdera abdera) { return (XPath) newInstance( CONFIG_XPATH, - abdera.getConfiguration().getDefaultXPath(), + abdera.getConfiguration().getConfigurationOption(CONFIG_XPATH, DEFAULT_XPATH), abdera); } @@ -87,7 +87,7 @@ public static Parser newParserInstance(Abdera abdera) { return (Parser) newInstance( CONFIG_PARSER, - abdera.getConfiguration().getDefaultParser(), + abdera.getConfiguration().getConfigurationOption(CONFIG_PARSER, DEFAULT_PARSER), abdera); } @@ -97,35 +97,35 @@ public static Factory newFactoryInstance(Abdera abdera) { return (Factory) newInstance( CONFIG_FACTORY, - abdera.getConfiguration().getDefaultFactory(), + abdera.getConfiguration().getConfigurationOption(CONFIG_FACTORY, DEFAULT_FACTORY), abdera); } public static ParserFactory newParserFactoryInstance(Abdera abdera) { return (ParserFactory) newInstance( CONFIG_PARSERFACTORY, - abdera.getConfiguration().getDefaultParserFactory(), + abdera.getConfiguration().getConfigurationOption(CONFIG_PARSERFACTORY, DEFAULT_PARSERFACTORY), abdera); } public static WriterFactory newWriterFactoryInstance(Abdera abdera) { return (WriterFactory) newInstance( CONFIG_WRITERFACTORY, - abdera.getConfiguration().getDefaultWriterFactory(), + abdera.getConfiguration().getConfigurationOption(CONFIG_WRITERFACTORY, DEFAULT_WRITERFACTORY), abdera) ; } public static Writer newWriterInstance(Abdera abdera) { return (Writer) newInstance( CONFIG_WRITER, - abdera.getConfiguration().getDefaultWriter(), + abdera.getConfiguration().getConfigurationOption(CONFIG_WRITER, DEFAULT_WRITER), abdera); } public static StreamWriter newStreamWriterInstance(Abdera abdera) { return (StreamWriter) newInstance( CONFIG_STREAMWRITER, - abdera.getConfiguration().getDefaultStreamWriter(), + abdera.getConfiguration().getConfigurationOption(CONFIG_STREAMWRITER, DEFAULT_STREAMWRITER), abdera); } Modified: incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java?rev=592206&r1=592205&r2=592206&view=diff ============================================================================== --- incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java (original) +++ incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java Mon Nov 5 16:38:58 2007 @@ -62,23 +62,24 @@ import org.apache.abdera.util.AbderaConfiguration; import org.apache.abdera.util.CompressionUtil; import org.apache.abdera.util.Configuration; +import org.apache.abdera.util.Constants; import org.apache.abdera.util.MimeTypeHelper; import org.apache.abdera.util.URIHelper; import org.apache.abdera.util.XmlRestrictedCharReader; import org.apache.abdera.writer.WriterOptions; -public class CoreTest extends TestCase { +public class CoreTest extends TestCase implements Constants { public static void testDefaultConfigurationProperties() { Configuration config = new AbderaConfiguration(); assertEquals( - config.getDefaultFactory(), + config.getConfigurationOption(CONFIG_FACTORY, DEFAULT_FACTORY), "org.apache.abdera.parser.stax.FOMFactory"); assertEquals( - config.getDefaultParser(), + config.getConfigurationOption(CONFIG_PARSER, DEFAULT_PARSER), "org.apache.abdera.parser.stax.FOMParser"); assertEquals( - config.getDefaultXPath(), + config.getConfigurationOption(CONFIG_XPATH, DEFAULT_XPATH), "org.apache.abdera.parser.stax.FOMXPath"); }