View Javadoc
1   /*
2    *    Copyright 2006-2023 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    *       https://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 type;
31  
32      ModelType(String type) {
33          this.type = type;
34      }
35  
36      public static ModelType getModelType(String type) {
37          if (HIERARCHICAL.type.equalsIgnoreCase(type)) {
38              return HIERARCHICAL;
39          } else if (FLAT.type.equalsIgnoreCase(type)) {
40              return FLAT;
41          } else if (CONDITIONAL.type.equalsIgnoreCase(type)) {
42              return CONDITIONAL;
43          } else {
44              throw new RuntimeException(getString("RuntimeError.13", type)); //$NON-NLS-1$
45          }
46      }
47  }