Author: rich Date: Wed Jun 22 12:25:21 2005 New Revision: 192976 URL: http://svn.apache.org/viewcvs?rev=192976&view=rev Log: Fix for http://issues.apache.org/jira/browse/BEEHIVE-831 : NPE if a required annotation attribute is missing for @Jpf.ValidateRequired
As part of this fix, I've filled out required-attribute constraints in our annotation processors across the board. Previously, we'd depended on pure Java constraints for required attributes in some cases. tests: bvt in neuti, bvt.myfaces and bvt.jsf-ri in netui/test/webapps/jsf (WinXP) BB: self (linux) Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/SimpleActionGrammar.java incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateCustomGrammar.java incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateValidWhenGrammar.java incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/internal/PageFlowNavigationHandler.java Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java (original) +++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java Wed Jun 22 12:25:21 2005 @@ -28,6 +28,7 @@ import java.util.List; import java.util.Iterator; +import java.util.ArrayList; public class BaseValidationRuleGrammar @@ -43,23 +44,35 @@ { BUNDLE_NAME_ATTR, MESSAGE_KEY_ATTR } }; + private String[][] _requiredAttrs = null; public BaseValidationRuleGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, RuntimeVersionChecker rvc ) { super( env, diags, VERSION_9_0_STRING, rvc ); - + addMemberType( MESSAGE_KEY_ATTR, new MessageKeyType( null, this ) ); addMemberArrayGrammar( MESSAGE_ARGS_ATTR, new ValidationMessageArgsGrammar( env, diags, rvc ) ); addMemberType( BUNDLE_NAME_ATTR, new BundleNameType( null, this ) ); } - + public BaseValidationRuleGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, + RuntimeVersionChecker rvc, String[][] requiredAttrs ) + { + this( env, diags, rvc ); + + _requiredAttrs = requiredAttrs; + } + + public String[][] getRequiredAttrs() + { + return _requiredAttrs; + } + public String[][] getMutuallyExclusiveAttrs() { return MUTUALLY_EXCLUSIVE_ATTRS; } - public String[][] getAttrDependencies() { Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/SimpleActionGrammar.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/SimpleActionGrammar.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/SimpleActionGrammar.java (original) +++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/SimpleActionGrammar.java Wed Jun 22 12:25:21 2005 @@ -113,6 +113,7 @@ { private static String[][] REQUIRED_SIMPLEACTION_ATTRS = { + { CONDITION_ATTR }, { PATH_ATTR, TILES_DEFINITION_ATTR, RETURN_ACTION_ATTR, NAVIGATE_TO_ATTR, ACTION_ATTR } }; Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateCustomGrammar.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateCustomGrammar.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateCustomGrammar.java (original) +++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateCustomGrammar.java Wed Jun 22 12:25:21 2005 @@ -20,21 +20,39 @@ import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; import org.apache.beehive.netui.compiler.Diagnostics; import org.apache.beehive.netui.compiler.RuntimeVersionChecker; +import org.apache.beehive.netui.compiler.AnnotationGrammar; public class ValidateCustomGrammar extends BaseValidationRuleGrammar { - private static final String[][] REQUIRED_ATTRS = { { MESSAGE_ATTR, MESSAGE_KEY_ATTR } }; + private static final String[][] REQUIRED_ATTRS = { { RULE_ATTR }, { MESSAGE_ATTR, MESSAGE_KEY_ATTR } }; + private static final String[][] VARIABLE_REQUIRED_ATTRS = { { NAME_ATTR }, { VALUE_ATTR } }; public ValidateCustomGrammar( AnnotationProcessorEnvironment env, Diagnostics diagnostics, RuntimeVersionChecker rvc ) { super( env, diagnostics, rvc ); + addMemberArrayGrammar( VARIABLES_ATTR, new ValidateCustomVariableGrammar() ); } public String[][] getRequiredAttrs() { return REQUIRED_ATTRS; + } + + private class ValidateCustomVariableGrammar + extends AnnotationGrammar + { + public ValidateCustomVariableGrammar() + { + super( ValidateCustomGrammar.this.getEnv(), ValidateCustomGrammar.this.getDiagnostics(), + null, ValidateCustomGrammar.this.getRuntimeVersionChecker() ); + } + + public String[][] getRequiredAttrs() + { + return VARIABLE_REQUIRED_ATTRS; + } } } Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java (original) +++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java Wed Jun 22 12:25:21 2005 @@ -33,12 +33,19 @@ public class ValidateTypeGrammar extends BaseValidationRuleGrammar { + private static final String[][] REQUIRED_ATTRS = { { TYPE_ATTR } }; + public ValidateTypeGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, - RuntimeVersionChecker runtimeVersionChecker ) + RuntimeVersionChecker runtimeVersionChecker ) { super( env, diags, runtimeVersionChecker ); addMemberType( TYPE_ATTR, new PrimitiveTypeType() ); + } + + public String[][] getRequiredAttrs() + { + return REQUIRED_ATTRS; } private class PrimitiveTypeType Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateValidWhenGrammar.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateValidWhenGrammar.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateValidWhenGrammar.java (original) +++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidateValidWhenGrammar.java Wed Jun 22 12:25:21 2005 @@ -25,7 +25,7 @@ public class ValidateValidWhenGrammar extends BaseValidationRuleGrammar { - private static final String[][] REQUIRED_ATTRS = { { MESSAGE_ATTR, MESSAGE_KEY_ATTR } }; + private static final String[][] REQUIRED_ATTRS = { { CONDITION_ATTR }, { MESSAGE_ATTR, MESSAGE_KEY_ATTR } }; public ValidateValidWhenGrammar( AnnotationProcessorEnvironment env, Diagnostics diagnostics, RuntimeVersionChecker rvc ) Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java (original) +++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java Wed Jun 22 12:25:21 2005 @@ -32,12 +32,16 @@ addMemberGrammar( VALIDATE_REQUIRED_ATTR, new ValidateRequiredGrammar( env, diags, rvc ) ); addMemberGrammar( VALIDATE_RANGE_ATTR, new ValidateRangeGrammar( env, diags, rvc ) ); - addMemberGrammar( VALIDATE_MIN_LENGTH_ATTR, new BaseValidationRuleGrammar( env, diags, rvc ) ); - addMemberGrammar( VALIDATE_MAX_LENGTH_ATTR, new BaseValidationRuleGrammar( env, diags, rvc ) ); + addMemberGrammar( VALIDATE_MIN_LENGTH_ATTR, + new BaseValidationRuleGrammar( env, diags, rvc, new String[][]{ { CHARS_ATTR } } ) ); + addMemberGrammar( VALIDATE_MAX_LENGTH_ATTR, + new BaseValidationRuleGrammar( env, diags, rvc, new String[][]{ { CHARS_ATTR } } ) ); addMemberGrammar( VALIDATE_CREDIT_CARD_ATTR, new BaseValidationRuleGrammar( env, diags, rvc ) ); addMemberGrammar( VALIDATE_EMAIL_ATTR, new BaseValidationRuleGrammar( env, diags, rvc ) ); - addMemberGrammar( VALIDATE_MASK_ATTR, new BaseValidationRuleGrammar( env, diags, rvc ) ); - addMemberGrammar( VALIDATE_DATE_ATTR, new BaseValidationRuleGrammar( env, diags, rvc ) ); + addMemberGrammar( VALIDATE_MASK_ATTR, + new BaseValidationRuleGrammar( env, diags, rvc, new String[][]{ { REGEX_ATTR } } ) ); + addMemberGrammar( VALIDATE_DATE_ATTR, + new BaseValidationRuleGrammar( env, diags, rvc, new String[][]{ { PATTERN_ATTR } } ) ); addMemberGrammar( VALIDATE_TYPE_ATTR, new ValidateTypeGrammar( env, diags, rvc ) ); addMemberGrammar( VALIDATE_VALID_WHEN_ATTR, new ValidateValidWhenGrammar( env, diags, rvc ) ); addMemberArrayGrammar( VALIDATE_CUSTOM_ATTR, new ValidateCustomGrammar( env, diags, rvc ) ); Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java (original) +++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java Wed Jun 22 12:25:21 2005 @@ -933,7 +933,7 @@ /** * A String version of the type information that can be used by tools or as runtime-accessable information, * particularly to add generics to the type (generics are "erased" during compilation and are not available - * to the runtime through reflection. + * to the runtime through reflection). */ String typeHint() default ""; Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/internal/PageFlowNavigationHandler.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/internal/PageFlowNavigationHandler.java?rev=192976&r1=192975&r2=192976&view=diff ============================================================================== --- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/internal/PageFlowNavigationHandler.java (original) +++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/internal/PageFlowNavigationHandler.java Wed Jun 22 12:25:21 2005 @@ -83,10 +83,12 @@ try { + // + // We only forward to Page Flow actions if there's a page flow appropriate for this request. + // ServletContext servletContext = ( ServletContext ) extContext; FlowControllerFactory fcFactory = FlowControllerFactory.get( servletContext ); PageFlowController pfc = fcFactory.getPageFlowForRequest( new RequestContext( httpRequest, httpResponse ) ); - PageFlowUtils.getCurrentPageFlow( httpRequest ); if ( pfc != null ) {