1 package org.opentrafficsim.xml.bindings;
2
3 import javax.xml.bind.annotation.adapters.XmlAdapter;
4
5 import org.opentrafficsim.xml.bindings.types.LaneKeepingType;
6
7
8
9
10
11
12
13
14
15 public class LaneKeepingAdapter extends XmlAdapter<String, LaneKeepingType>
16 {
17
18 @Override
19 public LaneKeepingType unmarshal(final String field) throws IllegalArgumentException
20 {
21 try
22 {
23 String lkpStr = field.replaceAll("\\s", "");
24 if (lkpStr.equals("KEEPRIGHT"))
25 {
26 return LaneKeepingType.KEEPRIGHT;
27 }
28 else if (lkpStr.equals("KEEPLEFT"))
29 {
30 return LaneKeepingType.KEEPLEFT;
31 }
32 else if (lkpStr.equals("KEEPLANE"))
33 {
34 return LaneKeepingType.KEEPLANE;
35 }
36 }
37 catch (Exception exception)
38 {
39 throw new IllegalArgumentException("Error parsing LaneKeeping " + field, exception);
40 }
41 throw new IllegalArgumentException("Error parsing LaneKeeping " + field);
42 }
43
44
45 @Override
46 public String marshal(final LaneKeepingType laneKeeping) throws IllegalArgumentException
47 {
48 if (laneKeeping.equals(LaneKeepingType.KEEPRIGHT))
49 return "KEEPRIGHT";
50 if (laneKeeping.equals(LaneKeepingType.KEEPLEFT))
51 return "KEEPLEFT";
52 if (laneKeeping.equals(LaneKeepingType.KEEPLANE))
53 return "KEEPLANE";
54 throw new IllegalArgumentException("Error parsing LaneKeeping " + laneKeeping);
55 }
56
57 }