1 18 19 package org.objectweb.jac.core; 20 21 import java.util.Iterator ; 22 import java.util.Vector ; 23 import org.apache.log4j.Logger; 24 import org.objectweb.jac.core.rtti.ClassItem; 25 import org.objectweb.jac.core.rtti.ClassRepository; 26 import org.objectweb.jac.core.rtti.NoSuchClassException; 27 28 public class Imports { 29 Logger logger = Logger.getLogger("imports"); 30 Vector imports = new Vector (); 31 public void add(String imp) { 32 imports.add(imp); 33 } 34 public ClassItem getClass(String className) { 35 logger.debug("Searching for "+className); 36 Iterator i = imports.iterator(); 37 ClassRepository cr = ClassRepository.get(); 38 ClassItem cli = null; 39 try { 40 cli = cr.getNonPrimitiveClass(className); 41 logger.debug(" Found "+className+": "+cli.getName()); 42 } catch (NoSuchClassException e) { 43 while (i.hasNext()) { 44 String imp = (String )i.next(); 45 try { 46 if (imp.endsWith("*")) { 47 cli = cr.getClass( 48 imp.substring(0,imp.length()-1)+className); 49 } else { 50 int index = imp.lastIndexOf('.'); 51 if (imp.substring(index+1).equals(className)) { 52 cli = cr.getClass(imp); 53 } 54 } 55 if (cli!=null) { 56 logger.debug(" Found "+cli.getName()); 57 break; 58 } 59 } catch(NoSuchClassException e2) { 60 } 61 } 62 } 63 if (cli==null) { 64 logger.debug(" Not found in "+imports); 65 throw new NoSuchClassException(className); 66 } 67 return cli; 68 } 69 } 70 | Popular Tags |