1 16 17 package org.springframework.jca.support; 18 19 import javax.resource.ResourceException ; 20 import javax.resource.spi.BootstrapContext ; 21 import javax.resource.spi.ResourceAdapter ; 22 import javax.resource.spi.XATerminator ; 23 import javax.resource.spi.work.WorkManager ; 24 25 import org.springframework.beans.BeanUtils; 26 import org.springframework.beans.factory.DisposableBean; 27 import org.springframework.beans.factory.FactoryBean; 28 import org.springframework.beans.factory.InitializingBean; 29 import org.springframework.util.Assert; 30 31 51 public class ResourceAdapterFactoryBean implements FactoryBean, InitializingBean, DisposableBean { 52 53 private ResourceAdapter resourceAdapter; 54 55 private BootstrapContext bootstrapContext; 56 57 private WorkManager workManager; 58 59 private XATerminator xaTerminator; 60 61 62 69 public void setResourceAdapterClass(Class resourceAdapterClass) { 70 Assert.isAssignable(ResourceAdapter .class, resourceAdapterClass); 71 this.resourceAdapter = (ResourceAdapter ) BeanUtils.instantiateClass(resourceAdapterClass); 72 } 73 74 80 public void setResourceAdapter(ResourceAdapter resourceAdapter) { 81 this.resourceAdapter = resourceAdapter; 82 } 83 84 91 public void setBootstrapContext(BootstrapContext bootstrapContext) { 92 this.bootstrapContext = bootstrapContext; 93 } 94 95 99 public void setWorkManager(WorkManager workManager) { 100 this.workManager = workManager; 101 } 102 103 107 public void setXaTerminator(XATerminator xaTerminator) { 108 this.xaTerminator = xaTerminator; 109 } 110 111 112 116 public void afterPropertiesSet() throws ResourceException { 117 if (this.resourceAdapter == null) { 118 throw new IllegalArgumentException ("'resourceAdapter' or 'resourceAdapterClass' is required"); 119 } 120 if (this.bootstrapContext == null) { 121 this.bootstrapContext = new SimpleBootstrapContext(this.workManager, this.xaTerminator); 122 } 123 this.resourceAdapter.start(this.bootstrapContext); 124 } 125 126 127 public Object getObject() { 128 return this.resourceAdapter; 129 } 130 131 public Class getObjectType() { 132 return (this.resourceAdapter != null ? this.resourceAdapter.getClass() : ResourceAdapter .class); 133 } 134 135 public boolean isSingleton() { 136 return true; 137 } 138 139 140 144 public void destroy() { 145 this.resourceAdapter.stop(); 146 } 147 148 } 149 | Popular Tags |