KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > grammar > ValidatablePropertyGrammar


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

18 package org.apache.beehive.netui.compiler.grammar;
19
20 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
22 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
23 import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
24 import org.apache.beehive.netui.compiler.AnnotationMemberType;
25 import org.apache.beehive.netui.compiler.Diagnostics;
26 import org.apache.beehive.netui.compiler.CompilerUtils;
27 import org.apache.beehive.netui.compiler.FatalCompileTimeException;
28
29
30 public class ValidatablePropertyGrammar
31         extends ValidationRulesContainerGrammar
32 {
33     private static String JavaDoc[][] REQUIRED_ATTRS = { { PROPERTY_NAME_ATTR } };
34     private static String JavaDoc[][] MUTUALLY_EXCLUSIVE_ATTRS = { { DISPLAY_NAME_ATTR, DISPLAY_NAME_KEY_ATTR } };
35     
36     
37     public ValidatablePropertyGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, RuntimeVersionChecker rvc )
38     {
39         super( env, diags, rvc );
40         
41         addMemberType( PROPERTY_NAME_ATTR, new AnnotationMemberType( null, this ) );
42         addMemberType( DISPLAY_NAME_ATTR, new AnnotationMemberType( null, this ) );
43         addMemberType( DISPLAY_NAME_KEY_ATTR, new AnnotationMemberType( null, this ) );
44         addMemberArrayGrammar( LOCALE_RULES_ATTR, new LocaleRulesGrammar( env, diags, rvc ) );
45     }
46
47     /**
48      * This is overridable by derived classes, which is why it's not simply defined as required in
49      * {@link org.apache.beehive.netui.pageflow.annotations.Jpf}.
50      */

51     public String JavaDoc[][] getRequiredAttrs()
52     {
53         return REQUIRED_ATTRS;
54     }
55
56     public String JavaDoc[][] getMutuallyExclusiveAttrs()
57     {
58         return MUTUALLY_EXCLUSIVE_ATTRS;
59     }
60
61     protected boolean onBeginCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations,
62                                     MemberDeclaration classMember )
63             throws FatalCompileTimeException
64     {
65         if ( parentAnnotations == null ) return true;
66         
67         //
68
// Look through all annotation parents for @Jpf.Action or @Jpf.SimpleAction. If we find one, and there's
69
// no validationErrorForward on it, print a warning.
70
//
71
for ( int i = parentAnnotations.length - 1; i >= 0; --i )
72         {
73             AnnotationInstance ann = parentAnnotations[i];
74             
75             if ( CompilerUtils.isJpfAnnotation( ann, ACTION_TAG_NAME )
76                  || CompilerUtils.isJpfAnnotation( ann, SIMPLE_ACTION_TAG_NAME ) )
77             {
78                 //
79
// Give a warning if there is no validationErrorForward annotation and doValidation isn't set to false.
80
//
81
if ( CompilerUtils.getAnnotationValue( ann, VALIDATION_ERROR_FORWARD_ATTR, true ) == null )
82                 {
83                     Boolean JavaDoc doValidation = CompilerUtils.getBoolean( ann, DO_VALIDATION_ATTR, true );
84                     
85                     if ( doValidation == null || doValidation.booleanValue() )
86                     {
87                         addWarning( annotation, "warning.validation-annotations-no-forward",
88                                     ANNOTATION_INTERFACE_PREFIX + ann.getAnnotationType().getDeclaration().getSimpleName(),
89                                     VALIDATION_ERROR_FORWARD_ATTR );
90                     }
91                 }
92             }
93         }
94         
95         return true;
96     }
97 }
98
Popular Tags