View Javadoc
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    * StripeType to convert between XML representations of a stripe type and its enum type. <br>
9    * <br>
10   * Copyright (c) 2003-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
11   * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
12   * source code and binary code of this software is proprietary information of Delft University of Technology.
13   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
14   */
15  public class StripeTypeAdapter extends XmlAdapter<String, StripeType>
16  {
17      /** {@inheritDoc} */
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      /** {@inheritDoc} */
38      @Override
39      public String marshal(final StripeType stripeType) throws IllegalArgumentException
40      {
41          return stripeType.name();
42      }
43  
44  }