KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > spi > retrieval > MetaDataRetrievalToMetaDataBridge


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.metadata.spi.retrieval;
23
24 import java.lang.annotation.Annotation JavaDoc;
25
26 import org.jboss.metadata.spi.MetaData;
27
28 /**
29  * MetaDataRetrievalToMetaDataBridge.
30  *
31  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
32  * @version $Revision: 46146 $
33  */

34 public class MetaDataRetrievalToMetaDataBridge implements MetaData
35 {
36    /** The meta data retrieval method */
37    private MetaDataRetrieval retrieval;
38    
39    public MetaDataRetrievalToMetaDataBridge(MetaDataRetrieval retrieval)
40    {
41       if (retrieval == null)
42          throw new IllegalArgumentException JavaDoc("Null retrieval");
43       this.retrieval = retrieval;
44    }
45
46    public long getValidTime()
47    {
48       ValidTime validTime = retrieval.getValidTime();
49       return validTime.getValidTime();
50    }
51
52    public <T extends Annotation JavaDoc> T getAnnotation(Class JavaDoc<T> annotationType)
53    {
54       if (annotationType == null)
55          throw new IllegalArgumentException JavaDoc("Null annotationType");
56       AnnotationItem<T> item = retrieval.retrieveAnnotation(annotationType);
57       if (item == null)
58          return null;
59       return item.getValue();
60    }
61
62    public Annotation JavaDoc[] getAnnotations()
63    {
64       AnnotationsItem item = retrieval.retrieveAnnotations();
65       if (item == null)
66          return NO_ANNOTATIONS;
67       return item.getValue();
68    }
69
70    public Annotation JavaDoc[] getLocalAnnotations()
71    {
72       AnnotationsItem item = retrieval.retrieveLocalAnnotations();
73       if (item == null)
74          return NO_ANNOTATIONS;
75       return item.getValue();
76    }
77
78    public Object JavaDoc[] getMetaData()
79    {
80       MetaDatasItem item = retrieval.retrieveMetaData();
81       if (item == null)
82          return NO_METADATA;
83       return item.getValue();
84    }
85
86    public Object JavaDoc[] getLocalMetaData()
87    {
88       MetaDatasItem item = retrieval.retrieveLocalMetaData();
89       if (item == null)
90          return NO_METADATA;
91       return item.getValue();
92    }
93
94    public <T> T getMetaData(Class JavaDoc<T> type)
95    {
96       if (type == null)
97          throw new IllegalArgumentException JavaDoc("Null type");
98       MetaDataItem<T> item = retrieval.retrieveMetaData(type);
99       if (item == null)
100          return null;
101       return item.getValue();
102    }
103
104    public <T> T getMetaData(String JavaDoc name, Class JavaDoc<T> type)
105    {
106       if (name == null)
107          throw new IllegalArgumentException JavaDoc("Null name");
108       if (type == null)
109          throw new IllegalArgumentException JavaDoc("Null type");
110       MetaDataItem item = retrieval.retrieveMetaData(name);
111       if (item == null)
112          return null;
113       return type.cast(item.getValue());
114    }
115
116    public Object JavaDoc getMetaData(String JavaDoc name)
117    {
118       if (name == null)
119          throw new IllegalArgumentException JavaDoc("Null name");
120       MetaDataItem item = retrieval.retrieveMetaData(name);
121       if (item == null)
122          return null;
123       return item.getValue();
124    }
125
126    public boolean isAnnotationPresent(Class JavaDoc<? extends Annotation JavaDoc> annotationType)
127    {
128       return getAnnotation(annotationType) != null;
129    }
130
131    public boolean isMetaDataPresent(Class JavaDoc<?> type)
132    {
133       return getMetaData(type) != null;
134    }
135
136    public boolean isMetaDataPresent(String JavaDoc name, Class JavaDoc<?> type)
137    {
138       if (type == null)
139          throw new IllegalArgumentException JavaDoc("Null type");
140        Object JavaDoc value = getMetaData(name);
141        if (value == null)
142           return false;
143        return type.isInstance(value);
144    }
145
146    public boolean isMetaDataPresent(String JavaDoc name)
147    {
148       return getMetaData(name) != null;
149    }
150
151    /**
152     * Get the meta data retrieval
153     *
154     * @return the retrieval
155     */

156    protected MetaDataRetrieval getMetaDataRetrieval()
157    {
158       return retrieval;
159    }
160 }
161
Popular Tags