You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2005/01/20 07:02:17 UTC
svn commit: r125721 - in incubator/beehive/trunk/netui/src: compiler/org/apache/beehive/netui/compiler compiler/org/apache/beehive/netui/compiler/grammar pageflow/org/apache/beehive/netui/pageflow
Author: rich
Date: Wed Jan 19 22:02:16 2005
New Revision: 125721
URL: http://svn.apache.org/viewcvs?view=rev&rev=125721
Log:
- Added warnings when:
- there is a @Jpf.ValidateRequired annotation on a form bean getter which returns a primitive type (which will never be null, and thus will never fail validation
- there is a @Jpf.ValidateType annotation on a form bean getter which returns the same type (which can never fail validation).
- Fixed an NPE that occurred in AutoRegisterActionServlet when a parse error occurred during auto-registration of a Struts module.
DRT: netui (WinXP)
BB: self (linux)
Added:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateRequiredGrammar.java (contents, props changed)
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java (contents, props changed)
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties?view=diff&rev=125721&p1=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties&r1=125720&p2=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties&r2=125721
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties (original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/diagnostics.properties Wed Jan 19 22:02:16 2005
@@ -173,3 +173,10 @@
File "{0}" (reference inherited from a {1} annotation on {2}) could not be found in the web application.
error.validate-with-no-validation-error-forward = The {0} attribute requires a value for {1} when set to true.
+
+warning.validate-required-on-primitive-type = \
+The {0} annotation has no effect on a primitive type property, since a primitive type can never have a null value.
+
+warning.validate-type-on-same-type = \
+This {0}(type={1}.class) annotation has no effect, since the property type is {1}.
+
Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java?view=diff&rev=125721&p1=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java&r1=125720&p2=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java&r2=125721
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java (original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BaseValidationRuleGrammar.java Wed Jan 19 22:02:16 2005
@@ -24,6 +24,9 @@
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.MemberDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.TypeMirror;
+import com.sun.mirror.type.PrimitiveType;
import static org.apache.beehive.netui.compiler.JpfLanguageConstants.VERSION_9_0_STRING;
import static org.apache.beehive.netui.compiler.JpfLanguageConstants.MESSAGE_KEY_ATTR;
Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java?view=diff&rev=125721&p1=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java&r1=125720&p2=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java&r2=125721
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java (original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/LocaleRulesGrammar.java Wed Jan 19 22:02:16 2005
@@ -47,7 +47,7 @@
public class LocaleRulesGrammar
- extends AnnotationGrammar
+ extends ValidationRulesContainerGrammar
{
private static final String[][] REQUIRED_ATTRS =
{
@@ -63,20 +63,7 @@
public LocaleRulesGrammar( AnnotationProcessorEnvironment env, Diagnostics diags,
RuntimeVersionChecker rvc )
{
- super( env, diags, VERSION_9_0_STRING, rvc );
-
- // The only member that needs its own type is validateRange
- addMemberGrammar( VALIDATE_REQUIRED_ATTR, new BaseValidationRuleGrammar( 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_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_TYPE_ATTR, new ValidateTypeGrammar( env, diags, rvc ) );
- addMemberGrammar( VALIDATE_CUSTOM_ATTR, new ValidateCustomGrammar( env, diags, rvc ) );
- addMemberGrammar( VALIDATE_VALID_WHEN_ATTR, new ValidateValidWhenGrammar( env, diags, rvc ) );
+ super( env, diags, rvc );
addMemberType( LANGUAGE_ATTR, new AnnotationMemberType( null, this ) );
addMemberType( COUNTRY_ATTR, new AnnotationMemberType( null, this ) );
Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java?view=diff&rev=125721&p1=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java&r1=125720&p2=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java&r2=125721
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java (original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidatablePropertyGrammar.java Wed Jan 19 22:02:16 2005
@@ -30,7 +30,7 @@
public class ValidatablePropertyGrammar
- extends AnnotationGrammar
+ extends ValidationRulesContainerGrammar
{
private static String[][] REQUIRED_ATTRS = { { PROPERTY_NAME_ATTR } };
private static String[][] MUTUALLY_EXCLUSIVE_ATTRS = { { DISPLAY_NAME_ATTR, DISPLAY_NAME_KEY_ATTR } };
@@ -38,24 +38,12 @@
public ValidatablePropertyGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, RuntimeVersionChecker rvc )
{
- super( env, diags, VERSION_9_0_STRING, rvc );
+ super( env, diags, rvc );
addMemberType( PROPERTY_NAME_ATTR, new AnnotationMemberType( null, this ) );
addMemberType( DISPLAY_NAME_ATTR, new AnnotationMemberType( null, this ) );
addMemberType( DISPLAY_NAME_KEY_ATTR, new AnnotationMemberType( null, this ) );
addMemberArrayGrammar( LOCALE_RULES_ATTR, new LocaleRulesGrammar( env, diags, rvc ) );
-
- addMemberGrammar( VALIDATE_REQUIRED_ATTR, new BaseValidationRuleGrammar( 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_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_TYPE_ATTR, new ValidateTypeGrammar( env, diags, rvc ) );
- addMemberGrammar( VALIDATE_CUSTOM_ATTR, new ValidateCustomGrammar( env, diags, rvc ) );
- addMemberGrammar( VALIDATE_VALID_WHEN_ATTR, new ValidateValidWhenGrammar( env, diags, rvc ) );
}
/**
Added: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateRequiredGrammar.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateRequiredGrammar.java?view=auto&rev=125721
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateRequiredGrammar.java Wed Jan 19 22:02:16 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.compiler.grammar;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.MemberDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.TypeMirror;
+import com.sun.mirror.type.PrimitiveType;
+import org.apache.beehive.netui.compiler.Diagnostics;
+import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
+
+import static org.apache.beehive.netui.compiler.JpfLanguageConstants.VALIDATE_REQUIRED_TAG_NAME;
+import static org.apache.beehive.netui.compiler.JpfLanguageConstants.ANNOTATION_INTERFACE_PREFIX;
+
+public class ValidateRequiredGrammar
+ extends BaseValidationRuleGrammar
+{
+ public ValidateRequiredGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, RuntimeVersionChecker rvc )
+ {
+ super( env, diags, rvc );
+ }
+
+ protected boolean onBeginCheck( AnnotationMirror annotation, AnnotationMirror[] parentAnnotations,
+ MemberDeclaration classMember )
+ {
+ //
+ // Add a warning when this annotation is on a getter method which returns a primitive type.
+ // In that case, it will never be null.
+ //
+ if ( classMember instanceof MethodDeclaration )
+ {
+ TypeMirror returnType = ( ( MethodDeclaration ) classMember ).getReturnType();
+
+ if ( returnType instanceof PrimitiveType )
+ {
+ addWarning( annotation, "warning.validate-required-on-primitive-type",
+ ANNOTATION_INTERFACE_PREFIX + VALIDATE_REQUIRED_TAG_NAME );
+ }
+ }
+
+ return super.onBeginCheck( annotation, parentAnnotations, classMember );
+ }
+}
Modified: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java?view=diff&rev=125721&p1=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java&r1=125720&p2=incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java&r2=125721
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java (original)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidateTypeGrammar.java Wed Jan 19 22:02:16 2005
@@ -17,15 +17,20 @@
*/
package org.apache.beehive.netui.compiler.grammar;
+import static org.apache.beehive.netui.compiler.JpfLanguageConstants.ANNOTATION_INTERFACE_PREFIX;
+import static org.apache.beehive.netui.compiler.JpfLanguageConstants.VALIDATE_REQUIRED_TAG_NAME;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
import com.sun.mirror.declaration.AnnotationValue;
import com.sun.mirror.declaration.MemberDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
import com.sun.mirror.type.PrimitiveType;
+import com.sun.mirror.type.TypeMirror;
import org.apache.beehive.netui.compiler.AnnotationMemberType;
import org.apache.beehive.netui.compiler.Diagnostics;
import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
+import org.apache.beehive.netui.compiler.CompilerUtils;
import static org.apache.beehive.netui.compiler.JpfLanguageConstants.TYPE_ATTR;
@@ -40,7 +45,7 @@
addMemberType( TYPE_ATTR, new PrimitiveTypeType() );
}
-
+
private class PrimitiveTypeType
extends AnnotationMemberType
{
@@ -54,13 +59,39 @@
{
Object val = value.getValue();
+ //
+ // Make sure the type is in the list of valid types.
+ //
if ( ! ( val instanceof PrimitiveType ) )
{
addError( value, "error.must-be-primitive-type" );
}
- else if ( ( ( PrimitiveType ) val ).getKind().equals( PrimitiveType.Kind.BOOLEAN ) )
+ else
{
- addError( value, "error.invalid-type" );
+ PrimitiveType.Kind kind = ( ( PrimitiveType ) val ).getKind();
+
+ if ( kind.equals( PrimitiveType.Kind.BOOLEAN ) )
+ {
+ addError( value, "error.invalid-type" );
+ }
+ else if ( classMember instanceof MethodDeclaration )
+ {
+ //
+ // Add a warning if this annotation is on a property getter of the same type, in which case the
+ // validation rule will never fail.
+ //
+ TypeMirror returnType = ( ( MethodDeclaration ) classMember ).getReturnType();
+
+ if ( returnType instanceof PrimitiveType )
+ {
+ if ( ( ( PrimitiveType ) returnType ).getKind().equals( kind ) )
+ {
+ addWarning( value, "warning.validate-type-on-same-type",
+ ANNOTATION_INTERFACE_PREFIX + VALIDATE_TYPE_TAG_NAME,
+ kind.toString().toLowerCase() );
+ }
+ }
+ }
}
return null;
Added: incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java?view=auto&rev=125721
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationRulesContainerGrammar.java Wed Jan 19 22:02:16 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.compiler.grammar;
+
+import org.apache.beehive.netui.compiler.AnnotationGrammar;
+import org.apache.beehive.netui.compiler.Diagnostics;
+import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
+import org.apache.beehive.netui.compiler.AnnotationMemberType;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+
+import static org.apache.beehive.netui.compiler.JpfLanguageConstants.*;
+
+public abstract class ValidationRulesContainerGrammar
+ extends AnnotationGrammar
+{
+ protected ValidationRulesContainerGrammar( AnnotationProcessorEnvironment env, Diagnostics diags,
+ RuntimeVersionChecker rvc )
+ {
+ super( env, diags, VERSION_9_0_STRING, rvc );
+
+ 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_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_TYPE_ATTR, new ValidateTypeGrammar( env, diags, rvc ) );
+ addMemberGrammar( VALIDATE_CUSTOM_ATTR, new ValidateCustomGrammar( env, diags, rvc ) );
+ addMemberGrammar( VALIDATE_VALID_WHEN_ATTR, new ValidateValidWhenGrammar( env, diags, rvc ) );
+ }
+}
Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java?view=diff&rev=125721&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java&r1=125720&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java&r2=125721
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java (original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java Wed Jan 19 22:02:16 2005
@@ -602,6 +602,10 @@
//
RequestUtils.selectModule( modulePath, request, servletContext );
ModuleConfig appConfig = getModuleConfig( request );
+ assert appConfig == registeredApp;
+ // TODO: after the above assert has existed for a while, remove the appConfig variable entirely.
+ // And take out the following null check. our getModuleConfig (which calls ensureModuleConfig)
+ // will put the right module into the ServletContext.
//
// Even if we've got a registered module, it may not be active with Struts in the ServletContext.
@@ -774,6 +778,7 @@
else
{
_registeredModules.put( modulePath, ac );
+ getServletContext().setAttribute( Globals.MODULE_KEY + modulePath, ac );
}
}