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.FatalCompileTimeException; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 28 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 29 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 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.TypeInstance; 33 34 import java.util.Collection ; 35 import java.util.Iterator ; 36 37 38 public class SimpleActionGrammar 39 extends ActionGrammar 40 { 41 private static String [][] REQUIRED_ATTRS = 42 { 43 { NAME_ATTR }, 44 { PATH_ATTR, TILES_DEFINITION_ATTR, RETURN_ACTION_ATTR, NAVIGATE_TO_ATTR, FORWARD_REF_ATTR, ACTION_ATTR } 45 }; 46 47 private static String [][] MUTUALLY_EXCLUSIVE_ATTRS = 48 { 49 { USE_FORM_BEAN_ATTR, USE_FORM_BEAN_TYPE_ATTR } 50 }; 51 52 53 private ForwardGrammar _forwardGrammar; 54 55 56 public SimpleActionGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, RuntimeVersionChecker rvc, 57 FlowControllerInfo fcInfo ) 58 { 59 super( env, diags, rvc, fcInfo ); 60 61 addMemberType( FORWARD_REF_ATTR, new ForwardRefType() ); 62 addMemberArrayGrammar( CONDITIONAL_FORWARDS_ATTR, 63 new SimpleActionForwardGrammar( env, diags, null, rvc, fcInfo ) ); 64 65 _forwardGrammar = new SimpleActionGrammarPart2(); 69 } 70 71 public String [][] getMutuallyExclusiveAttrs() 72 { 73 return MUTUALLY_EXCLUSIVE_ATTRS; 74 } 75 76 protected boolean onBeginCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations, 77 MemberDeclaration classMember ) 78 throws FatalCompileTimeException 79 { 80 String name = CompilerUtils.getString( annotation, NAME_ATTR, false ); 81 82 TypeDeclaration outerClass = CompilerUtils.getOuterClass( classMember ); 83 if ( WebappPathOrActionType.actionExists( name, outerClass, annotation, getEnv(), getFlowControllerInfo(), false ) ) 84 { 85 if ( ! UniqueValueType.alreadyAddedErrorForValue( classMember, annotation, name, getEnv() ) ) 86 { 87 addError( annotation, "error.duplicate-action", new Object []{ name } ); 88 } 89 } 90 91 _forwardGrammar.check( annotation, parentAnnotations, classMember ); 96 97 return super.onBeginCheck( annotation, parentAnnotations, classMember ); 98 } 99 100 protected String getActionName( AnnotationInstance annotation, MemberDeclaration classMember ) 101 { 102 return CompilerUtils.getString( annotation, NAME_ATTR, false ); 103 } 104 105 protected TypeInstance getFormBeanType( AnnotationInstance annotation, MemberDeclaration classMember ) 106 { 107 return getUseFormBeanType( annotation, classMember ); 109 } 110 111 private static class SimpleActionForwardGrammar 112 extends ForwardGrammar 113 { 114 private static String [][] REQUIRED_SIMPLEACTION_ATTRS = 115 { 116 { PATH_ATTR, TILES_DEFINITION_ATTR, RETURN_ACTION_ATTR, NAVIGATE_TO_ATTR, ACTION_ATTR } 117 }; 118 119 public SimpleActionForwardGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 120 String requiredRuntimeVersion, RuntimeVersionChecker runtimeVersionChecker, 121 FlowControllerInfo fcInfo ) 122 { 123 super( env, diags, requiredRuntimeVersion, runtimeVersionChecker, fcInfo ); 124 } 125 126 public String [][] getRequiredAttrs() 127 { 128 return REQUIRED_SIMPLEACTION_ATTRS; 129 } 130 131 protected AnnotationMemberType getNameType() 132 { 133 return new SimpleActionForwardNameType(); 134 } 135 136 private class SimpleActionForwardNameType 137 extends ForwardNameType 138 { 139 public SimpleActionForwardNameType() 140 { 141 super( CONDITIONAL_FORWARDS_ATTR ); 142 } 143 } 144 } 145 146 private class ForwardRefType 147 extends AnnotationMemberType 148 { 149 public ForwardRefType() 150 { 151 super( null, SimpleActionGrammar.this ); 152 } 153 154 155 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member, 156 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 157 int annotationArrayIndex ) 158 { 159 Collection forwards = 160 getFlowControllerInfo().getMergedControllerAnnotation().getForwards(); 161 String forwardName = ( String ) member.getValue(); 162 163 for ( Iterator ii = forwards.iterator(); ii.hasNext(); ) 164 { 165 AnnotationInstance forwardAnn = ( AnnotationInstance ) ii.next(); 166 if ( forwardName.equals( CompilerUtils.getString( forwardAnn, NAME_ATTR, true ) ) ) return null; 167 } 168 169 if ( forwardName.equals( "_auto" ) ) return null; 171 172 addError( member, "error.unresolvable-global-forward", forwardName ); 173 return null; 174 } 175 } 176 177 private class SimpleActionGrammarPart2 178 extends ForwardGrammar 179 { 180 public SimpleActionGrammarPart2() 181 { 182 super( SimpleActionGrammar.this.getEnv(), SimpleActionGrammar.this.getDiagnostics(), null, 183 SimpleActionGrammar.this.getRuntimeVersionChecker(), 184 SimpleActionGrammar.this.getFlowControllerInfo() ); 185 } 186 187 public String [][] getRequiredAttrs() 188 { 189 return REQUIRED_ATTRS; 190 } 191 } 192 } 193 | Popular Tags |