1 25 26 27 package org.objectweb.jonas_ejb.genic; 28 29 30 import java.lang.reflect.Field ; 31 32 import org.objectweb.jonas_ejb.deployment.api.FieldDesc; 33 import org.objectweb.jonas_ejb.lib.JavaType; 34 import org.objectweb.jonas_ejb.lib.JormType; 35 36 37 42 43 public class VcField { 44 45 48 private String mName = null; 49 52 private String mTypeName = null; 53 56 private boolean isPrimaryKey = false; 57 60 private boolean mIsCmp1 = false; 61 64 67 private String mDefaultValue = null; 68 71 private String mSqlTypeName = null; 72 75 private String mSqlGetMethod = null; 76 79 private String mSqlSetMethod = null; 80 83 private boolean hasNotPrimitiveType = false; 84 87 private boolean hasBigIntegerType = false; 88 91 private boolean hasSerializableType = false; 92 95 private boolean hasJavaLangTypeExceptString = false; 96 99 102 private String jormTypeName = null; 103 106 private boolean mustBeConvert = false; 107 110 private String convertClassName = null; 111 112 119 public VcField(String mName, Class fType, FieldDesc fd, boolean isCmp1) { 120 mIsCmp1 = isCmp1; 121 this.mName = mName; 122 mTypeName = JavaType.getName(fType); 123 isPrimaryKey = fd.isPrimaryKey(); 124 mDefaultValue = JavaType.getDefaultValue(fType); 125 if (mIsCmp1) { 126 mSqlTypeName = JavaType.getSQLType(fType); 128 mSqlGetMethod = JavaType.getSQLGetMethod(fType); 129 mSqlSetMethod = JavaType.getSQLSetMethod(fType); 130 hasNotPrimitiveType = !fType.isPrimitive(); 131 hasBigIntegerType = fType.equals(java.math.BigInteger .class); 132 hasSerializableType = "setSerializable".equals(mSqlSetMethod) 133 && "getSerializable".equals(mSqlGetMethod); 134 hasJavaLangTypeExceptString = false; 135 if (fType.getPackage() != null) { 136 if ("java.lang".equals(fType.getPackage().getName()) 137 && !java.lang.String .class.equals(fType)) { 138 hasJavaLangTypeExceptString = true; 139 } 140 } 141 } else { 142 jormTypeName = JormType.getPType(fType, isPrimaryKey).getJavaName(); 144 if (fType.equals(java.sql.Date .class)) { 145 mustBeConvert = true; 146 convertClassName = "org.objectweb.jonas_ejb.lib.SqlDateFieldMapping"; 147 } else if (fType.equals(java.sql.Time .class)) { 148 mustBeConvert = true; 149 convertClassName = "org.objectweb.jonas_ejb.lib.SqlTimeFieldMapping"; 150 } else if (fType.equals(java.sql.Timestamp .class)) { 151 mustBeConvert = true; 152 convertClassName = "org.objectweb.jonas_ejb.lib.SqlTimestampFieldMapping"; 153 } else if (isPrimaryKey && fType.equals(Float .class)) { 154 mustBeConvert = true; 156 convertClassName = "org.objectweb.jonas_ejb.lib.FloatPkFieldMapping"; 157 } 158 } 159 } 160 161 166 VcField(Field field, FieldDesc fd) { 167 this(field.getName(), field.getType(), fd, true); 168 } 169 170 174 VcField(FieldDesc fd) { 175 this(fd.getName(), fd.getFieldType(), fd, false); 176 } 177 178 181 public String getName() { 182 return mName; 183 } 184 185 188 public String getNameUpperFirst() { 189 return Character.toUpperCase(mName.charAt(0)) + mName.substring(1); 190 } 191 192 195 public String getGetterName() { 196 return "get" + Character.toUpperCase(mName.charAt(0)) + mName.substring(1); 197 } 198 199 202 public String getSetterName() { 203 return "set" + Character.toUpperCase(mName.charAt(0)) + mName.substring(1); 204 } 205 206 209 public String getTypeName() { 210 return mTypeName; 211 } 212 213 216 public boolean isPrimaryKey() { 217 return isPrimaryKey; 218 } 219 220 223 226 public String getDefaultValue() { 227 return mDefaultValue; 228 } 229 230 233 public String getSqlTypeName() { 234 return mSqlTypeName; 235 } 236 237 240 public String getSqlGetMethod() { 241 return mSqlGetMethod; 242 } 243 244 247 public String getSqlSetMethod() { 248 return mSqlSetMethod; 249 } 250 251 254 public boolean hasNotPrimitiveType() { 255 return hasNotPrimitiveType; 256 } 257 258 261 public boolean hasBigIntegerType() { 262 return hasBigIntegerType; 263 } 264 265 268 public boolean hasSerializableType() { 269 return hasSerializableType; 270 } 271 272 275 public boolean hasJavaLangTypeExceptString() { 276 return hasJavaLangTypeExceptString; 277 } 278 279 282 285 public String getJormTypeName() { 286 return jormTypeName; 287 } 288 289 292 public boolean isMustBeConvert() { 293 return mustBeConvert; 294 } 295 296 299 public String getConvertClassName() { 300 return convertClassName; 301 } 302 303 306 public String toString() { 307 StringBuffer ret = new StringBuffer (); 308 ret.append("\n Name = " + getName()); 309 ret.append("\n isPrimaryKey = " + isPrimaryKey()); 310 ret.append("\n NameUpperFirst = " + getNameUpperFirst()); 311 ret.append("\n GetterName = " + getGetterName()); 312 ret.append("\n SetterName = " + getSetterName()); 313 ret.append("\n TypeName = " + getTypeName()); 314 ret.append("\n DefaultValue = " + getDefaultValue()); 315 if (mIsCmp1) { 316 ret.append("\n SqlTypeName = " + getSqlTypeName()); 317 ret.append("\n SqlGetMethod = " + getSqlGetMethod()); 318 ret.append("\n SqlSetMethod = " + getSqlSetMethod()); 319 ret.append("\n hasNotPrimitiveType = " + hasNotPrimitiveType()); 320 ret.append("\n hasBigIntegerType = " + hasBigIntegerType()); 321 ret.append("\n hasSerializableType = " + hasSerializableType()); 322 ret.append("\n hasJavaLangTypeExceptString = " + hasJavaLangTypeExceptString()); 323 } else { 324 ret.append("\n JormTypeName = " + getJormTypeName()); 325 ret.append("\n MustBeConvert = " + isMustBeConvert()); 326 ret.append("\n ConvertClassName = " + getConvertClassName()); 327 } 328 return (ret.toString()); 329 } 330 331 } 332 | Popular Tags |