servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r722067 - in /servicemix/components/engines/servicemix-saxon/trunk/src: main/java/org/apache/servicemix/saxon/ test/resources/
Date Mon, 01 Dec 2008 13:32:20 GMT
Author: gnodet
Date: Mon Dec  1 05:32:19 2008
New Revision: 722067

URL: http://svn.apache.org/viewvc?rev=722067&view=rev
Log:
SM-1705: Make Resources in servicemix-saxon reloadable

Modified:
    servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java
    servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java
    servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java
    servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltProxyEndpoint.java
    servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java?rev=722067&r1=722066&r2=722067&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java
Mon Dec  1 05:32:19 2008
@@ -51,6 +51,7 @@
     private boolean copySubject = true;
     private String result = RESULT_DOM;
     private Resource resource;
+    private boolean reload;
     private Expression expression;
     private Resource wsdlResource;
     private SourceTransformer sourceTransformer = new SourceTransformer();
@@ -112,6 +113,22 @@
         this.resource = resource;
     }
 
+    public boolean isReload() {
+        return reload;
+    }
+
+    /**
+     * Sets whether the endpoint should reload the resource each time it is used.
+     * A value of <code>true</code> will ensure that the resource is not cached
which
+     * can be useful if the resource is updated regularly and is stored outside of 
+     * the service unit. 
+     *
+     * @param reload <code>true</true> if the resource should not be cached
+     */
+    public void setReload(boolean reload) {
+        this.reload = reload;
+    }
+
     /**
      * @return the result
      */

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java?rev=722067&r1=722066&r2=722067&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java
Mon Dec  1 05:32:19 2008
@@ -17,6 +17,7 @@
 package org.apache.servicemix.saxon;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.StringWriter;
 import java.util.Iterator;
 import java.util.Map;
@@ -32,6 +33,7 @@
 
 import net.sf.saxon.Configuration;
 import net.sf.saxon.om.DocumentInfo;
+import net.sf.saxon.trans.XPathException;
 import net.sf.saxon.query.DynamicQueryContext;
 import net.sf.saxon.query.StaticQueryContext;
 import net.sf.saxon.query.XQueryExpression;
@@ -96,11 +98,7 @@
         config.setHostLanguage(Configuration.XQUERY);
         setConfiguration(config);
         staticEnv = new StaticQueryContext(config);
-        if (getQuery() != null) {
-            exp = staticEnv.compileQuery(getQuery());
-        } else if (getResource() != null) {
-            exp = staticEnv.compileQuery(getResource().getInputStream(), null);
-        }
+        exp = compileQuery();
     }
     
     public void validate() throws DeploymentException {
@@ -173,8 +171,21 @@
             Resource r = getDynamicResource(exchange, in);
             return staticEnv.compileQuery(r.getInputStream(), null);
         } else {
-            return exp;
+            if (isReload()) {
+                return compileQuery();
+            } else {
+                return exp;
+            }
+        }
+    }
+
+    protected XQueryExpression compileQuery() throws XPathException, IOException {
+        if (getQuery() != null) {
+            return staticEnv.compileQuery(getQuery());
+        } else if (getResource() != null) {
+            return staticEnv.compileQuery(getResource().getInputStream(), null);
         }
+        return null;
     }
     
 }

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java?rev=722067&r1=722066&r2=722067&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java
Mon Dec  1 05:32:19 2008
@@ -49,7 +49,8 @@
     private Templates templates;
     private boolean useDomSourceForXslt = true;
     private Boolean useDomSourceForContent;
-    
+    private boolean reload = false;
+
     public TransformerFactory getTransformerFactory() {
         if (transformerFactory == null) {
             transformerFactory = createTransformerFactory();
@@ -77,6 +78,14 @@
         this.useDomSourceForContent = useDomSourceForContent;
     }
 
+    public boolean isReload() {
+        return reload;
+    }
+
+    public void setReload(boolean reload) {
+        this.reload = reload;
+    }
+
     public void validate() throws DeploymentException {
         if (xsltSource == null && getResource() == null && getExpression()
== null) {
             throw new DeploymentException("xsltSource, resource or expression must be specified");
@@ -172,7 +181,12 @@
             }
         // Use static stylesheet
         } else {
-            return getTemplates().newTransformer();
+            if (isReload()) {
+                Source source = createXsltSource(getResource());
+                return getTransformerFactory().newTransformer(source);
+            } else {
+                return getTemplates().newTransformer();
+            }
         }
     }
     

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltProxyEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltProxyEndpoint.java?rev=722067&r1=722066&r2=722067&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltProxyEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/main/java/org/apache/servicemix/saxon/XsltProxyEndpoint.java
Mon Dec  1 05:32:19 2008
@@ -344,7 +344,12 @@
             }
         // Use static stylesheet
         } else if (getResource(type) != null) {
-            return getTemplates(type).newTransformer();
+            if (isReload()) {
+                Source source = createXsltSource(getResource(type));
+                return getTransformerFactory().newTransformer(source);
+            } else {
+                return getTemplates(type).newTransformer();
+            }
         } else {
             return null;
         }

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml?rev=722067&r1=722066&r2=722067&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml (original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml Mon
Dec  1 05:32:19 2008
@@ -60,6 +60,7 @@
                   resource="classpath:doc-call.xsl"
                   useDomSourceForXslt="true"
                   useDomSourceForContent="false"
+                  reload="true"
                   result="bytes" />
 
       <!-- START SNIPPET: xquery -->
@@ -68,7 +69,7 @@
       <!-- END SNIPPET: xquery -->
       	      
       <!-- START SNIPPET: xquery-inline -->
-      <saxon:xquery service="test:xquery-inline" endpoint="endpoint">
+      <saxon:xquery service="test:xquery-inline" endpoint="endpoint" reload="true">
         <!-- CDATA are not supported currently -->
         <saxon:query>
            for $x in /bookstore/book
@@ -97,6 +98,7 @@
                    useDomSourceForContent="false"
                    result="dom"
                    resource="classpath:transform-in.xsl"
+                   reload="true"
                    outResource="classpath:transform-out.xsl">
         <saxon:target>
           <saxon:exchange-target service="test:echo" />



Mime
View raw message