1 28 29 package org.objectweb.jonas_ejb.container.jorm; 30 31 import java.util.HashMap ; 32 import java.util.Map ; 33 import java.util.Properties ; 34 35 import org.objectweb.jonas_ejb.container.JContainer; 36 import org.objectweb.jonas_ejb.container.TraceEjb; 37 38 import org.objectweb.jorm.lib.JormConfiguratorImpl; 39 import org.objectweb.jorm.api.JormConfigurator; 40 import org.objectweb.jorm.api.PException; 41 import org.objectweb.jorm.api.PMapper; 42 import org.objectweb.jorm.lib.Mapper; 43 import org.objectweb.jorm.util.api.Loggable; 44 45 import org.objectweb.medor.eval.prefetch.lib.PrefetchCacheImpl; 46 47 import org.objectweb.util.monolog.api.BasicLevel; 48 import org.objectweb.util.monolog.api.Logger; 49 50 58 public class MapperManager { 59 60 63 private static MapperManager singleton = null; 64 65 68 public static MapperManager getInstance() { 69 if (singleton == null) { 70 singleton = new MapperManager(); 71 } 72 return singleton; 73 } 74 75 78 private Logger logger = null; 79 80 86 private HashMap mappers = new HashMap (); 87 88 91 private JormConfigurator jormConfigurator; 92 93 protected MapperManager() { 94 logger = TraceEjb.logger; 95 jormConfigurator = new JormConfiguratorImpl(); 96 Properties prop = new Properties (); 97 prop.put("jorm.generator", "org.objectweb.jorm.generator.lib.JormGenerator"); 98 prop.put("jorm.mimanager", "org.objectweb.jorm.metainfo.lib.JormManager"); 99 prop.put("jorm.parser", "org.objectweb.jorm.xml2mi.lib.BasicDomParser"); 100 prop.put("jorm.verifier", "org.objectweb.jorm.verifier.lib.JormVerifier"); 101 prop.put("jorm.writer", "org.objectweb.jorm.mi2xml.lib.BasicDomWriter"); 102 prop.put("jorm.mapper.list", "rdb"); 103 prop.put("jorm.mapper.mifactory.rdb", "org.objectweb.jorm.mapper.rdb.metainfo.RdbMappingFactory"); 104 prop.put("jorm.mapper.mopfactory.rdb", "org.objectweb.jorm.mapper.rdb.generator.RdbMOPFactory"); 105 prop.put("jorm.mapper.gcmapping.rdb", "org.objectweb.jorm.mapper.rdb.genclass.RdbGenClassMapping"); 106 prop.put("jorm.mapper.schmgr.rdb", "org.objectweb.jorm.mapper.rdb.lib.RdbPMappingStructuresManager"); 107 jormConfigurator.configure(prop); 108 jormConfigurator.setLoggerFactory(TraceEjb.loggerFactory); 109 if (logger.isLoggable(BasicLevel.DEBUG)) { 110 logger.log(BasicLevel.DEBUG, "JormConfigurator created"); 111 } 112 } 113 114 121 public PMapper getMapper(JContainer c, Object cf) { 122 Map m = (Map ) mappers.get(c); 123 return (m == null ? null : (Mapper) m.get(cf)); 124 } 125 126 139 public PMapper addMapper(PMapper m, JContainer c, Object cf) throws PException { 140 Map map; 141 PMapper pm = null; 142 synchronized (mappers) { 143 map = (Map ) mappers.get(c); 144 if (map == null) { 145 map = new HashMap (); 146 mappers.put(c, map); 147 } 148 } 149 pm = (PMapper) map.get(cf); 150 if (pm != null) { 151 return pm; 152 } 153 synchronized(map) { 154 pm = (PMapper) map.get(cf); 155 if (pm == null) { 156 pm = m; 157 m.setPrefetchCache(new PrefetchCacheImpl(logger)); 159 if (TraceEjb.loggerFactory == null) { 161 m.setLogger(logger); 162 } else { 163 m.setLogger(TraceEjb.loggerFactory.getLogger(TraceEjb.prefix 164 + ".mapper." + m.getMapperName())); 165 if (m instanceof Loggable) { 166 ((Loggable) m).setLoggerFactory(TraceEjb.loggerFactory); 167 } 168 } 169 m.start(); 171 map.put(cf, m); 173 if (logger.isLoggable(BasicLevel.DEBUG)) { 174 logger.log(BasicLevel.DEBUG, "Mapper (" + m.getMapperName() 175 + ", " + cf + ") initialized"); 176 } 177 } 178 } 179 return pm; 180 } 181 182 public Logger getLogger() { 183 return logger; 184 } 185 186 public JormConfigurator getJormConfigurator() { 187 return jormConfigurator; 188 } 189 } 190 | Popular Tags |