1 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 ; 26 import java.util.LinkedHashMap ; 27 import java.util.List ; 28 import java.util.Iterator ; 29 30 public class MergedControllerAnnotation 31 implements JpfLanguageConstants 32 { 33 private String _strutsMerge; 34 private String _validatorVersion; 35 private String _validatorMerge; 36 private List _tilesDefsConfigs; 37 private boolean _nested; 38 private boolean _longLived; 39 private List _rolesAllowed; 40 private List _customValidatorConfigs; 41 private Boolean _loginRequired = null; 42 private boolean _readOnly; 43 private LinkedHashMap _forwards = new LinkedHashMap (); 44 private LinkedHashMap _sharedFlowRefs = new LinkedHashMap (); 45 private LinkedHashMap _catches = new LinkedHashMap (); 46 private LinkedHashMap _simpleActions = new LinkedHashMap (); 47 private LinkedHashMap _validatableBeans = new LinkedHashMap (); 48 private LinkedHashMap _messageResources = new LinkedHashMap (); 49 private LinkedHashMap _messageBundles = new LinkedHashMap (); 50 private String _multipartHandler; 51 52 public MergedControllerAnnotation( TypeDeclaration jclass ) 53 { 54 mergeControllerAnnotations( jclass ); 55 } 56 57 public void mergeAnnotation( AnnotationInstance controllerAnnotation ) 58 { 59 String strutsMerge = CompilerUtils.getString( controllerAnnotation, STRUTSMERGE_ATTR, true ); 60 if ( strutsMerge != null ) _strutsMerge = strutsMerge; 61 62 String validatorVersion = CompilerUtils.getEnumFieldName( controllerAnnotation, VALIDATOR_VERSION_ATTR, true ); 63 if ( validatorVersion != null ) _validatorVersion = validatorVersion; 64 65 String validatorMerge = CompilerUtils.getString( controllerAnnotation, VALIDATOR_MERGE_ATTR, true ); 66 if ( validatorMerge != null ) _validatorMerge = validatorMerge; 67 68 Boolean nested = CompilerUtils.getBoolean( controllerAnnotation, NESTED_ATTR, true ); 69 if ( nested != null ) _nested = nested.booleanValue(); 70 71 Boolean longLived = CompilerUtils.getBoolean( controllerAnnotation, LONGLIVED_ATTR, true ); 72 if ( longLived != null ) _longLived = longLived.booleanValue(); 73 74 Boolean loginRequired = CompilerUtils.getBoolean( controllerAnnotation, LOGIN_REQUIRED_ATTR, true ); 75 if ( loginRequired != null ) _loginRequired = loginRequired; 76 77 Boolean 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 multipartHandler = CompilerUtils.getEnumFieldName( controllerAnnotation, MULTIPART_HANDLER_ATTR, true ); 92 if ( multipartHandler != null ) _multipartHandler = multipartHandler; 93 } 94 95 private static List mergeStringArray( List memberList, AnnotationInstance parentAnnotation, 96 String attr ) 97 { 98 List 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 keyedList, 110 AnnotationInstance parentAnnotation, String attr, String keyAttr ) 111 { 112 List annotations = CompilerUtils.getAnnotationArray( parentAnnotation, attr, true ); 113 114 if ( annotations != null ) 115 { 116 for ( Iterator ii = annotations.iterator(); ii.hasNext(); ) 117 { 118 AnnotationInstance ann = ( AnnotationInstance ) ii.next(); 119 Object key = CompilerUtils.getAnnotationValue( ann, keyAttr, true ); 120 if ( key != null ) keyedList.put( key.toString(), ann ); 121 } 122 } 123 } 124 125 public String getStrutsMerge() 126 { 127 return _strutsMerge; 128 } 129 130 public String getValidatorVersion() 131 { 132 return _validatorVersion; 133 } 134 135 public String getValidatorMerge() 136 { 137 return _validatorMerge; 138 } 139 140 public List 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 getRolesAllowed() 156 { 157 return _rolesAllowed; 158 } 159 160 public List getCustomValidatorConfigs() 161 { 162 return _customValidatorConfigs; 163 } 164 165 public Boolean isLoginRequired() 166 { 167 return _loginRequired; 168 } 169 170 public boolean isReadOnly() 171 { 172 return _readOnly; 173 } 174 175 public Collection getForwards() 176 { 177 return _forwards.values(); 178 } 179 180 public Collection getSharedFlowRefs() 181 { 182 return _sharedFlowRefs.values(); 183 } 184 185 public Collection getCatches() 186 { 187 return _catches.values(); 188 } 189 190 public Collection getSimpleActions() 191 { 192 return _simpleActions.values(); 193 } 194 195 public Collection getValidatableBeans() 196 { 197 return _validatableBeans.values(); 198 } 199 200 public Collection getMessageResources() 201 { 202 return _messageResources.values(); 203 } 204 205 public Collection getMessageBundles() 206 { 207 return _messageBundles.values(); 208 } 209 210 public String getMultipartHandler() 211 { 212 return _multipartHandler; 213 } 214 215 private void mergeControllerAnnotations( TypeDeclaration jclass ) 216 { 217 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 |