1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import java.io.File ; 5 import java.io.IOException ; 6 7 11 public class CGFileAccess { 12 13 File _root; 14 boolean rewrite; 15 16 20 public CGFileAccess(String rootDir, boolean rewrite) throws IOException { 21 _root = new File (rootDir); 22 if (! _root.isDirectory()) { throw new IOException (rootDir+" "+Res.res.getString("MSG_IsNotDir")); 24 } 25 this.rewrite = rewrite; 26 } 27 28 29 public File root() { 30 return _root; 31 } 32 33 34 39 public CGFileWriter newCGWriter(String name) throws IOException { 40 File path = new File (_root, name); 41 if (path.exists()) { 42 if (path.isDirectory()) 43 throw new IOException (path+" "+Res.res.getString("MSG_IsDir")); 44 if (!rewrite) 45 throw new IOException (path+" "+Res.res.getString("MSG_Exists")); 46 } 47 File dir = path.getParentFile(); 48 if (dir != null) { 49 if (! dir.exists()) { 50 if (! dir.mkdirs()) 51 throw new IOException (path+" "+Res.res.getString("MSG_CantBeCreated")); 52 } 53 } 54 return new CGFileWriter(path); 55 } 56 57 63 public boolean exists(String name) throws IOException { 64 File path = new File (_root, name); 65 return path.exists(); 66 } 67 68 74 public static String absToPath(SOFA.SOFAnode.Made.TIR.AbsoluteName abs, String shortName, boolean extension) throws java.rmi.RemoteException { 75 StringBuffer sb = new StringBuffer (); 76 for (int i=0;i<abs.size()-1;i++) { 77 sb.append(abs.elementAt(i)); 78 sb.append(File.separator); 80 } 81 sb.append(shortName); 82 if (extension) 83 sb.append(".java"); 84 return sb.toString(); 85 } 86 87 91 public static String absToPkg(SOFA.SOFAnode.Made.TIR.AbsoluteName abs) throws java.rmi.RemoteException { 92 StringBuffer sb = new StringBuffer (); 93 for (int i=0;i<abs.size()-1;i++) { 94 sb.append(abs.elementAt(i)); 95 if (i < abs.size()-2) 96 sb.append("."); 97 } 98 return sb.toString(); 99 } 100 101 109 public static String absToPath(SOFA.SOFAnode.Made.TIR.AbsoluteName abs, String shortName, String pre, String post, boolean extension) throws java.rmi.RemoteException { 110 StringBuffer sb = new StringBuffer (); 111 for (int i=0;i<abs.size()-1;i++) { 112 sb.append(abs.elementAt(i)); 113 sb.append(File.separator); 115 } 116 sb.append(pre); 117 sb.append(shortName); 118 sb.append(post); 119 if (extension) 120 sb.append(".java"); 121 return sb.toString(); 122 } 123 124 130 public static String archAbsToPath(SOFA.SOFAnode.Made.TIR.AbsoluteName abs, String shortName, boolean extension) throws java.rmi.RemoteException { 131 StringBuffer sb = new StringBuffer (); 132 for (int i=1;i<abs.size()-1;i++) { 133 sb.append(abs.elementAt(i)); 134 sb.append(File.separator); 136 } 137 sb.append(shortName); 138 if (extension) 139 sb.append(".java"); 140 return sb.toString(); 141 } 142 143 147 public static String archAbsToPkg(SOFA.SOFAnode.Made.TIR.AbsoluteName abs) throws java.rmi.RemoteException { 148 StringBuffer sb = new StringBuffer (); 149 for (int i=1;i<abs.size()-1;i++) { 150 sb.append(abs.elementAt(i)); 151 if (i < abs.size()-2) 152 sb.append("."); 153 } 154 return sb.toString(); 155 } 156 157 174 175 } 176 | Popular Tags |