abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r417828 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/parser/ core/src/main/java/org/apache/abdera/util/ core/src/main/java/org/apache/abdera/writer/ parser/src/main/java/org/apache/abdera/parser/stax/
Date Wed, 28 Jun 2006 17:51:57 GMT
Author: jmsnell
Date: Wed Jun 28 10:51:56 2006
New Revision: 417828

URL: http://svn.apache.org/viewvc?rev=417828&view=rev
Log:
Adding custom parser/writer support

This introduces the concept of named parsers and named writers.  For instance, if I wanted
to have
a JSON serialization of a set of Abdera objects, I could do something like:

  Writer writer = WriterFactory.INSTANCE.getInstance("json");
  writer.writeTo(entry, outputStream);


Added:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/NamedParser.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserFactory.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/NamedWriter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/Writer.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterFactory.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriter.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java
Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/NamedParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/NamedParser.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/NamedParser.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/NamedParser.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,24 @@
+/*
+* 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.parser;
+
+public interface NamedParser extends Parser {
+
+  String getName();
+  
+}

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java?rev=417828&r1=417827&r2=417828&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java Wed
Jun 28 10:51:56 2006
@@ -93,5 +93,31 @@
     ParserOptions options) 
       throws ParseException, URISyntaxException;
   
+  <T extends Element>Document<T> parse(
+      Object in) 
+        throws ParseException;
+    
+  <T extends Element>Document<T> parse(
+    Object in, 
+    URI base) 
+      throws ParseException;
+  
+  <T extends Element>Document<T> parse(
+    Object in, 
+    URI base, 
+    ParserOptions options) 
+      throws ParseException;
+  
+  <T extends Element>Document<T> parse(
+    Object in, 
+    String base) 
+      throws ParseException, URISyntaxException;
+  
+  <T extends Element>Document<T> parse(
+    Object in, 
+    String base, 
+    ParserOptions options) 
+      throws ParseException, URISyntaxException;
+  
   ParserOptions getDefaultParserOptions();
 }

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserFactory.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserFactory.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserFactory.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,33 @@
+/*
+* 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.parser;
+
+import org.apache.abdera.util.ServiceUtil;
+
+public interface ParserFactory {
+
+  public static final ParserFactory INSTANCE = 
+    (ParserFactory) ServiceUtil.newInstance(
+    "org.apache.abdera.parser.ParserFactory",
+    "org.apache.abdera.parser.stax.FOMParserFactory");
+  
+  Parser getInstance();
+  
+  Parser getInstance(String name); 
+  
+}

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java?rev=417828&r1=417827&r2=417828&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
Wed Jun 28 10:51:56 2006
@@ -28,7 +28,6 @@
 import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
 
-
 /**
  * @author James M Snell (jasnell@us.ibm.com)
  */
@@ -88,6 +87,36 @@
   
   public <T extends Element>Document<T> parse(
     Reader in, 
+    String base, 
+    ParserOptions options) 
+      throws ParseException, 
+             URISyntaxException {
+    return parse(in, new URI(base), options);
+  }
+  
+  public <T extends Element>Document<T> parse(
+    Object in) 
+      throws ParseException {
+    return parse(in, (URI)null, getDefaultParserOptions());
+  }
+
+  public <T extends Element>Document<T> parse(
+    Object in, 
+    URI base) 
+      throws ParseException {
+    return parse(in, base, getDefaultParserOptions());
+  }
+
+  public <T extends Element>Document<T> parse(
+    Object in, 
+    String base) 
+      throws ParseException, 
+             URISyntaxException {
+    return parse(in, new URI(base), getDefaultParserOptions());
+  }
+  
+  public <T extends Element>Document<T> parse(
+    Object in, 
     String base, 
     ParserOptions options) 
       throws ParseException, 

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=417828&r1=417827&r2=417828&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
Wed Jun 28 10:51:56 2006
@@ -122,34 +122,40 @@
   
   public static List<ExtensionFactory> loadExtensionFactories() {
     if (factories == null) {
-      factories = new ArrayList<ExtensionFactory>();
-      String sid = "META-INF/services/org.apache.abdera.factory.ExtensionFactory";
-      ClassLoader loader = getClassLoader();
-      try {
-        Enumeration e = loader.getResources(sid);
-        for (;e.hasMoreElements();) {
-          try {
-            URL url = (URL) e.nextElement();
-            InputStream is = url.openStream();
-            if (is != null) {
-              BufferedReader buf = 
-                new BufferedReader(
-                  new InputStreamReader(is));
-              String line = null;
-              while ((line = buf.readLine()) != null) {
-                String s = line.split("#",2)[0].trim();
-                if (!"".equals(s)) { 
-                  ExtensionFactory factory = 
-                    (ExtensionFactory) loader.loadClass(s).newInstance();
-                  factories.add(factory);
-                }
-              }
-            }
-          } catch (Exception ex) {}
-        }
-      } catch (Exception e) {}
+      factories = _loadimpls(
+        "META-INF/services/org.apache.abdera.factory.ExtensionFactory");
     }
     return factories;
   }
   
