VcField.java

00001 
00027 package org.objectweb.jonas_ejb.genic;
00028 
00029 
00030 import java.lang.reflect.Field;
00031 
00032 import org.objectweb.jonas_ejb.deployment.api.FieldDesc;
00033 import org.objectweb.jonas_ejb.lib.JavaType;
00034 import org.objectweb.jonas_ejb.lib.JormType;
00035 
00036 
00043 public class VcField {
00044 
00048     private String  mName = null;
00052     private String  mTypeName = null;
00056     private boolean isPrimaryKey = false;
00060     private boolean mIsCmp1 = false;
00061     /*
00062      *  For Cmp1 only
00063      */
00067     private String  mDefaultValue = null;
00071     private String  mSqlTypeName = null;
00075     private String  mSqlGetMethod = null;
00079     private String  mSqlSetMethod = null;
00083     private boolean hasNotPrimitiveType = false;
00087     private boolean hasBigIntegerType = false;
00091     private boolean hasSerializableType = false;
00095     private boolean hasJavaLangTypeExceptString = false;
00096     /*
00097      * For CMP2 only
00098      */
00102     private String  jormTypeName = null;
00106     private boolean mustBeConvert = false;
00110     private String  convertClassName = null;
00111 
00119     public VcField(String mName, Class fType, FieldDesc fd, boolean isCmp1) {
00120         mIsCmp1 = isCmp1;
00121         this.mName = mName;
00122         mTypeName = JavaType.getName(fType);
00123         isPrimaryKey = fd.isPrimaryKey();
00124         mDefaultValue = JavaType.getDefaultValue(fType);
00125         if (mIsCmp1) {
00126             // CMP 1
00127             mSqlTypeName = JavaType.getSQLType(fType);
00128             mSqlGetMethod = JavaType.getSQLGetMethod(fType);
00129             mSqlSetMethod = JavaType.getSQLSetMethod(fType);
00130             hasNotPrimitiveType = !fType.isPrimitive();
00131             hasBigIntegerType = fType.equals(java.math.BigInteger.class);
00132             hasSerializableType = "setSerializable".equals(mSqlSetMethod)
00133                 && "getSerializable".equals(mSqlGetMethod);
00134             hasJavaLangTypeExceptString = false;
00135             if (fType.getPackage() != null) {
00136                 if ("java.lang".equals(fType.getPackage().getName())
00137                     && !java.lang.String.class.equals(fType)) {
00138                     hasJavaLangTypeExceptString = true;
00139                 }
00140             }
00141         } else {
00142             // CMP 2
00143             jormTypeName = JormType.getPType(fType, isPrimaryKey).getJavaName();
00144             if (fType.equals(java.sql.Date.class)) {
00145                 mustBeConvert = true;
00146                 convertClassName = "org.objectweb.jonas_ejb.lib.SqlDateFieldMapping";
00147             } else if (fType.equals(java.sql.Time.class)) {
00148                 mustBeConvert = true;
00149                 convertClassName = "org.objectweb.jonas_ejb.lib.SqlTimeFieldMapping";
00150             } else if (fType.equals(java.sql.Timestamp.class)) {
00151                 mustBeConvert = true;
00152                 convertClassName = "org.objectweb.jonas_ejb.lib.SqlTimestampFieldMapping";
00153             } else if (isPrimaryKey && fType.equals(Float.class)) {
00154                 // JORM does not support Float for the primary key, we must so convert it
00155                 mustBeConvert = true;
00156                 convertClassName = "org.objectweb.jonas_ejb.lib.FloatPkFieldMapping";
00157             }
00158         }
00159     }
00160 
00166     VcField(Field field, FieldDesc fd) {
00167         this(field.getName(), field.getType(), fd, true);
00168     }
00169 
00174     VcField(FieldDesc fd) {
00175         this(fd.getName(), fd.getFieldType(), fd, false);
00176     }
00177 
00181     public String getName() {
00182         return mName;
00183     }
00184 
00188     public String getNameUpperFirst() {
00189         return Character.toUpperCase(mName.charAt(0)) + mName.substring(1);
00190     }
00191 
00195     public String getGetterName() {
00196         return "get" + Character.toUpperCase(mName.charAt(0)) + mName.substring(1);
00197     }
00198 
00202     public String getSetterName() {
00203         return "set" + Character.toUpperCase(mName.charAt(0)) + mName.substring(1);
00204     }
00205 
00209     public String getTypeName() {
00210         return mTypeName;
00211     }
00212 
00216     public boolean isPrimaryKey() {
00217         return isPrimaryKey;
00218     }
00219 
00220     /*
00221      * CMP version 1 only
00222      */
00226     public String getDefaultValue() {
00227         return mDefaultValue;
00228     }
00229 
00233     public String getSqlTypeName() {
00234         return mSqlTypeName;
00235     }
00236 
00240     public String getSqlGetMethod() {
00241         return mSqlGetMethod;
00242     }
00243 
00247     public String getSqlSetMethod() {
00248         return mSqlSetMethod;
00249     }
00250 
00254     public boolean hasNotPrimitiveType() {
00255         return hasNotPrimitiveType;
00256     }
00257 
00261     public boolean hasBigIntegerType() {
00262         return hasBigIntegerType;
00263     }
00264 
00268     public boolean hasSerializableType() {
00269         return hasSerializableType;
00270     }
00271 
00275     public boolean hasJavaLangTypeExceptString() {
00276         return hasJavaLangTypeExceptString;
00277     }
00278 
00279     /*
00280      * CMP version 2 only
00281      */
00285     public String getJormTypeName() {
00286         return jormTypeName;
00287     }
00288 
00292     public boolean isMustBeConvert() {
00293         return mustBeConvert;
00294     }
00295 
00299     public String getConvertClassName() {
00300         return convertClassName;
00301     }
00302 
00306     public String toString() {
00307         StringBuffer ret = new StringBuffer();
00308         ret.append("\n    Name                 = " + getName());
00309         ret.append("\n    isPrimaryKey         = " + isPrimaryKey());
00310         ret.append("\n    NameUpperFirst       = " + getNameUpperFirst());
00311         ret.append("\n    GetterName           = " + getGetterName());
00312         ret.append("\n    SetterName           = " + getSetterName());
00313         ret.append("\n    TypeName             = " + getTypeName());
00314         ret.append("\n    DefaultValue         = " + getDefaultValue());
00315         if (mIsCmp1) {
00316             ret.append("\n    SqlTypeName          = " + getSqlTypeName());
00317             ret.append("\n    SqlGetMethod         = " + getSqlGetMethod());
00318             ret.append("\n    SqlSetMethod         = " + getSqlSetMethod());
00319             ret.append("\n    hasNotPrimitiveType  = " + hasNotPrimitiveType());
00320             ret.append("\n    hasBigIntegerType    = " + hasBigIntegerType());
00321             ret.append("\n    hasSerializableType  = " + hasSerializableType());
00322             ret.append("\n    hasJavaLangTypeExceptString = " + hasJavaLangTypeExceptString());
00323         } else {
00324             ret.append("\n    JormTypeName         = " + getJormTypeName());
00325             ret.append("\n    MustBeConvert        = " + isMustBeConvert());
00326             ret.append("\n    ConvertClassName     = " + getConvertClassName());
00327         }
00328         return (ret.toString());
00329     }
00330 
00331 }

Generated on Tue Feb 15 15:05:48 2005 for JOnAS by  doxygen 1.3.9.1