Coverage Report - org.mule.transport.ibean.IBeansEndpointURIBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
IBeansEndpointURIBuilder
0%
0/24
0%
0/14
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.ibean;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.endpoint.EndpointURI;
 11  
 import org.mule.api.endpoint.MalformedEndpointException;
 12  
 import org.mule.endpoint.ResourceNameEndpointURIBuilder;
 13  
 import org.mule.module.ibeans.config.IBeanHolder;
 14  
 import org.mule.module.ibeans.i18n.IBeansMessages;
 15  
 
 16  
 import java.lang.reflect.Method;
 17  
 import java.net.URI;
 18  
 import java.util.Properties;
 19  
 
 20  
 import org.ibeans.annotation.Call;
 21  
 import org.ibeans.annotation.Template;
 22  
 
 23  
 /**
 24  
  * A Resource name endpoint builder that will check the validity of an iBean endpoint by looking up the
 25  
  * iBean and checking the method exists on the iBean and pointing to a valid method (i.e. with a {@link org.ibeans.annotation.Call} or {@link org.ibeans.annotation.Template} annotation)
 26  
  */
 27  0
 public class IBeansEndpointURIBuilder extends ResourceNameEndpointURIBuilder
 28  
 {
 29  
     private MuleContext muleContext;
 30  
 
 31  
     @Override
 32  
     protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
 33  
     {
 34  0
         super.setEndpoint(uri, props);
 35  
         //Validate the iBean name and method
 36  0
         int i = address.indexOf(".");
 37  0
         if(i ==-1)
 38  
         {
 39  0
             throw new MalformedEndpointException(uri.toString());
 40  
         }
 41  
 
 42  0
         String ibean = address.substring(0, i);
 43  0
         String method = address. substring(i+1);
 44  0
         IBeanHolder holder = muleContext.getRegistry().lookupObject(ibean);
 45  0
         if(holder == null)
 46  
         {
 47  0
             throw new MalformedEndpointException(IBeansMessages.ibeanNotRegistered(ibean), uri.toString());
 48  
         }
 49  0
         boolean match = false;
 50  0
         Method[] methods = holder.getIbeanClass().getMethods();
 51  0
         for (int j = 0; j < methods.length; j++)
 52  
         {
 53  0
             Method m = methods[j];
 54  0
             if(m.getName().equals(method))
 55  
             {
 56  0
                 if(m.isAnnotationPresent(Call.class) || m.isAnnotationPresent(Template.class))
 57  
                 {
 58  0
                     match = true;
 59  0
                     break;
 60  
                 }
 61  
                 else
 62  
                 {
 63  0
                     throw new MalformedEndpointException(IBeansMessages.ibeanMethodFoundButNotValid(ibean, method), uri.toString());
 64  
                 }
 65  
             }
 66  
         }
 67  0
         if(!match)
 68  
         {
 69  0
             throw new MalformedEndpointException(IBeansMessages.ibeanMethodNotFound(ibean, method), uri.toString());
 70  
         }
 71  0
     }
 72  
 
 73  
     @Override
 74  
     public EndpointURI build(URI uri, MuleContext muleContext) throws MalformedEndpointException
 75  
     {
 76  0
         this.muleContext = muleContext;
 77  0
         return super.build(uri, muleContext);
 78  
     }
 79  
 }