KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > plugins > loader > AbstractMetaDataLoader


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.plugins.loader;
23
24 import java.lang.annotation.Annotation JavaDoc;
25
26 import org.jboss.metadata.spi.loader.MetaDataLoader;
27 import org.jboss.metadata.spi.retrieval.AnnotationItem;
28 import org.jboss.metadata.spi.retrieval.AnnotationsItem;
29 import org.jboss.metadata.spi.retrieval.Item;
30 import org.jboss.metadata.spi.retrieval.MetaDataItem;
31 import org.jboss.metadata.spi.retrieval.MetaDatasItem;
32 import org.jboss.metadata.spi.retrieval.ValidTime;
33 import org.jboss.metadata.spi.retrieval.helper.AnnotationToMetaDataBridge;
34 import org.jboss.metadata.spi.retrieval.helper.AnnotationsToMetaDatasBridge;
35 import org.jboss.metadata.spi.scope.ScopeKey;
36
37 /**
38  * AbstractMetaDataLoader.
39  *
40  * <p>The default behaviour is to assume there are only
41  * annotations with the types and names of the getMetadata()
42  * methods interpreted as annotation types and class names.
43  *
44  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
45  * @version $Revision: 46146 $
46  */

47 public abstract class AbstractMetaDataLoader implements MetaDataLoader
48 {
49    /** The valid time */
50    private ValidTime validTime;
51
52    /** The scope key */
53    private ScopeKey scopeKey;
54    
55    /**
56     * Create a new AbstractMetaDataLoader.
57     */

58    public AbstractMetaDataLoader()
59    {
60       this(ScopeKey.DEFAULT_SCOPE);
61    }
62
63    /**
64     * Create a new AbstractMetaDataLoader.
65     *
66     * @param key the scope
67     */

68    public AbstractMetaDataLoader(ScopeKey key)
69    {
70       this.scopeKey = key;
71       validTime = new ValidTime();
72    }
73    
74    public ScopeKey getScope()
75    {
76       return scopeKey;
77    }
78
79    public ValidTime getValidTime()
80    {
81       return validTime;
82    }
83    
84    public <T> boolean isCachable(Item<T> item)
85    {
86       return true;
87    }
88
89    public AnnotationsItem retrieveLocalAnnotations()
90    {
91       return retrieveAnnotations();
92    }
93
94    @SuppressWarnings JavaDoc("unchecked")
95    public <T> MetaDataItem<T> retrieveMetaData(Class JavaDoc<T> type)
96    {
97       if (type.isAnnotation() == false)
98          return null;
99       AnnotationItem annotation = retrieveAnnotation((Class JavaDoc<Annotation JavaDoc>) type);
100       if (annotation == null)
101          return null;
102       return new AnnotationToMetaDataBridge<T>(annotation);
103    }
104
105    public MetaDatasItem retrieveLocalMetaData()
106    {
107       return retrieveMetaData();
108    }
109
110    public MetaDatasItem retrieveMetaData()
111    {
112       AnnotationsItem annotations = retrieveAnnotations();
113       return new AnnotationsToMetaDatasBridge(annotations);
114    }
115
116    /**
117     * Invalidate
118     */

119    public void invalidate()
120    {
121       validTime.invalidate();
122    }
123 }
124
Popular Tags