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.MetaObject; 30 import org.objectweb.jorm.metainfo.api.Package; 31 import org.objectweb.jorm.util.api.Loggable; 32 import org.objectweb.util.monolog.api.BasicLevel; 33 import org.objectweb.util.monolog.api.Logger; 34 import org.objectweb.util.monolog.api.LoggerFactory; 35 36 import java.util.Iterator ; 37 import java.util.Map ; 38 import java.util.HashMap ; 39 import java.util.Collection ; 40 import java.util.ArrayList ; 41 42 48 public class BasicPackage extends BasicMetaObject implements Package { 49 55 protected Map classes; 56 57 63 protected Map compositeNames; 64 65 69 protected String name; 70 71 78 public BasicPackage(String name, Manager parent) { 79 super(parent); 80 this.name = name; 81 classes = new HashMap (); 82 compositeNames = new HashMap (); 83 } 84 85 89 96 public String getName() { 97 return name; 98 } 99 100 107 public Class getClass(String className) { 108 if (debug && classes.get(className) == null) { 109 logger.log(BasicLevel.DEBUG, "There is no class with this name (" 110 + className + ") for the current Package (" + name + ")"); 111 } 112 return (Class ) classes.get(className); 113 } 114 115 116 123 public CompositeName getCompositeName(String cn_Name) { 124 if (debug && compositeNames.get(cn_Name) == null) { 125 logger.log(BasicLevel.DEBUG, 126 "There is no composite name with this name (" + cn_Name 127 + ") for the current Package (" + name + ")"); 128 } 129 return (CompositeName) compositeNames.get(cn_Name); 130 } 131 132 142 public CompositeName createCompositeName(String CN_Name) { 143 if (debug) 144 logger.log(BasicLevel.DEBUG, "create a new CompositeName (" 145 + CN_Name + ") for the current Package (" + name + ")"); 146 147 CompositeName result = (CompositeName) compositeNames.get(CN_Name); 149 if (result != null) { 150 if (debug) { 151 logger.log(BasicLevel.DEBUG, 152 "return the existing CompositeName" + CN_Name); 153 } 154 } else { 155 result = new BasicCompositeName(CN_Name, this); 156 setLoggingOnChild(result); 157 compositeNames.put(CN_Name, result); 158 } 159 return result; 160 } 161 162 169 public Iterator iterateCompositeName() { 170 return compositeNames.values().iterator(); 171 } 172 173 183 public Class createClass(String className) { 184 if (debug) { 185 logger.log(BasicLevel.DEBUG, "create a new Class (" + className 186 + ") for the current Package (" + name + ")"); 187 } 188 Class result = (Class ) classes.get(className); 190 if (result != null) { 191 if (debug) { 192 logger.log(BasicLevel.DEBUG, "return the existing Class " + className); 193 } 194 } else { 195 result = new BasicClass(className, this); 196 setLoggingOnChild(result); 197 classes.put(className, result); 198 } 199 return result; 200 } 201 202 207 public void addClass(Class aClass) { 208 String aClassName = aClass.getName(); 209 if (classes.get(aClassName) != null) { 210 if (logger != null) { 211 logger.log(BasicLevel.INFO, "try to add an existing Class (" 212 + aClassName + ")"); 213 } 214 } else { 215 classes.put(aClassName, aClass); 216 } 217 } 218 219 224 public void addCompositeName(CompositeName composite) { 225 String compositeName = composite.getName(); 226 if (compositeNames.get(compositeName) != null) { 227 if (logger != null) { 228 logger.log(BasicLevel.INFO, "try to add an existing CompositeName (" 229 + compositeName + ")"); 230 } 231 } else { 232 compositeNames.put(compositeName, composite); 233 } 234 } 235 236 237 244 public Collection getClasses() { 245 return classes.values(); 246 } 247 248 public Collection getCompositeNames() { 249 return compositeNames.values(); 250 } 251 252 protected Collection getChildren() { 253 ArrayList res = new ArrayList (); 254 res.addAll(classes.values()); 255 res.addAll(compositeNames.values()); 256 return res; 257 } 258 } 259 | Popular Tags |