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