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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jms.jca;
030:
031: import com.caucho.config.ConfigException;
032: import com.caucho.log.Log;
033: import com.caucho.util.L10N;
034:
035: import javax.jms.ConnectionFactory;
036: import javax.jms.Destination;
037: import javax.resource.NotSupportedException;
038: import javax.resource.ResourceException;
039: import javax.resource.spi.ActivationSpec;
040: import javax.resource.spi.BootstrapContext;
041: import javax.resource.spi.ResourceAdapter;
042: import javax.resource.spi.ResourceAdapterInternalException;
043: import javax.resource.spi.endpoint.MessageEndpointFactory;
044: import javax.resource.spi.work.WorkManager;
045: import javax.transaction.xa.XAResource;
046: import java.util.ArrayList;
047: import java.util.logging.Logger;
048:
049: /**
050: * The JCA resource adapter.
051: */
052: public class ResourceAdapterImpl implements ResourceAdapter {
053: private static final Logger log = Log
054: .open(ResourceAdapterImpl.class);
055: private static final L10N L = new L10N(ResourceAdapterImpl.class);
056:
057: private BootstrapContext _ctx;
058:
059: private ConnectionFactory _connectionFactory;
060: private Destination _destination;
061:
062: private ArrayList<MessageListenerSpec> _listeners = new ArrayList<MessageListenerSpec>();
063:
064: /**
065: * Sets the connection factory.
066: */
067: public void setConnectionFactory(ConnectionFactory factory) {
068: _connectionFactory = factory;
069: }
070:
071: /**
072: * Gets the connection factory.
073: */
074: public ConnectionFactory getConnectionFactory() {
075: return _connectionFactory;
076: }
077:
078: /**
079: * Sets the destination
080: */
081: public void setDestination(Destination destination) {
082: _destination = destination;
083: }
084:
085: /**
086: * Gets the destination
087: */
088: public Destination getDestination() {
089: return _destination;
090: }
091:
092: /**
093: * Initialization.
094: */
095: public void init() throws ConfigException {
096: if (_connectionFactory == null)
097: throw new ConfigException(
098: L
099: .l("connection-factory is not configured. The JMS resource adapter needs a connection factory."));
100:
101: if (_destination == null)
102: throw new ConfigException(
103: L
104: .l("destination is not configured. The JMS resource adapter needs a destination."));
105: }
106:
107: /**
108: * Called when the resource adapter is started.
109: */
110: public void start(BootstrapContext ctx)
111: throws ResourceAdapterInternalException {
112: _ctx = ctx;
113: }
114:
115: /**
116: * Called when the resource adapter is stopped.
117: */
118: public void stop() throws ResourceAdapterInternalException {
119: _ctx = null;
120: }
121:
122: /**
123: * Returns the work manager.
124: */
125: WorkManager getWorkManager() {
126: return _ctx.getWorkManager();
127: }
128:
129: /**
130: * Called during activation of a message endpoint.
131: */
132: public void endpointActivation(
133: MessageEndpointFactory endpointFactory, ActivationSpec spec)
134: throws NotSupportedException {
135: MessageListenerSpec listener = (MessageListenerSpec) spec;
136: listener.setEndpointFactory(endpointFactory);
137:
138: try {
139: listener.start();
140: } catch (ResourceException e) {
141: throw new NotSupportedException(e);
142: }
143: }
144:
145: /**
146: * Called during deactivation of a message endpoint.
147: */
148: public void endpointDeactivation(
149: MessageEndpointFactory endpointFactory, ActivationSpec spec) {
150: }
151:
152: /**
153: * Called during crash recovery.
154: */
155: public XAResource[] getXAResources(ActivationSpec[] specs)
156: throws ResourceException {
157: return null;
158: }
159: }
|