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