1 23 24 package org.objectweb.jorm.metainfo.lib; 25 26 import org.objectweb.jorm.metainfo.api.Class; 27 import org.objectweb.jorm.metainfo.api.CompositeName; 28 import org.objectweb.jorm.metainfo.api.Manager; 29 import org.objectweb.jorm.metainfo.api.MappingFactory; 30 import org.objectweb.jorm.metainfo.api.MetaObject; 31 import org.objectweb.jorm.metainfo.api.Package; 32 import org.objectweb.jorm.type.api.PTypeSpace; 33 import org.objectweb.jorm.type.lib.PTypeSpacePAAH; 34 import org.objectweb.jorm.util.api.Loggable; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 import org.objectweb.util.monolog.api.Logger; 37 import org.objectweb.util.monolog.api.LoggerFactory; 38 39 import java.util.ArrayList ; 40 import java.util.Collection ; 41 import java.util.HashMap ; 42 import java.util.Iterator ; 43 import java.util.Map ; 44 45 52 public class JormManager extends BasicMetaObject implements Manager { 53 58 protected Map packages; 59 60 66 protected Map mappingFactories; 67 68 71 protected PTypeSpace ptypeSpace; 72 73 public JormManager() { 74 super(null); 75 init(); 76 } 77 78 82 86 public void init() { 87 packages = new HashMap (); 88 mappingFactories = new HashMap (); 89 ptypeSpace = new PTypeSpacePAAH(); 90 } 91 92 99 public Package getPackage(String schemaName) { 100 return (Package ) packages.get(schemaName); 101 } 102 103 111 public Package createPackage(String schemaName) { 112 if (debug) { 113 logger.log(BasicLevel.DEBUG, 114 "create a new Package (" + schemaName + ") for the current Manager"); 115 } 116 if (packages.get(schemaName) != null) { 118 if (debug) 119 logger.log(BasicLevel.DEBUG, "The Package already exist (" 120 + schemaName + "), return existing one"); 121 return (Package ) packages.get(schemaName); 122 } 123 124 Package newPackage = new BasicPackage(schemaName, this); 126 setLoggingOnChild(newPackage); 127 packages.put(schemaName, newPackage); 128 return newPackage; 129 } 130 131 139 public Collection getPackages() { 140 return packages.values(); 141 } 142 143 150 public void addMappingFactory(String mapperName, MappingFactory factory) { 151 setLoggingOnChild(factory); 152 mappingFactories.put(mapperName, factory); 153 } 154 155 163 public MappingFactory getMappingFactory(String mapperName) { 164 if (debug) { 165 logger.log(BasicLevel.DEBUG, "get the mappingFactory from " 166 + mapperName); 167 } 168 return (MappingFactory) mappingFactories.get(mapperName); 169 } 170 171 public Collection getMappingFactories() { 172 return mappingFactories.values(); 173 } 174 175 178 public PTypeSpace getPTypeSpace() { 179 return ptypeSpace; 180 } 181 182 186 public Collection getClasses() { 187 ArrayList v = new ArrayList (); 188 Iterator allPackages = packages.values().iterator(); 189 while (allPackages.hasNext()) { 190 v.addAll(((Package ) allPackages.next()).getClasses()); 191 } 192 return v; 193 } 194 195 199 public Collection getCompositeNames() { 200 ArrayList v = new ArrayList (); 201 Iterator allPackages = packages.values().iterator(); 202 while (allPackages.hasNext()) { 203 v.addAll(((Package ) allPackages.next()).getCompositeNames()); 204 } 205 return v; 206 } 207 208 public Collection getJormObjects() { 209 ArrayList v = new ArrayList (); 210 Iterator allPackages = packages.values().iterator(); 211 while (allPackages.hasNext()) { 212 Package p = (Package ) allPackages.next(); 213 v.addAll(p.getClasses()); 214 v.addAll(p.getCompositeNames()); 215 } 216 return v; 217 } 218 219 225 public Class getClass(String className) { 226 if (packages == null || className == null) { 227 return null; 228 } 229 int idx = className.lastIndexOf("."); 230 Package p = null; 231 if (idx == -1) { 232 p = (Package ) packages.get(""); 233 if (p != null) { 234 return p.getClass(className); 235 } 236 } else { 237 p = (Package ) packages.get(className.substring(0, idx)); 238 if (p != null) { 239 return p.getClass(className.substring(idx + 1)); 240 } 241 } 242 return null; 243 } 244 245 public Class createClass(String fqclassName) { 246 if (packages == null || fqclassName == null) { 247 return null; 248 } 249 int idx = fqclassName.lastIndexOf("."); 250 if (idx == -1) { 251 return createPackage("").createClass(fqclassName); 252 } else { 253 return createPackage(fqclassName.substring(0, idx)) 254 .createClass(fqclassName.substring(idx + 1)); 255 } 256 } 257 258 public CompositeName getCompositeName(String fqcompositeNameName) { 259 if (packages == null || fqcompositeNameName == null) { 260 return null; 261 } 262 int idx = fqcompositeNameName.lastIndexOf("."); 263 Package p = null; 264 if (idx == -1) { 265 p = (Package ) packages.get(""); 266 if (p != null) { 267 return p.getCompositeName(fqcompositeNameName); 268 } 269 } else { 270 p = (Package ) packages.get(fqcompositeNameName.substring(0, idx)); 271 if (p != null) { 272 return p.getCompositeName(fqcompositeNameName.substring(idx + 1)); 273 } 274 } 275 return null; 276 } 277 278 public CompositeName createCompositeName(String fqcompositeNameName) { 279 if (packages == null || fqcompositeNameName == null) { 280 return null; 281 } 282 int idx = fqcompositeNameName.lastIndexOf("."); 283 if (idx == -1) { 284 return createPackage("").createCompositeName(fqcompositeNameName); 285 } else { 286 return createPackage(fqcompositeNameName.substring(0, idx)) 287 .createCompositeName(fqcompositeNameName.substring(idx + 1)); 288 } 289 } 290 291 protected Collection getChildren() { 292 return packages.values(); 293 } 294 } 295 | Popular Tags |