-
Notifications
You must be signed in to change notification settings - Fork 188
/
PrismPropertyValueWrapper.java
114 lines (91 loc) · 3.29 KB
/
PrismPropertyValueWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright (c) 2010-2018 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.impl.prism;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import org.apache.commons.lang.StringUtils;
/**
* @author katka
*
*/
public class PrismPropertyValueWrapper<T> extends PrismValueWrapperImpl<T, PrismPropertyValue<T>> {
/**
* @param parent
* @param value
* @param status
*/
public PrismPropertyValueWrapper(ItemWrapper<?, ?, ?, ?> parent, PrismPropertyValue<T> value, ValueStatus status) {
super(parent, value, status);
}
private static final long serialVersionUID = 1L;
@Override
public void setRealValue(T newRealValue) {
newRealValue = trimValueIfNeeded(newRealValue);
if (newRealValue == null) {
getNewValue().setValue(null);
setStatus(ValueStatus.DELETED);
return;
}
if (newRealValue instanceof QName) {
if (QNameUtil.match((QName) newRealValue, (QName) getRealValue())) {
return;
}
} else if (newRealValue instanceof ItemPath) {
if (((ItemPath) newRealValue).equivalent((ItemPath) getRealValue())) {
return;
}
} else {
if (newRealValue.equals(getRealValue())) {
return;
}
}
getNewValue().setValue(newRealValue);
setStatus(ValueStatus.MODIFIED);
}
private T trimValueIfNeeded(T realValue) {
if (ValueStatus.ADDED == getStatus() || ValueStatus.MODIFIED == getStatus()) {
if (realValue instanceof String) {
return (T) ((String) realValue).trim();
}
if (realValue instanceof PolyString) {
PolyString polyString = (PolyString) realValue;
String polyStringOrig = polyString.getOrig();
if (StringUtils.isEmpty(polyStringOrig)) {
return realValue;
}
String trimmed = polyStringOrig.trim();
PolyString newPolyString = new PolyString(trimmed);
newPolyString.setLang(polyString.getLang());
newPolyString.setTranslation(polyString.getTranslation());
return (T) newPolyString;
}
}
return realValue;
}
public String toShortString() {
if (getRealValue() == null) {
return null;
}
if (getParent() == null) {
return getRealValue().toString();
}
QName typeName = getParent().getTypeName();
if (typeName == null) {
return getRealValue().toString();
}
if (QNameUtil.match(DOMUtil.XSD_QNAME, typeName)) {
return ((QName)getRealValue()).getLocalPart();
}
return getRealValue().toString();
}
}