You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/02/04 10:19:20 UTC
svn commit: r740663 -
/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
Author: davsclaus
Date: Wed Feb 4 09:19:19 2009
New Revision: 740663
URL: http://svn.apache.org/viewvc?rev=740663&view=rev
Log:
MR-46: Expose the saxon configuration on the exchange to allow eg type converters to get access to this configuration.
Modified:
camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
Modified: camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java?rev=740663&r1=740662&r2=740663&view=diff
==============================================================================
--- camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java (original)
+++ camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java Wed Feb 4 09:19:19 2009
@@ -64,9 +64,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
-
-
/**
* Creates an XQuery builder
*
@@ -100,8 +97,6 @@
public Object evaluate(Exchange exchange) {
try {
- initialize();
-
if (LOG.isDebugEnabled()) {
LOG.debug("Evaluation " + expression + " for exchange: " + exchange);
}
@@ -114,7 +109,7 @@
} else if (resultType.isAssignableFrom(Node.class)) {
return evaluateAsDOM(exchange);
} else {
- // TODO figure out how to convert to the given type
+ throw new IllegalArgumentException("ResultType: " + resultType.getCanonicalName() + " not supported");
}
}
switch (resultsFormat) {
@@ -138,27 +133,27 @@
}
public List evaluateAsList(Exchange exchange) throws Exception {
- initialize();
+ initialize(exchange);
return getExpression().evaluate(createDynamicContext(exchange));
}
public Object evaluateAsStringSource(Exchange exchange) throws Exception {
- initialize();
+ initialize(exchange);
String text = evaluateAsString(exchange);
return new StringSource(text);
}
public Object evaluateAsBytesSource(Exchange exchange) throws Exception {
- initialize();
+ initialize(exchange);
byte[] bytes = evaluateAsBytes(exchange);
return new BytesSource(bytes);
}
public Node evaluateAsDOM(Exchange exchange) throws Exception {
- initialize();
+ initialize(exchange);
DOMResult result = new DOMResult();
DynamicQueryContext context = createDynamicContext(exchange);
@@ -168,7 +163,7 @@
}
public byte[] evaluateAsBytes(Exchange exchange) throws Exception {
- initialize();
+ initialize(exchange);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Result result = new StreamResult(buffer);
@@ -178,7 +173,7 @@
}
public String evaluateAsString(Exchange exchange) throws Exception {
- initialize();
+ initialize(exchange);
StringWriter buffer = new StringWriter();
SequenceIterator iter = getExpression().iterator(createDynamicContext(exchange));
@@ -443,7 +438,7 @@
/**
* Initializes this builder - <b>Must be invoked before evaluation</b>.
*/
- protected synchronized void initialize() throws XPathException, IOException {
+ protected synchronized void initialize(Exchange exchange) throws XPathException, IOException {
// must use synchronized for concurrency issues and only let it initialize once
if (!initialized.get()) {
if (LOG.isDebugEnabled()) {
@@ -465,6 +460,10 @@
initialized.set(true);
}
+
+ // let the configuration be accessible on the exchange as its shared for this evaulation
+ // and can be needed for 3rd part type converters or in some other situations
+ exchange.setProperty("CamelSaxonConfiguration", configuration);
}
}