KickJava   Java API By Example, From Geeks To Geeks.

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


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.AnnotationGrammar;
22 import org.apache.beehive.netui.compiler.CompilerUtils;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
24 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
27 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
28 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
29
30
31 public class BundleNameType
32         extends AnnotationMemberType
33 {
34     public BundleNameType( String JavaDoc requiredRuntimeVersion, AnnotationGrammar parentGrammar )
35     {
36         super( requiredRuntimeVersion, parentGrammar );
37     }
38     
39     
40     public Object JavaDoc onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value,
41                            AnnotationInstance[] parentAnnotations, MemberDeclaration classMember,
42                            int annotationArrayIndex )
43     {
44         //
45
// Check that the bundle attribute isn't used with commons-validator v1.0
46
//
47
String JavaDoc bundle = ( String JavaDoc ) value.getValue();
48
49         if ( bundle != null && !bundlesSupported( parentAnnotations, classMember ) )
50         {
51             AnnotationInstance annotation = parentAnnotations[ parentAnnotations.length - 1 ];
52             addError( value, "error.validation-bundle-support", BUNDLE_NAME_ATTR, annotation );
53         }
54
55         return null;
56     }
57
58     protected static boolean bundlesSupported( AnnotationInstance[] parentAnnotations, MemberDeclaration classMember )
59     {
60         //
61
// Find the validator version attribute from the controller.
62
// Look at the annotation parent root for @Jpf.Controller,
63
// @Jpf.Action or @Jpf.ValidatableProperty. If the root is
64
// the Controller then just get the required attribute.
65
// Otherwise, get the controller class declaration then the
66
// attribute.
67
//
68
AnnotationInstance ann = parentAnnotations[0];
69         String JavaDoc validatorVersion = null;
70
71         if ( CompilerUtils.isJpfAnnotation( ann, CONTROLLER_TAG_NAME ) )
72         {
73             validatorVersion = CompilerUtils.getEnumFieldName( ann, VALIDATOR_VERSION_ATTR, true );
74         }
75         else
76         {
77             TypeDeclaration outerType = null;
78
79             if ( CompilerUtils.isJpfAnnotation( ann, ACTION_TAG_NAME ) )
80             {
81                 outerType = CompilerUtils.getOuterClass( classMember );
82             }
83             else if ( CompilerUtils.isJpfAnnotation( ann, VALIDATABLE_PROPERTY_TAG_NAME ) )
84             {
85                 outerType = CompilerUtils.getOutermostClass( classMember );
86             }
87             else
88             {
89                 // Should not hit this condition
90
assert false;
91             }
92
93             if ( outerType instanceof ClassDeclaration )
94             {
95                 ann = CompilerUtils.getAnnotation( outerType, CONTROLLER_TAG_NAME );
96
97                 if ( ann != null )
98                 {
99                     validatorVersion = CompilerUtils.getEnumFieldName( ann, VALIDATOR_VERSION_ATTR, true );
100                 }
101             }
102         }
103
104         //
105
// Default is commons-validator v1.0 unless otherwise declared with the @Jpf.Controller
106
// validator version attribute.
107
if ( validatorVersion == null || validatorVersion.equals( VALIDATOR_VERSION_ONE_ZERO_STR ) )
108         {
109             return false;
110         }
111
112         return true;
113     }
114 }
115
Popular Tags