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.BootstrapContext ; 23 import javax.resource.spi.ResourceAdapter ; 24 import javax.resource.spi.ResourceAdapterAssociation ; 25 import javax.resource.spi.ResourceAdapterInternalException ; 26 import javax.resource.spi.endpoint.MessageEndpointFactory ; 27 import javax.transaction.xa.XAResource ; 28 29 35 public class ResourceAdapterWrapper implements ResourceAdapter { 36 37 private final String resourceAdapterClass; 38 39 private final BootstrapContext bootstrapContext; 40 41 protected final ResourceAdapter resourceAdapter; 42 43 44 47 public ResourceAdapterWrapper() { 48 this.resourceAdapterClass = null; 49 this.bootstrapContext = null; 50 this.resourceAdapter = null; 51 } 52 53 public ResourceAdapterWrapper(String resourceAdapterClass, 54 BootstrapContext bootstrapContext, 55 ClassLoader cl) throws InstantiationException , IllegalAccessException , ClassNotFoundException { 56 this.resourceAdapterClass = resourceAdapterClass; 57 this.bootstrapContext = bootstrapContext; 58 Class clazz = cl.loadClass(resourceAdapterClass); 59 resourceAdapter = (ResourceAdapter ) clazz.newInstance(); 60 } 61 62 public ResourceAdapterWrapper(ResourceAdapter resourceAdapter, BootstrapContext bootstrapContext) { 63 this.resourceAdapterClass = resourceAdapter.getClass().getName(); 64 this.bootstrapContext = bootstrapContext; 65 this.resourceAdapter = resourceAdapter; 66 } 67 68 public String getResourceAdapterClass() { 69 return resourceAdapterClass; 70 } 71 72 public void registerResourceAdapterAssociation(final ResourceAdapterAssociation resourceAdapterAssociation) throws ResourceException { 73 resourceAdapterAssociation.setResourceAdapter(resourceAdapter); 74 } 75 76 public void start(BootstrapContext ctx) throws ResourceAdapterInternalException { 77 throw new IllegalStateException ("Don't call this"); 78 } 79 80 public void stop() { 81 throw new IllegalStateException ("Don't call this"); 82 } 83 84 public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException { 86 resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec); 87 } 88 89 public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) { 90 resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec); 91 } 92 93 public XAResource [] getXAResources(ActivationSpec [] specs) throws ResourceException { 94 return resourceAdapter.getXAResources(specs); 95 } 96 97 public void doStart() throws Exception { 98 resourceAdapter.start(bootstrapContext); 99 } 100 101 public void doStop() { 102 resourceAdapter.stop(); 103 } 104 105 public void doFail() { 106 resourceAdapter.stop(); 107 } 108 109 } 110 | Popular Tags |