Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package JSX; 2 import java.util.Map ; 3 import java.util.List ; 4 import java.util.Iterator ; 5 public class PackageRefactor implements Refactor { 6 Map map; 7 public PackageRefactor(Map map) { this.map = map; 9 } 15 public String mapClassname(String packageQualifiedClassname) { 16 String initialPackage = packageQualifiedClassname.substring(0, packageQualifiedClassname.lastIndexOf('.')); String initialClassname = packageQualifiedClassname.substring(packageQualifiedClassname.lastIndexOf('.')+1); 18 19 Object packageOrList = map.get(initialPackage); if (packageOrList==null) 21 return packageQualifiedClassname; else if (packageOrList instanceof String ) 23 return ((String ) packageOrList)+"."+initialClassname; else if (packageOrList instanceof List ) { boolean found = false; 26 String newFullName = null; 27 for (Iterator i = ((List )packageOrList).iterator(); i.hasNext(); ) { 28 newFullName = ((String )i.next())+"."+initialClassname; 29 Class clazz; 30 try { 31 clazz=Thread.currentThread().getContextClassLoader().loadClass(newFullName); found = true; 33 break; } catch (ClassNotFoundException ignored) {} 35 } 36 if (found) 37 return newFullName; 38 else 39 return null; } 41 else 42 throw new Error ("Value corresponding to "+ initialPackage +" is "+ packageOrList.getClass() + " but should be List, String or null"); 43 } 44 } 45
| Popular Tags
|