KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > Project


1 /*
2   Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.ide;
20
21 import java.util.Collection JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Vector JavaDoc;
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     /**
50      * Get the value of compilerCommand.
51      * @return value of compilerCommand.
52      */

53     public File getCompilerCommand() {
54         return compilerCommand;
55     }
56    
57     /**
58      * Set the value of compilerCommand.
59      * @param v Value to assign to compilerCommand.
60      */

61     public void setCompilerCommand(File v) {
62         this.compilerCommand = v;
63     }
64
65     String JavaDoc compilerOptions;
66     public String JavaDoc getCompilerOptions() {
67         return compilerOptions;
68     }
69     public void setCompilerOptions(String JavaDoc options) {
70         this.compilerOptions = options;
71     }
72
73     File generationPath;
74
75     /**
76      * Get the value of generationPath.
77      * @return value of generationPath.
78      */

79     public File getGenerationPath() {
80         return generationPath;
81     }
82    
83     /**
84      * Set the value of generationPath.
85      * @param v Value to assign to generationPath.
86      */

87     public void setGenerationPath(File v) {
88         this.generationPath = v;
89     }
90
91     /**
92      * Returns the directory where the .class files should be stored
93      */

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 JavaDoc packages = new Vector JavaDoc();
103    
104     /**
105      * Get the value of packages.
106      * @return value of packages.
107      */

108     public List JavaDoc getPackages() {
109         return packages;
110     }
111    
112     public void addPackage(Package JavaDoc p) {
113         packages.add(p);
114     }
115    
116     public void removePackage(Package JavaDoc p) {
117         packages.remove(p);
118     }
119    
120     /**
121      * Gets a package with a given name
122      * @param packageName the requested package name
123      */

124     public Package JavaDoc getPackageByName(String JavaDoc packageName) {
125         Iterator JavaDoc it = packages.iterator();
126         while (it.hasNext()) {
127             Package JavaDoc pkg = (Package JavaDoc)it.next();
128             if (pkg.getName().equals(packageName))
129                 return pkg;
130         }
131         return null;
132     }
133
134
135     /**
136      * Find a package by its full name (my.package.ClassName)
137      * @param pkgName the package name to find
138      */

139     public Package JavaDoc findPackage(String JavaDoc pkgName) {
140         int dot = pkgName.indexOf('.');
141         if (dot!=-1) {
142             Package JavaDoc 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 JavaDoc applications = new Vector JavaDoc();
153    
154     /**
155      * Get the value of applications.
156      * @return value of applications.
157      */

158     public List JavaDoc 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     /** List of File */
172     List JavaDoc classpath = new Vector JavaDoc();
173     public List JavaDoc getClasspath() {
174         return classpath;
175     }
176     public String JavaDoc 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     /**
187      * Find a class by its full name (my.package.ClassName)
188      * @param className the class name to find
189      */

190     public Class JavaDoc findClass(String JavaDoc className) {
191         int dot = className.indexOf('.');
192         if (dot!=-1) {
193             String JavaDoc packageName = className.substring(0,dot);
194             Package JavaDoc 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     /**
205      * Returns all classes of all packages of the project.
206      */

207     public Collection JavaDoc getClasses() {
208         Vector JavaDoc classes = new Vector JavaDoc();
209         Iterator JavaDoc it = packages.iterator();
210         while (it.hasNext()) {
211             Package JavaDoc pkg = (Package JavaDoc)it.next();
212             classes.addAll(pkg.getAllClasses());
213         }
214         return classes;
215     }
216
217     /**
218      * Returns all resources of all packages of the project.
219      */

220     public Map JavaDoc getAllResources() {
221         Hashtable JavaDoc resources = new Hashtable JavaDoc();
222         Iterator JavaDoc it = packages.iterator();
223         while (it.hasNext()) {
224             Package JavaDoc pkg = (Package JavaDoc)it.next();
225             resources.putAll(pkg.getAllResources());
226         }
227         return resources;
228     }
229
230     Map JavaDoc externalFiles = new Hashtable JavaDoc();
231     /**
232      * Add an external file to include in the JAR
233      * @param name name of the file in the JAR
234      * @param file the file to include
235      */

236     public void addExternalFile(String JavaDoc name, File file) {
237         externalFiles.put(name,file);
238     }
239     public void removeExternalFile(String JavaDoc name) {
240         externalFiles.remove(name);
241     }
242     public Map JavaDoc getExternalFiles() {
243         return externalFiles;
244     }
245
246     /**
247      * Remove "dangling" Roles (whose start or end is null)
248      */

249     public void cleanupModel() {
250         Iterator JavaDoc i = getClasses().iterator();
251         while (i.hasNext()) {
252             Class JavaDoc cl = (Class JavaDoc)i.next();
253             Iterator JavaDoc 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