1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.org.usurper.model;
20
21
22
23
24 public class SpecificPropertyDefinition implements ITargetDefinition {
25
26 public static final String CLASS_PROPERTY_SEPARATOR = ".";
27
28 private final Class<?> targetClass;
29 private final String targetProperty;
30
31
32
33
34
35
36
37
38
39 public SpecificPropertyDefinition(final Class<?> targetClass, final String targetProperty) {
40 super();
41 this.targetClass = targetClass;
42 this.targetProperty = targetProperty;
43 }
44
45
46
47
48
49
50
51
52
53
54 public SpecificPropertyDefinition(final String targetPropertyDescription) {
55 super();
56 String targetClassName = targetPropertyDescription.substring(0, targetPropertyDescription.lastIndexOf(CLASS_PROPERTY_SEPARATOR));
57 try {
58 this.targetClass = Class.forName(targetClassName);
59 } catch (ClassNotFoundException e) {
60 throw new IllegalArgumentException("Impossible to resolve class in: " + targetPropertyDescription, e);
61 }
62
63 String targetPropertyName = targetPropertyDescription.substring(targetPropertyDescription.lastIndexOf(CLASS_PROPERTY_SEPARATOR) + 1, targetPropertyDescription.length());
64 this.targetProperty = targetPropertyName;
65 }
66
67
68
69
70
71
72 public Class<?> getTargetClass() {
73 return targetClass;
74 }
75
76
77
78
79
80
81 public String getTargetProperty() {
82 return targetProperty;
83 }
84
85
86
87
88
89
90 public String getPropertyPathString() {
91 return buildPropertyPathString(targetClass, targetProperty);
92 }
93
94 public static String buildPropertyPathString(Class<?> targetClass, String targetPropertyName) {
95 return targetClass.getName() + CLASS_PROPERTY_SEPARATOR + targetPropertyName;
96 }
97
98 @Override
99 public String toString() {
100 return buildPropertyPathString(targetClass, targetProperty);
101 }
102
103 @Override
104 public boolean equals(Object obj) {
105 if (this == obj)
106 return true;
107 if ((obj == null) || (obj.getClass() != this.getClass()))
108 return false;
109
110 SpecificPropertyDefinition other = (SpecificPropertyDefinition) obj;
111 return targetProperty.equals(other.targetProperty) && targetClass.equals(other.targetClass);
112 }
113
114 @Override
115 public int hashCode() {
116 int hash = 7;
117 hash = 31 * hash + (null == targetClass ? 0 : targetClass.hashCode());
118 hash = 31 * hash + (null == targetProperty ? 0 : targetProperty.hashCode());
119 return hash;
120 }
121 }