1 10 11 package org.mule.config.builders; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.MuleManager; 16 import org.mule.config.i18n.Message; 17 import org.mule.config.i18n.Messages; 18 import org.mule.impl.endpoint.MuleEndpoint; 19 import org.mule.impl.endpoint.MuleEndpointURI; 20 import org.mule.umo.UMOFilter; 21 import org.mule.umo.UMOTransactionConfig; 22 import org.mule.umo.endpoint.UMOEndpoint; 23 import org.mule.umo.lifecycle.InitialisationException; 24 import org.mule.umo.transformer.UMOTransformer; 25 import org.mule.util.MuleObjectHelper; 26 27 import java.lang.reflect.Method ; 28 import java.util.Map ; 29 30 38 public class EndpointReference 39 { 40 43 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 { 64 this.propertyName = propertyName; 65 this.endpointName = endpointName; 66 this.address = address; 67 this.transformer = transformer; 68 this.responseTransformer = responseTransformer; 69 this.object = object; 70 this.createConnector = createConnector; 71 } 72 73 public String getPropertyName() 74 { 75 return propertyName; 76 } 77 78 public String getEndpointName() 79 { 80 return endpointName; 81 } 82 83 public Object getObject() 84 { 85 return object; 86 } 87 88 public UMOTransactionConfig getTransactionConfig() 89 { 90 return transactionConfig; 91 } 92 93 public void setTransactionConfig(UMOTransactionConfig transactionConfig) 94 { 95 this.transactionConfig = transactionConfig; 96 } 97 98 public UMOFilter getFilter() 99 { 100 return filter; 101 } 102 103 public void setFilter(UMOFilter filter) 104 { 105 this.filter = filter; 106 } 107 108 public Map getProperties() 109 { 110 return properties; 111 } 112 113 public void setProperties(Map properties) 114 { 115 this.properties = properties; 116 } 117 118 public String getCreateConnector() 119 { 120 return createConnector; 121 } 122 123 public void setCreateConnector(String createConnector) 124 { 125 this.createConnector = createConnector; 126 } 127 128 public void resolveEndpoint() throws InitialisationException 129 { 130 try 131 { 132 MuleEndpoint ep = (MuleEndpoint)MuleManager.getInstance().lookupEndpoint(endpointName); 133 if (ep == null) 134 { 135 throw new InitialisationException(new Message(Messages.X_NOT_REGISTERED_WITH_MANAGER, 136 "Endpoint '" + endpointName + "'"), this); 137 } 138 if (address != null) 139 { 140 if (logger.isDebugEnabled()) 141 { 142 logger.debug("Overloading endpoint uri for: " + endpointName + " from " 143 + ep.getEndpointURI().toString() + " to " + address); 144 } 145 ep.setEndpointURI(new MuleEndpointURI(address)); 146 } 147 if (createConnector != null) 148 { 149 if (logger.isDebugEnabled()) 150 { 151 logger.debug("Overloading createConnector property for endpoint: " + endpointName 152 + " from " + ep.getCreateConnector() + " to " + createConnector); 153 } 154 ep.setCreateConnectorAsString(createConnector); 155 } 156 if (transformer != null) 157 { 158 if (logger.isDebugEnabled()) 159 { 160 logger.debug("Overloading Transformer for: " + endpointName + " from " 161 + ep.getTransformer() + " to " + transformer); 162 } 163 UMOTransformer trans = MuleObjectHelper.getTransformer(transformer, " "); 164 ep.setTransformer(trans); 165 } 166 167 if (responseTransformer != null) 168 { 169 if (logger.isDebugEnabled()) 170 { 171 logger.debug("Overloading responseTransformer for: " + endpointName + " from " 172 + ep.getResponseTransformer() + " to " + responseTransformer); 173 } 174 UMOTransformer trans = MuleObjectHelper.getTransformer(responseTransformer, " "); 175 ep.setResponseTransformer(trans); 176 } 177 178 if (filter != null) 179 { 180 ep.setFilter(filter); 181 } 182 if (properties != null) 183 { 184 ep.getProperties().putAll(properties); 185 } 186 if (transactionConfig != null) 187 { 188 ep.setTransactionConfig(transactionConfig); 189 } 190 191 ep.initialise(); 192 Method m = object.getClass().getMethod(propertyName, new Class []{UMOEndpoint.class}); 193 if (m == null) 194 { 195 throw new InitialisationException(new Message(Messages.METHOD_X_WITH_PARAMS_X_NOT_FOUND_ON_X, 196 propertyName, UMOEndpoint.class.getName(), object.getClass().getName()), this); 197 } 198 199 m.invoke(object, new Object []{ep}); 200 } 201 catch (InitialisationException e) 202 { 203 throw e; 204 } 205 catch (Exception e) 206 { 207 throw new InitialisationException(new Message(Messages.CANT_SET_PROP_X_ON_X_OF_TYPE_X, 208 propertyName, object.getClass().getName(), UMOEndpoint.class.getName()), e, this); 209 } 210 } 211 212 public String toString() 213 { 214 return "EndpointReference{" + "propertyName='" + propertyName + "'" + ", endpointName='" 215 + endpointName + "'" + ", address='" + address + "'" + ", transformer='" + transformer + "'" 216 + ", responseTransformer='" + responseTransformer + "'" + ", object=" + object 217 + ", properties=" + properties + ", filter=" + filter + ", transactionConfig=" 218 + transactionConfig + "}"; 219 } 220 } 221 | Popular Tags |