View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.apt.annotation;
21  
22  public enum DynamicExpression {
23  
24    VALUE_EXPRESSION(false, true, false),
25    VALUE_EXPRESSION_REQUIRED(true, true, false),
26    METHOD_EXPRESSION(false, false, true),
27    METHOD_EXPRESSION_REQUIRED(true, false, true),
28    PROHIBITED(false, false, false),
29    /** @deprecated since 2.0.0 */
30    @Deprecated
31    VALUE_BINDING(false, true, false),
32    /** @deprecated since 2.0.0 */
33    @Deprecated
34    VALUE_BINDING_REQUIRED(true, true, false),
35    /** @deprecated since 2.0.0 */
36    @Deprecated
37    METHOD_BINDING(false, false, true),
38    /** @deprecated since 2.0.0 */
39    @Deprecated
40    METHOD_BINDING_REQUIRED(true, false, true);
41  
42    private boolean required;
43    private boolean valueExpression;
44    private boolean methodExpression;
45  
46    DynamicExpression(boolean required, boolean valueExpression, boolean methodExpression) {
47      this.required = required;
48      this.valueExpression = valueExpression;
49      this.methodExpression = methodExpression;
50    }
51  
52    public boolean isRequired() {
53      return required;
54    }
55  
56    public boolean isValueExpression() {
57      return valueExpression;
58    }
59  
60    public boolean isMethodExpression() {
61      return methodExpression;
62    }
63  
64    public String toMetaDataString() {
65      switch (this) {
66        case VALUE_EXPRESSION:
67        case VALUE_BINDING:
68          return "ALLOWED";
69        case METHOD_EXPRESSION:
70        case METHOD_BINDING:
71          return "ALLOWED";
72        case VALUE_EXPRESSION_REQUIRED:
73        case VALUE_BINDING_REQUIRED:
74          return "REQUIRED";
75        case METHOD_EXPRESSION_REQUIRED:
76        case METHOD_BINDING_REQUIRED:
77          return "REQUIRED";
78        case PROHIBITED:
79          return "PROHIBITED";
80        default:
81          throw new IllegalStateException("Unexpected DynamicExpression " + name());      
82      }
83    }
84  
85    public String toString() {
86      switch (this) {
87        case VALUE_EXPRESSION:
88        case VALUE_BINDING:
89          return "VB";
90        case VALUE_EXPRESSION_REQUIRED:
91        case VALUE_BINDING_REQUIRED:
92          return "VB";
93        case METHOD_EXPRESSION:
94        case METHOD_BINDING:
95          return "MB";
96        case METHOD_EXPRESSION_REQUIRED:
97        case METHOD_BINDING_REQUIRED:
98          return "MB";
99        case PROHIBITED:
100         return "NONE";
101       default:
102         throw new IllegalStateException("Unexpected DynamicExpression " + name());
103     }
104   }
105 }