abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r441299 - in /incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax: FOMBuilder.java FOMFactory.java FOMParserFactory.java FOMWriterFactory.java
Date Thu, 07 Sep 2006 23:24:55 GMT
Author: jmsnell
Date: Thu Sep  7 16:24:55 2006
New Revision: 441299

URL: http://svn.apache.org/viewvc?view=rev&rev=441299
Log:
General improvements by making some fields immutable, reducing some of the lazy instantiations

Modified:
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.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/FOMWriterFactory.java

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java?view=diff&rev=441299&r1=441298&r2=441299
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
Thu Sep  7 16:24:55 2006
@@ -47,9 +47,9 @@
   extends StAXOMBuilder
   implements Constants {
 
-  private FOMFactory fomfactory = null;
+  private final FOMFactory fomfactory;
+  private final ParserOptions parserOptions;
   private Document fomDocument = null;
-  private ParserOptions parserOptions = null;
   private int depth = 0;
   private int depthInSkipElement = 0;
   private boolean ignoreWhitespace = false;

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java?view=diff&rev=441299&r1=441298&r2=441299
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
Thu Sep  7 16:24:55 2006
@@ -18,6 +18,7 @@
 package org.apache.abdera.parser.stax;
  
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -68,26 +69,26 @@
   extends OMLinkedListImplFactory 
   implements Factory, Constants, ExtensionFactory, FOMExtensionFactory {
 
-  private Abdera abdera = null;
-  private Map<QName,Class> extensions = null;
-  private List<ExtensionFactory> factories = null;
+  private final Map<QName,Class> extensions;
+  private final List<ExtensionFactory> factories;
   
   public FOMFactory() {
-    this.abdera = new Abdera();
+    this(new Abdera());
   }
   
   public FOMFactory(Abdera abdera) {
-    this.abdera = abdera;
+    List<ExtensionFactory> f= abdera.getConfiguration().getExtensionFactories();
+    this.factories = (f != null) ? 
+      new ArrayList<ExtensionFactory>(f) :
+      new ArrayList<ExtensionFactory>();
+    this.factories.add(this);
+    this.extensions = Collections.synchronizedMap(new HashMap<QName,Class>());
   }
   
   public Parser newParser() {
     return new FOMParser();
   }
   
-  private Abdera getAbdera() {
-    return abdera;
-  }
-  
   @SuppressWarnings("unchecked")
   public <T extends Element>Document<T> newDocument() {
     return new FOMDocument(this);
@@ -233,7 +234,7 @@
         new FOMContent(type, (OMContainer)parent,this);
       try {
         if (type.equals(Content.Type.XML))
-          content.setMimeType("application/xml");
+          content.setMimeType(XML_MEDIA_TYPE);
       } catch (MimeTypeParseException e) { /* Can't happen */ }
       return content;
   }
@@ -423,11 +424,6 @@
   }
 
   private List<ExtensionFactory> getExtensionFactories() {
-    if (factories == null) {
-      factories = new ArrayList<ExtensionFactory>(
-        getAbdera().getConfiguration().getExtensionFactories());
-    }
-    factories.add(0, this);
     return factories;
   }
   
@@ -794,7 +790,6 @@
   }
 
   public void registerExtension(QName qname, Class impl) {
-    if (extensions == null) extensions = new HashMap<QName,Class>();
     extensions.put(qname, impl);
   }
   
