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 2020/10/02 08:50:46 UTC
[camel] 06/14: CAMEL-15605: Languages should be singleton for
better performance.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit d7ea35b7bbf072655337ab48faa84a3fc4a4338f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 1 20:41:26 2020 +0200
CAMEL-15605: Languages should be singleton for better performance.
---
.../apache/camel/language/xpath/XPathLanguage.java | 17 +++++++++++++
.../reifier/language/XPathExpressionReifier.java | 28 +++++++++++++++-------
.../java/org/apache/camel/language/XPathTest.java | 4 ++--
3 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
index fd90f94..5c6ccd5 100644
--- a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
+++ b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
@@ -18,6 +18,7 @@ package org.apache.camel.language.xpath;
import java.util.Map;
+import javax.xml.namespace.QName;
import javax.xml.xpath.XPathFactory;
import org.apache.camel.Expression;
@@ -31,6 +32,7 @@ import org.apache.camel.support.LanguageSupport;
@Language("xpath")
public class XPathLanguage extends LanguageSupport {
private Class<?> resultType;
+ private QName resultQName;
private Class<?> documentType;
private XPathFactory xpathFactory;
private Boolean useSaxon;
@@ -75,6 +77,10 @@ public class XPathLanguage extends LanguageSupport {
if (clazz != null) {
setResultType(clazz);
}
+ QName qname = property(QName.class, properties, "resultQName", null);
+ if (qname != null) {
+ setResultQName(qname);
+ }
setUseSaxon(property(Boolean.class, properties, "useSaxon", null));
setObjectModelUri(property(String.class, properties, "objectModelUri", null));
setThreadSafety(property(Boolean.class, properties, "threadSafety", null));
@@ -91,6 +97,14 @@ public class XPathLanguage extends LanguageSupport {
return resultType;
}
+ public void setResultQName(QName qName) {
+ this.resultQName = qName;
+ }
+
+ public QName getResultQName() {
+ return resultQName;
+ }
+
public void setResultType(Class<?> resultType) {
this.resultType = resultType;
}
@@ -159,6 +173,9 @@ public class XPathLanguage extends LanguageSupport {
if (threadSafety != null) {
builder.setThreadSafety(threadSafety);
}
+ if (resultQName != null) {
+ builder.setResultQName(resultQName);
+ }
if (resultType != null) {
builder.setResultType(resultType);
}
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java
index c49f1f0..b033b14 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java
@@ -19,6 +19,7 @@ package org.apache.camel.reifier.language;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.apache.camel.CamelContext;
@@ -68,6 +69,7 @@ public class XPathExpressionReifier extends ExpressionReifier<XPathExpression> {
Map<String, Object> properties = new HashMap<>(9);
properties.put("expression", expression);
properties.put("documentType", definition.getDocumentType());
+ properties.put("XPathTest", asQName(definition.getResultTypeName()));
properties.put("resultType", definition.getResultType());
properties.put("useSaxon", definition.getSaxon());
properties.put("xPathFactory", definition.getXPathFactory());
@@ -78,16 +80,26 @@ public class XPathExpressionReifier extends ExpressionReifier<XPathExpression> {
return properties;
}
+ private Object asQName(String resultTypeName) {
+ if (resultTypeName == null) {
+ return null;
+ }
+ if ("NUMBER".equalsIgnoreCase(resultTypeName)) {
+ return XPathConstants.NUMBER;
+ } else if ("STRING".equalsIgnoreCase(resultTypeName)) {
+ return XPathConstants.STRING;
+ } else if ("BOOLEAN".equalsIgnoreCase(resultTypeName)) {
+ return XPathConstants.BOOLEAN;
+ } else if ("NODESET".equalsIgnoreCase(resultTypeName)) {
+ return XPathConstants.NODESET;
+ } else if ("NODE".equalsIgnoreCase(resultTypeName)) {
+ return XPathConstants.NODE;
+ }
+ return null;
+ }
+
@Override
protected void configureLanguage(Language language) {
- if (definition.getResultType() == null && definition.getResultTypeName() != null) {
- try {
- Class<?> clazz = camelContext.getClassResolver().resolveMandatoryClass(definition.getResultTypeName());
- definition.setResultType(clazz);
- } catch (ClassNotFoundException e) {
- throw RuntimeCamelException.wrapRuntimeException(e);
- }
- }
if (definition.getDocumentType() == null && definition.getDocumentTypeName() != null) {
try {
Class<?> clazz = camelContext.getClassResolver().resolveMandatoryClass(definition.getDocumentTypeName());
diff --git a/core/camel-core/src/test/java/org/apache/camel/language/XPathTest.java b/core/camel-core/src/test/java/org/apache/camel/language/XPathTest.java
index 3b2ee7f..e07322d 100644
--- a/core/camel-core/src/test/java/org/apache/camel/language/XPathTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/language/XPathTest.java
@@ -56,8 +56,8 @@ public class XPathTest extends LanguageTestSupport {
@Override
protected Language assertResolveLanguage(String languageName) {
XPathLanguage answer = new XPathLanguage();
- answer.setResultType(XPathConstants.STRING);
- assertEquals(XPathConstants.STRING, answer.getResultType());
+ answer.setResultQName(XPathConstants.STRING);
+ assertEquals(XPathConstants.STRING, answer.getResultQName());
return answer;
}
}