1 18 19 package org.objectweb.jac.ide; 20 21 import java.util.Collection ; 22 import java.util.Hashtable ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.Vector ; 27 import org.objectweb.jac.util.File; 28 import org.objectweb.jac.util.Strings; 29 30 public class Project extends ModelElement { 31 32 public void checkGenerationPath() throws CannotGenerateException { 33 if (generationPath==null) { 34 throw new CannotGenerateException( 35 "Project \""+name+"\" does not have a generation path"); 36 } 37 } 38 39 boolean useToolsJavac = false; 40 public void setUseToolsJavac(boolean value) { 41 useToolsJavac = value; 42 } 43 public boolean getUseToolsJavac() { 44 return useToolsJavac; 45 } 46 47 File compilerCommand = new File("javac"); 48 49 53 public File getCompilerCommand() { 54 return compilerCommand; 55 } 56 57 61 public void setCompilerCommand(File v) { 62 this.compilerCommand = v; 63 } 64 65 String compilerOptions; 66 public String getCompilerOptions() { 67 return compilerOptions; 68 } 69 public void setCompilerOptions(String options) { 70 this.compilerOptions = options; 71 } 72 73 File generationPath; 74 75 79 public File getGenerationPath() { 80 return generationPath; 81 } 82 83 87 public void setGenerationPath(File v) { 88 this.generationPath = v; 89 } 90 91 94 public File getClassesDir() { 95 return new File(generationPath,"classes"); 96 } 97 98 public File getManifestDir() { 99 return new File(generationPath,"META-INF"); 100 } 101 102 Vector packages = new Vector (); 103 104 108 public List getPackages() { 109 return packages; 110 } 111 112 public void addPackage(Package p) { 113 packages.add(p); 114 } 115 116 public void removePackage(Package p) { 117 packages.remove(p); 118 } 119 120 124 public Package getPackageByName(String packageName) { 125 Iterator it = packages.iterator(); 126 while (it.hasNext()) { 127 Package pkg = (Package )it.next(); 128 if (pkg.getName().equals(packageName)) 129 return pkg; 130 } 131 return null; 132 } 133 134 135 139 public Package findPackage(String pkgName) { 140 int dot = pkgName.indexOf('.'); 141 if (dot!=-1) { 142 Package pkg = getPackageByName(pkgName.substring(0,dot)); 143 if (pkg!=null) 144 return pkg.findPackage(pkgName.substring(dot+1)); 145 else 146 return null; 147 } else { 148 return getPackageByName(pkgName); 149 } 150 } 151 152 Vector applications = new Vector (); 153 154 158 public List getApplications() { 159 return applications; 160 } 161 162 public void addApplication(Application a) { 163 applications.add(a); 164 a.addAspectConfiguration(new AspectConfiguration("rtti")); 165 } 166 167 public void removeApplication(Application a) { 168 applications.remove(a); 169 } 170 171 172 List classpath = new Vector (); 173 public List getClasspath() { 174 return classpath; 175 } 176 public String getClasspathString() { 177 return Strings.join(classpath,System.getProperty("path.separator")); 178 } 179 public void addClasspath(File path) { 180 classpath.add(path); 181 } 182 public void removeClasspath(File path) { 183 classpath.remove(path); 184 } 185 186 190 public Class findClass(String className) { 191 int dot = className.indexOf('.'); 192 if (dot!=-1) { 193 String packageName = className.substring(0,dot); 194 Package pkg = getPackageByName(packageName); 195 if (pkg!=null) 196 return pkg.findClass(className.substring(dot+1)); 197 else 198 return null; 199 } else { 200 return null; 201 } 202 } 203 204 207 public Collection getClasses() { 208 Vector classes = new Vector (); 209 Iterator it = packages.iterator(); 210 while (it.hasNext()) { 211 Package pkg = (Package )it.next(); 212 classes.addAll(pkg.getAllClasses()); 213 } 214 return classes; 215 } 216 217 220 public Map getAllResources() { 221 Hashtable resources = new Hashtable (); 222 Iterator it = packages.iterator(); 223 while (it.hasNext()) { 224 Package pkg = (Package )it.next(); 225 resources.putAll(pkg.getAllResources()); 226 } 227 return resources; 228 } 229 230 Map externalFiles = new Hashtable (); 231 236 public void addExternalFile(String name, File file) { 237 externalFiles.put(name,file); 238 } 239 public void removeExternalFile(String name) { 240 externalFiles.remove(name); 241 } 242 public Map getExternalFiles() { 243 return externalFiles; 244 } 245 246 249 public void cleanupModel() { 250 Iterator i = getClasses().iterator(); 251 while (i.hasNext()) { 252 Class cl = (Class )i.next(); 253 Iterator j = cl.getEndingLinks().iterator(); 254 while (j.hasNext()) { 255 Role role = (Role)j.next(); 256 if (role.getEnd()==null || role.getStart()==null) { 257 j.remove(); 258 } 259 } 260 } 261 } 262 } 263 | Popular Tags |