1 2 package SOFA.SOFAnode.Made.Tools; 3 4 12 public class CorrectOrdinaryAppl { 13 14 15 16 public static void main(String [] argv) { 17 18 java.util.Hashtable trTable = new java.util.Hashtable (); 19 java.util.Hashtable verTable = new java.util.Hashtable (); 20 java.util.ArrayList classes = new java.util.ArrayList (); 21 22 for (int i=0; i<argv.length; i++) { 23 if (argv[i].indexOf('[') != -1) { 24 SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd = getDeplDescr(argv[i], "index.dc"); 26 java.util.Hashtable ent = dd.getCDLEntities(); 27 for (java.util.Enumeration e = ent.keys(); e.hasMoreElements(); ) { 28 String javaName = (String ) e.nextElement(); 29 String fullName = (String ) ent.get(javaName); 30 String specVersion = fullName.substring(fullName.indexOf('?')+1); 31 trTable.put(InstallToTR.toVMName(javaName), InstallToTR.toVMName(javaName+InstallToTR.specVersionToFileName(specVersion))); 32 verTable.put(InstallToTR.toVMName(javaName), InstallToTR.specVersionToFileName(specVersion)); 33 } 34 } else if (argv[i].endsWith(".class")) { 35 classes.add(argv[i]); 37 } else { 38 System.out.println("Unrecognized type of name: "+argv[i]); 40 System.exit(1); 41 } 42 } 43 44 SOFA.Tools.Resolver.Resolver resolver = new SOFA.Tools.Resolver.Resolver(trTable); 45 for (int i=0; i<classes.size(); i++) { 46 try { 47 String cur = (String ) classes.get(i); 48 System.out.print("Correcting class \""+cur+"\"..."); 49 String className = new SOFA.Tools.Resolver.ClassInfo(cur).className(); 50 java.io.FileInputStream fis = new java.io.FileInputStream (cur); 51 byte [] b = resolver.process(fis); 52 fis.close(); 53 String ver = (String ) verTable.get(className); 54 if (ver != null) { 55 String old = cur; 56 cur = cur.replaceFirst("\\.class", ver+".class"); 57 new java.io.File (old).delete(); 58 } 59 java.io.FileOutputStream fos = new java.io.FileOutputStream (cur); 60 fos.write(b); 61 fos.close(); 62 System.out.println("OK"); 63 } catch (java.io.IOException e) { 64 System.out.println("IOException: "+e.getMessage()); 65 System.exit(1); 66 } 67 } 68 } 69 70 static SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor getDeplDescr(String applname, String ddname) { 71 try { 72 String trString = System.getProperty("sofa.tr.url","file:/sofa/tr/"); 73 String path = trString+"impl"; 74 path = path + fullNameToFileName(applname, ddname); 75 java.net.URL url = new java.net.URL (path); 76 java.net.URLConnection con = url.openConnection(); 77 java.io.InputStream is = con.getInputStream(); 78 SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl(is); 79 is.close(); 80 return dd; 81 } catch (java.net.MalformedURLException e) { 82 System.out.println("MalformedURLException: "+e.getMessage()); 83 e.printStackTrace(); 84 System.exit(1); 85 } catch (java.io.IOException e) { 86 System.out.println("IOException: "+e.getMessage()); 87 System.exit(1); 88 } catch (javax.xml.parsers.ParserConfigurationException e) { 89 System.out.println("ParserConfigurationExceptioni: "+e.getMessage() ); 90 System.exit(1); 91 } catch (org.xml.sax.SAXException e) { 92 System.out.println("SAXException: "+e.getMessage() ); 93 System.exit(1); 94 } 95 return null; 96 } 97 98 private static String fullNameToFileName(String clname, String ddname) { 99 clname = clname.replaceAll("::", "/"); 100 clname = clname.replace('[', '/'); 101 clname = clname.replace(']', '/'); 102 clname = clname + ddname; 103 if (clname.charAt(0) != '/') 104 clname = "/" + clname; 105 return clname; 106 } 107 } 108 | Popular Tags |