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