KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > metadata > FieldMetaData


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 /**
31  *
32  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
33  * @version $Revision: 37406 $
34  *
35  */

36 public class FieldMetaData implements MetaDataResolver
37 {
38    HashMap JavaDoc fieldMetaData = new HashMap JavaDoc();
39
40    public boolean hasTag(String JavaDoc tag)
41    {
42       Iterator JavaDoc 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 JavaDoc field, String JavaDoc tag)
51    {
52       return hasTag(field.getName(), tag);
53    }
54
55
56
57    public synchronized boolean hasTag(String JavaDoc fieldName, String JavaDoc 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 JavaDoc field, Object JavaDoc tag)
65    {
66       addFieldMetaData(field, tag, EMPTY_TAG, new Object JavaDoc(), PayloadKey.TRANSIENT);
67    }
68
69    public void tagField(String JavaDoc field, Object JavaDoc tag)
70    {
71       addFieldMetaData(field, tag, EMPTY_TAG, new Object JavaDoc(), PayloadKey.TRANSIENT);
72    }
73
74    public void addFieldMetaData(Field JavaDoc field, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value)
75    {
76       addFieldMetaData(field, tag, attr, value, PayloadKey.MARSHALLED);
77    }
78
79    public void addFieldMetaData(Field JavaDoc field, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value, PayloadKey type)
80    {
81       addFieldMetaData(field.getName(), tag, attr, value, type);
82    }
83    public void addFieldMetaData(String JavaDoc key, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value)
84    {
85       addFieldMetaData(key, tag, attr, value, PayloadKey.MARSHALLED);
86    }
87    public synchronized void addFieldMetaData(String JavaDoc key, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value, PayloadKey type)
88    {
89       String JavaDoc 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 JavaDoc getFieldMetaData(Field JavaDoc field, Object JavaDoc tag, Object JavaDoc 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 JavaDoc getFieldMetaData(String JavaDoc fieldName, Object JavaDoc tag, Object JavaDoc 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 JavaDoc getFields()
114    {
115       return fieldMetaData.keySet().iterator();
116    }
117
118    public synchronized SimpleMetaData getFieldMetaData(String JavaDoc field)
119    {
120       return (SimpleMetaData)fieldMetaData.get(field);
121    }
122
123    public synchronized void clear()
124    {
125       fieldMetaData.clear();
126    }
127
128    public Object JavaDoc resolve(Invocation invocation, Object JavaDoc tag, Object JavaDoc attr)
129    {
130       Field JavaDoc field = ((FieldInvocation)invocation).getField();
131       return getFieldMetaData(field, tag, attr);
132    }
133
134    public synchronized SimpleMetaData getAllMetaData(Invocation invocation)
135    {
136       Field JavaDoc field = ((FieldInvocation)invocation).getField();
137       return (SimpleMetaData)fieldMetaData.get(field);
138    }
139 }
140
Popular Tags