1 25 26 package org.objectweb.jonas_ejb.deployment.api; 27 28 import java.lang.reflect.Field ; 29 import java.lang.reflect.Method ; 30 import java.util.Iterator ; 31 32 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor; 33 import org.objectweb.jonas_ejb.deployment.xml.Entity; 34 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity; 35 import org.objectweb.jonas_lib.deployment.xml.JLinkedList; 36 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 37 38 44 public class EntityCmp1Desc extends EntityCmpDesc { 45 46 protected Method isModifiedMethod = null; 47 48 51 public EntityCmp1Desc(ClassLoader classLoader, Entity ent, 52 AssemblyDescriptor asd, JonasEntity jEnt, 53 JLinkedList jMDRList, String fileName) 54 throws DeploymentDescException { 55 56 super(classLoader, ent, asd, jEnt, jMDRList, fileName); 57 58 for (Iterator i = fieldDesc.keySet().iterator();i.hasNext();) { 60 String fn = (String )i.next(); 61 try { 63 Field f = ejbClass.getField(fn); 64 ((FieldDesc)(fieldDesc.get(fn))).setFieldType(f.getType()); 65 } catch (NoSuchFieldException e) { 66 throw new DeploymentDescException("Invalid field name "+fn+" in field-name in bean "+this.ejbName,e); 67 } catch (SecurityException e) { 68 throw new DeploymentDescException("Cannot use java reflexion on "+this.ejbClass.getName()); 69 } 70 } 71 72 if (jEnt.getIsModifiedMethodName() != null) { 74 String mName = jEnt.getIsModifiedMethodName(); 75 try { 76 isModifiedMethod = this.ejbClass.getMethod(mName, new Class [0]); 77 } catch (NoSuchMethodException e) { 78 isModifiedMethod = null; 79 throw new DeploymentDescException(mName + " is not a method of " + this.ejbClass.getName()); 80 } catch (SecurityException e) { 81 throw new DeploymentDescException("Cannot use java reflexion on " + this.ejbClass.getName()); 82 } 83 } 84 if (isUndefinedPK()) { 85 FieldDesc fd = this.newFieldDescInstance(); 86 fd.setName("JONASAUTOPKFIELD"); 87 fd.setPrimaryKey(true); 88 fieldDesc.put("JONASAUTOPKFIELD", fd); 89 ((FieldDesc) (fieldDesc.get("JONASAUTOPKFIELD"))).setFieldType(java.lang.Integer .class); 90 ((FieldJdbcDesc) (fieldDesc.get("JONASAUTOPKFIELD"))).setJdbcFieldName(this.getJdbcAutomaticPkFieldName()); 91 } 92 } 93 94 99 public FieldDesc getCmpFieldDesc(Field field) { 100 FieldDesc ret = (FieldDesc) fieldDesc.get(field.getName()); 101 if (ret == null) 102 throw new Error ("Field " + field.getName() + " is not a cmp field of class " + this.ejbClass.getName()); 103 return ret; 104 } 105 106 107 112 public Method getIsModifiedMethod(){ 113 if (isModifiedMethod == null) 114 throw new Error ("No isModified method defined for bean " + this.ejbName); 115 return isModifiedMethod; 116 } 117 118 122 public boolean hasIsModifiedMethod(){ 123 return isModifiedMethod != null; 124 } 125 126 131 public boolean hasCmpFieldDesc(Field field) { 132 return fieldDesc.containsKey(field.getName()); 133 } 134 135 139 public String toString() { 140 StringBuffer ret = new StringBuffer (); 141 ret.append(super.toString()); 142 if (hasIsModifiedMethod()) 143 ret.append("getIsModifiedMethod()=" + getIsModifiedMethod().toString()); 144 return ret.toString(); 145 } 146 147 } 148 | Popular Tags |