KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > ra > MuleActivationSpec


1 /*
2  * $Id: MuleActivationSpec.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.ra;
12
13 import java.io.Serializable JavaDoc;
14 import java.util.Properties JavaDoc;
15
16 import javax.resource.ResourceException JavaDoc;
17 import javax.resource.spi.ActivationSpec JavaDoc;
18 import javax.resource.spi.InvalidPropertyException JavaDoc;
19 import javax.resource.spi.ResourceAdapter JavaDoc;
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 /**
27  * <code>MuleActivationSpec</code> defines the contract between a Message Driven
28  * Bean (MDB) and the Mule Resource Adapter. This spec holds the configuration values
29  * used to register inbound communication with the Resource Adapter
30  */

31 public class MuleActivationSpec implements ActivationSpec JavaDoc, Serializable JavaDoc
32 {
33     /**
34      * Serial version
35      */

36     private static final long serialVersionUID = 735353511874563914L;
37
38     private Properties JavaDoc propertiesMap;
39     private String JavaDoc endpointName;
40     private String JavaDoc connectorName;
41     private int createConnector;
42     private MuleResourceAdapter resourceAdapter;
43     private String JavaDoc endpoint;
44     private UMOEndpointURI endpointURI;
45
46     public Properties JavaDoc getPropertiesMap()
47     {
48         return propertiesMap;
49     }
50
51     public void setPropertiesMap(Properties JavaDoc propertiesMap)
52     {
53         this.propertiesMap = propertiesMap;
54     }
55
56     public void setPropertiesMap(String JavaDoc properties)
57     {
58         String JavaDoc[] pairs = StringUtils.splitAndTrim(properties, ",");
59         Properties JavaDoc props = new Properties JavaDoc();
60
61         for (int i = 0; i < pairs.length; i++)
62         {
63             String JavaDoc 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 JavaDoc getEndpointName()
79     {
80         return endpointName;
81     }
82
83     public void setEndpointName(String JavaDoc endpointName)
84     {
85         this.endpointName = endpointName;
86     }
87
88     public String JavaDoc getConnectorName()
89     {
90         return connectorName;
91     }
92
93     public void setConnectorName(String JavaDoc 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 JavaDoc getEndpoint()
109     {
110         return endpoint;
111     }
112
113     public void setEndpoint(String JavaDoc endpoint)
114     {
115         this.endpoint = endpoint;
116
117     }
118
119     public void validate() throws InvalidPropertyException JavaDoc
120     {
121         try
122         {
123             this.endpointURI = new MuleEndpointURI(endpoint);
124         }
125         catch (MalformedEndpointException e)
126         {
127             throw new InvalidPropertyException JavaDoc(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 JavaDoc("endpoint is null");
141         }
142
143         if (endpointURI == null)
144         {
145             throw new InvalidPropertyException JavaDoc("endpointURI is null");
146         }
147     }
148
149     public ResourceAdapter JavaDoc getResourceAdapter()
150     {
151         return resourceAdapter;
152     }
153
154     public void setResourceAdapter(ResourceAdapter JavaDoc resourceAdapter) throws ResourceException JavaDoc
155     {
156         // spec section 5.3.3
157
if (this.resourceAdapter != null)
158         {
159             throw new ResourceException JavaDoc("ResourceAdapter already set");
160         }
161         if (!(resourceAdapter instanceof MuleResourceAdapter))
162         {
163             throw new ResourceException JavaDoc("ResourceAdapter is not of type: "
164                                         + MuleResourceAdapter.class.getName());
165         }
166         this.resourceAdapter = (MuleResourceAdapter)resourceAdapter;
167     }
168 }
169
Popular Tags