001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jms.jca;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.log.Log;
034: import com.caucho.util.L10N;
035:
036: import javax.resource.ResourceException;
037: import javax.resource.spi.ConnectionManager;
038: import javax.resource.spi.ConnectionRequestInfo;
039: import javax.resource.spi.ManagedConnection;
040: import javax.resource.spi.ManagedConnectionFactory;
041: import javax.resource.spi.ResourceAdapter;
042: import javax.security.auth.Subject;
043: import java.io.PrintWriter;
044: import java.util.Iterator;
045: import java.util.Set;
046: import java.util.logging.Logger;
047:
048: /**
049: * The managed factory implementation.
050: */
051: public class MessageSenderManager implements ManagedConnectionFactory {
052: protected static final Logger log = Log
053: .open(MessageSenderManager.class);
054: private static final L10N L = new L10N(MessageSenderManager.class);
055:
056: private ResourceAdapterImpl _ra;
057:
058: public MessageSenderManager() {
059: }
060:
061: public ResourceAdapter getResourceAdapter() {
062: return _ra;
063: }
064:
065: public void setResourceAdapter(ResourceAdapter adapter)
066: throws ResourceException {
067: if (!(adapter instanceof ResourceAdapterImpl))
068: throw new ResourceException(
069: L
070: .l(
071: "'{0}' is not a valid resource-adapter for MessageSenderManager.",
072: adapter.getClass().getName()));
073:
074: _ra = (ResourceAdapterImpl) adapter;
075: }
076:
077: public void init() throws ConfigException {
078: if (_ra == null)
079: throw new ConfigException(
080: L
081: .l("MessageSenderManager must be configured with a resource adapter"));
082: }
083:
084: /**
085: * Creates the data source the user sees.
086: */
087: public Object createConnectionFactory(ConnectionManager connManager)
088: throws ResourceException {
089: return new MessageSenderImpl(this , connManager);
090: }
091:
092: /**
093: * Creates the data source the user sees. Not needed in this case,
094: * since ManagedFactoryImpl is only allowed in Resin.
095: */
096: public Object createConnectionFactory() throws ResourceException {
097: throw new UnsupportedOperationException();
098: }
099:
100: /**
101: * Creates the underlying managed connection.
102: */
103: public ManagedConnection createManagedConnection(Subject subject,
104: ConnectionRequestInfo requestInfo) throws ResourceException {
105: ResourceAdapterImpl ra = _ra;
106:
107: return new ManagedSessionImpl(ra.getConnectionFactory(), ra
108: .getDestination());
109: }
110:
111: /**
112: * Creates the underlying managed connection.
113: */
114: public ManagedConnection matchManagedConnections(Set connSet,
115: Subject subject, ConnectionRequestInfo requestInfo)
116: throws ResourceException {
117: Iterator<ManagedSessionImpl> iter = (Iterator<ManagedSessionImpl>) connSet
118: .iterator();
119:
120: if (iter.hasNext()) {
121: ManagedSessionImpl mConn;
122: mConn = (ManagedSessionImpl) iter.next();
123:
124: return mConn;
125: }
126:
127: return null;
128: }
129:
130: /**
131: * Returns the dummy log writer.
132: */
133: public PrintWriter getLogWriter() {
134: return null;
135: }
136:
137: /**
138: * Sets the dummy log writer.
139: */
140: public void setLogWriter(PrintWriter log) {
141: }
142: }
|