abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r464603 - /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java
Date Mon, 16 Oct 2006 18:16:23 GMT
Author: jmsnell
Date: Mon Oct 16 11:16:22 2006
New Revision: 464603

URL: http://svn.apache.org/viewvc?view=rev&rev=464603
Log:
Cache the parsed document

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java?view=diff&rev=464603&r1=464602&r2=464603
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java
Mon Oct 16 11:16:22 2006
@@ -42,6 +42,7 @@
   protected final String method;
   protected final IRI requestUri;
   protected final IRI baseUri;
+  protected Document document;
   
   protected AbstractRequestContext(
     ServiceContext context,
@@ -54,44 +55,60 @@
       this.requestUri = requestUri;
   }
     
-  public <T extends Element>Document<T> getDocument()
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument()
     throws ParseException, 
            IOException {
-    Abdera abdera = context.getAbdera();
-    Parser parser = abdera.getParser();
-    ParserOptions options = parser.getDefaultParserOptions();
-    return getDocument(parser, options);
+    if (document == null) {
+      Abdera abdera = context.getAbdera();
+      Parser parser = abdera.getParser();
+      ParserOptions options = parser.getDefaultParserOptions();
+      document = getDocument(parser, options);
+    } 
+    return document;
   }
   
-  public <T extends Element>Document<T> getDocument(
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument(
     Parser parser)
       throws ParseException, 
              IOException {
+    if (document == null) {
       ParserOptions options = parser.getDefaultParserOptions();
-      return getDocument(parser, options);
+      document = getDocument(parser, options);
+    }
+    return document;
   }
   
-  public <T extends Element>Document<T> getDocument(
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument(
     ParserOptions options)
      throws ParseException, 
             IOException  {
+    if (document == null) {
       Abdera abdera = context.getAbdera();
       Parser parser = abdera.getParser();
-      return getDocument(parser, options);
+      document = getDocument(parser, options);
+    }
+    return document;
   }
   
-  public <T extends Element>Document<T> getDocument(
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument(
     Parser parser, 
     ParserOptions options) 
       throws ParseException, 
              IOException {
-    try {
-      return parser.parse(
-        getInputStream(), 
-        null, options);
-    } catch (IRISyntaxException e) {
-      throw new ParseException(e); // won't never happen
-    }
+    if (document == null) {
+      try {
+        return parser.parse(
+          getInputStream(), 
+          null, options);
+      } catch (IRISyntaxException e) {
+        throw new ParseException(e); // won't never happen
+      }
+    } 
+    return document;
   }
   
   public IRI getBaseUri() {



Mime
View raw message