1 package nl.tudelft.goal.ut2004.translators; 2 3 import nl.tudelft.goal.ut2004.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 public class UnrealIdOrLocationTranslator implements Parameter2Java<UnrealIdOrLocation> { 12 13 @Override 14 public UnrealIdOrLocation translate(Parameter parameter) throws TranslationException { 15 16 TranslationException translationExceptionId; 17 try { 18 UnrealId id = Translator.getInstance().translate2Java(parameter, UnrealId.class); 19 return new UnrealIdOrLocation(id); 20 } catch (TranslationException e) { 21 translationExceptionId = e; 22 } 23 24 TranslationException translationExceptionLocation; 25 try { 26 Location location = Translator.getInstance().translate2Java(parameter, Location.class); 27 return new UnrealIdOrLocation(location); 28 } catch (TranslationException e) { 29 translationExceptionLocation = e; 30 } 31 32 String message = String.format("Could not translate to either UnrealId or Location. " 33 + "\nCause 1: %s\nCause 2: %s", translationExceptionId, translationExceptionLocation); 34 throw new TranslationException(message); 35 36 } 37 38 @Override 39 public Class<UnrealIdOrLocation> translatesTo() { 40 return UnrealIdOrLocation.class; 41 } 42 43 }