Coverage Report - org.mule.routing.nested.DefaultNestedRouter
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultNestedRouter
0%
0/30
0%
0/4
1.455
 
 1  
 /*
 2  
  * $Id: DefaultNestedRouter.java 12269 2008-07-10 04:19:03Z dfeist $
 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.api.MessagingException;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.api.MuleRuntimeException;
 16  
 import org.mule.api.MuleSession;
 17  
 import org.mule.api.endpoint.OutboundEndpoint;
 18  
 import org.mule.api.routing.NestedRouter;
 19  
 import org.mule.api.routing.OutboundRouter;
 20  
 import org.mule.config.i18n.CoreMessages;
 21  
 import org.mule.management.stats.RouterStatistics;
 22  
 import org.mule.routing.AbstractRouter;
 23  
 import org.mule.routing.outbound.OutboundPassThroughRouter;
 24  
 
 25  
 import java.lang.reflect.Proxy;
 26  
 
 27  
 import org.apache.commons.logging.Log;
 28  
 import org.apache.commons.logging.LogFactory;
 29  
 
 30  
 public class DefaultNestedRouter extends AbstractRouter implements NestedRouter
 31  
 {
 32  
 
 33  0
     private static final Log logger = LogFactory.getLog(DefaultNestedRouter.class);
 34  
 
 35  
     private Class interfaceClass;
 36  
 
 37  
     private String methodName;
 38  
 
 39  
     // The router used to actually dispatch the message
 40  
     protected OutboundRouter outboundRouter;
 41  
 
 42  
     public DefaultNestedRouter()
 43  0
     {
 44  0
         setRouterStatistics(new RouterStatistics(RouterStatistics.TYPE_NESTED));
 45  0
     }
 46  
 
 47  
     public MuleMessage route(MuleMessage message, MuleSession session, boolean synchronous) throws MessagingException
 48  
     {
 49  0
         return outboundRouter.route(message, session, synchronous);
 50  
     }
 51  
 
 52  
     public void setInterface(Class interfaceClass)
 53  
     {
 54  0
         this.interfaceClass = interfaceClass;
 55  0
     }
 56  
 
 57  
     public Class getInterface()
 58  
     {
 59  0
         return interfaceClass;
 60  
     }
 61  
 
 62  
     public String getMethod()
 63  
     {
 64  0
         return methodName;
 65  
     }
 66  
 
 67  
     public void setMethod(String methodName)
 68  
     {
 69  0
         this.methodName = methodName;
 70  0
     }
 71  
 
 72  
     /*
 73  
      * (non-Javadoc)
 74  
      * 
 75  
      * @see org.mule.api.routing.NestedRouter#createProxy(java.lang.Object,
 76  
      *      UMODescriptor descriptor java.lang.Class)
 77  
      */
 78  
     public Object createProxy(Object target)
 79  
     {
 80  
         try
 81  
         {
 82  0
             Object proxy = Proxy.newProxyInstance(getInterface().getClassLoader(), new Class[]{getInterface()},
 83  
                 new NestedInvocationHandler(this));
 84  0
             logger.debug("Have proxy?: " + (null != proxy));
 85  0
             return proxy;
 86  
 
 87  
         }
 88  0
         catch (Exception e)
 89  
         {
 90  0
             throw new MuleRuntimeException(CoreMessages.failedToCreateProxyFor(target), e);
 91  
         }
 92  
     }
 93  
 
 94  
     public void setEndpoint(OutboundEndpoint e)
 95  
     {
 96  0
         outboundRouter = new OutboundPassThroughRouter();
 97  0
         outboundRouter.addEndpoint(e);
 98  0
         outboundRouter.setTransactionConfig(e.getTransactionConfig());
 99  0
     }
 100  
 
 101  
     public Class getInterfaceClass()
 102  
     {
 103  0
         return interfaceClass;
 104  
     }
 105  
 
 106  
     public String toString()
 107  
     {
 108  0
         final StringBuffer sb = new StringBuffer();
 109  0
         sb.append("DefaultNestedRouter");
 110  0
         sb.append("{method='").append(methodName).append('\'');
 111  0
         sb.append(", interface=").append(interfaceClass);
 112  0
         sb.append('}');
 113  0
         return sb.toString();
 114  
     }
 115  
 
 116  
     public OutboundEndpoint getEndpoint()
 117  
     {
 118  0
         if (outboundRouter != null)
 119  
         {
 120  0
             return (OutboundEndpoint) outboundRouter.getEndpoints().get(0);
 121  
         }
 122  
         else
 123  
         {
 124  0
             return null;
 125  
         }
 126  
     }
 127  
 }