KickJava   Java API By Example, From Geeks To Geeks.

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


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.AnnotationMemberType;
21 import org.apache.beehive.netui.compiler.CompilerUtils;
22 import org.apache.beehive.netui.compiler.Diagnostics;
23 import org.apache.beehive.netui.compiler.JpfLanguageConstants;
24 import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
27 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
28 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
29 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
30
31
32 public class LocaleRulesGrammar
33         extends ValidationRulesContainerGrammar
34         implements JpfLanguageConstants
35 {
36     private static final String JavaDoc[][] REQUIRED_ATTRS =
37             {
38                 { APPLY_TO_UNHANDLED_LOCALES_ATTR, LANGUAGE_ATTR },
39             };
40     
41     private static final String JavaDoc[][] ATTR_DEPENDENCIES =
42             {
43                 { COUNTRY_ATTR, LANGUAGE_ATTR },
44                 { VARIANT_ATTR, LANGUAGE_ATTR }
45             };
46     
47     public LocaleRulesGrammar( AnnotationProcessorEnvironment env, Diagnostics diags,
48                                          RuntimeVersionChecker rvc )
49     {
50         super( env, diags, rvc );
51         
52         addMemberType( LANGUAGE_ATTR, new AnnotationMemberType( null, this ) );
53         addMemberType( COUNTRY_ATTR, new AnnotationMemberType( null, this ) );
54         addMemberType( VARIANT_ATTR, new AnnotationMemberType( null, this ) );
55         addMemberType( APPLY_TO_UNHANDLED_LOCALES_ATTR, new ApplyToUnhandledLocalesType() );
56     }
57
58     public String JavaDoc[][] getRequiredAttrs()
59     {
60         return REQUIRED_ATTRS;
61     }
62
63     public String JavaDoc[][] getAttrDependencies()
64     {
65         return ATTR_DEPENDENCIES;
66     }
67     
68     private class ApplyToUnhandledLocalesType
69             extends AnnotationMemberType
70     {
71         public ApplyToUnhandledLocalesType()
72         {
73             super( null, LocaleRulesGrammar.this );
74         }
75
76         
77         public Object JavaDoc onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member,
78                                AnnotationInstance[] parentAnnotations, MemberDeclaration classMember,
79                                int annotationArrayIndex )
80         {
81             AnnotationInstance parentAnnotation = parentAnnotations[ parentAnnotations.length - 1 ];
82             String JavaDoc language = CompilerUtils.getString( parentAnnotation, LANGUAGE_ATTR, true );
83             
84             if ( ( ( Boolean JavaDoc ) member.getValue() ).booleanValue() )
85             {
86                 if ( language != null )
87                 {
88                     addError( member, "error.incompatible-locale-annotations", LANGUAGE_ATTR,
89                               APPLY_TO_UNHANDLED_LOCALES_ATTR );
90                 }
91             }
92             else
93             {
94                 if ( language == null || language.length() == 0 )
95                 {
96                     addError( member, "error.missing-locale-annotations", LANGUAGE_ATTR,
97                               APPLY_TO_UNHANDLED_LOCALES_ATTR );
98                 }
99             }
100             
101             return null;
102         }
103     }
104 }
105
Popular Tags