1 package org.apache.ojb.broker.metadata.fieldaccess; 2 3 17 18 import java.util.Vector ; 19 20 import org.apache.ojb.broker.metadata.ClassDescriptor; 21 import org.apache.ojb.broker.metadata.MetadataException; 22 import org.apache.ojb.broker.util.ClassHelper; 23 24 28 public class AnonymousPersistentFieldForInheritance extends AnonymousPersistentField 29 { 30 private static final long serialVersionUID = -8367827598025566663L; 31 32 ClassDescriptor cld = null; 33 34 public AnonymousPersistentFieldForInheritance(ClassDescriptor cld, String fieldname) 35 { 36 super(fieldname); 37 this.cld = cld; 38 } 39 40 private void copyObjectToObject(Object fromObject, Object toObject) 41 { 42 Vector persistentFields = cld.getSuperPersistentFieldDescriptors(); 43 for (int i = persistentFields.size() - 1; i >= 0; i--) 44 { 45 PersistentField pf = (PersistentField) persistentFields.get(i); 46 pf.set(toObject, pf.get(fromObject)); 47 } 48 } 49 50 58 public synchronized void set(Object obj, Object value) throws MetadataException 59 { 60 copyObjectToObject(value, obj); 61 putToFieldCache(obj, value); 62 } 63 64 71 public synchronized Object get(Object obj) throws MetadataException 72 { 73 Object value = getFromFieldCache(obj); 74 if (null == value) 75 { 76 try 77 { 78 ClassDescriptor baseCld = cld.getRepository().getDescriptorFor(cld.getBaseClass()); 79 value = ClassHelper.buildNewObjectInstance(baseCld); 80 } 81 catch (Exception e) 82 { 83 throw new MetadataException("Can't create new base class object for '" + cld.getBaseClass()+"'", e); 84 } 85 putToFieldCache(obj, value); 86 } 87 88 copyObjectToObject(obj, value); 89 return value; 90 } 91 } 92 | Popular Tags |