1 23 24 package org.objectweb.jorm.mapper.fos.lib; 25 26 import org.objectweb.jorm.api.PMappingStructuresManager; 27 import org.objectweb.jorm.api.PMapper; 28 import org.objectweb.jorm.api.PException; 29 import org.objectweb.jorm.api.PExceptionProtocol; 30 import org.objectweb.jorm.api.PMapCluster; 31 import org.objectweb.util.monolog.api.Logger; 32 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import java.util.Collection ; 36 37 41 public class FosPMappingStructuresManager implements PMappingStructuresManager { 42 private PMapper pMapper = null; 43 private ArrayList clusterList = new ArrayList (); 44 protected Logger logger = null; 45 46 47 public synchronized void declareClass(String jcname) { 48 Iterator it = clusterList.iterator(); 49 FosPMapCluster cl; 50 while (it.hasNext()) { 51 cl = (FosPMapCluster) it.next(); 52 if (cl.containClass(jcname)) { 53 return; 54 } 55 } 56 cl = new FosPMapCluster(jcname, this); 57 clusterList.add(cl); 58 } 59 60 65 void closeConnection(Object conn) throws PException { 66 pMapper.closeConnection(conn); 67 } 68 69 74 Object getConnection() throws PException { 75 Object conn = pMapper.getConnection(); 76 if (conn == null) 77 throw new PExceptionProtocol("Impossible to initialize the mapping structures without connection"); 78 return conn; 79 } 80 81 86 private FosPMapCluster getAlwaysPMapCluster(String jcname, 87 String dirname) 88 throws PException { 89 FosPMapCluster cl = null; 90 Iterator it = clusterList.iterator(); 91 while (it.hasNext()) { 92 cl = (FosPMapCluster) it.next(); 93 if (cl.containDirectory(dirname)) { 94 break; 95 } 96 cl = null; 97 } 98 if (cl == null) { 99 cl = (FosPMapCluster) getPMapCluster(jcname); 101 if (cl == null) { 102 cl = new FosPMapCluster(jcname, dirname, this); 104 clusterList.add(cl); 105 } 106 } else { 108 FosPMapCluster cl2 = (FosPMapCluster) getPMapCluster(jcname); 110 if ((cl != cl2) && (cl2 != null)) { 111 cl.merge(cl2); 113 cl.addDirName(dirname); 114 clusterList.remove(cl2); 115 } else { 116 cl.addDependency(jcname); 118 } 119 } 120 return cl; 121 } 122 123 public void addDependency(String jcname1, String jcname2) throws PException { 124 } 126 127 public void classDefined(String jcname) throws PException { 128 } 130 131 137 synchronized public void addDirName(String jcname, String dirname) 138 throws PException { 139 FosPMapCluster cl = getAlwaysPMapCluster(jcname, dirname); 140 cl.addDirName(dirname); 141 } 142 143 145 150 public PMapCluster getPMapCluster(String jcname) throws PException { 151 Iterator it = clusterList.iterator(); 152 while (it.hasNext()) { 153 FosPMapCluster cl = (FosPMapCluster) it.next(); 154 if (cl.containClass(jcname)) { 155 return cl; 156 } 157 } 158 return null; 159 } 160 161 165 public Collection getPMapClusters() { 166 return clusterList; 167 } 168 169 173 public void setPMapper(PMapper pm) { 174 pMapper = pm; 175 } 176 177 181 public void setLogger(Logger l) { 182 logger = l; 183 } 184 } 185 | Popular Tags |