1 23 24 package org.objectweb.jorm; 25 26 import org.objectweb.jorm.api.PException; 27 import org.objectweb.jorm.api.PMapper; 28 import org.objectweb.jorm.lib.MapperJCA; 29 import org.objectweb.jorm.lib.JormConfiguratorImpl; 30 import org.objectweb.jorm.api.JormConfigurator; 31 import org.objectweb.jorm.util.api.Loggable; 32 33 import javax.resource.spi.ManagedConnectionFactory ; 34 import javax.resource.ResourceException ; 35 import java.util.Properties ; 36 37 40 public class JcaMapperFactory implements JormTestMapperFactory { 41 public static final String RESOURCE_MCF_CLASSNAME = "mapper.jca.mcf.classname"; 42 public static final String ADAPTER_PROPERTIES_SETTER = "mapper.jca.mcf.propsetter"; 43 public static final String DEFAULT_MAPPER_NAME = "fos"; 44 45 52 public PMapper createMapper(Properties prop) throws PException { 53 String mcfcn, ascn, jormconf, submapper = null; 54 if ((mcfcn = prop.getProperty(RESOURCE_MCF_CLASSNAME)) == null) { 55 throw new PException("TEST: ManagedConnectionFactory class name mandatory for configuring a JCA adapter."); 56 } 57 if ((ascn = prop.getProperty(ADAPTER_PROPERTIES_SETTER)) == null) { 58 throw new PException("TEST: JcaAdapterPropertiesSetter class name mandatory for configuring a JCA adapter."); 59 } 60 if ((jormconf = prop.getProperty(JormTestMapperFactory.JORM_CONFIG_FILE)) == null) { 61 throw new PException("TEST: JORM config file mandatory for configuring tests."); 62 } 63 JormConfigurator jc = new JormConfiguratorImpl(); 64 jc.configure(jormconf); 65 jc.configureLog(jormconf); 66 PMapper res = new MapperJCA(jc); 67 res.setMapperName((submapper == null) ? DEFAULT_MAPPER_NAME : DEFAULT_MAPPER_NAME + "." + submapper); 68 ((Loggable) res).setLoggerFactory(jc.getLoggerFactory()); 69 ManagedConnectionFactory cs = null; 70 try { 71 cs = (ManagedConnectionFactory ) Class.forName(mcfcn).newInstance(); 72 JcaAdapterPropertiesSetter as = (JcaAdapterPropertiesSetter) Class.forName(ascn).newInstance(); 73 as.assignProperties(cs, prop, jc.getLoggerFactory()); 74 res.setConnectionFactory(cs.createConnectionFactory()); 75 } catch (Exception e) { 76 e.printStackTrace(); 77 if (e instanceof ResourceException ) { 78 ((ResourceException ) e).getLinkedException().printStackTrace(); 79 } 80 } 81 res.start(); 82 return res; 83 } 84 } 85 | Popular Tags |