1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.yaml.snakeyaml.introspector; |
17 | |
|
18 | |
import java.beans.PropertyDescriptor; |
19 | |
|
20 | |
import org.yaml.snakeyaml.error.YAMLException; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class MethodProperty extends GenericProperty { |
32 | |
|
33 | |
private final PropertyDescriptor property; |
34 | |
private final boolean readable; |
35 | |
private final boolean writable; |
36 | |
|
37 | |
public MethodProperty(PropertyDescriptor property) { |
38 | 1278 | super(property.getName(), property.getPropertyType(), |
39 | |
property.getReadMethod() == null ? null : property.getReadMethod() |
40 | |
.getGenericReturnType()); |
41 | 1278 | this.property = property; |
42 | 1278 | this.readable = property.getReadMethod() != null; |
43 | 1278 | this.writable = property.getWriteMethod() != null; |
44 | 1278 | } |
45 | |
|
46 | |
@Override |
47 | |
public void set(Object object, Object value) throws Exception { |
48 | 2416 | property.getWriteMethod().invoke(object, value); |
49 | 2414 | } |
50 | |
|
51 | |
@Override |
52 | |
public Object get(Object object) { |
53 | |
try { |
54 | 35580 | property.getReadMethod().setAccessible(true); |
55 | 35580 | return property.getReadMethod().invoke(object); |
56 | 1 | } catch (Exception e) { |
57 | 1 | throw new YAMLException("Unable to find getter for property '" + property.getName() |
58 | |
+ "' on object " + object + ":" + e); |
59 | |
} |
60 | |
} |
61 | |
|
62 | |
@Override |
63 | |
public boolean isWritable() { |
64 | 2991 | return writable; |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
public boolean isReadable() { |
69 | 605 | return readable; |
70 | |
} |
71 | |
} |