View Javadoc

1   /*
2    * This file is part of hyphenType. hyphenType is free software: you can
3    * redistribute it and/or modify it under the terms of the GNU General Public
4    * License as published by the Free Software Foundation, either version 3 of the
5    * License, or (at your option) any later version. hyphenType is distributed in
6    * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
8    * the GNU General Public License for more details. You should have received a
9    * copy of the GNU General Public License along with hyphenType. If not, see
10   * <http://www.gnu.org/licenses/>.
11   */
12  package org.hyphenType.documentation;
13  
14  import java.lang.reflect.Method;
15  import java.util.ArrayList;
16  import java.util.ListResourceBundle;
17  
18  import org.hyphenType.datastructure.annotations.Option;
19  import org.hyphenType.datastructure.annotations.SimpleArgument;
20  
21  /**
22   * @author Aurelio Akira M. Matsui
23   */
24  public class OptionListResourceBundle extends ListResourceBundle {
25  
26      public static final String PROPERTIES_PREFIX = OptionListResourceBundle.class.getPackage().getName();
27  
28      private Object[][] map;
29  
30      @SuppressWarnings("unchecked")
31      public OptionListResourceBundle(Class optionsInterface) {
32  
33          ArrayList<String> keys = new ArrayList<String>();
34          ArrayList<String> values = new ArrayList<String>();
35  
36          for (Method method : optionsInterface.getMethods()) {
37              if (method.isAnnotationPresent(Option.class)) {
38                  keys.add(PROPERTIES_PREFIX + method.getName());
39                  values.add(((Option) method.getAnnotation(Option.class)).description());
40              } else if (method.isAnnotationPresent(SimpleArgument.class)) {
41                  keys.add(PROPERTIES_PREFIX + method.getName());
42                  values.add(((SimpleArgument) method.getAnnotation(SimpleArgument.class)).description());
43              }
44          }
45  
46          map = new Object[keys.size()][2];
47          for (int i = 0; i < keys.size(); i++) {
48              map[i][0] = keys.get(i);
49              map[i][1] = values.get(i);
50          }
51      }
52  
53      @Override
54      protected Object[][] getContents() {
55          return map;
56      }
57  }