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