View Javadoc

1   package org.lsst.ccs.command;
2   
3   import java.util.Arrays;
4   import java.util.Collections;
5   import java.util.List;
6   
7   /**
8    * An implementation of DictionaryArgument based on a single method argument
9    * @author turri
10   */
11  class MethodBasedDictionaryArgument implements DictionaryArgument {
12      
13      private String name;
14      private String description;
15      private String type;
16      private String simpleType;
17      private String[] values;
18      
19      MethodBasedDictionaryArgument(String name, Class type, String description) {
20          this.name = name;
21          this.type = type.getCanonicalName();
22          this.simpleType = type.getSimpleName();
23          if (type.isEnum()) {
24              Enum[] enums = ((Class<? extends Enum>) type).getEnumConstants();
25              values = new String[enums.length];
26              for (int i=0; i<enums.length; i++) {
27                  values[i] = enums[i].name().toLowerCase();
28              }
29          }
30          this.description = description;
31      }
32      
33      @Override
34      public String getName() {
35          return name;
36      }
37  
38      /**
39       * Get the type of this parameter
40       * @return The full canonical type (e.g. java.lang.String)
41       */
42      @Override
43      public String getType() {
44          return type;
45      }
46      
47      /**
48       * Get the simple type of this parameter
49       * @return The simple type (e.g. String)
50       */
51      @Override
52      public String getSimpleType() {
53          return simpleType;
54      }
55  
56      @Override
57      public String getDescription() {
58          return description;
59      }
60  
61      @Override
62      public List<String> getValues() {
63          return values == null ? Collections.<String>emptyList() : Collections.unmodifiableList(Arrays.asList(values));
64      }
65      
66      String getDefaultValue() {
67          //FIXME: Not implemented yet
68          throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
69      }
70  }