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