+  @SuppressWarnings("unchecked")
+  public static <T>List<T> _loadimpls(String sid) {
+    List<T> impls = null;
+    impls = new ArrayList<T>();
+    ClassLoader loader = getClassLoader();
+    try {
+      Enumeration e = loader.getResources(sid);
+      for (;e.hasMoreElements();) {
+        try {
+          URL url = (URL) e.nextElement();
+          InputStream is = url.openStream();
+          if (is != null) {
+            BufferedReader buf = 
+              new BufferedReader(
+                new InputStreamReader(is));
+            String line = null;
+            while ((line = buf.readLine()) != null) {
+              String s = line.split("#",2)[0].trim();
+              if (!"".equals(s)) { 
+                T impl = (T) loader.loadClass(s).newInstance();
+                impls.add(impl);
+              }
+            }
+          }
+        } catch (Exception ex) {}
+      }
+    } catch (Exception e) {}
+    
+    return impls;
+  }
 }

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/NamedWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/NamedWriter.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/NamedWriter.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/NamedWriter.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,7 @@
+package org.apache.abdera.writer;
+
+public interface NamedWriter extends Writer {
+
+  String getName();
+  
+}

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/Writer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/Writer.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/Writer.java (added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/Writer.java Wed
Jun 28 10:51:56 2006
@@ -0,0 +1,43 @@
+/*
+* 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.writer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.abdera.model.Base;
+import org.apache.abdera.util.ServiceUtil;
+
+public interface Writer {
+
+  public static final Writer INSTANCE = 
+    (Writer) ServiceUtil.newInstance(
+    "org.apache.abdera.writer.Writer",
+    "org.apache.abdera.parser.stax.FOMWriter");
+  
+  void writeTo(Base base, 
+    OutputStream out) 
+      throws IOException;
+  
+  void writeTo(
+    Base base, 
+    java.io.Writer out) 
+      throws IOException;
+
+  Object write(Base base) throws IOException;
+}

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterFactory.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterFactory.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterFactory.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,33 @@
+/*
+* 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.writer;
+
+import org.apache.abdera.util.ServiceUtil;
+
+public interface WriterFactory {
+
+  public static final WriterFactory INSTANCE = 
+    (WriterFactory) ServiceUtil.newInstance(
+    "org.apache.abdera.writer.WriterFactory",
+    "org.apache.abdera.parser.stax.FOMWriterFactory");
+  
+  Writer getInstance();
+  
+  Writer getInstance(String name);
+  
+}

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java?rev=417828&r1=417827&r2=417828&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
Wed Jun 28 10:51:56 2006
@@ -20,6 +20,7 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.net.URI;
+import java.net.URISyntaxException;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
@@ -36,7 +37,7 @@
 public class FOMParser 
   extends AbstractParser 
   implements Parser {
-
+  
   private FOMFactory getFomFactory(ParserOptions options) {
     FOMFactory factory = 
       (options != null && options.getFactory() != null) ? 
@@ -108,6 +109,49 @@
   @Override
   public ParserOptions getDefaultParserOptions() {
     return new FOMParserOptions();
+  }
+
+  public <T extends Element> Document<T> parse(
+    Object in) 
+      throws ParseException {
+    return parse(in, (URI)null, null);
+  }
+
+  public <T extends Element> Document<T> parse(
+    Object in, 
+    URI base) 
+      throws ParseException {
+    return parse(in, base, null);
+  }
+
+  public <T extends Element> Document<T> parse(
+    Object in, 
+    URI base, 
+    ParserOptions options) 
+      throws ParseException {
+    if (in instanceof InputStream)
+      return parse((InputStream)in, base, options);
+    else if (in instanceof Reader)
+      return parse((Reader)in, base, options);
+    else 
+      throw new IllegalArgumentException("Unsupported input");
+  }
+
+  public <T extends Element> Document<T> parse(
+    Object in, 
+    String base) 
+      throws ParseException, 
+             URISyntaxException {
+    return parse(in, new URI(base), null);
+  }
+
+  public <T extends Element> Document<T> parse(
+    Object in, 
+    String base, 
+    ParserOptions options) 
+      throws ParseException, 
+             URISyntaxException {
+    return parse(in, new URI(base), options);
   }
 
 }

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,55 @@
+/*
+* 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.parser.stax;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera.parser.NamedParser;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.parser.ParserFactory;
+import org.apache.abdera.util.ServiceUtil;
+
+public class FOMParserFactory 
+  implements ParserFactory {
+
+  public Parser getInstance() {
+    return Parser.INSTANCE;
+  }
+
+  public Parser getInstance(String name) {
+    return (name != null) ? 
+      loadParsers().get(name) : getInstance();
+  }
+
+  private static Map<String,NamedParser> parsers = null;
+  
+  public static Map<String,NamedParser> loadParsers() {
+    if (parsers == null) {
+      List<NamedParser> _parsers = 
+        ServiceUtil._loadimpls(
+          "META-INF/services/org.apache.abdera.parser.NamedParser");
+      parsers = new HashMap<String,NamedParser>();
+      for (NamedParser parser : _parsers) {
+        parsers.put(parser.getName(), parser);
+      }
+    }
+    return parsers;
+  }
+}

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriter.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriter.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriter.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,52 @@
+/*
+* 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.parser.stax;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import org.apache.abdera.model.Base;
+
+public class FOMWriter 
+  implements org.apache.abdera.writer.Writer {
+
+  public void writeTo(
+    Base base, 
+    OutputStream out) 
+      throws IOException {
+        base.writeTo(out);
+  }
+
+  public void writeTo(
+    Base base, 
+    Writer out) 
+      throws IOException {
+        base.writeTo(out);
+  }
+
+  public Object write(
+    Base base) 
+      throws IOException {
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    writeTo(base, out);
+    return out.toString();
+  }
+
+}

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java?rev=417828&view=auto
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java
Wed Jun 28 10:51:56 2006
@@ -0,0 +1,55 @@
+/*
+* 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.parser.stax;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera.util.ServiceUtil;
+import org.apache.abdera.writer.NamedWriter;
+import org.apache.abdera.writer.Writer;
+import org.apache.abdera.writer.WriterFactory;
+
+public class FOMWriterFactory 
+  implements WriterFactory {
+
+  public Writer getInstance() {
+    return Writer.INSTANCE;
+  }
+
+  public Writer getInstance(String name) {
+    return (name != null) ? 
+      loadWriters().get(name) : getInstance();
+  }
+
+  private static Map<String,NamedWriter> writers = null;
+  
+  public static Map<String,NamedWriter> loadWriters() {
+    if (writers == null) {
+      List<NamedWriter> _writers = 
+        ServiceUtil._loadimpls(
+          "META-INF/services/org.apache.abdera.writer.NamedWriter");
+      writers = new HashMap<String,NamedWriter>();
+      for (NamedWriter writer : _writers) {
+        writers.put(writer.getName(), writer);
+      }
+    }
+    return writers;
+  }
+}



Mime
View raw message