abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r592200 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/ core/src/main/java/org/apache/abdera/util/ core/src/test/java/org/apache/abdera/test/core/ security/src/main/java/org/apache/abdera/security/
Date Tue, 06 Nov 2007 00:08:13 GMT
Author: jmsnell
Date: Mon Nov  5 16:08:12 2007
New Revision: 592200

URL: http://svn.apache.org/viewvc?rev=592200&view=rev
Log:
Extract out a Configuration interface; this will allow developers to provide alternative 
implementations of the configuration mechanism.  The one place where this will come in handy
is if a particular implementation wishes to not use the automatic classpath scanning used
for discovering ExtensionFactory implementations, NamedWriters, etc.  Instead, someone may
want to put together something based on Spring (for instance) or implement a static configuration
using a hard coded set of extension factories, etc.

Added:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java
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/util/AbderaConfiguration.java
    incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java
    incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.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=592200&r1=592199&r2=592200&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:08:12 2007
@@ -26,6 +26,7 @@
 import org.apache.abdera.parser.Parser;
 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;
@@ -67,7 +68,7 @@
     return instance;
   }
   
-  private final AbderaConfiguration config;
+  private final Configuration config;
   private final Factory factory;
   private final Parser parser;
   private final XPath xpath;
@@ -86,7 +87,7 @@
    * Initialize using the specified Abdera Configuration
    * @param config The Abdera Configuration to use
    */
-  public Abdera(AbderaConfiguration config) {
+  public Abdera(Configuration config) {
     this.config = config;
     factory = newFactory();
     parser = newParser();
@@ -138,8 +139,9 @@
    * 
    * @return The Abdera configuration
    */
-  public AbderaConfiguration getConfiguration() {
-    return config;
+  @SuppressWarnings("unchecked") 
+  public <T extends Configuration>T getConfiguration() {
+    return (T)config;
   }
   
   /**

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=592200&r1=592199&r2=592200&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:08:12 2007
@@ -17,7 +17,6 @@
 */
 package org.apache.abdera.util;
 
-import java.io.Serializable;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.util.Collections;
@@ -38,7 +37,7 @@
  * class should not be accessed by applications directly without very good reason.
  */
 public final class AbderaConfiguration 
-  implements Constants, Cloneable, Serializable {
+  implements Constants, Configuration {
   
   private static final long serialVersionUID = 7460203853824337559L;
 
@@ -46,8 +45,8 @@
    * Returns the default configuration. Every call to this method returns
    * a new AbderaConfiguration instance using abdera.properties
    */
-  public static synchronized AbderaConfiguration getDefault() {
-    AbderaConfiguration instance = null;
+  public static synchronized Configuration getDefault() {
+    Configuration instance = null;
     try {
       ResourceBundle bundle = ResourceBundle.getBundle("abdera");
       instance = new AbderaConfiguration(bundle);
@@ -302,8 +301,12 @@
     return parsers;
   }
   
-  public Object clone() throws CloneNotSupportedException {
-    return super.clone();
+  public Object clone() {
+    try {
+      return super.clone();
+    } catch (CloneNotSupportedException e) {
+      throw new RuntimeException(e);
+    }
   }
   
 }

Added: 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=592200&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Configuration.java
Mon Nov  5 16:08:12 2007
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.util;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera.converter.ConverterProvider;
+import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.parser.NamedParser;
+import org.apache.abdera.writer.NamedWriter;
+import org.apache.abdera.writer.StreamWriter;
+
+public interface Configuration 
+  extends Cloneable, Serializable {
+  
+  /**
+   * Retrieve the value of the specified configuration option
+   * @return The configuration option value or null
+   */
+  public abstract String getConfigurationOption(String id);
+  
+  /**
+   * Retrieve the value of the specified configuration option or _default
+   * if the value is null
+   * @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
+   */
+  public abstract String getDefaultFactory();
+  
+  /**
+   * Returns the Java classname of the default ParserFactory implementation
+   */
+  public abstract String getDefaultParserFactory();
+  
+  /**
+   * Returns the Java classname of the default WriterFactory implementation
+   */
+  public abstract String getDefaultWriterFactory();
+  
+  /**
+   * Returns the Java classname of the default Writer implementation
+   */
+  public abstract String getDefaultWriter();
+  
+  /**
+   * Returns the Java classname of the default StreamWriter implementation
+   */
+  public abstract String getDefaultStreamWriter();
+  
+  /**
+   * Registers an ExtensionFactory implementation.
+   */
+  public abstract void addExtensionFactory(ExtensionFactory factory);
+  
+  /**
+   * Returns the listing of registered ExtensionFactory implementations
+   */
+  public abstract List<ExtensionFactory> getExtensionFactories();
+  
+  /**
+   * Returns the listing of registered ConverterProvider implementations
+   */
+  public abstract List<ConverterProvider> getConverterProviders();
+  
+  /**
+   * Registers a NamedWriter implementation
+   */
+  public abstract void addNamedWriter(NamedWriter writer);
+  
+  /**
+   * Returns the collection of NamedWriters
+   */
+  public abstract Map<String, NamedWriter> getNamedWriters();
+  
+  /**
+   * Returns the collection of NamedWriters
+   */
+  public abstract Map<String, Class<? extends StreamWriter>> getStreamWriters();
+  
+  /**
+   * Registers a NamedParser implementation
+   */
+  public abstract void addNamedParser(NamedParser parser);
+  
+  /**
+   * Returns the collection of Named Parsers
+   */
+  public abstract Map<String, NamedParser> getNamedParsers();
+  
+  public abstract Object clone();
+  
+}
\ No newline at end of file

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=592200&r1=592199&r2=592200&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:08:12 2007
@@ -61,6 +61,7 @@
 import org.apache.abdera.model.Content.Type;
 import org.apache.abdera.util.AbderaConfiguration;
 import org.apache.abdera.util.CompressionUtil;
+import org.apache.abdera.util.Configuration;
 import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.util.URIHelper;
 import org.apache.abdera.util.XmlRestrictedCharReader;
@@ -69,7 +70,7 @@
 public class CoreTest extends TestCase {
 
   public static void testDefaultConfigurationProperties() {
-    AbderaConfiguration config = new AbderaConfiguration();
+    Configuration config = new AbderaConfiguration();
     assertEquals(
       config.getDefaultFactory(), 
       "org.apache.abdera.parser.stax.FOMFactory");

Modified: incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java?rev=592200&r1=592199&r2=592200&view=diff
==============================================================================
--- incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java
(original)
+++ incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java
Mon Nov  5 16:08:12 2007
@@ -18,7 +18,7 @@
 package org.apache.abdera.security;
 
 import org.apache.abdera.Abdera;
-import org.apache.abdera.util.AbderaConfiguration;
+import org.apache.abdera.util.Configuration;
 import org.apache.abdera.util.ServiceUtil;
 
 /**
@@ -41,7 +41,7 @@
     this.signature = newSignature();
   }
   
-  public AbderaSecurity(AbderaConfiguration config) {
+  public AbderaSecurity(Configuration config) {
     this(new Abdera(config));
   }
   



Mime
View raw message