1 18 19 package org.objectweb.jac.ide; 20 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Vector ; 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 ; 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 notPrimitiveType(Wrappee substance, 43 FieldItem field, 44 Object value, 45 Object [] values) 46 { 47 Iterator it = Projects.types.getPrimitiveTypes().iterator(); 48 while(it.hasNext()) { 49 Type type = (Type)it.next(); 50 if (((String )value).equals(type.getName())) { 51 return Boolean.FALSE; 52 } 53 } 54 return Boolean.TRUE; 55 } 56 57 63 private static Type initExternalClass(String name, String 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 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 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 [] 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 113 initPrimitiveType("void"); 114 initPrimitiveType("boolean"); 115 initPrimitiveType("int"); 116 initPrimitiveType("long"); 117 initPrimitiveType("float"); 118 initPrimitiveType("double"); 119 120 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 projects = new Vector (); 157 158 162 public List 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 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 189 public void startCurrentApplication() throws IOException { 190 if (currentApplication!=null) { 191 currentApplication.start(); 192 } 193 } 194 195 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 216 public static void export(File f) throws IOException , Exception { 217 ExportAC exportAC = (ExportAC)ACManager.getACM().getACFromFullName("ide.export"); 218 if (exportAC==null) { 219 throw new Exception ("No export aspect found"); 220 } else { 221 exportAC.export(f); 222 } 223 } 224 225 public static void importObjects(File f) throws SAXException , IOException { 226 Importer importer = new Importer(); 227 importer.importObjects(f); 228 } 229 } 230 | Popular Tags |