1 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 ; 36 import javax.jms.Destination ; 37 import javax.resource.NotSupportedException ; 38 import javax.resource.ResourceException ; 39 import javax.resource.spi.ActivationSpec ; 40 import javax.resource.spi.BootstrapContext ; 41 import javax.resource.spi.ResourceAdapter ; 42 import javax.resource.spi.ResourceAdapterInternalException ; 43 import javax.resource.spi.endpoint.MessageEndpointFactory ; 44 import javax.resource.spi.work.WorkManager ; 45 import javax.transaction.xa.XAResource ; 46 import java.util.ArrayList ; 47 import java.util.logging.Logger ; 48 49 52 public class ResourceAdapterImpl implements ResourceAdapter { 53 private static final Logger log = Log.open(ResourceAdapterImpl.class); 54 private static final L10N L = new L10N(ResourceAdapterImpl.class); 55 56 private BootstrapContext _ctx; 57 58 private ConnectionFactory _connectionFactory; 59 private Destination _destination; 60 61 private ArrayList <MessageListenerSpec> _listeners = 62 new ArrayList <MessageListenerSpec>(); 63 64 67 public void setConnectionFactory(ConnectionFactory factory) 68 { 69 _connectionFactory = factory; 70 } 71 72 75 public ConnectionFactory getConnectionFactory() 76 { 77 return _connectionFactory; 78 } 79 80 83 public void setDestination(Destination destination) 84 { 85 _destination = destination; 86 } 87 88 91 public Destination getDestination() 92 { 93 return _destination; 94 } 95 96 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 112 public void start(BootstrapContext ctx) 113 throws ResourceAdapterInternalException 114 { 115 _ctx = ctx; 116 } 117 118 121 public void stop() 122 throws ResourceAdapterInternalException 123 { 124 _ctx = null; 125 } 126 127 130 WorkManager getWorkManager() 131 { 132 return _ctx.getWorkManager(); 133 } 134 135 138 public void endpointActivation(MessageEndpointFactory endpointFactory, 139 ActivationSpec spec) 140 throws NotSupportedException 141 { 142 MessageListenerSpec listener = (MessageListenerSpec) spec; 143 listener.setEndpointFactory(endpointFactory); 144 145 try { 146 listener.start(); 147 } catch (ResourceException e) { 148 throw new NotSupportedException (e); 149 } 150 } 151 152 155 public void endpointDeactivation(MessageEndpointFactory endpointFactory, 156 ActivationSpec spec) 157 { 158 } 159 160 163 public XAResource []getXAResources(ActivationSpec []specs) 164 throws ResourceException 165 { 166 return null; 167 } 168 } 169 170 | Popular Tags |