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 super(property.getName(), property.getPropertyType(),
39 property.getReadMethod() == null ? null : property.getReadMethod()
40 .getGenericReturnType());
41 this.property = property;
42 this.readable = property.getReadMethod() != null;
43 this.writable = property.getWriteMethod() != null;
44 }
45
46 @Override
47 public void set(Object object, Object value) throws Exception {
48 property.getWriteMethod().invoke(object, value);
49 }
50
51 @Override
52 public Object get(Object object) {
53 try {
54 property.getReadMethod().setAccessible(true);
55 return property.getReadMethod().invoke(object);
56 } catch (Exception e) {
57 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 return writable;
65 }
66
67 @Override
68 public boolean isReadable() {
69 return readable;
70 }
71 }