Author: hadrian
Date: Sun Nov 29 17:53:18 2009
New Revision: 885249
URL: http://svn.apache.org/viewvc?rev=885249&view=rev
Log:
Create juel impl using a finder. Support for el.properties. Checkstyle fix
Added:
camel/trunk/components/camel-juel/src/main/resources/el.properties
Modified:
camel/trunk/components/camel-juel/pom.xml
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/BeanAndMethodELResolver.java
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/JuelExpression.java
camel/trunk/components/camel-juel/src/main/resources/META-INF/services/org/apache/camel/language/el
camel/trunk/components/camel-juel/src/test/java/org/apache/camel/language/juel/JuelTest.java
Modified: camel/trunk/components/camel-juel/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-juel/pom.xml?rev=885249&r1=885248&r2=885249&view=diff
==============================================================================
--- camel/trunk/components/camel-juel/pom.xml (original)
+++ camel/trunk/components/camel-juel/pom.xml Sun Nov 29 17:53:18 2009
@@ -40,6 +40,11 @@
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-el_1.0_spec</artifactId>
+ <version>${geronimo-el-spec-version}</version>
+ </dependency>
+ <dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel</artifactId>
<version>${juel-version}</version>
Modified:
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/BeanAndMethodELResolver.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/BeanAndMethodELResolver.java?rev=885249&r1=885248&r2=885249&view=diff
==============================================================================
---
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/BeanAndMethodELResolver.java
(original)
+++
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/BeanAndMethodELResolver.java
Sun Nov 29 17:53:18 2009
@@ -38,8 +38,7 @@
@Override
public Object getValue(ELContext elContext, Object base, Object property) {
try {
- return (property instanceof Method) ? property :
- super.getValue(elContext, base, property);
+ return (property instanceof Method) ? property :
super.getValue(elContext, base, property);
} catch (PropertyNotFoundException e) {
// lets see if its a method call...
Method method = findMethod(elContext, base, property);
Modified:
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/JuelExpression.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/JuelExpression.java?rev=885249&r1=885248&r2=885249&view=diff
==============================================================================
---
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/JuelExpression.java
(original)
+++
camel/trunk/components/camel-juel/src/main/java/org/apache/camel/language/juel/JuelExpression.java
Sun Nov 29 17:53:18 2009
@@ -16,6 +16,7 @@
*/
package org.apache.camel.language.juel;
+import java.io.IOException;
import java.util.Properties;
import javax.el.ArrayELResolver;
@@ -29,9 +30,14 @@
import javax.el.ValueExpression;
import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;
+
+import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.impl.ExpressionSupport;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* The <a href="http://camel.apache.org/el.html">EL Language from JSP and
JSF</a>
@@ -40,6 +46,9 @@
* @version $Revision$
*/
public class JuelExpression extends ExpressionSupport {
+ public static final String DEFAULT_EXPRESSION_FACTORY_IMPL_CLASS =
"de.odysseus.el.ExpressionFactoryImpl";
+ private static final Log LOG = LogFactory.getLog(JuelExpression.class);
+
private final String expression;
private final Class<?> type;
private ExpressionFactory expressionFactory;
@@ -58,11 +67,32 @@
// TODO we could use caching here but then we'd have possible
concurrency issues
// so lets assume that the provider caches
ELContext context = populateContext(createContext(), exchange);
- ValueExpression valueExpression =
getExpressionFactory().createValueExpression(context, expression, type);
+ ValueExpression valueExpression =
getExpressionFactory(exchange.getContext()).createValueExpression(context,
expression, type);
Object value = valueExpression.getValue(context);
return exchange.getContext().getTypeConverter().convertTo(tClass,
value);
}
+ public ExpressionFactory getExpressionFactory(CamelContext context) {
+ if (expressionFactory == null && context != null) {
+ try {
+ FactoryFinder finder =
context.getFactoryFinder("META-INF/services/org/apache/camel/component/");
+ Class<?> clazz = finder.findClass("juel", "impl.");
+ if (clazz != null) {
+ expressionFactory = (ExpressionFactory)clazz.newInstance();
+ }
+ } catch (ClassNotFoundException e) {
+ LOG.debug("'impl.class' not found", e);
+ } catch (IOException e) {
+ LOG.debug("No impl class for juel ExpressionFactory defined in
'META-INF/services/org/apache/camel/component/el'", e);
+ } catch (InstantiationException e) {
+ LOG.debug("Failed to instantiate juel ExpressionFactory
implementation class.", e);
+ } catch (IllegalAccessException e) {
+ LOG.debug("Failed to instantiate juel ExpressionFactory
implementation class.", e);
+ }
+ }
+ return getExpressionFactory();
+ }
+
public ExpressionFactory getExpressionFactory() {
if (expressionFactory == null) {
Properties properties = getExpressionFactoryProperties();
Modified:
camel/trunk/components/camel-juel/src/main/resources/META-INF/services/org/apache/camel/language/el
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-juel/src/main/resources/META-INF/services/org/apache/camel/language/el?rev=885249&r1=885248&r2=885249&view=diff
==============================================================================
---
camel/trunk/components/camel-juel/src/main/resources/META-INF/services/org/apache/camel/language/el
(original)
+++
camel/trunk/components/camel-juel/src/main/resources/META-INF/services/org/apache/camel/language/el
Sun Nov 29 17:53:18 2009
@@ -15,4 +15,5 @@
# limitations under the License.
#
-class=org.apache.camel.language.juel.JuelLanguage
\ No newline at end of file
+class=org.apache.camel.language.juel.JuelLanguage
+impl.class=de.odysseus.el.ExpressionFactoryImpl
\ No newline at end of file
Added: camel/trunk/components/camel-juel/src/main/resources/el.properties
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-juel/src/main/resources/el.properties?rev=885249&view=auto
==============================================================================
--- camel/trunk/components/camel-juel/src/main/resources/el.properties (added)
+++ camel/trunk/components/camel-juel/src/main/resources/el.properties Sun Nov
29 17:53:18 2009
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+javax.el.methodInvocations=true
+
Modified:
camel/trunk/components/camel-juel/src/test/java/org/apache/camel/language/juel/JuelTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-juel/src/test/java/org/apache/camel/language/juel/JuelTest.java?rev=885249&r1=885248&r2=885249&view=diff
==============================================================================
---
camel/trunk/components/camel-juel/src/test/java/org/apache/camel/language/juel/JuelTest.java
(original)
+++
camel/trunk/components/camel-juel/src/test/java/org/apache/camel/language/juel/JuelTest.java
Sun Nov 29 17:53:18 2009
@@ -22,6 +22,7 @@
import junit.framework.TestCase;
+import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;
/**
@@ -30,7 +31,7 @@
public class JuelTest extends TestCase {
public void testJuel() throws Exception {
- ExpressionFactory factory = ExpressionFactory.newInstance();
+ ExpressionFactory factory = new ExpressionFactoryImpl();
ELContext context = new SimpleContext();
ValueExpression valueExpression =
factory.createValueExpression(context, "${123 * 2}", Object.class);
Object value = valueExpression.getValue(context);