forked from apache/camel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
applied patch from Gert for JXPath support with thanks : https://issu…
…es.apache.org/activemq/browse/CAMEL-241 I also added the new language into the XSD and DSL git-svn-id: https://svn.apache.org/repos/asf/activemq/camel/trunk@638833 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
15 changed files
with
568 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
camel-core/src/main/java/org/apache/camel/model/language/JXPathExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* 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.model.language; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
/** | ||
* For <a href="http://commons.apache.org/jxpath/">JXPath</a> expresions and predicates | ||
* | ||
* @version $Revision$ | ||
*/ | ||
@XmlRootElement(name = "jxpath") | ||
public class JXPathExpression extends ExpressionType { | ||
public JXPathExpression() { | ||
} | ||
|
||
public JXPathExpression(String expression) { | ||
super(expression); | ||
} | ||
|
||
public String getLanguage() { | ||
return "jaxpath"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-parent</artifactId> | ||
<version>1.3-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>camel-jxpath</artifactId> | ||
<packaging>bundle</packaging> | ||
<name>Camel :: JXPath</name> | ||
<description>Camel JXPath support</description> | ||
|
||
<properties> | ||
<camel.osgi.export.pkg>org.apache.camel.language.jxpath.*</camel.osgi.export.pkg> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-jxpath</groupId> | ||
<artifactId>commons-jxpath</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<!-- testing --> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-core</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
82 changes: 82 additions & 0 deletions
82
components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* 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.language.jxpath; | ||
|
||
import org.apache.camel.Exchange; | ||
import org.apache.camel.Expression; | ||
import org.apache.camel.impl.ExpressionSupport; | ||
import org.apache.camel.language.ExpressionEvaluationException; | ||
import org.apache.commons.jxpath.CompiledExpression; | ||
import org.apache.commons.jxpath.JXPathContext; | ||
import org.apache.commons.jxpath.JXPathException; | ||
|
||
/** | ||
* <a href="http://commons.apache.org/jxpath/">JXPath</a> {@link Expression} support | ||
*/ | ||
public class JXPathExpression extends ExpressionSupport<Exchange> { | ||
|
||
private String expression; | ||
private CompiledExpression compiledExpression; | ||
private final Class<?> type; | ||
|
||
/** | ||
* Creates a new JXPathExpression instance | ||
* | ||
* @param expression the JXPath expression to be evaluated | ||
* @param type the expected result type | ||
*/ | ||
public JXPathExpression(String expression, Class<?> type) { | ||
super(); | ||
this.expression = expression; | ||
this.type = type; | ||
} | ||
|
||
|
||
public Object evaluate(Exchange exchange) { | ||
try { | ||
Object result = getJXPathExpression().getValue(JXPathContext.newContext(exchange)); | ||
assertResultType(exchange, result); | ||
return result; | ||
} catch (JXPathException e) { | ||
throw new ExpressionEvaluationException(this, exchange, e); | ||
} | ||
} | ||
|
||
/* | ||
* Check if the result is of the specified type | ||
*/ | ||
private void assertResultType(Exchange exchange, Object result) { | ||
if (!type.isAssignableFrom(result.getClass())) { | ||
throw new JXPathException("JXPath result type is " + result.getClass() + " instead of required type " + type); | ||
} | ||
} | ||
|
||
@Override | ||
protected String assertionFailureMessage(Exchange exchange) { | ||
return expression.toString(); | ||
} | ||
|
||
/* | ||
* Get a compiled expression instance for better performance | ||
*/ | ||
private synchronized CompiledExpression getJXPathExpression() { | ||
if (compiledExpression == null) { | ||
compiledExpression = JXPathContext.compile(expression); | ||
} | ||
return compiledExpression; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathLanguage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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.language.jxpath; | ||
|
||
import org.apache.camel.Exchange; | ||
import org.apache.camel.Expression; | ||
import org.apache.camel.Predicate; | ||
import org.apache.camel.spi.Language; | ||
|
||
/** | ||
* <a href="http://commons.apache.org/jxpath/">JXPath</a> {@link Language} provider | ||
*/ | ||
public class JXPathLanguage implements Language { | ||
|
||
public Expression<Exchange> createExpression(String expression) { | ||
return new JXPathExpression(expression, Object.class); | ||
} | ||
|
||
public Predicate<Exchange> createPredicate(String predicate) { | ||
return new JXPathExpression(predicate, Boolean.class); | ||
} | ||
|
||
} |
Oops, something went wrong.