001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler;
020:
021: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
022: import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
023: import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
024: import org.apache.beehive.netui.compiler.typesystem.type.ClassType;
025:
026: import java.util.Collection;
027: import java.util.LinkedHashMap;
028: import java.util.List;
029: import java.util.Iterator;
030:
031: /**
032: *
033: */
034: public class MergedControllerAnnotation implements JpfLanguageConstants {
035: private static final String NULL_KEY = "";
036:
037: private String _strutsMerge;
038: private String _validatorVersion;
039: private String _validatorMerge;
040: private List _tilesDefsConfigs;
041: private boolean _nested = false;
042: private boolean _longLived = false;
043: private List _rolesAllowed;
044: private List _customValidatorConfigs;
045: private Boolean _loginRequired = null;
046: private Boolean _readOnly = null;
047: private boolean _inheritLocalPaths = false;
048: private LinkedHashMap _forwards = new LinkedHashMap();
049: private LinkedHashMap _sharedFlowRefs = new LinkedHashMap();
050: private LinkedHashMap _catches = new LinkedHashMap();
051: private LinkedHashMap _simpleActions = new LinkedHashMap();
052: private LinkedHashMap _validatableBeans = new LinkedHashMap();
053: private LinkedHashMap _messageResources = new LinkedHashMap();
054: private LinkedHashMap _messageBundles = new LinkedHashMap();
055: private String _multipartHandler;
056:
057: public MergedControllerAnnotation(TypeDeclaration jclass) {
058: mergeControllerAnnotations(jclass);
059: }
060:
061: public void mergeAnnotation(AnnotationInstance controllerAnnotation) {
062: String strutsMerge = CompilerUtils.getString(
063: controllerAnnotation, STRUTSMERGE_ATTR, true);
064: if (strutsMerge != null)
065: _strutsMerge = strutsMerge;
066:
067: String validatorVersion = CompilerUtils.getEnumFieldName(
068: controllerAnnotation, VALIDATOR_VERSION_ATTR, true);
069: if (validatorVersion != null)
070: _validatorVersion = validatorVersion;
071:
072: String validatorMerge = CompilerUtils.getString(
073: controllerAnnotation, VALIDATOR_MERGE_ATTR, true);
074: if (validatorMerge != null)
075: _validatorMerge = validatorMerge;
076:
077: Boolean nested = CompilerUtils.getBoolean(controllerAnnotation,
078: NESTED_ATTR, true);
079: if (nested != null)
080: _nested = nested.booleanValue();
081:
082: Boolean longLived = CompilerUtils.getBoolean(
083: controllerAnnotation, LONGLIVED_ATTR, true);
084: if (longLived != null)
085: _longLived = longLived.booleanValue();
086:
087: Boolean loginRequired = CompilerUtils.getBoolean(
088: controllerAnnotation, LOGIN_REQUIRED_ATTR, true);
089: if (loginRequired != null)
090: _loginRequired = loginRequired;
091:
092: Boolean readOnly = CompilerUtils.getBoolean(
093: controllerAnnotation, READONLY_ATTR, true);
094: if (readOnly != null)
095: _readOnly = readOnly;
096:
097: Boolean inheritLocalPaths = CompilerUtils.getBoolean(
098: controllerAnnotation, INHERIT_LOCAL_PATHS_ATTR, true);
099: if (inheritLocalPaths != null)
100: _inheritLocalPaths = inheritLocalPaths.booleanValue();
101:
102: _rolesAllowed = mergeStringArray(_rolesAllowed,
103: controllerAnnotation, ROLES_ALLOWED_ATTR);
104: _customValidatorConfigs = mergeStringArray(
105: _customValidatorConfigs, controllerAnnotation,
106: CUSTOM_VALIDATOR_CONFIGS_ATTR);
107: _tilesDefsConfigs = mergeStringArray(_tilesDefsConfigs,
108: controllerAnnotation, TILES_DEFINITIONS_CONFIGS_ATTR);
109: mergeAnnotationArray(_forwards, controllerAnnotation,
110: FORWARDS_ATTR, NAME_ATTR);
111: mergeAnnotationArray(_sharedFlowRefs, controllerAnnotation,
112: SHARED_FLOW_REFS_ATTR, NAME_ATTR);
113: mergeAnnotationArray(_catches, controllerAnnotation,
114: CATCHES_ATTR, TYPE_ATTR);
115: mergeAnnotationArray(_simpleActions, controllerAnnotation,
116: SIMPLE_ACTIONS_ATTR, NAME_ATTR);
117: mergeAnnotationArray(_validatableBeans, controllerAnnotation,
118: VALIDATABLE_BEANS_ATTR, TYPE_ATTR);
119: mergeAnnotationArray(_messageBundles, controllerAnnotation,
120: MESSAGE_BUNDLES_ATTR, BUNDLE_NAME_ATTR);
121:
122: String multipartHandler = CompilerUtils.getEnumFieldName(
123: controllerAnnotation, MULTIPART_HANDLER_ATTR, true);
124: if (multipartHandler != null)
125: _multipartHandler = multipartHandler;
126: }
127:
128: private static List mergeStringArray(List memberList,
129: AnnotationInstance parentAnnotation, String attr) {
130: List newList = CompilerUtils.getStringArray(parentAnnotation,
131: attr, true);
132:
133: if (newList != null) {
134: if (memberList == null)
135: return newList;
136: memberList.addAll(newList);
137: }
138:
139: return memberList;
140: }
141:
142: private static void mergeAnnotationArray(LinkedHashMap keyedList,
143: AnnotationInstance parentAnnotation, String attr,
144: String keyAttr) {
145: List annotations = CompilerUtils.getAnnotationArray(
146: parentAnnotation, attr, true);
147:
148: if (annotations != null) {
149: for (Iterator ii = annotations.iterator(); ii.hasNext();) {
150: AnnotationInstance ann = (AnnotationInstance) ii.next();
151: Object key = CompilerUtils.getAnnotationValue(ann,
152: keyAttr, true);
153: if (key != null) {
154: keyedList.put(key.toString(), ann);
155: } else {
156: keyedList.put(NULL_KEY, ann);
157: }
158: }
159: }
160: }
161:
162: public String getStrutsMerge() {
163: return _strutsMerge;
164: }
165:
166: public String getValidatorVersion() {
167: return _validatorVersion;
168: }
169:
170: public String getValidatorMerge() {
171: return _validatorMerge;
172: }
173:
174: public List getTilesDefinitionsConfigs() {
175: return _tilesDefsConfigs;
176: }
177:
178: public boolean isNested() {
179: return _nested;
180: }
181:
182: public boolean isLongLived() {
183: return _longLived;
184: }
185:
186: public List getRolesAllowed() {
187: return _rolesAllowed;
188: }
189:
190: public List getCustomValidatorConfigs() {
191: return _customValidatorConfigs;
192: }
193:
194: public Boolean isLoginRequired() {
195: return _loginRequired;
196: }
197:
198: public Boolean isReadOnly() {
199: return _readOnly;
200: }
201:
202: public boolean isInheritLocalPaths() {
203: return _inheritLocalPaths;
204: }
205:
206: public Collection getForwards() {
207: return _forwards.values();
208: }
209:
210: public Collection getSharedFlowRefs() {
211: return _sharedFlowRefs.values();
212: }
213:
214: public Collection getCatches() {
215: return _catches.values();
216: }
217:
218: public Collection getSimpleActions() {
219: return _simpleActions.values();
220: }
221:
222: public Collection getValidatableBeans() {
223: return _validatableBeans.values();
224: }
225:
226: public Collection getMessageResources() {
227: return _messageResources.values();
228: }
229:
230: public Collection getMessageBundles() {
231: return _messageBundles.values();
232: }
233:
234: public String getMultipartHandler() {
235: return _multipartHandler;
236: }
237:
238: private void mergeControllerAnnotations(TypeDeclaration jclass) {
239: //
240: // Merge in all the controller annotations, starting with the most remote superclass first.
241: //
242: if (jclass != null && jclass instanceof ClassDeclaration) {
243: ClassType super Class = ((ClassDeclaration) jclass)
244: .getSuperclass();
245: if (super Class != null)
246: mergeControllerAnnotations(super Class.getDeclaration());
247: AnnotationInstance controllerAnnotation = CompilerUtils
248: .getAnnotation(jclass, CONTROLLER_TAG_NAME);
249: if (controllerAnnotation != null)
250: mergeAnnotation(controllerAnnotation);
251: }
252: }
253: }
|