KickJava   Java API By Example, From Geeks To Geeks.

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


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 javassist.CtConstructor;
24 import org.jboss.aop.joinpoint.ConstructorInvocation;
25 import org.jboss.aop.joinpoint.Invocation;
26 import org.jboss.aop.util.PayloadKey;
27
28 import java.lang.reflect.Constructor JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Iterator JavaDoc;
31 /**
32  *
33  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
34  * @version $Revision: 37406 $
35  *
36  */

37 public class ConstructorMetaData implements MetaDataResolver
38 {
39    HashMap JavaDoc constructorMetaData = new HashMap JavaDoc();
40
41    public boolean hasTag(String JavaDoc tag)
42    {
43       Iterator JavaDoc values = constructorMetaData.values().iterator();
44       while (values.hasNext())
45       {
46          SimpleMetaData map = (SimpleMetaData)values.next();
47          if (map.hasTag(tag)) return true;
48       }
49       return false;
50    }
51    public synchronized boolean hasTag(Constructor constructor, String JavaDoc tag)
52    {
53       SimpleMetaData meta = getConstructorMetaData(constructor);
54       if (meta == null) return false;
55       return meta.hasTag(tag);
56    }
57
58    public void tagConstructor(Constructor con, Object JavaDoc tag)
59    {
60       addConstructorMetaData(con, tag, EMPTY_TAG, new Object JavaDoc(), PayloadKey.TRANSIENT);
61    }
62
63    public void addConstructorMetaData(Constructor constructor, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value)
64    {
65       addConstructorMetaData(constructor.toString(), tag, attr, value, PayloadKey.MARSHALLED);
66    }
67    public void addConstructorMetaData(Constructor constructor, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value, PayloadKey type)
68    {
69       addConstructorMetaData(constructor.toString(), tag, attr, value, type);
70    }
71    public synchronized void addConstructorMetaData(String JavaDoc key, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value, PayloadKey type)
72    {
73       SimpleMetaData constructorData = (SimpleMetaData)constructorMetaData.get(key);
74       if (constructorData == null)
75       {
76          constructorData = new SimpleMetaData();
77          constructorMetaData.put(key, constructorData);
78       }
79       constructorData.addMetaData(tag, attr, value, type);
80    }
81
82    public synchronized Iterator JavaDoc getConstructors()
83    {
84       return constructorMetaData.keySet().iterator();
85    }
86
87    public synchronized SimpleMetaData getConstructorMetaData(Constructor constructor)
88    {
89       return (SimpleMetaData)constructorMetaData.get(constructor.toString());
90    }
91
92    public synchronized SimpleMetaData getConstructorMetaData(String JavaDoc constructor)
93    {
94       return (SimpleMetaData)constructorMetaData.get(constructor);
95    }
96
97    public synchronized Object JavaDoc getConstructorMetaData(Constructor constructor, Object JavaDoc tag, Object JavaDoc attr)
98    {
99       SimpleMetaData constructorData = (SimpleMetaData)constructorMetaData.get(constructor.toString());
100       if (constructorData == null) return null;
101       return constructorData.getMetaData(tag, attr);
102    }
103
104    public synchronized Object JavaDoc getConstructorMetaData(String JavaDoc constructor, Object JavaDoc tag, Object JavaDoc attr)
105    {
106       SimpleMetaData constructorData = (SimpleMetaData)constructorMetaData.get(constructor);
107       if (constructorData == null) return null;
108       return constructorData.getMetaData(tag, attr);
109    }
110
111    public synchronized void clear()
112    {
113       constructorMetaData.clear();
114    }
115
116    public Object JavaDoc resolve(Invocation invocation, Object JavaDoc tag, Object JavaDoc attr)
117    {
118       Constructor constructor = ((ConstructorInvocation)invocation).getConstructor();
119       return getConstructorMetaData(constructor, tag, attr);
120    }
121
122    public synchronized SimpleMetaData getAllMetaData(Invocation invocation)
123    {
124       Constructor constructor = ((ConstructorInvocation)invocation).getConstructor();
125       return (SimpleMetaData)constructorMetaData.get(constructor);
126    }
127
128    // temporary interface so that loader/compiler can get annotations
129

130    public void tagConstructor(CtConstructor con, Object JavaDoc tag)
131    {
132       addConstructorMetaData(con, tag, EMPTY_TAG, new Object JavaDoc());
133    }
134
135    public void addConstructorMetaData(CtConstructor constructor, Object JavaDoc tag, Object JavaDoc attr, Object JavaDoc value)
136    {
137       addConstructorMetaData(constructor.getSignature(), tag, attr, value, PayloadKey.TRANSIENT);
138    }
139
140    public synchronized boolean hasGroup(CtConstructor constructor, String JavaDoc tag)
141    {
142       SimpleMetaData meta = (SimpleMetaData)constructorMetaData.get(constructor.getSignature());
143       if (meta == null) return false;
144       return meta.hasTag(tag);
145    }
146
147
148 }
149
Popular Tags