1 16 17 package org.springframework.jca.support; 18 19 import javax.resource.ResourceException ; 20 import javax.resource.spi.ConnectionManager ; 21 import javax.resource.spi.ManagedConnectionFactory ; 22 23 import org.springframework.beans.factory.FactoryBean; 24 import org.springframework.beans.factory.InitializingBean; 25 26 71 public class LocalConnectionFactoryBean implements FactoryBean, InitializingBean { 72 73 private ManagedConnectionFactory managedConnectionFactory; 74 75 private ConnectionManager connectionManager; 76 77 private Object connectionFactory; 78 79 80 96 public void setManagedConnectionFactory(ManagedConnectionFactory managedConnectionFactory) { 97 this.managedConnectionFactory = managedConnectionFactory; 98 } 99 100 108 public void setConnectionManager(ConnectionManager connectionManager) { 109 this.connectionManager = connectionManager; 110 } 111 112 public void afterPropertiesSet() throws ResourceException { 113 if (this.managedConnectionFactory == null) { 114 throw new IllegalArgumentException ("Property 'managedConnectionFactory' is required"); 115 } 116 if (this.connectionManager != null) { 117 this.connectionFactory = this.managedConnectionFactory.createConnectionFactory(this.connectionManager); 118 } 119 else { 120 this.connectionFactory = this.managedConnectionFactory.createConnectionFactory(); 121 } 122 } 123 124 125 public Object getObject() { 126 return this.connectionFactory; 127 } 128 129 public Class getObjectType() { 130 return (this.connectionFactory != null ? this.connectionFactory.getClass() : null); 131 } 132 133 public boolean isSingleton() { 134 return true; 135 } 136 137 } 138 | Popular Tags |