View Javadoc

1   /**
2    * Emohawk Bot, an implementation of the environment interface standard that 
3    * facilitates the connection between GOAL and Emohawk. 
4    * 
5    * Copyright (C) 2012 Emohawk Bot authors.
6    * 
7    * This program is free software: you can redistribute it and/or modify it under
8    * the terms of the GNU General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10   * version.
11   * 
12   * This program is distributed in the hope that it will be useful, but WITHOUT
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15   * details.
16   * 
17   * You should have received a copy of the GNU General Public License along with
18   * this program. If not, see <http://www.gnu.org/licenses/>.
19   */
20  package nl.tudelft.goal.emohawk.translators;
21  
22  import java.util.Arrays;
23  
24  import nl.tudelft.goal.EIS2Java.exception.TranslationException;
25  import nl.tudelft.goal.EIS2Java.translation.Java2Parameter;
26  import nl.tudelft.goal.EIS2Java.translation.Parameter2Java;
27  import nl.tudelft.goal.EIS2Java.translation.Translator;
28  import cz.cuni.amis.pogamut.emohawk.agent.module.sensomotoric.AnimType;
29  import cz.cuni.amis.pogamut.emohawk.agent.module.sensomotoric.EmoticonType;
30  import eis.iilang.Identifier;
31  import eis.iilang.Parameter;
32  
33  public class AnimTypeTranslator implements Java2Parameter<AnimType>, Parameter2Java<AnimType> {
34  
35  	@Override
36  	public AnimType translate(Parameter parameter) throws TranslationException {
37  		String animTypeString = Translator.getInstance().translate2Java(parameter, String.class);
38  
39  		try {
40  			return AnimType.valueOf(animTypeString);
41  		} catch (IllegalArgumentException e) {
42  			String message = String.format("%s was not a skin. Expected one of %s.", animTypeString,
43  					Arrays.toString(EmoticonType.values()));
44  			throw new TranslationException(message, e);
45  		}
46  	}
47  
48  	@Override
49  	public Class<AnimType> translatesTo() {
50  		return AnimType.class;
51  	}
52  
53  	@Override
54  	public Parameter[] translate(AnimType argument) throws TranslationException {
55  		return new Parameter[] { new Identifier(argument.name()) };
56  	}
57  
58  	@Override
59  	public Class<? extends AnimType> translatesFrom() {
60  		return AnimType.class;
61  	}
62  
63  }