This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch xpath in repository https://gitbox.apache.org/repos/asf/camel.git
commit f261486499aad0ecd337a6ac36e80e5f0a7b82e0 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Apr 23 12:32:10 2019 +0200 CAMEL-13442: camel3 - Move xpath out of camel-core --- .../apache/camel/language/xpath/XPathBuilder.java | 9 +++++- .../camel/spi/ExpressionResultTypeAware.java | 34 ++++++++++++++++++++++ .../org/apache/camel/builder/SimpleBuilder.java | 9 +++++- .../apache/camel/model/ExpressionNodeHelper.java | 31 +++++++++----------- 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java index d5c8a09..c930b85 100644 --- a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java +++ b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java @@ -55,6 +55,7 @@ import org.apache.camel.Predicate; import org.apache.camel.RuntimeCamelException; import org.apache.camel.RuntimeExpressionException; import org.apache.camel.WrappedFile; +import org.apache.camel.spi.ExpressionResultTypeAware; import org.apache.camel.spi.Language; import org.apache.camel.spi.NamespaceAware; import org.apache.camel.support.DefaultExchange; @@ -93,7 +94,7 @@ import static org.apache.camel.support.builder.xml.Namespaces.isMatchingNamespac * * @see XPathConstants#NODESET */ -public class XPathBuilder extends ServiceSupport implements CamelContextAware, Expression, Predicate, NamespaceAware { +public class XPathBuilder extends ServiceSupport implements CamelContextAware, Expression, Predicate, NamespaceAware, ExpressionResultTypeAware { private static final Logger LOG = LoggerFactory.getLogger(XPathBuilder.class); private static final String SAXON_OBJECT_MODEL_URI = "http://saxon.sf.net/jaxp/xpath/om"; private static final String SAXON_FACTORY_CLASS_NAME = "net.sf.saxon.xpath.XPathFactoryImpl"; @@ -796,6 +797,12 @@ public class XPathBuilder extends ServiceSupport implements CamelContextAware, E this.simpleFunction = simpleFunction; } + @Override + public String getExpressionText() { + return text; + } + + @Override public Class<?> getResultType() { return resultType; } diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/ExpressionResultTypeAware.java b/core/camel-api/src/main/java/org/apache/camel/spi/ExpressionResultTypeAware.java new file mode 100644 index 0000000..0e95d60 --- /dev/null +++ b/core/camel-api/src/main/java/org/apache/camel/spi/ExpressionResultTypeAware.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spi; + +/** + * Represents an {@link org.apache.camel.Expression} or {@link org.apache.camel.Predicate} that supports a result type. + */ +public interface ExpressionResultTypeAware { + + /** + * Gets the expression or predicate as text + */ + String getExpressionText(); + + /** + * Gets the result type + */ + Class<?> getResultType(); + +} diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java index ca64713..ef15a26 100644 --- a/core/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java +++ b/core/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java @@ -20,6 +20,7 @@ import org.apache.camel.CamelExecutionException; import org.apache.camel.Exchange; import org.apache.camel.Expression; import org.apache.camel.Predicate; +import org.apache.camel.spi.ExpressionResultTypeAware; import org.apache.camel.spi.Language; import org.apache.camel.support.PredicateToExpressionAdapter; import org.apache.camel.support.ScriptHelper; @@ -30,7 +31,7 @@ import org.apache.camel.support.ScriptHelper; * This builder is available in the Java DSL from the {@link RouteBuilder} which means that using * simple language for {@link Expression}s or {@link Predicate}s is very easy with the help of this builder. */ -public class SimpleBuilder implements Predicate, Expression { +public class SimpleBuilder implements Predicate, Expression, ExpressionResultTypeAware { private final String text; private Class<?> resultType; @@ -64,6 +65,12 @@ public class SimpleBuilder implements Predicate, Expression { return text; } + @Override + public String getExpressionText() { + return getText(); + } + + @Override public Class<?> getResultType() { return resultType; } diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java index ac18235..38d75b1 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java @@ -23,6 +23,7 @@ import org.apache.camel.builder.ValueBuilder; import org.apache.camel.model.language.ExpressionDefinition; import org.apache.camel.model.language.SimpleExpression; import org.apache.camel.model.language.XPathExpression; +import org.apache.camel.spi.ExpressionResultTypeAware; /** * Helper for {@link ExpressionNode} @@ -49,16 +50,13 @@ public final class ExpressionNodeHelper { answer.setExpression(builder.getText()); answer.setResultType(builder.getResultType()); return answer; - - // TODO: Make some kind of resulttype expression so we can use an interface to set both kinds - -/* } else if (expression instanceof XPathBuilder) { - XPathBuilder builder = (XPathBuilder) expression; + } else if (expression instanceof ExpressionResultTypeAware && expression.getClass().getName().equals("org.apache.camel.language.xpath.XPathBuilder")) { + ExpressionResultTypeAware aware = (ExpressionResultTypeAware) expression; // we keep the original expression by using the constructor that accepts an expression - XPathExpression answer = new XPathExpression(builder); - answer.setExpression(builder.getText()); - answer.setResultType(builder.getResultType()); - return answer;*/ + XPathExpression answer = new XPathExpression(expression); + answer.setExpression(aware.getExpressionText()); + answer.setResultType(answer.getResultType()); + return answer; } else if (expression instanceof ValueBuilder) { // ValueBuilder wraps the actual expression so unwrap ValueBuilder builder = (ValueBuilder) expression; @@ -87,15 +85,14 @@ public final class ExpressionNodeHelper { SimpleExpression answer = new SimpleExpression(builder); answer.setExpression(builder.getText()); return answer; - - // TODO: Make some kind of resulttype expression so we can use an interface to set both kinds - -/* } else if (predicate instanceof XPathBuilder) { - XPathBuilder builder = (XPathBuilder) predicate; + } else if (predicate instanceof ExpressionResultTypeAware && predicate.getClass().getName().equals("org.apache.camel.language.xpath.XPathBuilder")) { + ExpressionResultTypeAware aware = (ExpressionResultTypeAware) predicate; + Expression expression = (Expression) predicate; // we keep the original expression by using the constructor that accepts an expression - XPathExpression answer = new XPathExpression(builder); - answer.setExpression(builder.getText()); - return answer;*/ + XPathExpression answer = new XPathExpression(expression); + answer.setExpression(aware.getExpressionText()); + answer.setResultType(answer.getResultType()); + return answer; } else if (predicate instanceof ValueBuilder) { // ValueBuilder wraps the actual predicate so unwrap ValueBuilder builder = (ValueBuilder) predicate;