| 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 | 7135 | super(); |
| 41 | 7135 | this.targetClass = targetClass; |
| 42 | 7135 | this.targetProperty = targetProperty; |
| 43 | 7135 | } |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
public SpecificPropertyDefinition(final String targetPropertyDescription) { |
| 55 | 2 | super(); |
| 56 | 2 | String targetClassName = targetPropertyDescription.substring(0, targetPropertyDescription.lastIndexOf(CLASS_PROPERTY_SEPARATOR)); |
| 57 | |
try { |
| 58 | 2 | this.targetClass = Class.forName(targetClassName); |
| 59 | 0 | } catch (ClassNotFoundException e) { |
| 60 | 0 | throw new IllegalArgumentException("Impossible to resolve class in: " + targetPropertyDescription, e); |
| 61 | 2 | } |
| 62 | |
|
| 63 | 2 | String targetPropertyName = targetPropertyDescription.substring(targetPropertyDescription.lastIndexOf(CLASS_PROPERTY_SEPARATOR) + 1, targetPropertyDescription.length()); |
| 64 | 2 | this.targetProperty = targetPropertyName; |
| 65 | 2 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public Class<?> getTargetClass() { |
| 73 | 0 | return targetClass; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public String getTargetProperty() { |
| 82 | 0 | return targetProperty; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
public String getPropertyPathString() { |
| 91 | 0 | return buildPropertyPathString(targetClass, targetProperty); |
| 92 | |
} |
| 93 | |
|
| 94 | |
public static String buildPropertyPathString(Class<?> targetClass, String targetPropertyName) { |
| 95 | 0 | return targetClass.getName() + CLASS_PROPERTY_SEPARATOR + targetPropertyName; |
| 96 | |
} |
| 97 | |
|
| 98 | |
@Override |
| 99 | |
public String toString() { |
| 100 | 0 | return buildPropertyPathString(targetClass, targetProperty); |
| 101 | |
} |
| 102 | |
|
| 103 | |
@Override |
| 104 | |
public boolean equals(Object obj) { |
| 105 | 40 | if (this == obj) |
| 106 | 0 | return true; |
| 107 | 40 | if ((obj == null) || (obj.getClass() != this.getClass())) |
| 108 | 0 | return false; |
| 109 | |
|
| 110 | 40 | SpecificPropertyDefinition other = (SpecificPropertyDefinition) obj; |
| 111 | 40 | return targetProperty.equals(other.targetProperty) && targetClass.equals(other.targetClass); |
| 112 | |
} |
| 113 | |
|
| 114 | |
@Override |
| 115 | |
public int hashCode() { |
| 116 | 7026 | int hash = 7; |
| 117 | 7026 | hash = 31 * hash + (null == targetClass ? 0 : targetClass.hashCode()); |
| 118 | 7026 | hash = 31 * hash + (null == targetProperty ? 0 : targetProperty.hashCode()); |
| 119 | 7026 | return hash; |
| 120 | |
} |
| 121 | |
} |