1 17 18 package org.apache.geronimo.connector; 19 20 import javax.resource.ResourceException ; 21 import javax.resource.spi.ActivationSpec ; 22 import javax.resource.spi.ResourceAdapter ; 23 import javax.resource.spi.endpoint.MessageEndpointFactory ; 24 import javax.transaction.SystemException ; 25 import javax.transaction.xa.XAResource ; 26 27 import org.apache.geronimo.transaction.manager.NamedXAResource; 28 import org.apache.geronimo.transaction.manager.ResourceManager; 29 import org.apache.geronimo.transaction.manager.WrapperNamedXAResource; 30 31 38 public class ActivationSpecWrapper implements ResourceManager { 39 40 protected final ActivationSpec activationSpec; 41 42 private final ResourceAdapterWrapper resourceAdapterWrapper; 43 private final String containerId; 44 45 48 public ActivationSpecWrapper() { 49 activationSpec = null; 50 containerId = null; 51 resourceAdapterWrapper = null; 52 } 53 54 61 public ActivationSpecWrapper(final String activationSpecClass, 62 final String containerId, 63 final ResourceAdapterWrapper resourceAdapterWrapper, 64 final ClassLoader cl) throws IllegalAccessException , InstantiationException , ClassNotFoundException { 65 Class clazz = cl.loadClass(activationSpecClass); 66 this.activationSpec = (ActivationSpec ) clazz.newInstance(); 67 this.containerId = containerId; 68 this.resourceAdapterWrapper = resourceAdapterWrapper; 69 } 70 71 73 public ActivationSpecWrapper(ActivationSpec activationSpec, ResourceAdapterWrapper resourceAdapterWrapper) { 74 this.activationSpec = activationSpec; 75 this.resourceAdapterWrapper = resourceAdapterWrapper; 76 this.containerId = null; 77 } 78 79 84 88 public String getContainerId() { 89 return containerId; 90 } 91 92 public ResourceAdapterWrapper getResourceAdapterWrapper() { 93 return resourceAdapterWrapper; 94 } 95 96 97 public void activate(final MessageEndpointFactory messageEndpointFactory) throws ResourceException { 99 ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter(); 100 if (resourceAdapter == null) { 101 resourceAdapterWrapper.registerResourceAdapterAssociation(activationSpec); 102 } 103 resourceAdapterWrapper.endpointActivation(messageEndpointFactory, activationSpec); 104 } 105 106 public void deactivate(final MessageEndpointFactory messageEndpointFactory) { 107 ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter(); 108 if (resourceAdapter != null) { 109 resourceAdapterWrapper.endpointDeactivation(messageEndpointFactory, activationSpec); 110 } else { 111 throw new IllegalStateException ("ActivationSpec was never registered with ResourceAdapter"); 113 } 114 } 115 116 public NamedXAResource getRecoveryXAResources() throws SystemException { 118 if (resourceAdapterWrapper == null) { 119 throw new IllegalStateException ("Attempting to use activation spec when it is not activated"); 120 } 121 try { 122 XAResource [] xaResources = resourceAdapterWrapper.getXAResources(new ActivationSpec []{activationSpec}); 123 if (xaResources == null || xaResources.length == 0) { 124 return null; 125 } 126 return new WrapperNamedXAResource(xaResources[0], containerId); 127 } catch (ResourceException e) { 128 throw (SystemException ) new SystemException ("Could not get XAResource for recovery for mdb: " + containerId).initCause(e); 129 } 130 } 131 132 public void returnResource(NamedXAResource xaResource) { 133 } 135 136 } 137 | Popular Tags |