1 10 11 package org.mule.ra; 12 13 import java.io.Serializable ; 14 import java.util.Properties ; 15 16 import javax.resource.ResourceException ; 17 import javax.resource.spi.ActivationSpec ; 18 import javax.resource.spi.InvalidPropertyException ; 19 import javax.resource.spi.ResourceAdapter ; 20 21 import org.mule.impl.endpoint.MuleEndpointURI; 22 import org.mule.umo.endpoint.MalformedEndpointException; 23 import org.mule.umo.endpoint.UMOEndpointURI; 24 import org.mule.util.StringUtils; 25 26 31 public class MuleActivationSpec implements ActivationSpec , Serializable 32 { 33 36 private static final long serialVersionUID = 735353511874563914L; 37 38 private Properties propertiesMap; 39 private String endpointName; 40 private String connectorName; 41 private int createConnector; 42 private MuleResourceAdapter resourceAdapter; 43 private String endpoint; 44 private UMOEndpointURI endpointURI; 45 46 public Properties getPropertiesMap() 47 { 48 return propertiesMap; 49 } 50 51 public void setPropertiesMap(Properties propertiesMap) 52 { 53 this.propertiesMap = propertiesMap; 54 } 55 56 public void setPropertiesMap(String properties) 57 { 58 String [] pairs = StringUtils.splitAndTrim(properties, ","); 59 Properties props = new Properties (); 60 61 for (int i = 0; i < pairs.length; i++) 62 { 63 String pair = pairs[i]; 64 int x = pair.indexOf('='); 65 if (x == -1) 66 { 67 props.setProperty(pair, null); 68 } 69 else 70 { 71 props.setProperty(pair.substring(0, x), pair.substring(x + 1)); 72 } 73 } 74 75 this.setPropertiesMap(props); 76 } 77 78 public String getEndpointName() 79 { 80 return endpointName; 81 } 82 83 public void setEndpointName(String endpointName) 84 { 85 this.endpointName = endpointName; 86 } 87 88 public String getConnectorName() 89 { 90 return connectorName; 91 } 92 93 public void setConnectorName(String connectorName) 94 { 95 this.connectorName = connectorName; 96 } 97 98 public int getCreateConnector() 99 { 100 return createConnector; 101 } 102 103 public void setCreateConnector(int createConnector) 104 { 105 this.createConnector = createConnector; 106 } 107 108 public String getEndpoint() 109 { 110 return endpoint; 111 } 112 113 public void setEndpoint(String endpoint) 114 { 115 this.endpoint = endpoint; 116 117 } 118 119 public void validate() throws InvalidPropertyException 120 { 121 try 122 { 123 this.endpointURI = new MuleEndpointURI(endpoint); 124 } 125 catch (MalformedEndpointException e) 126 { 127 throw new InvalidPropertyException (e); 128 } 129 130 if (propertiesMap != null) 131 { 132 propertiesMap.putAll(this.endpointURI.getParams()); 133 } 134 else 135 { 136 propertiesMap = this.endpointURI.getParams(); 137 } 138 if (endpoint == null) 139 { 140 throw new InvalidPropertyException ("endpoint is null"); 141 } 142 143 if (endpointURI == null) 144 { 145 throw new InvalidPropertyException ("endpointURI is null"); 146 } 147 } 148 149 public ResourceAdapter getResourceAdapter() 150 { 151 return resourceAdapter; 152 } 153 154 public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException 155 { 156 if (this.resourceAdapter != null) 158 { 159 throw new ResourceException ("ResourceAdapter already set"); 160 } 161 if (!(resourceAdapter instanceof MuleResourceAdapter)) 162 { 163 throw new ResourceException ("ResourceAdapter is not of type: " 164 + MuleResourceAdapter.class.getName()); 165 } 166 this.resourceAdapter = (MuleResourceAdapter)resourceAdapter; 167 } 168 } 169 | Popular Tags |