1 package org.apache.ojb.broker.metadata.fieldaccess; 2 3 17 18 import java.util.Map ; 19 20 import org.apache.commons.collections.map.ReferenceIdentityMap; 21 import org.apache.ojb.broker.metadata.MetadataException; 22 23 29 public class AnonymousPersistentField implements PersistentField 30 { 31 private static final long serialVersionUID = 3989863424358352941L; 32 33 private transient Map fkCache; 34 private String fieldname; 35 36 public AnonymousPersistentField(String fieldname) 37 { 38 this.fieldname = fieldname; 39 } 40 41 public synchronized void set(Object obj, Object value) throws MetadataException 42 { 43 putToFieldCache(obj, value); 44 } 45 46 public synchronized Object get(Object anObject) throws MetadataException 47 { 48 return getFromFieldCache(anObject); 49 } 50 51 78 protected void putToFieldCache(Object key, Object value) 79 { 80 if (key != null) 81 { 82 if (fkCache == null) 83 { 84 fkCache = new ReferenceIdentityMap (ReferenceIdentityMap.WEAK, ReferenceIdentityMap.HARD, true); 85 } 86 if (value != null) 87 fkCache.put(key, value); 88 else 89 fkCache.remove (key); 90 } 91 } 92 93 protected Object getFromFieldCache(Object key) 94 { 95 return (key != null && fkCache != null) ? fkCache.get(key) : null; 96 } 97 98 102 public Class getDeclaringClass() 103 { 104 return null; 105 } 106 107 110 public String getName() 111 { 112 return fieldname; 113 } 114 115 119 public Class getType() 120 { 121 return null; 122 } 123 124 128 public boolean usesAccessorsAndMutators() 129 { 130 return false; 131 } 132 } 133 | Popular Tags |