1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.jca; |
12 | |
|
13 | |
import org.mule.api.endpoint.EndpointException; |
14 | |
import org.mule.api.endpoint.EndpointURI; |
15 | |
import org.mule.endpoint.MuleEndpointURI; |
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 EndpointURI endpointURI; |
45 | |
private String modelName; |
46 | |
|
47 | |
public Properties getPropertiesMap() |
48 | |
{ |
49 | 0 | return propertiesMap; |
50 | |
} |
51 | |
|
52 | |
public void setPropertiesMap(Properties propertiesMap) |
53 | |
{ |
54 | 0 | this.propertiesMap = propertiesMap; |
55 | 0 | } |
56 | |
|
57 | |
public void setPropertiesMap(String properties) |
58 | |
{ |
59 | 0 | String[] pairs = StringUtils.splitAndTrim(properties, ","); |
60 | 0 | Properties props = new Properties(); |
61 | |
|
62 | 0 | for (int i = 0; i < pairs.length; i++) |
63 | |
{ |
64 | 0 | String pair = pairs[i]; |
65 | 0 | int x = pair.indexOf('='); |
66 | 0 | if (x == -1) |
67 | |
{ |
68 | 0 | props.setProperty(pair, null); |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | 0 | props.setProperty(pair.substring(0, x), pair.substring(x + 1)); |
73 | |
} |
74 | |
} |
75 | |
|
76 | 0 | this.setPropertiesMap(props); |
77 | 0 | } |
78 | |
|
79 | |
public String getEndpointName() |
80 | |
{ |
81 | 0 | return endpointName; |
82 | |
} |
83 | |
|
84 | |
public void setEndpointName(String endpointName) |
85 | |
{ |
86 | 0 | this.endpointName = endpointName; |
87 | 0 | } |
88 | |
|
89 | |
public String getConnectorName() |
90 | |
{ |
91 | 0 | return connectorName; |
92 | |
} |
93 | |
|
94 | |
public void setConnectorName(String connectorName) |
95 | |
{ |
96 | 0 | this.connectorName = connectorName; |
97 | 0 | } |
98 | |
|
99 | |
public int getCreateConnector() |
100 | |
{ |
101 | 0 | return createConnector; |
102 | |
} |
103 | |
|
104 | |
public void setCreateConnector(int createConnector) |
105 | |
{ |
106 | 0 | this.createConnector = createConnector; |
107 | 0 | } |
108 | |
|
109 | |
public String getEndpoint() |
110 | |
{ |
111 | 0 | return endpoint; |
112 | |
} |
113 | |
|
114 | |
public void setEndpoint(String endpoint) |
115 | |
{ |
116 | 0 | this.endpoint = endpoint; |
117 | |
|
118 | 0 | } |
119 | |
|
120 | |
public void validate() throws InvalidPropertyException |
121 | |
{ |
122 | |
try |
123 | |
{ |
124 | 0 | this.endpointURI = new MuleEndpointURI(endpoint, resourceAdapter.muleContext); |
125 | |
} |
126 | 0 | catch (EndpointException e) |
127 | |
{ |
128 | 0 | throw new InvalidPropertyException(e); |
129 | 0 | } |
130 | |
|
131 | 0 | if (propertiesMap != null) |
132 | |
{ |
133 | 0 | propertiesMap.putAll(this.endpointURI.getParams()); |
134 | |
} |
135 | |
else |
136 | |
{ |
137 | 0 | propertiesMap = this.endpointURI.getParams(); |
138 | |
} |
139 | 0 | if (endpoint == null) |
140 | |
{ |
141 | 0 | throw new InvalidPropertyException("endpoint is null"); |
142 | |
} |
143 | |
|
144 | 0 | if (endpointURI == null) |
145 | |
{ |
146 | 0 | throw new InvalidPropertyException("endpointURI is null"); |
147 | |
} |
148 | 0 | } |
149 | |
|
150 | |
public ResourceAdapter getResourceAdapter() |
151 | |
{ |
152 | 0 | return resourceAdapter; |
153 | |
} |
154 | |
|
155 | |
public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException |
156 | |
{ |
157 | |
|
158 | 0 | if (this.resourceAdapter != null) |
159 | |
{ |
160 | 0 | throw new ResourceException("ResourceAdapter already set"); |
161 | |
} |
162 | 0 | if (!(resourceAdapter instanceof MuleResourceAdapter)) |
163 | |
{ |
164 | 0 | throw new ResourceException("ResourceAdapter is not of type: " |
165 | |
+ MuleResourceAdapter.class.getName()); |
166 | |
} |
167 | 0 | this.resourceAdapter = (MuleResourceAdapter)resourceAdapter; |
168 | 0 | } |
169 | |
|
170 | |
public String getModelName() { |
171 | 0 | return modelName; |
172 | |
} |
173 | |
|
174 | |
public void setModelName(String modelName) { |
175 | 0 | this.modelName = modelName; |
176 | 0 | } |
177 | |
} |