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.util.monolog.api.Logger; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 import java.util.Properties ; 32 33 37 public class MapperFactory implements JormTestMapperFactory { 38 public final static String FACTORY = "mapper.factory"; 39 46 public PMapper createMapper(Properties prop) throws PException { 47 String mfn; 48 if ((mfn = prop.getProperty(FACTORY)) == null) { 49 throw new PException("TEST: mapper factory mandatory for configuring tests."); 50 } 51 try { 52 return ((JormTestMapperFactory) Class.forName(mfn).newInstance()).createMapper(prop); 53 } catch (InstantiationException e) { 54 throw new PException(e, "TEST: cannot create mapper factory."); 55 } catch (IllegalAccessException e) { 56 throw new PException(e, "TEST: cannot create mapper factory."); 57 } catch (ClassNotFoundException e) { 58 throw new PException(e, "TEST: cannot create mapper factory."); 59 } 60 } 61 62 public void traceException(Logger logger, Exception e) { 63 int i = 0; 64 while (e != null) { 65 logger.log(BasicLevel.ERROR, (i == 0) ? "" : "Nested level " + i, e); 66 i++; 67 if (e instanceof PException) { 68 e = ((PException) e).getNestedException(); 69 } else { 70 e = null; 71 } 72 } 73 } 74 } 75 | Popular Tags |