You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/18 10:25:17 UTC

svn commit: r567244 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/ main/java/org/apache/camel/language/ test/java/org/apache/camel/processor/

Author: jstrachan
Date: Sat Aug 18 01:25:16 2007
New Revision: 567244

URL: http://svn.apache.org/viewvc?view=rev&rev=567244
Log:
Initial spike of expression injection for method parameters

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultInjectionExpressionFactory.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/InjectionExpressionFactory.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageAnnotation.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageExpression.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/NamespacePrefix.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/Simple.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java   (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExpressionInjectionTest.java
      - copied, changed from r567097, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java?view=diff&rev=567244&r1=567243&r2=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java Sat Aug 18 01:25:16 2007
@@ -56,7 +56,7 @@
 
     protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
         Object bean = getBean(remaining);
-        BeanProcessor processor = new BeanProcessor(bean, getParameterMappingStrategy());
+        BeanProcessor processor = new BeanProcessor(bean, getCamelContext(), getParameterMappingStrategy());
         IntrospectionSupport.setProperties(processor, parameters);
         return new ProcessorEndpoint(uri, this, processor);
     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?view=diff&rev=567244&r1=567243&r2=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Sat Aug 18 01:25:16 2007
@@ -16,16 +16,6 @@
  */
 package org.apache.camel.component.bean;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
 import org.apache.camel.Body;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
@@ -33,11 +23,23 @@
 import org.apache.camel.Message;
 import org.apache.camel.Property;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.CamelContext;
 import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.language.LanguageAnnotation;
+import static org.apache.camel.util.ExchangeHelper.convertToType;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import static org.apache.camel.util.ExchangeHelper.convertToType;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Represents the metadata about a bean type created via a combination of
@@ -47,13 +49,15 @@
  */
 public class BeanInfo {
     private static final transient Log LOG = LogFactory.getLog(BeanInfo.class);
+    private final CamelContext camelContext;
     private Class type;
     private ParameterMappingStrategy strategy;
     private Map<String, MethodInfo> operations = new ConcurrentHashMap<String, MethodInfo>();
     private MethodInfo defaultMethod;
     private List<MethodInfo> operationsWithBody = new ArrayList<MethodInfo>();
 
-    public BeanInfo(Class type, ParameterMappingStrategy strategy) {
+    public BeanInfo(CamelContext camelContext, Class type, ParameterMappingStrategy strategy) {
+        this.camelContext = camelContext;
         this.type = type;
         this.strategy = strategy;
         introspect(getType());
@@ -273,7 +277,23 @@
              * (XPath) annotation; return new
              * JAXPStringXPathExpression(xpathAnnotation.xpath()); }
              */
+        } else {
+            LanguageAnnotation languageAnnotation = annotation.annotationType().getAnnotation(LanguageAnnotation.class);
+            if (languageAnnotation != null) {
+                Class<?> type = languageAnnotation.factory();
+                Object object = camelContext.getInjector().newInstance(type);
+                if (object instanceof InjectionExpressionFactory) {
+                    InjectionExpressionFactory expressionFactory = (InjectionExpressionFactory) object;
+                    return expressionFactory.createExpression(camelContext, annotation, languageAnnotation, parameterType);
+                }
+                else {
+                    LOG.error("Ignoring bad annotation: " + languageAnnotation + "on method: " + method
+                            + " which declares a factory: " + type.getName()
+                            + " which does not implement " + InjectionExpressionFactory.class.getName());
+                }
+            }
         }
+
         return null;
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?view=diff&rev=567244&r1=567243&r2=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java Sat Aug 18 01:25:16 2007
@@ -49,12 +49,12 @@
         this.beanInfo = beanInfo;
     }
 
-    public BeanProcessor(Object pojo, ParameterMappingStrategy parameterMappingStrategy) {
-        this(pojo, new BeanInfo(pojo.getClass(), parameterMappingStrategy));
+    public BeanProcessor(Object pojo, CamelContext camelContext, ParameterMappingStrategy parameterMappingStrategy) {
+        this(pojo, new BeanInfo(camelContext, pojo.getClass(), parameterMappingStrategy));
     }
 
     public BeanProcessor(Object pojo, CamelContext camelContext) {
-        this(pojo, createParameterMappingStrategy(camelContext));
+        this(pojo, camelContext, createParameterMappingStrategy(camelContext));
     }
 
     public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultInjectionExpressionFactory.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultInjectionExpressionFactory.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultInjectionExpressionFactory.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultInjectionExpressionFactory.java Sat Aug 18 01:25:16 2007
@@ -0,0 +1,60 @@
+/**
+ *
+ * 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.component.bean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Expression;
+import org.apache.camel.language.LanguageAnnotation;
+import org.apache.camel.spi.Language;
+import org.apache.camel.util.ObjectHelper;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DefaultInjectionExpressionFactory implements InjectionExpressionFactory {
+    public Expression createExpression(CamelContext camelContext, Annotation annotation, LanguageAnnotation languageAnnotation, Class expressionReturnType) {
+        String languageName = languageAnnotation.language();
+        if (languageName == null) {
+            throw new IllegalArgumentException("Cannot determine the language from the annotation: " + annotation);
+        }
+        Language language = camelContext.resolveLanguage(languageName);
+        if (language == null) {
+            throw new IllegalArgumentException("Cannot find the language: " + languageName + " on the classpath");
+        }
+        String expression = getExpressionFromAnnotation(annotation);
+        return language.createExpression(expression);
+    }
+
+    protected String getExpressionFromAnnotation(Annotation annotation) {
+        // lets try the 'value()' method
+        try {
+            Method method = annotation.getClass().getMethod("value");
+            Object value = ObjectHelper.invokeMethod(method, annotation);
+            if (value == null) {
+                throw new IllegalArgumentException("Cannot determine the expression from the annotation: " + annotation);
+            }
+            return value.toString();
+        }
+        catch (NoSuchMethodException e) {
+            throw new IllegalArgumentException("Cannot determine the expression of the annotation: " + annotation + " as it does not have an value() method");
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultInjectionExpressionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/InjectionExpressionFactory.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/InjectionExpressionFactory.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/InjectionExpressionFactory.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/InjectionExpressionFactory.java Sat Aug 18 01:25:16 2007
@@ -0,0 +1,35 @@
+/**
+ *
+ * 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.component.bean;
+
+import org.apache.camel.Expression;
+import org.apache.camel.CamelContext;
+import org.apache.camel.language.LanguageAnnotation;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * A factory which creates an {@link Expression} object from an annotation on a field, property or method parameter
+ * of a specified type.
+ *
+ * @version $Revision: 1.1 $
+ */
+public interface InjectionExpressionFactory {
+
+    Expression createExpression(CamelContext camelContext, Annotation annotation, LanguageAnnotation languageAnnotation, Class expressionReturnType);
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/InjectionExpressionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageAnnotation.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageAnnotation.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageAnnotation.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageAnnotation.java Sat Aug 18 01:25:16 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * 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;
+
+import org.apache.camel.component.bean.DefaultInjectionExpressionFactory;
+import org.apache.camel.component.bean.InjectionExpressionFactory;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.ANNOTATION_TYPE })
+public @interface LanguageAnnotation {
+    public abstract String language();
+    public abstract Class<?> factory() default DefaultInjectionExpressionFactory.class;
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageAnnotation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageExpression.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageExpression.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageExpression.java Sat Aug 18 01:25:16 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
+public @interface LanguageExpression {
+    String language();
+    String expression();
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/LanguageExpression.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/NamespacePrefix.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/NamespacePrefix.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/NamespacePrefix.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/NamespacePrefix.java Sat Aug 18 01:25:16 2007
@@ -0,0 +1,35 @@
+/**
+ *
+ * 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;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * Creates a namespace prefix for an XPath
+ * 
+ * @version $Revision: 1.1 $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.ANNOTATION_TYPE })
+public @interface NamespacePrefix {
+    public abstract String prefix();
+    public abstract String uri();
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/NamespacePrefix.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/Simple.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/Simple.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/Simple.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/Simple.java Sat Aug 18 01:25:16 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
+@LanguageAnnotation(language = "simple")
+public @interface Simple {
+    public String value();
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/Simple.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java?view=auto&rev=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java Sat Aug 18 01:25:16 2007
@@ -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.language;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+public @interface XPath {
+    public String value();
+
+    public NamespacePrefix[] namespaces() default {@NamespacePrefix(prefix = "soap", uri = "TODO")};
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExpressionInjectionTest.java (from r567097, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExpressionInjectionTest.java?view=diff&rev=567244&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java&r1=567097&p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExpressionInjectionTest.java&r2=567244
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExpressionInjectionTest.java Sat Aug 18 01:25:16 2007
@@ -17,52 +17,28 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.bean.BeanProcessor;
+import org.apache.camel.language.Simple;
 import org.apache.camel.util.jndi.JndiContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.naming.Context;
-import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class BeanRouteTest extends ContextTestSupport {
+public class BeanWithExpressionInjectionTest extends ContextTestSupport {
     private static final transient Log LOG = LogFactory.getLog(BeanRouteTest.class);
     protected MyBean myBean = new MyBean();
 
-    public void testSendingMessageWithMethodNameHeader() throws Exception {
+    public void testSendMessage() throws Exception {
         String expectedBody = "Wobble";
 
-        template.sendBodyAndHeader("direct:in", expectedBody, BeanProcessor.METHOD_NAME, "read");
+        template.sendBodyAndHeader("direct:in", expectedBody, "foo", "bar");
 
-        assertEquals("bean received correct value for: " + myBean, expectedBody, myBean.body);
-    }
-
-    public void testSendingMessageWithMethodNameHeaderWithMoreVerboseCoe() throws Exception {
-        final String expectedBody = "Wibble";
-
-        template.send("direct:in", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody(expectedBody);
-                in.setHeader(BeanProcessor.METHOD_NAME, "read");
-            }
-        });
-        assertEquals("bean received correct value", expectedBody, myBean.body);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        Object lookedUpBean = context.getRegistry().lookup("myBean");
-        assertSame("Lookup of 'myBean' should return same object!", myBean, lookedUpBean);
+        assertEquals("bean body: " + myBean, expectedBody, myBean.body);
+        assertEquals("bean foo: " + myBean, "bar", myBean.foo);
     }
 
     @Override
@@ -75,32 +51,24 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("direct:in").beanRef("myBean").to("seda:out");
+                from("direct:in").beanRef("myBean");
             }
         };
     }
 
     public static class MyBean {
         public String body;
-        private static AtomicInteger counter = new AtomicInteger(0);
-        private int id;
-
-        public MyBean() {
-            id = counter.incrementAndGet();
-        }
+        public String foo;
 
         @Override
         public String toString() {
-            return "MyBean:" + id;
+            return "MyBean[foo: " + foo + " body: " + body + "]";
         }
 
-        public void read(String body) {
+        public void read(String body, @Simple("header.foo") String foo) {
+            this.foo = foo;
             this.body = body;
-            LOG.info("read() method on " + this + " with body: " + body);
-        }
-
-        public void wrongMethod(String body) {
-            fail("wrongMethod() called with: " + body);
+            LOG.info("read() method called on " + this);
         }
     }
 }