Coverage Summary for Class: PropertyInfo (net.sf.persism)
Class |
Class, %
|
Method, %
|
Line, %
|
PropertyInfo |
100%
(1/1)
|
100%
(6/6)
|
87.5%
(14/16)
|
1 package net.sf.persism;
2
3 import java.lang.annotation.Annotation;
4 import java.lang.reflect.Field;
5 import java.lang.reflect.InvocationTargetException;
6 import java.lang.reflect.Method;
7 import java.util.HashMap;
8 import java.util.Map;
9
10 /**
11 * Created by IntelliJ IDEA.
12 * User: DHoward
13 * Date: 9/8/11
14 * Time: 8:09 AM
15 */
16 final class PropertyInfo {
17
18 String propertyName;
19 Method getter;
20 Method setter;
21 Field field;
22 boolean isJoin;
23
24 Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>(4);
25
26 Annotation getAnnotation(Class<? extends Annotation> annotationClass) {
27 return annotations.get(annotationClass);
28 }
29
30 // for collections
31 boolean isJoin() {
32 return isJoin;
33 }
34
35 // Convenience getter with runtime exception for functional
36 Object getValue(Object object) {
37 try {
38 return getter.invoke(object);
39 } catch (IllegalAccessException | InvocationTargetException e) {
40 throw new PersismException(e.getMessage(), e);
41 }
42 }
43
44 void setValue(Object object, Object value) {
45 try {
46 if (setter != null) {
47 setter.invoke(object, value);
48 } else {
49 field.setAccessible(true);
50 field.set(object, value);
51 field.setAccessible(false);
52 }
53 } catch (IllegalAccessException | InvocationTargetException e) {
54 throw new PersismException(e.getMessage(), e);
55 }
56 }
57
58 @Override
59 public String toString() {
60 return "PropertyInfo{" +
61 "propertyName='" + propertyName + '\'' +
62 ", getter=" + getter +
63 ", setter=" + setter +
64 ", annotations=" + annotations +
65 '}';
66 }
67 }