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 |
|
package info.magnolia.rest.delivery.jcr.decorator; |
35 |
|
|
36 |
|
import java.math.BigDecimal; |
37 |
|
import java.util.Arrays; |
38 |
|
|
39 |
|
import javax.jcr.Binary; |
40 |
|
import javax.jcr.Item; |
41 |
|
import javax.jcr.Node; |
42 |
|
import javax.jcr.RepositoryException; |
43 |
|
import javax.jcr.Session; |
44 |
|
import javax.jcr.Value; |
45 |
|
import javax.jcr.ValueFormatException; |
46 |
|
import javax.jcr.nodetype.PropertyDefinition; |
47 |
|
|
48 |
|
import org.apache.commons.lang3.StringUtils; |
49 |
|
import org.apache.jackrabbit.commons.AbstractProperty; |
50 |
|
|
51 |
|
|
52 |
|
@link |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 22 |
Complexity Density: 0.65 |
|
54 |
|
public class ReadOnlyProperty extends AbstractProperty { |
55 |
|
|
56 |
|
private final String name; |
57 |
|
private boolean multiple; |
58 |
|
private Value[] values = new Value[0]; |
59 |
|
private Node parent; |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
61 |
0 |
public ReadOnlyProperty(String name, Value[] values, Node parent) {... |
62 |
0 |
this.name = name; |
63 |
0 |
this.values = values; |
64 |
0 |
this.parent = parent; |
65 |
0 |
this.multiple = true; |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
68 |
0 |
public ReadOnlyProperty(String name, Value value, Node parent) {... |
69 |
0 |
this(name, new Value[] { value }, parent); |
70 |
0 |
this.multiple = false; |
71 |
|
} |
72 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
73 |
|
@Override... |
74 |
|
public String getName() { |
75 |
|
return name; |
76 |
|
} |
77 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
78 |
|
@Override... |
79 |
|
public Node getParent() throws RepositoryException { |
80 |
|
return parent; |
81 |
|
} |
82 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
83 |
|
@Override... |
84 |
|
public Session getSession() throws RepositoryException { |
85 |
|
return parent.getSession(); |
86 |
|
} |
87 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
88 |
|
@Override... |
89 |
|
public Binary getBinary() throws RepositoryException { |
90 |
|
return getValue().getBinary(); |
91 |
|
} |
92 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
93 |
|
@Override... |
94 |
|
public BigDecimal getDecimal() throws RepositoryException { |
95 |
|
return getValue().getDecimal(); |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
98 |
0 |
@Override... |
99 |
|
public String getString() throws RepositoryException { |
100 |
0 |
return getValue() != null ? getValue().getString() : null; |
101 |
|
} |
102 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
103 |
|
@Override... |
104 |
|
public int getType() throws RepositoryException { |
105 |
|
return values[0].getType(); |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
108 |
0 |
@Override... |
109 |
|
public Value getValue() throws ValueFormatException { |
110 |
0 |
if (isMultiple()) { |
111 |
0 |
throw new ValueFormatException("Cannot call getValue() on a multi-value property."); |
112 |
|
} |
113 |
0 |
return values[0]; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
116 |
0 |
@Override... |
117 |
|
public Value[] getValues() throws ValueFormatException { |
118 |
0 |
if (isMultiple()) { |
119 |
0 |
return values; |
120 |
|
} |
121 |
0 |
throw new ValueFormatException("Cannot call getValues() on a single-value property."); |
122 |
|
} |
123 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
124 |
|
@Override... |
125 |
|
public long[] getLengths() throws RepositoryException { |
126 |
|
throw new UnsupportedOperationException("Not implemented."); |
127 |
|
} |
128 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
129 |
|
@Override... |
130 |
|
public PropertyDefinition getDefinition() throws RepositoryException { |
131 |
|
throw new UnsupportedOperationException("Not implemented."); |
132 |
|
} |
133 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
134 |
|
@Override... |
135 |
|
public Node getNode() throws RepositoryException { |
136 |
|
return parent; |
137 |
|
} |
138 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
139 |
|
@Override... |
140 |
|
public void setValue(Binary value) throws RepositoryException { |
141 |
|
throw new UnsupportedOperationException("Not implemented."); |
142 |
|
} |
143 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
144 |
|
@Override... |
145 |
|
public void setValue(BigDecimal value) throws RepositoryException { |
146 |
|
throw new UnsupportedOperationException("Not implemented."); |
147 |
|
} |
148 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
149 |
|
@Override... |
150 |
|
public boolean isMultiple() { |
151 |
|
return multiple; |
152 |
|
} |
153 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
154 |
|
@Override... |
155 |
|
public boolean isModified() { |
156 |
|
return false; |
157 |
|
} |
158 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
159 |
|
@Override... |
160 |
|
public boolean isNew() { |
161 |
|
return false; |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
0 |
@Override... |
165 |
|
public boolean isSame(Item otherItem) throws RepositoryException { |
166 |
0 |
throw new UnsupportedOperationException("Not implemented."); |
167 |
|
} |
168 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
169 |
0 |
@Override... |
170 |
|
public void refresh(boolean keepChanges) throws RepositoryException { |
171 |
|
|
172 |
|
} |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0 |
@Override... |
175 |
|
public void save() throws RepositoryException { |
176 |
0 |
throw new UnsupportedOperationException("Not implemented."); |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
179 |
0 |
@Override... |
180 |
|
public String toString() { |
181 |
0 |
String valueString; |
182 |
0 |
if (isMultiple()) { |
183 |
0 |
valueString = StringUtils.join(values, ", "); |
184 |
|
} else { |
185 |
0 |
valueString = values.length == 0 ? "" : values[0].toString(); |
186 |
|
} |
187 |
0 |
return super.toString() + ": " + valueString; |
188 |
|
} |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
190 |
0 |
@Override... |
191 |
|
public boolean equals(Object o) { |
192 |
0 |
if (this == o) return true; |
193 |
0 |
if (o == null || getClass() != o.getClass()) return false; |
194 |
|
|
195 |
0 |
ReadOnlyProperty that = (ReadOnlyProperty) o; |
196 |
|
|
197 |
0 |
if (isMultiple() != that.isMultiple()) return false; |
198 |
0 |
if (!getName().equals(that.getName())) return false; |
199 |
|
|
200 |
0 |
return Arrays.equals(values, that.values); |
201 |
|
} |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
203 |
0 |
@Override... |
204 |
|
public int hashCode() { |
205 |
0 |
int result = getName().hashCode(); |
206 |
0 |
result = 31 * result + (isMultiple() ? 1 : 0); |
207 |
0 |
result = 31 * result + Arrays.hashCode(values); |
208 |
0 |
return result; |
209 |
|
} |
210 |
|
} |