KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > MergedControllerAnnotation


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;
19
20 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
22 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
23 import org.apache.beehive.netui.compiler.typesystem.type.ClassType;
24
25 import java.util.Collection JavaDoc;
26 import java.util.LinkedHashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 public class MergedControllerAnnotation
31         implements JpfLanguageConstants
32 {
33     private String JavaDoc _strutsMerge;
34     private String JavaDoc _validatorVersion;
35     private String JavaDoc _validatorMerge;
36     private List JavaDoc _tilesDefsConfigs;
37     private boolean _nested;
38     private boolean _longLived;
39     private List JavaDoc _rolesAllowed;
40     private List JavaDoc _customValidatorConfigs;
41     private Boolean JavaDoc _loginRequired = null;
42     private boolean _readOnly;
43     private LinkedHashMap JavaDoc _forwards = new LinkedHashMap JavaDoc();
44     private LinkedHashMap JavaDoc _sharedFlowRefs = new LinkedHashMap JavaDoc();
45     private LinkedHashMap JavaDoc _catches = new LinkedHashMap JavaDoc();
46     private LinkedHashMap JavaDoc _simpleActions = new LinkedHashMap JavaDoc();
47     private LinkedHashMap JavaDoc _validatableBeans = new LinkedHashMap JavaDoc();
48     private LinkedHashMap JavaDoc _messageResources = new LinkedHashMap JavaDoc();
49     private LinkedHashMap JavaDoc _messageBundles = new LinkedHashMap JavaDoc();
50     private String JavaDoc _multipartHandler;
51     
52     public MergedControllerAnnotation( TypeDeclaration jclass )
53     {
54         mergeControllerAnnotations( jclass );
55     }
56     
57     public void mergeAnnotation( AnnotationInstance controllerAnnotation )
58     {
59         String JavaDoc strutsMerge = CompilerUtils.getString( controllerAnnotation, STRUTSMERGE_ATTR, true );
60         if ( strutsMerge != null ) _strutsMerge = strutsMerge;
61         
62         String JavaDoc validatorVersion = CompilerUtils.getEnumFieldName( controllerAnnotation, VALIDATOR_VERSION_ATTR, true );
63         if ( validatorVersion != null ) _validatorVersion = validatorVersion;
64
65         String JavaDoc validatorMerge = CompilerUtils.getString( controllerAnnotation, VALIDATOR_MERGE_ATTR, true );
66         if ( validatorMerge != null ) _validatorMerge = validatorMerge;
67         
68         Boolean JavaDoc nested = CompilerUtils.getBoolean( controllerAnnotation, NESTED_ATTR, true );
69         if ( nested != null ) _nested = nested.booleanValue();
70         
71         Boolean JavaDoc longLived = CompilerUtils.getBoolean( controllerAnnotation, LONGLIVED_ATTR, true );
72         if ( longLived != null ) _longLived = longLived.booleanValue();
73         
74         Boolean JavaDoc loginRequired = CompilerUtils.getBoolean( controllerAnnotation, LOGIN_REQUIRED_ATTR, true );
75         if ( loginRequired != null ) _loginRequired = loginRequired;
76         
77         Boolean JavaDoc readOnly = CompilerUtils.getBoolean( controllerAnnotation, READONLY_ATTR, true );
78         if ( readOnly != null ) _readOnly = readOnly.booleanValue();
79         
80         _rolesAllowed = mergeStringArray( _rolesAllowed, controllerAnnotation, ROLES_ALLOWED_ATTR );
81         _customValidatorConfigs =
82                 mergeStringArray( _customValidatorConfigs, controllerAnnotation, CUSTOM_VALIDATOR_CONFIGS_ATTR );
83         _tilesDefsConfigs = mergeStringArray( _tilesDefsConfigs, controllerAnnotation, TILES_DEFINITIONS_CONFIGS_ATTR );
84         mergeAnnotationArray( _forwards, controllerAnnotation, FORWARDS_ATTR, NAME_ATTR );
85         mergeAnnotationArray( _sharedFlowRefs, controllerAnnotation, SHARED_FLOW_REFS_ATTR, NAME_ATTR );
86         mergeAnnotationArray( _catches, controllerAnnotation, CATCHES_ATTR, TYPE_ATTR );
87         mergeAnnotationArray( _simpleActions, controllerAnnotation, SIMPLE_ACTIONS_ATTR, NAME_ATTR );
88         mergeAnnotationArray( _validatableBeans, controllerAnnotation, VALIDATABLE_BEANS_ATTR, TYPE_ATTR );
89         mergeAnnotationArray( _messageBundles, controllerAnnotation, MESSAGE_BUNDLES_ATTR, BUNDLE_PATH_ATTR );
90         
91         String JavaDoc multipartHandler = CompilerUtils.getEnumFieldName( controllerAnnotation, MULTIPART_HANDLER_ATTR, true );
92         if ( multipartHandler != null ) _multipartHandler = multipartHandler;
93     }
94     
95     private static List JavaDoc mergeStringArray( List JavaDoc memberList, AnnotationInstance parentAnnotation,
96                                                     String JavaDoc attr )
97     {
98         List JavaDoc newList = CompilerUtils.getStringArray( parentAnnotation, attr, true );
99         
100         if ( newList != null )
101         {
102             if ( memberList == null ) return newList;
103             memberList.addAll( newList );
104         }
105         
106         return memberList;
107     }
108     
109     private static void mergeAnnotationArray( LinkedHashMap JavaDoc keyedList,
110                                               AnnotationInstance parentAnnotation, String JavaDoc attr, String JavaDoc keyAttr )
111     {
112         List JavaDoc annotations = CompilerUtils.getAnnotationArray( parentAnnotation, attr, true );
113         
114         if ( annotations != null )
115         {
116             for ( Iterator JavaDoc ii = annotations.iterator(); ii.hasNext(); )
117             {
118                 AnnotationInstance ann = ( AnnotationInstance ) ii.next();
119                 Object JavaDoc key = CompilerUtils.getAnnotationValue( ann, keyAttr, true );
120                 if ( key != null ) keyedList.put( key.toString(), ann );
121             }
122         }
123     }
124
125     public String JavaDoc getStrutsMerge()
126     {
127         return _strutsMerge;
128     }
129
130     public String JavaDoc getValidatorVersion()
131     {
132         return _validatorVersion;
133     }
134
135     public String JavaDoc getValidatorMerge()
136     {
137         return _validatorMerge;
138     }
139
140     public List JavaDoc getTilesDefinitionsConfigs()
141     {
142         return _tilesDefsConfigs;
143     }
144
145     public boolean isNested()
146     {
147         return _nested;
148     }
149
150     public boolean isLongLived()
151     {
152         return _longLived;
153     }
154
155     public List JavaDoc getRolesAllowed()
156     {
157         return _rolesAllowed;
158     }
159     
160     public List JavaDoc getCustomValidatorConfigs()
161     {
162         return _customValidatorConfigs;
163     }
164
165     public Boolean JavaDoc isLoginRequired()
166     {
167         return _loginRequired;
168     }
169
170     public boolean isReadOnly()
171     {
172         return _readOnly;
173     }
174
175     public Collection JavaDoc getForwards()
176     {
177         return _forwards.values();
178     }
179
180     public Collection JavaDoc getSharedFlowRefs()
181     {
182         return _sharedFlowRefs.values();
183     }
184
185     public Collection JavaDoc getCatches()
186     {
187         return _catches.values();
188     }
189
190     public Collection JavaDoc getSimpleActions()
191     {
192         return _simpleActions.values();
193     }
194
195     public Collection JavaDoc getValidatableBeans()
196     {
197         return _validatableBeans.values();
198     }
199
200     public Collection JavaDoc getMessageResources()
201     {
202         return _messageResources.values();
203     }
204     
205     public Collection JavaDoc getMessageBundles()
206     {
207         return _messageBundles.values();
208     }
209
210     public String JavaDoc getMultipartHandler()
211     {
212         return _multipartHandler;
213     }
214     
215     private void mergeControllerAnnotations( TypeDeclaration jclass )
216     {
217         //
218
// Merge in all the controller annotations, starting with the most remote superclass first.
219
//
220
if ( jclass != null && jclass instanceof ClassDeclaration )
221         {
222             ClassType superClass = ( ( ClassDeclaration ) jclass ).getSuperclass();
223             if ( superClass != null ) mergeControllerAnnotations( superClass.getDeclaration() );
224             AnnotationInstance controllerAnnotation = CompilerUtils.getAnnotation( jclass, CONTROLLER_TAG_NAME );
225             if ( controllerAnnotation != null ) mergeAnnotation( controllerAnnotation );
226         }
227     }
228 }
229
Popular Tags