1 21 package oracle.toplink.essentials.internal.expressions; 23 24 import java.io.*; 25 import java.math.*; 26 import java.util.Calendar ; 27 import oracle.toplink.essentials.internal.databaseaccess.*; 28 import oracle.toplink.essentials.internal.helper.ClassConstants; 29 import oracle.toplink.essentials.internal.helper.ConversionManager; 30 31 39 public class ExpressionJavaPrinter { 40 41 protected StringWriter writer; 43 44 protected String builderString; 46 47 protected DatabasePlatform platform; 49 50 public ExpressionJavaPrinter(String builderString, StringWriter writer, DatabasePlatform platform) { 51 this.builderString = builderString; 52 this.writer = writer; 53 this.platform = platform; 54 } 55 56 public String getBuilderString() { 57 return builderString; 58 } 59 60 public DatabasePlatform getPlatform() { 61 return platform; 62 } 63 64 public StringWriter getWriter() { 65 return writer; 66 } 67 68 public void printString(String value) { 69 getWriter().write(value); 70 } 71 72 public void printJava(Object object) { 74 if (object == null) { 75 printString("null"); 76 } else if (object.getClass() == ClassConstants.STRING) { 77 printString("\""); 78 printString((String )object); 79 printString("\""); 80 } else if (object instanceof Calendar ) { 81 printString("new java.util.Date("); 82 printString(String.valueOf(((Calendar )object).getTimeInMillis())); 83 printString("L)"); 84 } else if (object.getClass() == ClassConstants.TIMESTAMP) { 85 printString("new java.sql.Timestamp("); 86 printString(String.valueOf(((java.sql.Timestamp )object).getTime())); 87 printString("L)"); 88 } else if (object.getClass() == ClassConstants.SQLDATE) { 89 printString("new java.sql.Date("); 90 printString(String.valueOf(((java.sql.Date )object).getTime())); 91 printString("L)"); 92 } else if (object.getClass() == ClassConstants.TIME) { 93 printString("new java.sql.Time("); 94 printString(String.valueOf(((java.sql.Time )object).getTime())); 95 printString("L)"); 96 } else if (object.getClass() == ClassConstants.UTILDATE) { 97 printString("new java.util.Date("); 98 printString(String.valueOf(((java.util.Date )object).getTime())); 99 printString("L)"); 100 } else if (object.getClass() == ClassConstants.BYTE) { 101 printByte((Byte )object); 102 } else if (object.getClass() == ClassConstants.APBYTE) { 103 printString("new byte[] {"); 104 byte[] bytes = (byte[])object; 105 if (bytes.length > 0) { 106 printString(String.valueOf((int)bytes[0])); 107 for (int index = 1; index < bytes.length; index++) { 108 printString(","); 109 printString(String.valueOf((int)bytes[index])); 110 } 111 } 112 printString("}"); 113 } else if (object.getClass() == ClassConstants.ABYTE) { 114 printString("new Byte[] {"); 115 Byte [] bytes = (Byte [])object; 116 if (bytes.length > 0) { 117 printByte(bytes[0]); 118 for (int index = 1; index < bytes.length; index++) { 119 printString(","); 120 printByte(bytes[index]); 121 } 122 } 123 printString("}"); 124 } else if (object.getClass() == ClassConstants.CHAR) { 125 printCharacter((Character )object); 126 } else if (object.getClass() == ClassConstants.APCHAR) { 127 printString("new char[] {"); 128 char[] chars = (char[])object; 129 if (chars.length > 0) { 130 printString("'"); 131 printString(String.valueOf(chars[0])); 132 printString("'"); 133 for (int index = 1; index < chars.length; index++) { 134 printString(","); 135 printString("'"); 136 printString(String.valueOf(chars[index])); 137 printString("'"); 138 } 139 } 140 printString("}"); 141 } else if (object.getClass() == ClassConstants.ACHAR) { 142 printString("new Character[] {"); 143 Character [] chars = (Character [])object; 144 if (chars.length > 0) { 145 printCharacter(chars[0]); 146 for (int index = 1; index < chars.length; index++) { 147 printString(","); 148 printCharacter(chars[index]); 149 } 150 } 151 printString("}"); 152 } else if (object.getClass() == ClassConstants.BIGDECIMAL) { 153 printString("new java.math.BigDecimal(\""); 154 printString(((BigDecimal)object).toString()); 155 printString("\")"); 156 } else if (object.getClass() == ClassConstants.BIGINTEGER) { 157 printString("new java.math.BigInteger(\""); 158 printString(((BigInteger)object).toString()); 159 printString("\")"); 160 } else { 161 printString((String )ConversionManager.getDefaultManager().convertObject(object, String .class)); 162 } 163 164 } 165 166 public void printByte(Byte aByte) { 167 printString("new Byte((byte)"); 168 printString((aByte).toString()); 169 printString(")"); 170 } 171 172 public void printCharacter(Character aCharacter) { 173 printString("new Character('"); 174 printString((aCharacter).toString()); 175 printString("')"); 176 } 177 } 178 | Popular Tags |