KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jms > jca > ResourceAdapterImpl


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.jms.jca;
30
31 import com.caucho.config.ConfigException;
32 import com.caucho.log.Log;
33 import com.caucho.util.L10N;
34
35 import javax.jms.ConnectionFactory JavaDoc;
36 import javax.jms.Destination JavaDoc;
37 import javax.resource.NotSupportedException JavaDoc;
38 import javax.resource.ResourceException JavaDoc;
39 import javax.resource.spi.ActivationSpec JavaDoc;
40 import javax.resource.spi.BootstrapContext JavaDoc;
41 import javax.resource.spi.ResourceAdapter JavaDoc;
42 import javax.resource.spi.ResourceAdapterInternalException JavaDoc;
43 import javax.resource.spi.endpoint.MessageEndpointFactory JavaDoc;
44 import javax.resource.spi.work.WorkManager JavaDoc;
45 import javax.transaction.xa.XAResource JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.logging.Logger JavaDoc;
48
49 /**
50  * The JCA resource adapter.
51  */

52 public class ResourceAdapterImpl implements ResourceAdapter JavaDoc {
53   private static final Logger JavaDoc log = Log.open(ResourceAdapterImpl.class);
54   private static final L10N L = new L10N(ResourceAdapterImpl.class);
55
56   private BootstrapContext JavaDoc _ctx;
57   
58   private ConnectionFactory JavaDoc _connectionFactory;
59   private Destination JavaDoc _destination;
60
61   private ArrayList JavaDoc<MessageListenerSpec> _listeners =
62     new ArrayList JavaDoc<MessageListenerSpec>();
63
64   /**
65    * Sets the connection factory.
66    */

67   public void setConnectionFactory(ConnectionFactory JavaDoc factory)
68   {
69     _connectionFactory = factory;
70   }
71
72   /**
73    * Gets the connection factory.
74    */

75   public ConnectionFactory JavaDoc getConnectionFactory()
76   {
77     return _connectionFactory;
78   }
79
80   /**
81    * Sets the destination
82    */

83   public void setDestination(Destination JavaDoc destination)
84   {
85     _destination = destination;
86   }
87
88   /**
89    * Gets the destination
90    */

91   public Destination JavaDoc getDestination()
92   {
93     return _destination;
94   }
95
96   /**
97    * Initialization.
98    */

99   public void init()
100     throws ConfigException
101   {
102     if (_connectionFactory == null)
103       throw new ConfigException(L.l("connection-factory is not configured. The JMS resource adapter needs a connection factory."));
104     
105     if (_destination == null)
106       throw new ConfigException(L.l("destination is not configured. The JMS resource adapter needs a destination."));
107   }
108   
109   /**
110    * Called when the resource adapter is started.
111    */

112   public void start(BootstrapContext JavaDoc ctx)
113     throws ResourceAdapterInternalException JavaDoc
114   {
115     _ctx = ctx;
116   }
117   
118   /**
119    * Called when the resource adapter is stopped.
120    */

121   public void stop()
122     throws ResourceAdapterInternalException JavaDoc
123   {
124     _ctx = null;
125   }
126
127   /**
128    * Returns the work manager.
129    */

130   WorkManager JavaDoc getWorkManager()
131   {
132     return _ctx.getWorkManager();
133   }
134
135   /**
136    * Called during activation of a message endpoint.
137    */

138   public void endpointActivation(MessageEndpointFactory JavaDoc endpointFactory,
139                  ActivationSpec JavaDoc spec)
140     throws NotSupportedException JavaDoc
141   {
142     MessageListenerSpec listener = (MessageListenerSpec) spec;
143     listener.setEndpointFactory(endpointFactory);
144
145     try {
146       listener.start();
147     } catch (ResourceException JavaDoc e) {
148       throw new NotSupportedException JavaDoc(e);
149     }
150   }
151   
152   /**
153    * Called during deactivation of a message endpoint.
154    */

155   public void endpointDeactivation(MessageEndpointFactory JavaDoc endpointFactory,
156                    ActivationSpec JavaDoc spec)
157   {
158   }
159   
160   /**
161    * Called during crash recovery.
162    */

163   public XAResource JavaDoc []getXAResources(ActivationSpec JavaDoc []specs)
164     throws ResourceException JavaDoc
165   {
166     return null;
167   }
168 }
169
170
Popular Tags