View Javadoc

1   /*
2    * Copyright (C) 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.translators;
18  
19  import eis.eis2java.exception.TranslationException;
20  import eis.eis2java.translation.Parameter2Java;
21  import eis.eis2java.translation.Translator;
22  import eis.iilang.Parameter;
23  import java.util.Arrays;
24  import nl.tudelft.goal.ut2004.messages.Scope;
25  
26  /**
27   *
28   * @author Michiel
29   */
30  public class ScopeTranslator implements Parameter2Java<Scope> {
31  
32      @Override
33      public Scope translate(Parameter parameter) throws TranslationException {
34          String scopeString = Translator.getInstance().translate2Java(parameter, String.class);
35          
36          try {
37              return Scope.valueOfIgnoreCase(scopeString);
38          } catch (IllegalArgumentException e) {
39              String message = String.format("%s is not a valid scope. Excepted one off %", scopeString, Arrays.toString(Scope.values()));
40              throw new TranslationException(message, e);
41          }
42      }
43  
44      @Override
45      public Class<Scope> translatesTo() {
46          return Scope.class;
47      }
48      
49  }