View Javadoc

1   package nl.tudelft.goal.emohawk.translators;
2   
3   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
4   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
5   import eis.iilang.Parameter;
6   import nl.tudelft.goal.EIS2Java.exception.TranslationException;
7   import nl.tudelft.goal.EIS2Java.translation.Parameter2Java;
8   import nl.tudelft.goal.EIS2Java.translation.Translator;
9   
10  public class UnrealIdOrLocationTranslator implements Parameter2Java<UnrealIdOrLocation> {
11  
12  	@Override
13  	public UnrealIdOrLocation translate(Parameter parameter) throws TranslationException {
14  
15  		TranslationException translationExceptionId;
16  		try {
17  			UnrealId id = Translator.getInstance().translate2Java(parameter, UnrealId.class);
18  			return new UnrealIdOrLocation(id);
19  		} catch (TranslationException e) {
20  			translationExceptionId = e;
21  		}
22  
23  		TranslationException translationExceptionLocation;
24  		try {
25  			Location location = Translator.getInstance().translate2Java(parameter, Location.class);
26  			return new UnrealIdOrLocation(location);
27  		} catch (TranslationException e) {
28  			translationExceptionLocation = e;
29  		}
30  
31  		String message = String.format("Could not translate to either UnrealId or Location. "
32  				+ "\nCause 1: %s\nCause 2: %s", translationExceptionId, translationExceptionLocation);
33  		throw new TranslationException(message);
34  
35  	}
36  
37  	@Override
38  	public Class<UnrealIdOrLocation> translatesTo() {
39  		return UnrealIdOrLocation.class;
40  	}
41  
42  }