Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BeanClazzProperty |
|
| 1.0909090909090908;1.091 |
1 | /* | |
2 | * Copyright 2002-2004 The Apache Software Foundation | |
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 | package org.apache.commons.clazz.bean; | |
17 | ||
18 | import org.apache.commons.clazz.Clazz; | |
19 | import org.apache.commons.clazz.ClazzProperty; | |
20 | import org.apache.commons.clazz.common.ClazzFeatureSupport; | |
21 | ||
22 | /** | |
23 | * | |
24 | * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a> | |
25 | * @version $Id: BeanClazzProperty.java 155436 2005-02-26 13:17:48Z dirkv $ | |
26 | */ | |
27 | public class BeanClazzProperty extends ClazzFeatureSupport | |
28 | implements ClazzProperty | |
29 | { | |
30 | ||
31 | private String name; | |
32 | private String clazzName; | |
33 | private String type; | |
34 | private Clazz clazz; | |
35 | ||
36 | public BeanClazzProperty(Clazz declaringClazz, String name) { | |
37 | 0 | this(declaringClazz, name, Object.class.getName()); |
38 | 0 | } |
39 | ||
40 | public BeanClazzProperty(Clazz declaringClazz, String name, String type) { | |
41 | 0 | super(declaringClazz); |
42 | 0 | this.name = name; |
43 | 0 | this.clazzName = type; |
44 | 0 | } |
45 | ||
46 | /** | |
47 | * @see org.apache.commons.clazz.ClazzProperty#getName() | |
48 | */ | |
49 | public String getName() { | |
50 | 0 | return name; |
51 | } | |
52 | ||
53 | /** | |
54 | * @see org.apache.commons.clazz.ClazzProperty#getClazz() | |
55 | */ | |
56 | public Clazz getClazz() { | |
57 | 0 | if (clazz == null) { |
58 | 0 | clazz = |
59 | getDeclaringClazz().getClazzLoader().getClazzForName(clazzName); | |
60 | } | |
61 | 0 | return clazz; |
62 | } | |
63 | ||
64 | /** | |
65 | * Returns true if the property is a collection. | |
66 | */ | |
67 | public boolean isCollection() { | |
68 | 0 | return false; |
69 | } | |
70 | ||
71 | /** | |
72 | * Returns true if the property is a map. | |
73 | */ | |
74 | public boolean isMap() { | |
75 | 0 | return false; |
76 | } | |
77 | ||
78 | /** | |
79 | * @see org.apache.commons.clazz.ClazzProperty#getContentClazz() | |
80 | */ | |
81 | public Clazz getContentClazz() { | |
82 | 0 | return null; |
83 | } | |
84 | ||
85 | /** | |
86 | * @see org.apache.commons.clazz.ClazzProperty#getKeyClazz() | |
87 | */ | |
88 | public Clazz getKeyClazz() { | |
89 | 0 | return null; |
90 | } | |
91 | ||
92 | /** | |
93 | * @see org.apache.commons.clazz.ClazzProperty#isReadOnly() | |
94 | */ | |
95 | public boolean isReadOnly() { | |
96 | 0 | return false; |
97 | } | |
98 | ||
99 | /** | |
100 | * @see org.apache.commons.clazz.ClazzProperty#get(java.lang.Object) | |
101 | */ | |
102 | public Object get(Object instance) { | |
103 | 0 | return ((Bean) instance).get(getName()); |
104 | } | |
105 | ||
106 | /** | |
107 | * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object) | |
108 | */ | |
109 | public void set(Object instance, Object value) { | |
110 | 0 | ((Bean) instance).set(getName(), value); |
111 | 0 | } |
112 | ||
113 | } |