1 package org.opentrafficsim.xml.bindings;
2
3 import javax.xml.bind.annotation.adapters.XmlAdapter;
4
5 import org.opentrafficsim.xml.bindings.types.StripeType;
6
7
8
9
10
11
12
13
14
15 public class StripeTypeAdapter extends XmlAdapter<String, StripeType>
16 {
17
18 @Override
19 public StripeType unmarshal(final String field) throws IllegalArgumentException
20 {
21 try
22 {
23 String clean = field.replaceAll("\\s", "");
24 for (StripeType st : StripeType.values())
25 if (clean.equals(st.name()))
26 {
27 return st;
28 }
29 }
30 catch (Exception exception)
31 {
32 throw new IllegalArgumentException("Error parsing StripeType " + field, exception);
33 }
34 throw new IllegalArgumentException("Error parsing StripeType " + field);
35 }
36
37
38 @Override
39 public String marshal(final StripeType stripeType) throws IllegalArgumentException
40 {
41 return stripeType.name();
42 }
43
44 }