1 22 package org.jboss.aop.metadata; 23 import org.jboss.aop.joinpoint.FieldInvocation; 24 import org.jboss.aop.joinpoint.Invocation; 25 import org.jboss.aop.util.PayloadKey; 26 27 import java.lang.reflect.Field ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 36 public class FieldMetaData implements MetaDataResolver 37 { 38 HashMap fieldMetaData = new HashMap (); 39 40 public boolean hasTag(String tag) 41 { 42 Iterator values = fieldMetaData.values().iterator(); 43 while (values.hasNext()) 44 { 45 SimpleMetaData map = (SimpleMetaData)values.next(); 46 if (map.hasTag(tag)) return true; 47 } 48 return false; 49 } 50 public boolean hasTag(Field field, String tag) 51 { 52 return hasTag(field.getName(), tag); 53 } 54 55 56 57 public synchronized boolean hasTag(String fieldName, String tag) 58 { 59 SimpleMetaData meta = getFieldMetaData(fieldName); 60 if (meta == null) return false; 61 return meta.hasTag(tag); 62 } 63 64 public void tagField(Field field, Object tag) 65 { 66 addFieldMetaData(field, tag, EMPTY_TAG, new Object (), PayloadKey.TRANSIENT); 67 } 68 69 public void tagField(String field, Object tag) 70 { 71 addFieldMetaData(field, tag, EMPTY_TAG, new Object (), PayloadKey.TRANSIENT); 72 } 73 74 public void addFieldMetaData(Field field, Object tag, Object attr, Object value) 75 { 76 addFieldMetaData(field, tag, attr, value, PayloadKey.MARSHALLED); 77 } 78 79 public void addFieldMetaData(Field field, Object tag, Object attr, Object value, PayloadKey type) 80 { 81 addFieldMetaData(field.getName(), tag, attr, value, type); 82 } 83 public void addFieldMetaData(String key, Object tag, Object attr, Object value) 84 { 85 addFieldMetaData(key, tag, attr, value, PayloadKey.MARSHALLED); 86 } 87 public synchronized void addFieldMetaData(String key, Object tag, Object attr, Object value, PayloadKey type) 88 { 89 String fieldName = key; 90 SimpleMetaData fieldData = (SimpleMetaData)fieldMetaData.get(fieldName); 91 if (fieldData == null) 92 { 93 fieldData = new SimpleMetaData(); 94 fieldMetaData.put(fieldName, fieldData); 95 } 96 fieldData.addMetaData(tag, attr, value, type); 97 } 98 99 public Object getFieldMetaData(Field field, Object tag, Object attr) 100 { 101 SimpleMetaData data = getFieldMetaData(field.getName()); 102 if (data == null) return null; 103 return data.getMetaData(tag, attr); 104 } 105 106 public synchronized Object getFieldMetaData(String fieldName, Object tag, Object attr) 107 { 108 SimpleMetaData fieldData = (SimpleMetaData)fieldMetaData.get(fieldName); 109 if (fieldData == null) return null; 110 return fieldData.getMetaData(tag, attr); 111 } 112 113 public synchronized Iterator getFields() 114 { 115 return fieldMetaData.keySet().iterator(); 116 } 117 118 public synchronized SimpleMetaData getFieldMetaData(String field) 119 { 120 return (SimpleMetaData)fieldMetaData.get(field); 121 } 122 123 public synchronized void clear() 124 { 125 fieldMetaData.clear(); 126 } 127 128 public Object resolve(Invocation invocation, Object tag, Object attr) 129 { 130 Field field = ((FieldInvocation)invocation).getField(); 131 return getFieldMetaData(field, tag, attr); 132 } 133 134 public synchronized SimpleMetaData getAllMetaData(Invocation invocation) 135 { 136 Field field = ((FieldInvocation)invocation).getField(); 137 return (SimpleMetaData)fieldMetaData.get(field); 138 } 139 } 140 | Popular Tags |