1 16 17 package org.springframework.orm.ibatis; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.InputStreamReader ; 22 import java.util.Properties ; 23 24 import com.ibatis.db.sqlmap.SqlMap; 25 import com.ibatis.db.sqlmap.XmlSqlMapBuilder; 26 27 import org.springframework.beans.factory.FactoryBean; 28 import org.springframework.beans.factory.InitializingBean; 29 import org.springframework.core.io.Resource; 30 31 42 public class SqlMapFactoryBean implements FactoryBean, InitializingBean { 43 44 private Resource configLocation; 45 46 private Properties sqlMapProperties; 47 48 private SqlMap sqlMap; 49 50 51 55 public void setConfigLocation(Resource configLocation) { 56 this.configLocation = configLocation; 57 } 58 59 63 public void setSqlMapProperties(Properties sqlMapProperties) { 64 this.sqlMapProperties = sqlMapProperties; 65 } 66 67 68 public void afterPropertiesSet() throws IOException { 69 if (this.configLocation == null) { 70 throw new IllegalArgumentException ("configLocation is required"); 71 } 72 73 InputStream is = this.configLocation.getInputStream(); 75 this.sqlMap = (this.sqlMapProperties != null) ? 76 XmlSqlMapBuilder.buildSqlMap(new InputStreamReader (is), this.sqlMapProperties) : 77 XmlSqlMapBuilder.buildSqlMap(new InputStreamReader (is)); 78 } 79 80 81 public Object getObject() { 82 return this.sqlMap; 83 } 84 85 public Class getObjectType() { 86 return (this.sqlMap != null ? this.sqlMap.getClass() : SqlMap.class); 87 } 88 89 public boolean isSingleton() { 90 return true; 91 } 92 93 } 94 | Popular Tags |