1 package org.opentrafficsim.xml.bindings;
2
3 import javax.xml.bind.annotation.adapters.XmlAdapter;
4
5 /**
6 * AngleAdapter converts between the XML String for a class name and the Class object. <br>
7 * <br>
8 * Copyright (c) 2003-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
9 * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
10 * source code and binary code of this software is proprietary information of Delft University of Technology.
11 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
12 */
13 public class ClassNameAdapter extends XmlAdapter<String, Class<?>>
14 {
15 /** {@inheritDoc} */
16 @Override
17 public Class<?> unmarshal(final String field) throws IllegalArgumentException
18 {
19 try
20 {
21 return Class.forName(field);
22 }
23 catch (Exception exception)
24 {
25 throw new IllegalArgumentException("Error parsing classname " + field, exception);
26 }
27 }
28
29 /** {@inheritDoc} */
30 @Override
31 public String marshal(final Class<?> clazz) throws IllegalArgumentException
32 {
33 return clazz.getName();
34 }
35
36 }