servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r464967 - in /incubator/servicemix/trunk/servicemix-bean/src: main/java/org/apache/servicemix/bean/ main/java/org/apache/servicemix/bean/support/ test/java/org/apache/servicemix/bean/ test/java/org/apache/servicemix/bean/beans/
Date Tue, 17 Oct 2006 17:21:12 GMT
Author: gnodet
Date: Tue Oct 17 10:21:10 2006
New Revision: 464967

URL: http://svn.apache.org/viewvc?view=rev&rev=464967
Log:
Fix servicemix-bean compilation problem
Allow the operation name to be defaulted to the method name when using the Operation annotation

Modified:
    incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
    incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/Operation.java
    incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java
    incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java
    incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/AnnotatedBean.java
    incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ConsumerBean.java

Modified: incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java?view=diff&rev=464967&r1=464966&r2=464967
==============================================================================
--- incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
Tue Oct 17 10:21:10 2006
@@ -64,15 +64,15 @@
  *
  * @version $Revision: $
  * @org.apache.xbean.XBean element="endpoint"
- * 
- * TODO: handle correlations to create / scope beans
  */
 public class BeanEndpoint extends ProviderEndpoint implements BeanFactoryAware {
+
     private BeanFactory beanFactory;
     private String beanName;
     private Object bean;
     private BeanInfo beanInfo;
     private Class<?> beanType;
+    private String beanClassName;
     private MethodInvocationStrategy methodInvocationStrategy;
     private org.apache.servicemix.expression.Expression correlationExpression;
     
@@ -138,6 +138,33 @@
         this.bean = bean;
     }
 
+    /**
+     * @return the beanType
+     */
+    public Class<?> getBeanType() {
+        return beanType;
+    }
+
+    /**
+     * @param beanType the beanType to set
+     */
+    public void setBeanType(Class<?> beanType) {
+        this.beanType = beanType;
+    }
+
+    /**
+     * @return the beanClassName
+     */
+    public String getBeanClassName() {
+        return beanClassName;
+    }
+
+    /**
+     * @param beanClassName the beanClassName to set
+     */
+    public void setBeanClassName(String beanClassName) {
+        this.beanClassName = beanClassName;
+    }
 
     public BeanInfo getBeanInfo() {
         if (beanInfo == null) {
@@ -182,7 +209,7 @@
             if (pojo == null) {
                 pojo = createBean();
                 injectBean(pojo);
-                ReflectionUtils.callLifecycleMethod(bean, PostConstruct.class);
+                ReflectionUtils.callLifecycleMethod(pojo, PostConstruct.class);
             }
             req = new Request(pojo, exchange);
             requests.put(corId, req);
@@ -256,15 +283,26 @@
         return getCorrelationExpression().evaluate(exchange, exchange.getMessage("in"));
     }
 
-    protected Object createBean() {
-        if (beanName == null) {
+    protected Object createBean() throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
+        if (beanName == null && beanType == null) {
             throw new IllegalArgumentException("Property 'beanName' has not been set!");
         }
-        Object answer = beanFactory.getBean(beanName);
-        if (answer == null) {
-            throw new NoSuchBeanException(beanName, this);
+        if (beanType == null && beanClassName != null) {
+            beanType = Class.forName(beanClassName, true, getServiceUnit().getConfigurationClassLoader());
+        }
+        if (beanType != null) {
+            return beanType.newInstance();
+        } else if (beanName == null) {
+            throw new IllegalArgumentException("Property 'beanName', 'beanType' or 'beanClassName'
must be set!");
+        } else if (beanFactory == null) {
+            throw new IllegalArgumentException("Property 'beanName' specified, but no BeanFactory
set!");
+        } else {
+            Object answer = beanFactory.getBean(beanName);
+            if (answer == null) {
+                throw new NoSuchBeanException(beanName, this);
+            }
+            return answer;
         }
-        return answer;
     }
 
     protected MethodInvocationStrategy createMethodInvocationStrategy() {
@@ -309,9 +347,9 @@
                         if (r instanceof Boolean == false) {
                             throw new RuntimeException("Expression did not returned a boolean
value but: " + r);
                         }
-                        boolean oldVal = req.getCallbacks().get(method);
-                        boolean newVal = (Boolean) r;
-                        if (oldVal == false && newVal == true) {
+                        Boolean oldVal = req.getCallbacks().get(method);
+                        Boolean newVal = (Boolean) r;
+                        if ((oldVal == null || oldVal == false) && newVal == true)
{
                             req.getCallbacks().put(method, newVal);
                             Object o = method.invoke(bean, new Object[0]);
                             // TODO: handle return value and sent it as the answer

Modified: incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/Operation.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/Operation.java?view=diff&rev=464967&r1=464966&r2=464967
==============================================================================
--- incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/Operation.java
(original)
+++ incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/Operation.java
Tue Oct 17 10:21:10 2006
@@ -26,16 +26,6 @@
 @Target( { METHOD })
 public @interface Operation {
     
-    enum MEP {
-        InOnly,
-        RobustInOnly,
-        InOut,
-        InOptionalOut,
-        Default,
-    }
-    
     String name() default "";
 
-    MEP mep() default MEP.Default;
-    
 }

Modified: incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java?view=diff&rev=464967&r1=464966&r2=464967
==============================================================================
--- incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java
(original)
+++ incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java
Tue Oct 17 10:21:10 2006
@@ -113,7 +113,10 @@
         // now lets add the method to the repository
         String opName = method.getName();
         if (method.getAnnotation(Operation.class) != null) {
-            opName = method.getAnnotation(Operation.class).name();
+            String name = method.getAnnotation(Operation.class).name();
+            if (name != null && name.length() > 0) {
+                opName = name;
+            }
         }
         Expression parametersExpression = createMethodParametersExpression(parameterExpressions);
         operations.put(opName, new MethodInfo(type, method, parametersExpression));

Modified: incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java?view=diff&rev=464967&r1=464966&r2=464967
==============================================================================
--- incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java
Tue Oct 17 10:21:10 2006
@@ -47,7 +47,7 @@
         BeanEndpoint ep = new BeanEndpoint();
         ep.setService(new QName("bean"));
         ep.setEndpoint("endpoint");
-        ep.setBean(new ConsumerBean());
+        ep.setBeanType(ConsumerBean.class);
         bc.setEndpoints(new BeanEndpoint[] { ep });
         jbi.activateComponent(bc, "servicemix-bean");
         

Modified: incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/AnnotatedBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/AnnotatedBean.java?view=diff&rev=464967&r1=464966&r2=464967
==============================================================================
--- incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/AnnotatedBean.java
(original)
+++ incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/AnnotatedBean.java
Tue Oct 17 10:21:10 2006
@@ -39,7 +39,7 @@
 
         log.info("myExchangeMethod() received exchange: " + messageExchange);
     }
-
+    
     public MessageExchange getMyExchangeMethod() {
         return myExchangeMethod;
     }

Modified: incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ConsumerBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ConsumerBean.java?view=diff&rev=464967&r1=464966&r2=464967
==============================================================================
--- incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ConsumerBean.java
(original)
+++ incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ConsumerBean.java
Tue Oct 17 10:21:10 2006
@@ -74,7 +74,7 @@
     public void destroy() {
     }
     
-    @Operation(name="receive")
+    @Operation
     public void receive(NormalizedMessage message) throws Exception {
         request1 = service1.send(MessageUtil.copy(message));
         request2 = service2.send(MessageUtil.copy(message));



Mime
View raw message