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  
  * $Id: IBeansEndpointURIBuilder.java 19026 2010-08-16 07:30:47Z dirk.olmes $
 3  
  * -------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  
 package org.mule.transport.ibean;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.endpoint.EndpointURI;
 14  
 import org.mule.api.endpoint.MalformedEndpointException;
 15  
 import org.mule.endpoint.ResourceNameEndpointURIBuilder;
 16  
 import org.mule.module.ibeans.config.IBeanHolder;
 17  
 import org.mule.module.ibeans.i18n.IBeansMessages;
 18  
 
 19  
 import java.lang.reflect.Method;
 20  
 import java.net.URI;
 21  
 import java.util.Properties;
 22  
 
 23  
 import org.ibeans.annotation.Call;
 24  
 import org.ibeans.annotation.Template;
 25  
 
 26  
 /**
 27  
  * A Resource name endpoint builder that will check the validity of an iBean endpoint by looking up the
 28  
  * 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)
 29  
  */
 30  0
 public class IBeansEndpointURIBuilder extends ResourceNameEndpointURIBuilder
 31  
 {
 32  
     private MuleContext muleContext;
 33  
 
 34  
     @Override
 35  
     protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
 36  
     {
 37  0
         super.setEndpoint(uri, props);
 38  
         //Validate the iBean name and method
 39  0
         int i = address.indexOf(".");
 40  0
         if(i ==-1)
 41  
         {
 42  0
             throw new MalformedEndpointException(uri.toString());
 43  
         }
 44  
 
 45  0
         String ibean = address.substring(0, i);
 46  0
         String method = address. substring(i+1);
 47  0
         IBeanHolder holder = muleContext.getRegistry().lookupObject(ibean);
 48  0
         if(holder == null)
 49  
         {
 50  0
             throw new MalformedEndpointException(IBeansMessages.ibeanNotRegistered(ibean), uri.toString());
 51  
         }
 52  0
         boolean match = false;
 53  0
         Method[] methods = holder.getIbeanClass().getMethods();
 54  0
         for (int j = 0; j < methods.length; j++)
 55  
         {
 56  0
             Method m = methods[j];
 57  0
             if(m.getName().equals(method))
 58  
             {
 59  0
                 if(m.isAnnotationPresent(Call.class) || m.isAnnotationPresent(Template.class))
 60  
                 {
 61  0
                     match = true;
 62  0
                     break;
 63  
                 }
 64  
                 else
 65  
                 {
 66  0
                     throw new MalformedEndpointException(IBeansMessages.ibeanMethodFoundButNotValid(ibean, method), uri.toString());
 67  
                 }
 68  
             }
 69  
         }
 70  0
         if(!match)
 71  
         {
 72  0
             throw new MalformedEndpointException(IBeansMessages.ibeanMethodNotFound(ibean, method), uri.toString());
 73  
         }
 74  0
     }
 75  
 
 76  
     @Override
 77  
     public EndpointURI build(URI uri, MuleContext muleContext) throws MalformedEndpointException
 78  
     {
 79  0
         this.muleContext = muleContext;
 80  0
         return super.build(uri, muleContext);
 81  
     }
 82  
 }