Coverage Report - org.mule.routing.nested.NestedRouter
 
Classes in this File Line Coverage Branch Coverage Complexity
NestedRouter
0%
0/30
N/A
1.273
 
 1  
 /*
 2  
  * $Id: NestedRouter.java 7963 2007-08-21 08:53:15Z 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.routing.nested;
 12  
 
 13  
 import org.mule.management.stats.RouterStatistics;
 14  
 import org.mule.routing.AbstractRouter;
 15  
 import org.mule.routing.outbound.OutboundPassThroughRouter;
 16  
 import org.mule.umo.MessagingException;
 17  
 import org.mule.umo.UMOEvent;
 18  
 import org.mule.umo.UMOMessage;
 19  
 import org.mule.umo.endpoint.UMOEndpoint;
 20  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 21  
 import org.mule.umo.routing.UMONestedRouter;
 22  
 import org.mule.umo.routing.UMOOutboundRouter;
 23  
 
 24  
 import java.lang.reflect.Proxy;
 25  
 
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 public class NestedRouter extends AbstractRouter implements UMONestedRouter
 30  
 {
 31  
 
 32  0
     protected static Log logger = LogFactory.getLog(NestedRouter.class);
 33  
 
 34  
     private Class interfaceClass;
 35  
 
 36  
     private String methodName;
 37  
 
 38  
     private UMOEndpoint endpoint;
 39  
 
 40  
     //The router ued to actually ispatch the message
 41  
     protected UMOOutboundRouter outboundRouter;
 42  
 
 43  
     public NestedRouter()
 44  0
     {
 45  0
         setRouterStatistics(new RouterStatistics(RouterStatistics.TYPE_NESTED));
 46  0
     }
 47  
 
 48  
     public UMOMessage route(final UMOEvent event) throws MessagingException
 49  
     {
 50  0
         final UMOImmutableEndpoint endpoint = event.getEndpoint();
 51  
 
 52  0
         return outboundRouter.route(event.getMessage(), event.getSession(), endpoint.isSynchronous());
 53  
     }
 54  
 
 55  
 
 56  
     public void setInterface(Class interfaceClass)
 57  
     {
 58  0
         this.interfaceClass = interfaceClass;
 59  0
     }
 60  
 
 61  
     public Class getInterface()
 62  
     {
 63  0
         return interfaceClass;
 64  
     }
 65  
 
 66  
 
 67  
     public String getMethod()
 68  
     {
 69  0
         return methodName;
 70  
     }
 71  
 
 72  
     public void setMethod(String methodName)
 73  
     {
 74  0
         this.methodName = methodName;
 75  0
     }
 76  
 
 77  
     /* (non-Javadoc)
 78  
      * @see org.mule.umo.routing.UMONestedRouter#createProxy(java.lang.Object, UMODescriptor descriptor java.lang.Class)
 79  
      */
 80  
     public Object createProxy(Object target)
 81  
     {
 82  
         try
 83  
         {
 84  0
             Object proxy = Proxy.newProxyInstance(getInterface().getClassLoader(),
 85  
                     new Class[]{getInterface()}, new NestedInvocationHandler(this));
 86  0
             return proxy;
 87  
 
 88  
         }
 89  0
         catch (Exception e)
 90  
         {
 91  0
             logger.error(e);
 92  0
             throw new RuntimeException(e);
 93  
         }
 94  
     }
 95  
 
 96  
     public UMOEndpoint getEndpoint()
 97  
     {
 98  0
         return endpoint;
 99  
     }
 100  
 
 101  
     public void setEndpoint(UMOEndpoint e)
 102  
     {
 103  0
         endpoint = e;
 104  
         //TODO RM** endpoint.setType(UMOEndpoint.ENDPOINT_TYPE_SENDER_AND_RECEIVER);
 105  0
         outboundRouter = new OutboundPassThroughRouter();
 106  0
         outboundRouter.addEndpoint(endpoint);
 107  0
         outboundRouter.setTransactionConfig(endpoint.getTransactionConfig());
 108  0
     }
 109  
 
 110  
 
 111  
     public Class getInterfaceClass()
 112  
     {
 113  0
         return interfaceClass;
 114  
     }
 115  
 
 116  
 
 117  
     public String toString()
 118  
     {
 119  0
         final StringBuffer sb = new StringBuffer();
 120  0
         sb.append("NestedRouter");
 121  0
         sb.append("{method='").append(methodName).append('\'');
 122  0
         sb.append(", interface=").append(interfaceClass);
 123  0
         sb.append('}');
 124  0
         return sb.toString();
 125  
     }
 126  
 }