1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.requests.query;
17
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlTransient;
21 import javax.xml.bind.annotation.XmlType;
22 import javax.xml.bind.annotation.adapters.XmlAdapter;
23 import java.util.List;
24 import java.util.stream.Collectors;
25
26
27
28
29
30
31
32
33 @XmlTransient
34 public class ListOfListAdapter<T> extends XmlAdapter<ListOfListAdapter.ListOfListWrapper<T>, List<List<T>>> {
35 @Override
36 public List<List<T>> unmarshal(ListOfListWrapper<T> v) throws Exception {
37 return v.getInnerList().stream()
38 .map(ListWrapper::getValue)
39 .collect(Collectors.toList());
40 }
41
42 @Override
43 public ListOfListWrapper<T> marshal(List<List<T>> v) throws Exception {
44 List<ListWrapper<T>> outerList = v.stream()
45 .map(ListWrapper::new)
46 .collect(Collectors.toList());
47 return new ListOfListWrapper<>(outerList);
48 }
49
50 @XmlType(name = "ListOfListWrapper", namespace = "http://www.openehealth.org/ipf/xds")
51 @XmlAccessorType(XmlAccessType.FIELD)
52 public static class ListOfListWrapper<T> {
53 private List<ListWrapper<T>> innerList;
54
55
56 @SuppressWarnings({"UnusedDeclaration"})
57 protected ListOfListWrapper() {
58 }
59
60 public ListOfListWrapper(List<ListWrapper<T>> list) {
61 this.innerList = list;
62 }
63
64 public List<ListWrapper<T>> getInnerList() {
65 return innerList;
66 }
67 }
68
69 @XmlType(name = "ListWrapper", namespace = "http://www.openehealth.org/ipf/xds")
70 @XmlAccessorType(XmlAccessType.FIELD)
71 public static class ListWrapper<T> {
72 private List<T> value;
73
74
75 @SuppressWarnings({"UnusedDeclaration"})
76 protected ListWrapper() {
77 }
78
79 public ListWrapper(List<T> list) {
80 this.value = list;
81 }
82
83 public List<T> getValue() {
84 return value;
85 }
86 }
87 }
88