1 9 package org.ozoneDB.tools; 10 11 import java.lang.*; 12 import java.util.*; 13 import java.io.*; 14 15 16 108 public class OIG { 109 110 111 public static void main( String [] args ) { 112 Vector updatePatterns = null; 113 BufferedReader in = null; 114 PrintWriter out = null; 115 116 updatePatterns = getPatterns(); 117 118 try { 119 in = new BufferedReader( new FileReader( args[0] + ".java" ), 1024 ); 121 out = new PrintWriter( new FileWriter( args[0] + "_Int.java" ) ); 122 } catch (Exception e) { 123 System.err.println( "Using stdin" ); 124 in = new BufferedReader( new InputStreamReader( System.in ), 1024 ); 125 out = new PrintWriter( System.out ); 126 } 127 try { 128 String buf; 129 String tbuf; 130 StringTokenizer tok; 131 boolean fndOpen = false; 132 boolean fndConst = false; 133 String classname = null; 134 String intname = null; 135 136 while ((buf = in.readLine()) != null) { 137 if (buf.startsWith( "{" )) { 138 out.println( buf ); 139 fndOpen = true; 140 } 141 142 if (!fndOpen) { 143 if (buf.startsWith( "import" ) || buf.startsWith( "package" )) { 144 out.println( buf ); 145 } else { 146 147 if (buf.startsWith( "public class" ) || buf.startsWith( "public abstract class" )) { 148 int beg; 149 int end; 150 beg = buf.indexOf( "class" ) + 6; 151 end = buf.indexOf( " ", beg ); 152 classname = buf.substring( beg, end ); 153 intname = classname + "_Int"; 154 155 out.print( "import org.ozoneDB.OzoneRemote;\n" + "import org.ozoneDB.DxLib.*;\n" 156 + "\npublic interface " + intname + " extends OzoneRemote\n" ); 157 158 } 159 } 160 } else { 161 if (buf.indexOf( "static" ) == -1) { 162 buf = remove( buf, "synchronized" ); 163 tok = new StringTokenizer( buf ); 164 if (tok.hasMoreTokens()) { 165 tbuf = tok.nextToken(); 166 if (tbuf.startsWith( "public" ) && (buf.indexOf( "(" ) > 0 && buf.indexOf( "{" ) > 0 167 || buf.indexOf( ");" ) > 0)) { 168 if (!fndConst) { 169 fndConst = true; 170 } else { 171 tbuf = tok.nextToken(); 172 if (!tbuf.startsWith( classname )) { 173 out.print( buf.substring( 0, buf.indexOf( ")" ) + 1 ) + ";" ); 174 Enumeration en = updatePatterns.elements(); 175 while (en.hasMoreElements()) { 176 String s = (String )en.nextElement(); 177 if (buf.indexOf( s ) != -1) { 178 out.println( "//update" ); 179 break; 180 } 181 } 182 out.print( "\n" ); 183 } 184 } 185 } 186 } 187 } 188 } 189 } 190 out.println( "}" ); 191 out.close(); 192 193 } catch (Exception e) { 194 System.out.flush(); 195 System.err.println( e ); 196 } 197 } 198 199 200 private static Vector getPatterns() { 201 BufferedReader in = null; 202 Vector lst = new Vector(); 203 try { 204 in = new BufferedReader( new FileReader( "int_config" ), 1024 ); 205 String buf = null; 206 while ((buf = in.readLine()) != null) { 207 lst.addElement( buf ); 208 } 209 in.close(); 210 return lst; 211 } catch (Exception e) { 212 lst.addElement( "delete" ); 213 lst.addElement( "set" ); 214 lst.addElement( "update" ); 215 lst.addElement( "modify" ); 216 lst.addElement( "reset" ); 217 return lst; 218 } 219 } 220 221 222 private static String remove( String buf, String rem ) { 223 try { 224 int beg; 225 int end; 226 227 beg = buf.indexOf( rem ); 228 if (beg == -1) { 229 return buf; 230 } 231 end = buf.indexOf( " ", beg ); 232 if (end == -1) { 233 return buf; 234 } 235 return buf.substring( 0, beg - 1 ) + buf.substring( end ); 236 } catch (Exception e) { 237 return buf; 238 } 239 240 } 241 } 242 | Popular Tags |