KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jms.jca;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.log.Log;
34 import com.caucho.util.L10N;
35
36 import javax.resource.ResourceException JavaDoc;
37 import javax.resource.spi.ConnectionManager JavaDoc;
38 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
39 import javax.resource.spi.ManagedConnection JavaDoc;
40 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
41 import javax.resource.spi.ResourceAdapter JavaDoc;
42 import javax.security.auth.Subject JavaDoc;
43 import java.io.PrintWriter JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.Set JavaDoc;
46 import java.util.logging.Logger JavaDoc;
47
48 /**
49  * The managed factory implementation.
50  */

51 public class MessageSenderManager implements ManagedConnectionFactory JavaDoc {
52   protected static final Logger JavaDoc log = Log.open(MessageSenderManager.class);
53   private static final L10N L = new L10N(MessageSenderManager.class);
54
55   private ResourceAdapterImpl _ra;
56
57   public MessageSenderManager()
58   {
59   }
60
61   public ResourceAdapter JavaDoc getResourceAdapter()
62   {
63     return _ra;
64   }
65
66   public void setResourceAdapter(ResourceAdapter JavaDoc adapter)
67     throws ResourceException JavaDoc
68   {
69     if (! (adapter instanceof ResourceAdapterImpl))
70       throw new ResourceException JavaDoc(L.l("'{0}' is not a valid resource-adapter for MessageSenderManager.",
71                       adapter.getClass().getName()));
72
73     _ra = (ResourceAdapterImpl) adapter;
74   }
75
76   public void init()
77     throws ConfigException
78   {
79     if (_ra == null)
80       throw new ConfigException(L.l("MessageSenderManager must be configured with a resource adapter"));
81   }
82   
83   /**
84    * Creates the data source the user sees.
85    */

86   public Object JavaDoc createConnectionFactory(ConnectionManager JavaDoc connManager)
87     throws ResourceException JavaDoc
88   {
89     return new MessageSenderImpl(this, connManager);
90   }
91
92   /**
93    * Creates the data source the user sees. Not needed in this case,
94    * since ManagedFactoryImpl is only allowed in Resin.
95    */

96   public Object JavaDoc createConnectionFactory()
97     throws ResourceException JavaDoc
98   {
99     throw new UnsupportedOperationException JavaDoc();
100   }
101
102   /**
103    * Creates the underlying managed connection.
104    */

105   public ManagedConnection JavaDoc
106     createManagedConnection(Subject JavaDoc subject,
107                 ConnectionRequestInfo JavaDoc requestInfo)
108     throws ResourceException JavaDoc
109   {
110     ResourceAdapterImpl ra = _ra;
111     
112     return new ManagedSessionImpl(ra.getConnectionFactory(),
113                   ra.getDestination());
114   }
115
116   /**
117    * Creates the underlying managed connection.
118    */

119   public ManagedConnection JavaDoc
120     matchManagedConnections(Set JavaDoc connSet,
121                 Subject JavaDoc subject,
122                 ConnectionRequestInfo JavaDoc requestInfo)
123     throws ResourceException JavaDoc
124   {
125     Iterator JavaDoc<ManagedSessionImpl> iter = (Iterator JavaDoc<ManagedSessionImpl>) connSet.iterator();
126
127     if (iter.hasNext()) {
128       ManagedSessionImpl mConn;
129       mConn = (ManagedSessionImpl) iter.next();
130
131       return mConn;
132     }
133     
134     return null;
135   }
136
137   /**
138    * Returns the dummy log writer.
139    */

140   public PrintWriter JavaDoc getLogWriter()
141   {
142     return null;
143   }
144
145   /**
146    * Sets the dummy log writer.
147    */

148   public void setLogWriter(PrintWriter JavaDoc log)
149   {
150   }
151 }
152
153
Popular Tags