001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler.grammar;
020:
021: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
022: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
023: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
024: import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
025: import org.apache.beehive.netui.compiler.AnnotationMemberType;
026: import org.apache.beehive.netui.compiler.Diagnostics;
027: import org.apache.beehive.netui.compiler.CompilerUtils;
028: import org.apache.beehive.netui.compiler.FatalCompileTimeException;
029:
030: public class ValidatablePropertyGrammar extends
031: ValidationRulesContainerGrammar {
032: private static String[][] REQUIRED_ATTRS = { { PROPERTY_NAME_ATTR } };
033: private static String[][] MUTUALLY_EXCLUSIVE_ATTRS = { {
034: DISPLAY_NAME_ATTR, DISPLAY_NAME_KEY_ATTR } };
035:
036: public ValidatablePropertyGrammar(CoreAnnotationProcessorEnv env,
037: Diagnostics diags, RuntimeVersionChecker rvc) {
038: super (env, diags, rvc);
039:
040: addMemberType(PROPERTY_NAME_ATTR, new AnnotationMemberType(
041: null, this ));
042: addMemberType(DISPLAY_NAME_ATTR, new AnnotationMemberType(null,
043: this ));
044: addMemberType(DISPLAY_NAME_KEY_ATTR, new AnnotationMemberType(
045: null, this ));
046: addMemberArrayGrammar(LOCALE_RULES_ATTR,
047: new LocaleRulesGrammar(env, diags, rvc));
048: }
049:
050: /**
051: * This is overridable by derived classes, which is why it's not simply defined as required in
052: * {@link org.apache.beehive.netui.pageflow.annotations.Jpf}.
053: */
054: public String[][] getRequiredAttrs() {
055: return REQUIRED_ATTRS;
056: }
057:
058: public String[][] getMutuallyExclusiveAttrs() {
059: return MUTUALLY_EXCLUSIVE_ATTRS;
060: }
061:
062: protected boolean onBeginCheck(AnnotationInstance annotation,
063: AnnotationInstance[] parentAnnotations,
064: MemberDeclaration classMember)
065: throws FatalCompileTimeException {
066: if (parentAnnotations == null)
067: return true;
068:
069: //
070: // Look through all annotation parents for @Jpf.Action or @Jpf.SimpleAction. If we find one, and there's
071: // no validationErrorForward on it, print a warning.
072: //
073: for (int i = parentAnnotations.length - 1; i >= 0; --i) {
074: AnnotationInstance ann = parentAnnotations[i];
075:
076: if (CompilerUtils.isJpfAnnotation(ann, ACTION_TAG_NAME)
077: || CompilerUtils.isJpfAnnotation(ann,
078: SIMPLE_ACTION_TAG_NAME)) {
079: //
080: // Give a warning if there is no validationErrorForward annotation and doValidation isn't set to false.
081: //
082: if (CompilerUtils.getAnnotationValue(ann,
083: VALIDATION_ERROR_FORWARD_ATTR, true) == null) {
084: Boolean doValidation = CompilerUtils.getBoolean(
085: ann, DO_VALIDATION_ATTR, true);
086:
087: if (doValidation == null
088: || doValidation.booleanValue()) {
089: addWarning(
090: annotation,
091: "warning.validation-annotations-no-forward",
092: ANNOTATION_INTERFACE_PREFIX
093: + ann.getAnnotationType()
094: .getDeclaration()
095: .getSimpleName(),
096: VALIDATION_ERROR_FORWARD_ATTR);
097: }
098: }
099: }
100: }
101:
102: return true;
103: }
104: }
|