View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.config;
17  
18  import static org.mybatis.generator.internal.util.messages.Messages.getString;
19  
20  /**
21   * Typesafe enum of different model types
22   * 
23   * @author Jeff Butler
24   */
25  public enum ModelType {
26      HIERARCHICAL("hierarchical"), //$NON-NLS-1$
27      FLAT("flat"), //$NON-NLS-1$
28      CONDITIONAL("conditional"); //$NON-NLS-1$
29  
30      private final String modelType;
31  
32      /**
33       * 
34       */
35      private ModelType(String modelType) {
36          this.modelType = modelType;
37      }
38  
39      public String getModelType() {
40          return modelType;
41      }
42  
43      public static ModelType getModelType(String type) {
44          if (HIERARCHICAL.getModelType().equalsIgnoreCase(type)) {
45              return HIERARCHICAL;
46          } else if (FLAT.getModelType().equalsIgnoreCase(type)) {
47              return FLAT;
48          } else if (CONDITIONAL.getModelType().equalsIgnoreCase(type)) {
49              return CONDITIONAL;
50          } else {
51              throw new RuntimeException(getString(
52                      "RuntimeError.13", type)); //$NON-NLS-1$
53          }
54      }
55  }