Coverage Report - org.mule.extras.spring.remoting.SpringRemoteInvokerComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringRemoteInvokerComponent
0%
0/42
0%
0/5
1.733
SpringRemoteInvokerComponent$1
N/A
N/A
1.733
SpringRemoteInvokerComponent$Delegate
0%
0/8
N/A
1.733
 
 1  
 /*
 2  
  * $Id: SpringRemoteInvokerComponent.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.extras.spring.remoting;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.umo.UMOEventContext;
 15  
 import org.mule.umo.lifecycle.Callable;
 16  
 import org.mule.umo.lifecycle.Initialisable;
 17  
 import org.mule.umo.lifecycle.InitialisationException;
 18  
 import org.mule.util.ClassUtils;
 19  
 
 20  
 import org.springframework.beans.factory.InitializingBean;
 21  
 import org.springframework.remoting.support.RemoteInvocation;
 22  
 import org.springframework.remoting.support.RemoteInvocationBasedExporter;
 23  
 import org.springframework.remoting.support.RemoteInvocationExecutor;
 24  
 import org.springframework.remoting.support.RemoteInvocationResult;
 25  
 
 26  
 public class SpringRemoteInvokerComponent implements Initialisable, Callable
 27  
 {
 28  
     private Delegate delegate;
 29  
     private Class serviceClass;
 30  
     private Class serviceInterface;
 31  
     private Object serviceBean;
 32  0
     private boolean registerTraceInterceptor = false;
 33  
     private RemoteInvocationExecutor remoteInvocationExecutor;
 34  
 
 35  0
     private class Delegate extends RemoteInvocationBasedExporter implements InitializingBean
 36  
     {
 37  
         private Object proxy;
 38  
 
 39  
         public void afterPropertiesSet()
 40  
         {
 41  0
             this.proxy = getProxyForService();
 42  0
         }
 43  
 
 44  
         public Object execute(RemoteInvocation invocation)
 45  
         {
 46  
             try
 47  
             {
 48  0
                 Object value = invoke(invocation, proxy);
 49  0
                 return value;
 50  
             }
 51  0
             catch (Throwable ex)
 52  
             {
 53  0
                 ex.printStackTrace();
 54  0
                 return new RemoteInvocationResult(ex);
 55  
             }
 56  
         }
 57  
     }
 58  
 
 59  
     public SpringRemoteInvokerComponent()
 60  0
     {
 61  0
         delegate = new Delegate();
 62  0
     }
 63  
 
 64  
     public void initialise() throws InitialisationException {
 65  0
         if (serviceClass == null && serviceBean == null)
 66  
         {
 67  0
             throw new InitialisationException(
 68  
                 CoreMessages.propertiesNotSet("serviceClass or serviceBean"), this);
 69  
         }
 70  0
         if (serviceInterface == null)
 71  
         {
 72  0
             throw new InitialisationException(
 73  
                 CoreMessages.propertiesNotSet("serviceInterface"), this);
 74  
         }
 75  
 
 76  0
         if (serviceClass != null)
 77  
         {
 78  0
             Object service = null;
 79  
             try
 80  
             {
 81  0
                 service = ClassUtils.instanciateClass(serviceClass, null);
 82  
             }
 83  0
             catch (Exception e)
 84  
             {
 85  0
                 throw new InitialisationException(e, this);
 86  0
             }
 87  0
             delegate.setService(service);
 88  
         }
 89  0
         else if (serviceBean != null)
 90  
         {
 91  0
             delegate.setService(serviceBean);
 92  
         }
 93  0
         delegate.setServiceInterface(serviceInterface);
 94  0
         delegate.setRegisterTraceInterceptor(registerTraceInterceptor);
 95  0
         if (remoteInvocationExecutor != null)
 96  
         {
 97  0
             delegate.setRemoteInvocationExecutor(remoteInvocationExecutor);
 98  
         }
 99  0
         delegate.afterPropertiesSet();
 100  0
     }
 101  
 
 102  
     public Class getServiceClass()
 103  
     {
 104  0
         return serviceClass;
 105  
     }
 106  
 
 107  
     public void setServiceClass(Class serviceClass)
 108  
     {
 109  0
         this.serviceClass = serviceClass;
 110  0
     }
 111  
 
 112  
     public Object getServiceBean()
 113  
     {
 114  0
         return serviceBean;
 115  
     }
 116  
 
 117  
     public void setServiceBean(Object serviceBean)
 118  
     {
 119  0
         this.serviceBean = serviceBean;
 120  0
     }
 121  
 
 122  
     public Class getServiceInterface()
 123  
     {
 124  0
         return serviceInterface;
 125  
     }
 126  
 
 127  
     public void setServiceInterface(Class serviceInterface)
 128  
     {
 129  0
         this.serviceInterface = serviceInterface;
 130  0
     }
 131  
 
 132  
     public boolean isRegisterTraceInterceptor()
 133  
     {
 134  0
         return registerTraceInterceptor;
 135  
     }
 136  
 
 137  
     public void setRegisterTraceInterceptor(boolean registerTraceInterceptor)
 138  
     {
 139  0
         this.registerTraceInterceptor = registerTraceInterceptor;
 140  0
     }
 141  
 
 142  
     public RemoteInvocationExecutor getRemoteInvocationExecutor()
 143  
     {
 144  0
         return remoteInvocationExecutor;
 145  
     }
 146  
 
 147  
     public void setRemoteInvocationExecutor(RemoteInvocationExecutor remoteInvocationExecutor)
 148  
     {
 149  0
         this.remoteInvocationExecutor = remoteInvocationExecutor;
 150  0
     }
 151  
 
 152  
     public Object onCall(UMOEventContext eventContext) throws Exception
 153  
     {
 154  0
         Object transformedMessage = eventContext.getTransformedMessage();
 155  0
         RemoteInvocation ri = (RemoteInvocation)transformedMessage;
 156  0
         Object rval = delegate.execute(ri);
 157  0
         return rval;
 158  
     }
 159  
 }