KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Vector JavaDoc;
25 import org.objectweb.jac.aspects.gui.swing.SHEditorConfig;
26 import org.objectweb.jac.aspects.export.ExportAC;
27 import org.objectweb.jac.aspects.export.Importer;
28 import org.objectweb.jac.aspects.timestamp.Timestamps;
29 import org.objectweb.jac.core.ACManager;
30 import org.objectweb.jac.core.Wrappee;
31 import org.objectweb.jac.core.rtti.FieldItem;
32 import org.objectweb.jac.util.File;
33 import org.xml.sax.SAXException JavaDoc;
34
35 public class Projects {
36     public static transient Projects root;
37     public static transient TypeRepository types;
38     public static transient Plurals plurals;
39     public static transient Timestamps stamps;
40     public static transient Preferences prefs;
41
42     public static Boolean JavaDoc notPrimitiveType(Wrappee substance,
43                                            FieldItem field,
44                                            Object JavaDoc value,
45                                            Object JavaDoc[] values)
46     {
47         Iterator JavaDoc it = Projects.types.getPrimitiveTypes().iterator();
48         while(it.hasNext()) {
49             Type type = (Type)it.next();
50             if (((String JavaDoc)value).equals(type.getName())) {
51                 return Boolean.FALSE;
52             }
53         }
54         return Boolean.TRUE;
55     }
56
57     /**
58      * Handle upgrading from class with no package to a class with
59      * package, for compatibility with 0.10 versions
60      * @param name name the class to add
61      * @param pkg package name of the class to add
62      */

63     private static Type initExternalClass(String JavaDoc name, String JavaDoc pkg) {
64         Type type = types.resolveType(name, "");
65         if (type!=null) {
66             type.setPackagePath(pkg);
67         } else {
68             type = types.resolveType(name,pkg);
69             if (type==null) {
70                 type = new Type(name,pkg);
71                 types.addExternalClass(type);
72             }
73         }
74         return type;
75     }
76
77     private static ExtendedType initExtendedType(String JavaDoc name, Type realType) {
78         Type type = types.resolveType(name, "");
79         if (type!=null) {
80             if (type instanceof ExtendedType)
81                 ((ExtendedType)type).setRealType(realType);
82             else {
83                 System.err.println("Warning: there's alreayd a type named "+
84                                    name+", but it's not an extended type");
85                 return null;
86             }
87         } else {
88             type = new ExtendedType(name,realType);
89             types.addExtendedType((ExtendedType)type);
90         }
91         return (ExtendedType)type;
92     }
93
94     private static Type initPrimitiveType(String JavaDoc name) {
95         Type type = types.resolveType(name, "");
96         if (type==null) {
97             type = new Type(name,"");
98             types.addPrimitiveType(type);
99         }
100         return type;
101     }
102
103     public static void main(String JavaDoc[] args) {
104         root = new Projects();
105         types = new TypeRepository();
106         plurals = new Plurals();
107         stamps = new Timestamps();
108         prefs = new Preferences();
109         prefs.setEditorPrefs(new SHEditorConfig());
110
111         // create the primitive types if needed
112

113         initPrimitiveType("void");
114         initPrimitiveType("boolean");
115         initPrimitiveType("int");
116         initPrimitiveType("long");
117         initPrimitiveType("float");
118         initPrimitiveType("double");
119
120         // create some useful external classes
121
initExternalClass("Object","java.lang");
122       
123         Type type = initExternalClass("String","java.lang");
124         initExtendedType("text",type);
125         initExtendedType("email",type);
126         initExtendedType("password",type);
127         initExtendedType("javaCode",type);
128         initExtendedType("accCode",type);
129       
130         type = initExternalClass("float","");
131         initExtendedType("percentage",type);
132
133         type = initExternalClass("File","java.io");
134         initExtendedType("directory",type);
135       
136         type = initExternalClass("URL","java.net");
137         initExtendedType("directoryURL",type);
138         initExtendedType("imageURL",type);
139       
140         type = initExternalClass("Date","java.util");
141         initExtendedType("dateHour",type);
142       
143         type = initExternalClass("Vector","java.util");
144         type = initExternalClass("List","java.util");
145         type = initExternalClass("Map","java.util");
146         type = initExternalClass("HashMap","java.util");
147         type = initExternalClass("Set","java.util");
148         type = initExternalClass("HashSet","java.util");
149         type = initExternalClass("Collection","java.util");
150         type = initExternalClass("Reader","java.io");
151         type = initExternalClass("Writer","java.io");
152         type = initExternalClass("InputStream","java.io");
153         type = initExternalClass("OutputStream","java.io");
154     }
155
156     Vector JavaDoc projects = new Vector JavaDoc();
157    
158     /**
159      * Get the value of projects.
160      * @return value of projects.
161      */

162     public List JavaDoc getProjects() {
163         return projects;
164     }
165    
166     public void addProject(Project p) {
167         projects.add(p);
168     }
169    
170     public void removeProject(Project p) {
171         projects.remove(p);
172     }
173
174     public String JavaDoc toString() {
175         return "projects";
176     }
177
178     Application currentApplication = null;
179     public void setCurrentApplication(Application application) {
180         currentApplication = application;
181     }
182     public Application getCurrentApplication() {
183         return currentApplication;
184     }
185
186     /**
187      * Starts the current application
188      */

189     public void startCurrentApplication() throws IOException JavaDoc {
190         if (currentApplication!=null) {
191             currentApplication.start();
192         }
193     }
194
195     /**
196      * Stops the current application
197      */

198     public void stopCurrentApplication() {
199         if (currentApplication!=null) {
200             currentApplication.stop();
201         }
202     }
203
204     public boolean isNotStarted() {
205         return currentApplication!=null && currentApplication.isNotStarted();
206     }
207
208     public boolean isStarted() {
209         return currentApplication!=null && currentApplication.isStarted();
210     }
211
212     /**
213      * Exports projects to an XML file
214      * @param f the file to export to
215      */

216     public static void export(File f) throws IOException JavaDoc, Exception JavaDoc {
217         ExportAC exportAC = (ExportAC)ACManager.getACM().getACFromFullName("ide.export");
218         if (exportAC==null) {
219             throw new Exception JavaDoc("No export aspect found");
220         } else {
221             exportAC.export(f);
222         }
223     }
224
225     public static void importObjects(File f) throws SAXException JavaDoc, IOException JavaDoc {
226         Importer importer = new Importer();
227         importer.importObjects(f);
228     }
229 }
230
Popular Tags