@@ -804,11 +799,9 @@
 
   public List<String> getNamespaces() {
     List<String> namespaces = new ArrayList<String>();
-    if (extensions != null) {
-      for (QName qname : extensions.keySet()) {
-        if (!namespaces.contains(qname.getNamespaceURI()))
-          namespaces.add(qname.getNamespaceURI());
-      }
+    for (QName qname : extensions.keySet()) {
+      if (!namespaces.contains(qname.getNamespaceURI()))
+        namespaces.add(qname.getNamespaceURI());
     }
     return namespaces;
   }
@@ -822,21 +815,19 @@
     QName qname, 
     Base parent, 
     Factory factory) {
-      if (extensions != null) {
-        Class _class = extensions.get(qname);
-        if (_class != null) {
-          try {
-            return (T)_class.getConstructor(
-              new Class[] {
-                QName.class,
-                OMContainer.class,
-                OMFactory.class}).newInstance(
-                  new Object[] {
-                    qname, 
-                    parent, 
-                    factory});
-          } catch (Exception e) {}
-        }
+      Class _class = extensions.get(qname);
+      if (_class != null) {
+        try {
+          return (T)_class.getConstructor(
+            new Class[] {
+              QName.class,
+              OMContainer.class,
+              OMFactory.class}).newInstance(
+                new Object[] {
+                  qname, 
+                  parent, 
+                  factory});
+        } catch (Exception e) {}
       }
       return null;
   }
@@ -847,23 +838,21 @@
     Base parent, 
     Factory factory, 
     OMXMLParserWrapper parserWrapper) {
-      if (extensions != null) {
-        Class _class = extensions.get(qname);
-        if (_class != null) {
-          try {
-            return (T)_class.getConstructor(
-              new Class[] {
-                QName.class,
-                OMContainer.class,
-                OMFactory.class,
-                OMXMLParserWrapper.class}).newInstance(
-                  new Object[] {
-                    qname, 
-                    parent, 
-                    factory,
-                    parserWrapper});
-          } catch (Exception e) {}
-        }
+      Class _class = extensions.get(qname);
+      if (_class != null) {
+        try {
+          return (T)_class.getConstructor(
+            new Class[] {
+              QName.class,
+              OMContainer.class,
+              OMFactory.class,
+              OMXMLParserWrapper.class}).newInstance(
+                new Object[] {
+                  qname, 
+                  parent, 
+                  factory,
+                  parserWrapper});
+        } catch (Exception e) {}
       }
       return null;
   }

Modified: 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?view=diff&rev=441299&r1=441298&r2=441299
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParserFactory.java
Thu Sep  7 16:24:55 2006
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.parser.stax;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.abdera.Abdera;
@@ -27,14 +28,17 @@
 public class FOMParserFactory 
   implements ParserFactory {
 
-  private Abdera abdera = null;
+  private final Abdera abdera;
+  private final Map<String,NamedParser> parsers; 
   
   public FOMParserFactory() {
-    this.abdera = new Abdera();
+    this(new Abdera());
   }
   
   public FOMParserFactory(Abdera abdera) {
     this.abdera = abdera;
+    Map<String,NamedParser> p = getAbdera().getConfiguration().getNamedParsers();
+    this.parsers = (p != null) ? p : new HashMap<String,NamedParser>();
   }
   
   protected Abdera getAbdera() {
@@ -47,11 +51,11 @@
 
   public Parser getParser(String name) {
     return (name != null) ? 
-      loadParsers().get(name.toLowerCase()) : getParser();
+      getParsers().get(name.toLowerCase()) : getParser();
   }
 
-  private Map<String,NamedParser> loadParsers() {
-    return getAbdera().getConfiguration().getNamedParsers();
+  private Map<String,NamedParser> getParsers() {
+    return parsers;
   }
   
 }

Modified: 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?view=diff&rev=441299&r1=441298&r2=441299
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMWriterFactory.java
Thu Sep  7 16:24:55 2006
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.parser.stax;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.abdera.Abdera;
@@ -27,14 +28,17 @@
 public class FOMWriterFactory 
   implements WriterFactory {
 
-  private Abdera abdera = null;
+  private final Abdera abdera;
+  private final Map<String,NamedWriter> writers;
   
   public FOMWriterFactory() {
-    this.abdera = new Abdera();
+    this(new Abdera());
   }
   
   public FOMWriterFactory(Abdera abdera) {
     this.abdera = abdera;
+    Map<String,NamedWriter>  w = getAbdera().getConfiguration().getNamedWriters();
+    writers = (w != null) ? w : new HashMap<String,NamedWriter>();
   }
   
   protected Abdera getAbdera() {
@@ -47,19 +51,19 @@
 
   public Writer getWriter(String name) {
     return (name != null) ? 
-      loadWriters().get(name.toLowerCase()) : getWriter();
+      getWriters().get(name.toLowerCase()) : getWriter();
   }
 
   public Writer getWriterByMediaType(String mediatype) {
-    Map<String,NamedWriter> writers = loadWriters();
+    Map<String,NamedWriter> writers = getWriters();
     for (NamedWriter writer : writers.values()) {
       if (writer.outputsFormat(mediatype)) return writer;
     }
     return null;
   }
   
-  private Map<String,NamedWriter> loadWriters() {
-    return getAbdera().getConfiguration().getNamedWriters();
+  private Map<String,NamedWriter> getWriters() {
+    return writers;
   }
   
 }



Mime
View raw message