EntityCmp1Desc.java

00001 
00026 package org.objectweb.jonas_ejb.deployment.api;
00027 
00028 import java.lang.reflect.Field;
00029 import java.lang.reflect.Method;
00030 import java.util.Iterator;
00031 
00032 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
00033 import org.objectweb.jonas_ejb.deployment.xml.Entity;
00034 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
00035 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
00036 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00037 
00044 public class EntityCmp1Desc extends EntityCmpDesc {
00045 
00046     protected Method isModifiedMethod = null;
00047 
00051     public EntityCmp1Desc(ClassLoader classLoader, Entity ent,
00052                           AssemblyDescriptor asd, JonasEntity jEnt,
00053                           JLinkedList jMDRList, String fileName)
00054         throws DeploymentDescException {
00055         
00056         super(classLoader, ent, asd, jEnt, jMDRList, fileName);
00057 
00058         // check if persistent fields map to fields
00059         for (Iterator i = fieldDesc.keySet().iterator();i.hasNext();) {
00060             String fn = (String)i.next();
00061             // check for valid field name
00062             try {
00063                 Field f = ejbClass.getField(fn);
00064                 ((FieldDesc)(fieldDesc.get(fn))).setFieldType(f.getType());
00065             } catch (NoSuchFieldException e) {
00066                 throw new DeploymentDescException("Invalid field name "+fn+" in field-name in bean "+this.ejbName,e);
00067             } catch (SecurityException e) {
00068                 throw new DeploymentDescException("Cannot use java reflexion on "+this.ejbClass.getName());
00069             }
00070         }
00071 
00072         // isModifiedMethod
00073         if (jEnt.getIsModifiedMethodName() != null) {
00074             String mName = jEnt.getIsModifiedMethodName();
00075             try {
00076                 isModifiedMethod = this.ejbClass.getMethod(mName, new Class[0]);
00077             } catch (NoSuchMethodException e) {
00078                 isModifiedMethod = null;
00079                 throw new DeploymentDescException(mName + " is not a method of " + this.ejbClass.getName());
00080             } catch (SecurityException e) {
00081                 throw new DeploymentDescException("Cannot use java reflexion on " + this.ejbClass.getName());
00082             }
00083         }
00084         if (isUndefinedPK()) {
00085            FieldDesc fd = this.newFieldDescInstance();
00086            fd.setName("JONASAUTOPKFIELD");
00087            fd.setPrimaryKey(true);
00088            fieldDesc.put("JONASAUTOPKFIELD", fd);
00089            ((FieldDesc) (fieldDesc.get("JONASAUTOPKFIELD"))).setFieldType(java.lang.Integer.class); 
00090            ((FieldJdbcDesc) (fieldDesc.get("JONASAUTOPKFIELD"))).setJdbcFieldName(this.getJdbcAutomaticPkFieldName());
00091         } 
00092     }
00093 
00099     public FieldDesc getCmpFieldDesc(Field field) {
00100         FieldDesc ret = (FieldDesc) fieldDesc.get(field.getName());
00101         if (ret == null)
00102             throw new Error("Field " + field.getName() + " is not a cmp field of class " + this.ejbClass.getName());
00103         return ret;
00104     }
00105 
00106 
00112     public Method getIsModifiedMethod(){
00113         if (isModifiedMethod == null)
00114             throw new Error("No isModified method defined for bean " + this.ejbName);
00115         return isModifiedMethod;
00116     }
00117 
00122     public boolean hasIsModifiedMethod(){
00123         return isModifiedMethod != null;
00124     }
00125 
00131     public boolean hasCmpFieldDesc(Field field) {
00132         return fieldDesc.containsKey(field.getName());
00133     }
00134 
00139     public String toString() {
00140         StringBuffer ret = new StringBuffer();
00141         ret.append(super.toString());
00142         if (hasIsModifiedMethod())
00143             ret.append("getIsModifiedMethod()=" + getIsModifiedMethod().toString());
00144         return ret.toString();
00145     }
00146 
00147 }

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