Coverage Report - org.mule.config.builders.EndpointReference
 
Classes in this File Line Coverage Branch Coverage Complexity
EndpointReference
0%
0/63
0%
0/32
2.357
 
 1  
 /*
 2  
  * $Id: EndpointReference.java 9539 2007-11-01 14:07:28Z akuzmin $
 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.config.builders;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.config.i18n.CoreMessages;
 15  
 import org.mule.impl.endpoint.MuleEndpoint;
 16  
 import org.mule.impl.endpoint.MuleEndpointURI;
 17  
 import org.mule.umo.UMOFilter;
 18  
 import org.mule.umo.UMOTransactionConfig;
 19  
 import org.mule.umo.endpoint.UMOEndpoint;
 20  
 import org.mule.umo.lifecycle.InitialisationException;
 21  
 import org.mule.umo.transformer.UMOTransformer;
 22  
 import org.mule.util.MuleObjectHelper;
 23  
 
 24  
 import java.lang.reflect.Method;
 25  
 import java.util.Map;
 26  
 
 27  
 import org.apache.commons.logging.Log;
 28  
 import org.apache.commons.logging.LogFactory;
 29  
 
 30  
 /**
 31  
  * <code>EndpointReference</code> maintains a endpoint reference. Endpoints are
 32  
  * cloned when they are looked up for the manager, if there are container properties
 33  
  * or transformers set on the Endpoint the clone will have an inconsistent state if
 34  
  * the transformers or container properties have not been resolved. This class holds
 35  
  * the refernece and is invoked after the container properties/transformers are
 36  
  * resolved.
 37  
  */
 38  
 public class EndpointReference
 39  
 {
 40  
     /**
 41  
      * logger used by this class
 42  
      */
 43  0
     protected static final Log logger = LogFactory.getLog(EndpointReference.class);
 44  
 
 45  
     private String propertyName;
 46  
     private String endpointName;
 47  
     private String address;
 48  
     private String transformer;
 49  
     private String responseTransformer;
 50  
     private String createConnector;
 51  
     private Object object;
 52  
     private Map properties;
 53  
     private UMOFilter filter;
 54  
     private UMOTransactionConfig transactionConfig;
 55  
 
 56  
     public EndpointReference(String propertyName,
 57  
                              String endpointName,
 58  
                              String address,
 59  
                              String transformer,
 60  
                              String responseTransformer,
 61  
                              String createConnector,
 62  
                              Object object)
 63  0
     {
 64  0
         this.propertyName = propertyName;
 65  0
         this.endpointName = endpointName;
 66  0
         this.address = address;
 67  0
         this.transformer = transformer;
 68  0
         this.responseTransformer = responseTransformer;
 69  0
         this.object = object;
 70  0
         this.createConnector = createConnector;
 71  0
     }
 72  
 
 73  
     public String getPropertyName()
 74  
     {
 75  0
         return propertyName;
 76  
     }
 77  
 
 78  
     public String getEndpointName()
 79  
     {
 80  0
         return endpointName;
 81  
     }
 82  
 
 83  
     public Object getObject()
 84  
     {
 85  0
         return object;
 86  
     }
 87  
 
 88  
     public UMOTransactionConfig getTransactionConfig()
 89  
     {
 90  0
         return transactionConfig;
 91  
     }
 92  
 
 93  
     public void setTransactionConfig(UMOTransactionConfig transactionConfig)
 94  
     {
 95  0
         this.transactionConfig = transactionConfig;
 96  0
     }
 97  
 
 98  
     public UMOFilter getFilter()
 99  
     {
 100  0
         return filter;
 101  
     }
 102  
 
 103  
     public void setFilter(UMOFilter filter)
 104  
     {
 105  0
         this.filter = filter;
 106  0
     }
 107  
 
 108  
     public Map getProperties()
 109  
     {
 110  0
         return properties;
 111  
     }
 112  
 
 113  
     public void setProperties(Map properties)
 114  
     {
 115  0
         this.properties = properties;
 116  0
     }
 117  
 
 118  
     public String getCreateConnector()
 119  
     {
 120  0
         return createConnector;
 121  
     }
 122  
 
 123  
     public void setCreateConnector(String createConnector)
 124  
     {
 125  0
         this.createConnector = createConnector;
 126  0
     }
 127  
 
 128  
     public void resolveEndpoint() throws InitialisationException
 129  
     {
 130  
         try
 131  
         {
 132  0
             MuleEndpoint ep = (MuleEndpoint) MuleManager.getInstance().lookupEndpoint(endpointName);
 133  0
             if (ep == null)
 134  
             {
 135  0
                 throw new InitialisationException(
 136  
                     CoreMessages.objectNotRegisteredWithManager("Endpoint '" + endpointName + "'"), this);
 137  
             }
 138  0
             if (address != null)
 139  
             {
 140  0
                 if (logger.isDebugEnabled())
 141  
                 {
 142  0
                     logger.debug("Overloading endpoint uri for: " + endpointName + " from "
 143  
                                  + ep.getEndpointURI().toString() + " to " + address);
 144  
                 }
 145  0
                 ep.setEndpointURI(new MuleEndpointURI(address));
 146  
             }
 147  0
             if (createConnector != null)
 148  
             {
 149  0
                 if (logger.isDebugEnabled())
 150  
                 {
 151  0
                     logger.debug("Overloading createConnector property for endpoint: " + endpointName
 152  
                                  + " from " + ep.getCreateConnector() + " to " + createConnector);
 153  
                 }
 154  0
                 ep.setCreateConnectorAsString(createConnector);
 155  
             }
 156  0
             if (transformer != null)
 157  
             {
 158  0
                 if (logger.isDebugEnabled())
 159  
                 {
 160  0
                     logger.debug("Overloading Transformer for: " + endpointName + " from "
 161  
                                  + ep.getTransformer() + " to " + transformer);
 162  
                 }
 163  0
                 UMOTransformer trans = MuleObjectHelper.getTransformer(transformer, " ");
 164  0
                 ep.setTransformer(trans);
 165  
             }
 166  
 
 167  0
             if (responseTransformer != null)
 168  
             {
 169  0
                 if (logger.isDebugEnabled())
 170  
                 {
 171  0
                     logger.debug("Overloading responseTransformer for: " + endpointName + " from "
 172  
                                  + ep.getResponseTransformer() + " to " + responseTransformer);
 173  
                 }
 174  0
                 UMOTransformer trans = MuleObjectHelper.getTransformer(responseTransformer, " ");
 175  0
                 ep.setResponseTransformer(trans);
 176  
             }
 177  
 
 178  0
             if (filter != null)
 179  
             {
 180  0
                 ep.setFilter(filter);
 181  
             }
 182  0
             if (properties != null)
 183  
             {
 184  0
                 ep.getProperties().putAll(properties);
 185  
             }
 186  0
             if (transactionConfig != null)
 187  
             {
 188  0
                 ep.setTransactionConfig(transactionConfig);
 189  
             }
 190  
 
 191  0
             Method m = object.getClass().getMethod(propertyName, new Class[]{UMOEndpoint.class});
 192  0
             if (m == null)
 193  
             {
 194  0
                 throw new InitialisationException(
 195  
                     CoreMessages.methodWithParamsNotFoundOnObject(propertyName, 
 196  
                         UMOEndpoint.class, object.getClass()), this);
 197  
             }
 198  
 
 199  0
             m.invoke(object, new Object[]{ep});
 200  
         }
 201  0
         catch (InitialisationException e)
 202  
         {
 203  0
             throw e;
 204  
         }
 205  0
         catch (Exception e)
 206  
         {
 207  0
             throw new InitialisationException(
 208  
                 CoreMessages.cannotSetPropertyOnObjectWithParamType(propertyName, 
 209  
                     object.getClass(), UMOEndpoint.class), e, this);
 210  0
         }
 211  0
     }
 212  
 
 213  
     public String toString()
 214  
     {
 215  0
         return "EndpointReference{" + "propertyName='" + propertyName + "'" + ", endpointName='"
 216  
                + endpointName + "'" + ", address='" + address + "'" + ", transformer='" + transformer + "'"
 217  
                + ",  responseTransformer='" + responseTransformer + "'" + ", object=" + object
 218  
                + ", properties=" + properties + ", filter=" + filter + ", transactionConfig="
 219  
                + transactionConfig + "}";
 220  
     }
 221  
 }