KickJava   Java API By Example, From Geeks To Geeks.

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


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.RuntimeVersionChecker;
21 import org.apache.beehive.netui.compiler.Diagnostics;
22 import org.apache.beehive.netui.compiler.CompilerUtils;
23 import org.apache.beehive.netui.compiler.FlowControllerInfo;
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 import java.util.List JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32
33 public class MessageBundleGrammar
34         extends BaseFlowControllerGrammar
35 {
36     private static final String JavaDoc[][] REQUIRED_ATTRS = { { BUNDLE_PATH_ATTR } };
37     
38     
39     public MessageBundleGrammar( AnnotationProcessorEnvironment env, Diagnostics diags,
40                                     String JavaDoc requiredRuntimeVersion, RuntimeVersionChecker runtimeVersionChecker,
41                                     FlowControllerInfo fcInfo )
42     {
43         super( env, diags, requiredRuntimeVersion, runtimeVersionChecker, fcInfo );
44         
45         addMemberType( BUNDLE_PATH_ATTR,
46                        new UniqueValueType( MESSAGE_BUNDLES_ATTR, false, false, null, this ) );
47         addMemberType( BUNDLE_NAME_ATTR, new UniqueValueType( MESSAGE_BUNDLES_ATTR, true, true, null, this ) );
48     }
49
50     public String JavaDoc[][] getRequiredAttrs()
51     {
52         return REQUIRED_ATTRS;
53     }
54
55     protected Object JavaDoc onEndCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations,
56                                  MemberDeclaration classMember, Map JavaDoc checkResults )
57     {
58         String JavaDoc bundlePath = CompilerUtils.getString( annotation, BUNDLE_PATH_ATTR, false );
59         String JavaDoc bundleName = CompilerUtils.getString( annotation, BUNDLE_NAME_ATTR, false );
60         
61         if ( bundleName.length() == 0 )
62         {
63             AnnotationInstance immediateParent = parentAnnotations[parentAnnotations.length - 1];
64             List JavaDoc peerAnnotations =
65                     CompilerUtils.getAnnotationArray( immediateParent, MESSAGE_BUNDLES_ATTR, false );
66             
67             for ( Iterator JavaDoc ii = peerAnnotations.iterator(); ii.hasNext(); )
68             {
69                 AnnotationInstance peerAnnotation = ( AnnotationInstance ) ii.next();
70                 if ( ! CompilerUtils.annotationsAreEqual( annotation, peerAnnotation, false, getEnv() )
71                      && CompilerUtils.getString( peerAnnotation, BUNDLE_NAME_ATTR, false ).length() == 0 )
72                 {
73                     addError( annotation, "error.multiple-default-message-resources", BUNDLE_NAME_ATTR );
74                 }
75             }
76         }
77         
78         getFlowControllerInfo().addMessageBundle( bundleName, bundlePath );
79         
80         return null;
81     }
82 }
83
Popular Tags