KickJava   Java API By Example, From Geeks To Geeks.

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


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.AnnotationGrammar;
21 import org.apache.beehive.netui.compiler.CompilerUtils;
22 import org.apache.beehive.netui.compiler.Diagnostics;
23 import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
27
28 import java.util.Map JavaDoc;
29
30
31 public class ValidationMessageArgsGrammar
32         extends AnnotationGrammar
33 {
34     private static final String JavaDoc[][] MUTUALLY_EXCLUSIVE_ATTRS =
35             {
36                 { ARG_KEY_ATTR, ARG_ATTR }
37             };
38
39     private static final String JavaDoc[][] REQUIRED_ATTRS =
40             {
41                 { ARG_KEY_ATTR, ARG_ATTR },
42             };
43
44     private static final String JavaDoc[][] ATTR_DEPENDENCIES =
45             {
46                 { BUNDLE_NAME_ATTR, ARG_KEY_ATTR }
47             };
48
49
50     public ValidationMessageArgsGrammar( AnnotationProcessorEnvironment env, Diagnostics diags,
51                                          RuntimeVersionChecker rvc )
52     {
53         super( env, diags, VERSION_9_0_STRING, rvc );
54
55         // ARG_KEY_ATTR, ARG_ATTR do not need a custom type.
56
addMemberType( POSITION_ATTR, new UniqueValueType( MESSAGE_ARGS_ATTR, false, true, null, this ) );
57         addMemberType( BUNDLE_NAME_ATTR, new BundleNameType( null, this ) );
58     }
59
60     
61     public String JavaDoc[][] getMutuallyExclusiveAttrs()
62     {
63         return MUTUALLY_EXCLUSIVE_ATTRS;
64     }
65
66     
67     public String JavaDoc[][] getRequiredAttrs()
68     {
69         return REQUIRED_ATTRS;
70     }
71
72     
73     public String JavaDoc[][] getAttrDependencies()
74     {
75         return ATTR_DEPENDENCIES;
76     }
77
78     
79     protected Object JavaDoc onEndCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations,
80                                  MemberDeclaration classMember, Map JavaDoc checkResults )
81     {
82         Integer JavaDoc position = CompilerUtils.getInteger( annotation, POSITION_ATTR, true );
83
84         if ( position == null )
85         {
86             //
87
// Note, GenValidationModel.addMessageArgs() infers the position for
88
// a null position attribute from the postion of the arg in the array.
89
//
90
}
91         else if ( position.intValue() < 0 || position.intValue() > 3 )
92         {
93             addError( annotation, "error.integer-attribute-not-in-range", POSITION_ATTR,
94                       new Integer JavaDoc( 0 ), new Integer JavaDoc( 3 ) );
95         }
96
97         return null;
98     }
99 }
100
Popular Tags