1 package org.apache.turbine.services.urlmapper.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.LinkedHashMap;
23 import java.util.Map;
24 import java.util.stream.Collectors;
25
26 import javax.xml.bind.annotation.adapters.XmlAdapter;
27
28 import org.apache.turbine.services.urlmapper.model.XmlParameterList.XmlParameter;
29
30
31
32
33
34
35 public class XmlParameterAdapter extends XmlAdapter<XmlParameterList, Map<String, String>>
36 {
37
38
39
40 @Override
41 public Map<String, String> unmarshal(XmlParameterList xmlList) throws Exception
42 {
43
44 return xmlList.getXmlParameters().stream()
45 .collect(Collectors.toMap(xml -> xml.key, xml -> xml.value,
46 (e1, e2) -> e1, LinkedHashMap::new));
47 }
48
49
50
51
52 @Override
53 public XmlParameterList marshal(Map<String, String> map) throws Exception
54 {
55 XmlParameterListpper/model/XmlParameterList.html#XmlParameterList">XmlParameterList xmlList = new XmlParameterList();
56 xmlList.setXmlParameters(map.entrySet().stream()
57 .map(entry -> new XmlParameter(entry.getKey(), entry.getValue()))
58 .collect(Collectors.toList()));
59
60 return xmlList;
61 }
62 }