KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jca > cfg > ResourceAdapterConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jca.cfg;
30
31 import com.caucho.config.ConfigException;
32 import com.caucho.log.Log;
33 import com.caucho.util.L10N;
34
35 import java.util.ArrayList JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37
38 /**
39  * Configuration for a connector.
40  */

41 public class ResourceAdapterConfig extends ObjectConfig {
42   private static final L10N L = new L10N(ResourceAdapterConfig.class);
43   private static final Logger JavaDoc log = Log.open(ResourceAdapterConfig.class);
44
45   private Class JavaDoc _adapterClass;
46
47   private ArrayList JavaDoc<ConnectionDefinition> _outboundConnections =
48     new ArrayList JavaDoc<ConnectionDefinition>();
49
50   private ArrayList JavaDoc<MessageListenerConfig> _inboundConnections =
51     new ArrayList JavaDoc<MessageListenerConfig>();
52
53   private ArrayList JavaDoc<AdminObjectConfig> _resources =
54     new ArrayList JavaDoc<AdminObjectConfig>();
55
56   private ConnectionDefinition _connectionDefinition;
57
58   private String JavaDoc _transactionSupport;
59   
60   public ResourceAdapterConfig()
61   {
62   }
63
64   /**
65    * Sets the resource adapter class
66    */

67   public void setResourceadapterClass(Class JavaDoc cl)
68     throws ConfigException
69   {
70     _adapterClass = cl;
71
72     setType(cl);
73   }
74
75   /**
76    * Gets the resource adapter class
77    */

78   public Class JavaDoc getResourceadapterClass()
79   {
80     return _adapterClass;
81   }
82
83   /**
84    * Adds an admin object.
85    */

86   public void addAdminobject(AdminObjectConfig adminObject)
87   {
88     _resources.add(adminObject);
89   }
90
91   /**
92    * Sets the ManagedConnectionFactory class.
93    */

94   public void setManagedconnectionfactoryClass(Class JavaDoc cl)
95     throws ConfigException
96   {
97     getConnectionDefinition().setManagedconnectionfactoryClass(cl);
98   }
99
100   /**
101    * Sets the ConnectionFactory interface
102    */

103   public void setConnectionfactoryInterface(String JavaDoc cl)
104   {
105   }
106
107   /**
108    * Sets the ConnectionFactory impl class
109    */

110   public void setConnectionfactoryImplClass(String JavaDoc cl)
111   {
112   }
113
114   /**
115    * Sets the Connection interface
116    */

117   public void setConnectionInterface(String JavaDoc cl)
118   {
119   }
120
121   /**
122    * Sets the Connection impl class
123    */

124   public void setConnectionImplClass(String JavaDoc cl)
125   {
126   }
127
128   /**
129    * Returns the top connection definition (for backward compatibility).
130    */

131   private ConnectionDefinition getConnectionDefinition()
132     throws ConfigException
133   {
134     if (_connectionDefinition == null) {
135       _connectionDefinition = new ConnectionDefinition();
136       _outboundConnections.add(_connectionDefinition);
137     }
138
139     return _connectionDefinition;
140   }
141
142   /**
143    * Adds a new connection definitin.
144    */

145   void addConnectionDefinition(ConnectionDefinition conn)
146     throws ConfigException
147   {
148     if (getConnectionDefinition(conn.getConnectionFactoryInterface().getName()) != null)
149       throw new ConfigException(L.l("'{0}' is a duplicate connection-definition. The <connectionfactory-interface> must be unique.",
150                     conn.getConnectionFactoryInterface().getName()));
151     
152     _outboundConnections.add(conn);
153   }
154
155   /**
156    * Gets the connection definition for the named class.
157    */

158   public ConnectionDefinition getConnectionDefinition(String JavaDoc type)
159   {
160     if (type == null && _outboundConnections.size() == 1)
161       return _outboundConnections.get(0);
162     else if (type == null)
163       return null;
164     
165     for (int i = 0; i < _outboundConnections.size(); i++) {
166       ConnectionDefinition cfg = _outboundConnections.get(i);
167
168       Class JavaDoc cl = cfg.getConnectionFactoryInterface();
169       
170       if (cl != null && cl.getName().equals(type))
171     return cfg;
172     }
173
174     return null;
175   }
176
177   /**
178    * Adds a new connection definitin.
179    */

180   void addMessageListener(MessageListenerConfig cfg)
181     throws ConfigException
182   {
183     if (getMessageListener(cfg.getMessageListenerType().getName()) != null)
184       throw new ConfigException(L.l("'{0}' is a duplicate messagelistener-type. The <messagelistener-type> must be unique.",
185                     cfg.getMessageListenerType().getName()));
186     
187     _inboundConnections.add(cfg);
188   }
189
190   /**
191    * Gets the resource adapter class
192    */

193   public MessageListenerConfig getMessageListener(String JavaDoc type)
194   {
195     if (type == null && _inboundConnections.size() == 1)
196       return _inboundConnections.get(0);
197     else if (type == null)
198       return null;
199     
200     for (int i = 0; i < _inboundConnections.size(); i++) {
201       MessageListenerConfig cfg = _inboundConnections.get(i);
202
203       Class JavaDoc cl = cfg.getMessageListenerType();
204
205       if (cl != null && cl.getName().equals(type))
206     return cfg;
207     }
208
209     return null;
210   }
211
212   /**
213    * Adds a new resource
214    */

215   void addResource(AdminObjectConfig cfg)
216   {
217     _resources.add(cfg);
218   }
219
220   /**
221    * Gets the resource adapter class
222    */

223   public AdminObjectConfig getAdminObject(String JavaDoc type)
224   {
225     for (int i = 0; i < _resources.size(); i++) {
226       AdminObjectConfig cfg = _resources.get(i);
227
228       Class JavaDoc cl = cfg.getAdminObjectClass();
229
230       if (cl != null && cl.getName().equals(type))
231     return cfg;
232
233       cl = cfg.getAdminObjectInterface();
234       
235       if (cl != null && cl.getName().equals(type))
236     return cfg;
237     }
238
239     return null;
240   }
241
242   /**
243    * Sets the transaction support.
244    */

245   public void setTransactionSupport(String JavaDoc xa)
246   {
247     _transactionSupport = xa;
248   }
249
250   /**
251    * Gets the transaction support.
252    */

253   public String JavaDoc getTransactionSupport()
254   {
255     return _transactionSupport;
256   }
257
258   /**
259    * Sets the reauthentication support.
260    */

261   public void setReauthenticationSupport(boolean support)
262   {
263   }
264
265   /**
266    * Creates an authentication mechanism
267    */

268   public AuthenticationMechanism createAuthenticationMechanism()
269   {
270     return new AuthenticationMechanism();
271   }
272
273   /**
274    * Creates a security permission
275    */

276   public SecurityPermission createSecurityPermission()
277   {
278     return new SecurityPermission();
279   }
280
281   /**
282    * Adds an outbound resource adapter.
283    */

284   public OutboundResourceAdapterConfig createOutboundResourceadapter()
285     throws ConfigException
286   {
287     return new OutboundResourceAdapterConfig(this);
288   }
289
290   /**
291    * Adds an inbound resource adapter.
292    */

293   public InboundResourceAdapterConfig createInboundResourceadapter()
294     throws ConfigException
295   {
296     return new InboundResourceAdapterConfig(this);
297   }
298
299   public static class AuthenticationMechanism {
300     public void setDescription(String JavaDoc description)
301     {
302     }
303     
304     public void setAuthenticationMechanismType(String JavaDoc type)
305     {
306     }
307     
308     public void setCredentialInterface(String JavaDoc type)
309     {
310     }
311   }
312
313   public static class SecurityPermission {
314     public void setDescription(String JavaDoc description)
315     {
316     }
317
318     public void setSecurityPermissionSpec(String JavaDoc spec)
319     {
320     }
321   }
322 }
323
Popular Tags