1 18 package org.apache.beehive.netui.compiler.grammar; 19 20 import org.apache.beehive.netui.compiler.AnnotationMemberType; 21 import org.apache.beehive.netui.compiler.CompilerUtils; 22 import org.apache.beehive.netui.compiler.Diagnostics; 23 import org.apache.beehive.netui.compiler.FlowControllerInfo; 24 import org.apache.beehive.netui.compiler.RuntimeVersionChecker; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 28 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 29 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration; 30 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration; 31 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 32 import org.apache.beehive.netui.compiler.typesystem.type.DeclaredType; 33 import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance; 34 35 import java.util.ArrayList ; 36 import java.util.Collection ; 37 import java.util.Iterator ; 38 import java.util.List ; 39 40 41 public class ForwardGrammar 42 extends BaseFlowControllerGrammar 43 { 44 private static final String [][] NAVIGATE_TO_VALS = new String [][] 45 { 46 { NAVIGATE_TO_CURRENT_PAGE_STR, VERSION_8_SP2_STRING }, 47 { NAVIGATE_TO_PREVIOUS_PAGE_STR, VERSION_8_SP2_STRING }, 48 { NAVIGATE_TO_PAGE_LEGACY_STR, null }, 49 { NAVIGATE_TO_PREVIOUS_ACTION_STR, VERSION_8_SP2_STRING }, 50 }; 51 52 private static final String [][] DEPRECATED_NAVIGATE_TO_VALS = new String [][] 53 { 54 { NAVIGATE_TO_PAGE_LEGACY_STR, "warning.return-to-page-deprecated" }, 55 }; 56 57 private static String [][] MUTUALLY_EXCLUSIVE_ATTRS = 58 { 59 { PATH_ATTR, TILES_DEFINITION_ATTR, RETURN_ACTION_ATTR, NAVIGATE_TO_ATTR, ACTION_ATTR }, 60 { OUTPUT_FORM_BEAN_TYPE_ATTR, OUTPUT_FORM_BEAN_ATTR }, 61 { REDIRECT_ATTR, EXTERNAL_REDIRECT_ATTR } 62 }; 63 64 private static String [][] REQUIRED_ATTRS = 65 { 66 { NAME_ATTR }, 67 { PATH_ATTR, TILES_DEFINITION_ATTR, RETURN_ACTION_ATTR, NAVIGATE_TO_ATTR, ACTION_ATTR } 68 }; 69 70 private static String [][] ATTR_DEPENDENCIES = 71 { 72 { REDIRECT_ATTR, PATH_ATTR, NAVIGATE_TO_ATTR }, 73 { EXTERNAL_REDIRECT_ATTR, PATH_ATTR }, 74 { RESTORE_QUERY_STRING_ATTR, NAVIGATE_TO_ATTR } 75 }; 76 77 78 public ForwardGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, String requiredRuntimeVersion, 79 RuntimeVersionChecker runtimeVersionChecker, FlowControllerInfo fcInfo ) 80 { 81 super( env, diags, requiredRuntimeVersion, runtimeVersionChecker, fcInfo ); 82 83 addMemberType( NAME_ATTR, getNameType() ); 84 addMemberType( OUTPUT_FORM_BEAN_TYPE_ATTR, new TypeNameType( null, false, null, this ) ); 85 addMemberType( OUTPUT_FORM_BEAN_ATTR, new MemberFieldType( null , null, this ) ); 86 addMemberType( RETURN_ACTION_ATTR, new JavaIdentifierType( null, this, new char[]{ '.' } ) ); 87 addMemberType( PATH_ATTR, new ExternalPathOrActionType( false, null, this, fcInfo ) ); 88 addMemberType( ACTION_ATTR, new ValidActionType( null, this, fcInfo ) ); 89 addMemberType( TILES_DEFINITION_ATTR, new AnnotationMemberType( null, this ) ); 90 addMemberType( REDIRECT_ATTR, new AnnotationMemberType( null, this ) ); 91 addMemberType( EXTERNAL_REDIRECT_ATTR, new AbsolutePathType( null , this ) ); 92 addMemberType( NAVIGATE_TO_ATTR, new EnumType( NAVIGATE_TO_VALS, DEPRECATED_NAVIGATE_TO_VALS, null, this ) ); 93 addMemberType( RESTORE_QUERY_STRING_ATTR, new AnnotationMemberType( null, this ) ); 94 95 addMemberArrayGrammar( ACTION_OUTPUTS_ATTR, new ActionOutputGrammar( env, diags, runtimeVersionChecker ) ); 96 } 97 98 protected AnnotationMemberType getNameType() 99 { 100 return new ForwardNameType(); 101 } 102 103 public String [][] getMutuallyExclusiveAttrs() 104 { 105 return MUTUALLY_EXCLUSIVE_ATTRS; 106 } 107 108 public String [][] getRequiredAttrs() 109 { 110 return REQUIRED_ATTRS; 111 } 112 113 public String [][] getAttrDependencies() 114 { 115 return ATTR_DEPENDENCIES; 116 } 117 118 protected void onCheckMember( AnnotationTypeElementDeclaration memberDecl, AnnotationValue value, 119 AnnotationInstance annotation, AnnotationInstance[] parentAnnotations, 120 MemberDeclaration classMember ) 121 { 122 String valueName = memberDecl.getSimpleName(); 123 boolean isReturnAction = valueName.equals( RETURN_ACTION_ATTR ); 124 125 if ( isReturnAction ) 126 { 127 if ( ! getFlowControllerInfo().isNested() ) 128 { 129 addError( value, "error.only-valid-in-nested", new Object []{ valueName } ); 130 } 131 } 132 133 if ( valueName.equals( ACTION_OUTPUTS_ATTR ) && ( ( List ) value.getValue() ).size() > 0 ) 134 { 135 if ( CompilerUtils.getBoolean( annotation, REDIRECT_ATTR, false ).booleanValue() ) 136 { 137 addError( value, "error.action-outputs-with-redirect", REDIRECT_ATTR ); 138 } 139 140 String path = CompilerUtils.getString( annotation, PATH_ATTR, true ); 141 if ( path != null && CompilerUtils.isAbsoluteURI( path ) ) 142 { 143 addError( value, "error.action-outputs-with-absolute-uri", PATH_ATTR ); 144 } 145 } 146 147 if ( isReturnAction ) 151 { 152 TypeDeclaration outerType = CompilerUtils.getOuterClass( classMember ); 153 TypeInstance formBeanType = 154 getFlowControllerInfo().addReturnAction( ( String ) value.getValue(), annotation, outerType ); 155 156 if ( formBeanType != null && ! ( formBeanType instanceof DeclaredType ) ) 157 { 158 addError( annotation, "error.action-invalid-form-bean-type", formBeanType.toString() ); 159 } 160 } 161 } 162 163 protected class ForwardNameType 164 extends UniqueValueType 165 { 166 public ForwardNameType() 167 { 168 this( FORWARDS_ATTR ); 169 } 170 171 protected ForwardNameType( String memberGroupName ) 172 { 173 super( memberGroupName, false, false, null, ForwardGrammar.this ); 174 } 175 176 179 protected List getAdditionalAnnotationsToCheck( MemberDeclaration classMember ) 180 { 181 List additionalEntities = new ArrayList (); 187 188 TypeDeclaration outerType = CompilerUtils.getOuterClass( classMember ); 189 190 Collection classLevelCatches = 191 getFlowControllerInfo().getMergedControllerAnnotation().getCatches(); 192 addAdditionalAnnotationsToCheck( classLevelCatches, outerType, additionalEntities ); 193 194 if ( classMember instanceof MethodDeclaration ) 195 { 196 Collection methodLevelCatches = 197 CompilerUtils.getAnnotationArrayValue( classMember, ACTION_TAG_NAME, CATCHES_ATTR, true ); 198 addAdditionalAnnotationsToCheck( methodLevelCatches, outerType, additionalEntities ); 199 } 200 201 return additionalEntities; 202 } 203 204 private void addAdditionalAnnotationsToCheck( Collection catches, 205 TypeDeclaration outerType, List additionalEntities ) 206 { 207 if ( catches != null ) 212 { 213 for ( Iterator ii = catches.iterator(); ii.hasNext(); ) 214 { 215 AnnotationInstance catchAnnotation = ( AnnotationInstance ) ii.next(); 216 String methodName = CompilerUtils.getString( catchAnnotation, METHOD_ATTR, false ); 217 218 if ( methodName.length() > 0 ) 219 { 220 MethodDeclaration[] allMethods = CompilerUtils.getClassMethods( outerType, null ); 221 222 for ( int i = 0; i < allMethods.length; i++ ) 223 { 224 MethodDeclaration method = allMethods[i]; 225 AnnotationInstance exHandlerAnnotation = 226 CompilerUtils.getAnnotation( method, EXCEPTION_HANDLER_TAG_NAME ); 227 228 if ( exHandlerAnnotation != null && method.getSimpleName().equals( methodName ) ) 229 { 230 Collection forwardAnnotations = 231 CompilerUtils.getAnnotationArray( exHandlerAnnotation, FORWARDS_ATTR, false ); 232 233 for ( Iterator i3 = forwardAnnotations.iterator(); i3.hasNext(); ) 234 { 235 AnnotationInstance forwardAnnotation = ( AnnotationInstance ) i3.next(); 236 additionalEntities.add( forwardAnnotation ); 237 } 238 } 239 } 240 } 241 242 } 243 } 244 } 245 246 protected String getErrorMessageExtraInfo() 247 { 248 return CATCH_TAG_NAME; 249 } 250 251 252 protected boolean allowExactDuplicates() 253 { 254 return true; 255 } 256 } 257 } 258 | Popular Tags |