1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.panels.search;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import org.apache.commons.lang3.StringUtils;
25 import org.apache.wicket.core.util.lang.PropertyResolver;
26 import org.apache.wicket.model.PropertyModel;
27
28 public class MapOfListModel<T> extends PropertyModel<List<T>> {
29
30 private static final long serialVersionUID = -7647997536634092231L;
31
32 private final String key;
33
34 public MapOfListModel(final Object modelObject, final String expression, final String key) {
35 super(modelObject, expression);
36 this.key = key;
37 }
38
39 @Override
40 @SuppressWarnings("unchecked")
41 public List<T> getObject() {
42 final String expression = propertyExpression();
43 final Object target = getInnermostModelOrObject();
44
45 if (target == null || StringUtils.isBlank(expression) || expression.startsWith(".")) {
46 throw new IllegalArgumentException("Property expressions cannot start with a '.' character");
47 }
48
49 Map<String, List<T>> map = (Map<String, List<T>>) PropertyResolver.getValue(expression, target);
50
51 List<T> res;
52 if (map.containsKey(key)) {
53 res = map.get(key);
54 } else {
55 res = new ArrayList<>();
56 map.put(key, res);
57 }
58 return res;
59 }
60
61 @Override
62 @SuppressWarnings("unchecked")
63 public void setObject(final List<T> object) {
64 final String expression = propertyExpression();
65 final Object target = getInnermostModelOrObject();
66 ((Map<String, List<T>>) PropertyResolver.getValue(expression, target)).put(key, object);
67 }
68 }