1 21 22 package org.apache.derby.impl.services.bytecode; 23 24 import org.apache.derby.iapi.services.compiler.ClassBuilder; 25 import org.apache.derby.iapi.services.loader.ClassFactory; 26 import org.apache.derby.iapi.services.loader.GeneratedClass; 27 import org.apache.derby.iapi.error.StandardException; 28 import org.apache.derby.iapi.services.sanity.SanityManager; 29 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 30 import org.apache.derby.iapi.services.monitor.Monitor; 31 32 import org.apache.derby.iapi.util.ByteArray; 33 34 import java.io.File ; 35 import java.io.FileOutputStream ; 36 import java.io.IOException ; 37 38 44 public abstract class GClass implements ClassBuilder { 45 46 protected ByteArray bytecode; 47 protected final ClassFactory cf; 48 protected final String qualifiedName; 49 50 51 52 public GClass(ClassFactory cf, String qualifiedName) { 53 this.cf = cf; 54 this.qualifiedName = qualifiedName; 55 } 56 public String getFullName() { 57 return qualifiedName; 58 } 59 public GeneratedClass getGeneratedClass() throws StandardException { 60 return cf.loadGeneratedClass(qualifiedName, getClassBytecode()); 61 } 62 63 protected void writeClassFile(String dir, boolean logMessage, Throwable t) 64 throws StandardException { 65 66 if (SanityManager.DEBUG) { 67 68 if (bytecode == null) getClassBytecode(); 70 if (dir == null) dir=""; 71 72 String filename = getName(); 74 filename = filename + ".class"; 75 76 File classFile = new File (dir,filename); 77 78 HeaderPrintWriter errorStream = Monitor.getStream(); 80 81 try { 82 FileOutputStream fis = new FileOutputStream (classFile); 83 fis.write(bytecode.getArray(), 84 bytecode.getOffset(), bytecode.getLength()); 85 fis.flush(); 86 if (logMessage) { 87 errorStream.printlnWithHeader("Wrote class "+getFullName()+" to file "+classFile.toString()+". Please provide support with the file and the following exception message: "+t); 88 } 89 fis.close(); 90 } catch (IOException e) { 91 if (SanityManager.DEBUG) 92 SanityManager.THROWASSERT("Unable to write .class file"); 93 } 94 } 95 } 96 97 final void validateType(String typeName1) 98 { 99 if (SanityManager.DEBUG) 100 { 101 SanityManager.ASSERT(typeName1 != null); 102 103 String typeName = typeName1.trim(); 104 105 if ("void".equals(typeName)) return; 106 107 while (typeName.endsWith("[]")) typeName = typeName.substring(0,typeName.length()-2); 109 110 SanityManager.ASSERT(typeName.length() > 0); 111 112 if ("boolean".equals(typeName)) return; 114 if ("byte".equals(typeName)) return; 115 if ("char".equals(typeName)) return; 116 if ("double".equals(typeName)) return; 117 if ("float".equals(typeName)) return; 118 if ("int".equals(typeName)) return; 119 if ("long".equals(typeName)) return; 120 if ("short".equals(typeName)) return; 121 122 try { 129 if (cf == null) 130 Class.forName(typeName); 131 else 132 cf.loadApplicationClass(typeName); 133 } catch (ClassNotFoundException cnfe) { 134 SanityManager.THROWASSERT("Class "+typeName+" not found"); 135 } 136 137 return; 139 } 140 } 141 } 142 | Popular Tags |