KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > metadata > support > MapAttributes


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.metadata.support;
18
19 import java.lang.reflect.Field JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.Map JavaDoc;
26
27
28 /**
29  * Convenient class for simulating attributes.
30  *
31  * @author Rod Johnson
32  */

33 public class MapAttributes extends AbstractAttributes {
34     
35     private Map JavaDoc attMap = new HashMap JavaDoc();
36     
37     
38     public void register(Class JavaDoc clazz, Object JavaDoc[] atts) {
39         attMap.put(clazz, atts);
40     }
41     
42     public void register(Method JavaDoc method, Object JavaDoc[] atts) {
43         attMap.put(method, atts);
44     }
45
46     private Collection JavaDoc getAllAttributes(Object JavaDoc o) {
47         Object JavaDoc[] atts = (Object JavaDoc[]) attMap.get(o);
48         return (atts == null) ?
49              new LinkedList JavaDoc() :
50              Arrays.asList(atts);
51     }
52
53     /**
54      * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Field)
55      */

56     public Collection JavaDoc getAttributes(Field JavaDoc targetField) {
57         return getAllAttributes(targetField);
58     }
59
60     /**
61      * @see org.springframework.metadata.Attributes#getAttributes(java.lang.Class)
62      */

63     public Collection JavaDoc getAttributes(Class JavaDoc targetClass) {
64         return getAllAttributes(targetClass);
65     }
66
67     /**
68      * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Method)
69      */

70     public Collection JavaDoc getAttributes(Method JavaDoc targetMethod) {
71         return getAllAttributes(targetMethod);
72     }
73
74
75 }
76
Popular Tags