Author: rich
Date: Tue Feb 22 21:40:51 2005
New Revision: 154962
URL: http://svn.apache.org/viewcvs?view=rev&rev=154962
Log:
This is a contribution from Carlin Rogers, for
http://issues.apache.org/jira/browse/BEEHIVE-262 :
"- Updated the validator schema to version 1.1.
- Modified the name of the v1.1 validator package for the
XMLBean classes.
- Implemented new message arg annotation and bundle name
attributes.
- Added a grammar class for the array of message arguments.
- Provided support for the ealier, v1.0 validator that is
part of struts 1.1.
- Created a new test for the message args.
- Fixed Jira bug (BEEHIVE-261) for validation merge feature
and added a test."
DRT/BVT: netui (WinXP)
BB: self (linux)
Added:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BundleNameType.java
(with props)
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/ValidationMessageArgsGrammar.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args/Controller.jpf
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args11/Controller.jpf
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge/Controller.jpf
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge11/Controller.jpf
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&r1=154961&r2=154962
==============================================================================
---
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
Tue Feb 22 21:40:51 2005
@@ -193,8 +193,12 @@
warning.validate-type-on-same-type = \
This {0}(type={1}.class) annotation has no effect, since the property type is
{1}.
-error.nonnegative-integer-attribute = Attribute "{0}" must be a nonnegative
integer value.
-
warning.use-form-bean-on-readonly-action = \
This action has the {0} attribute set to true, but the {1} attribute may cause
the value of member field {2} \
to be modified.
+
+error.integer-attribute-not-in-range = Attribute "{0}" must be an integer
value from {1} through {2}.
+
+error.validation-bundle-support = \
+The PageFlowController validator version attribute must be more recent than
1.0 to use the {0} attribute on \
+the annotation, {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&r1=154961&r2=154962
==============================================================================
---
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
Tue Feb 22 21:40:51 2005
@@ -31,6 +31,9 @@
import static
org.apache.beehive.netui.compiler.JpfLanguageConstants.BUNDLE_NAME_ATTR;
import static
org.apache.beehive.netui.compiler.JpfLanguageConstants.MESSAGE_ARGS_ATTR;
import static
org.apache.beehive.netui.compiler.JpfLanguageConstants.DISPLAY_NAME_ATTR;
+import static
org.apache.beehive.netui.compiler.JpfLanguageConstants.POSITION_ATTR;
+
+import java.util.List;
public class BaseValidationRuleGrammar
@@ -54,6 +57,7 @@
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 ) );
}
@Override
@@ -84,10 +88,35 @@
&& CompilerUtils.getString( annotation, MESSAGE_KEY_ATTR, true )
== null
&& CompilerUtils.getString( annotation, MESSAGE_ATTR, true ) ==
null )
{
- addWarning( annotation, "warning.using-default-display-name",
- CompilerUtils.getDeclaration(
immediateParent.getAnnotationType() ).getSimpleName() );
+ boolean useDefaultDisplayName = true;
+ List< AnnotationMirror > messageArgs =
+ CompilerUtils.getAnnotationArray( annotation,
MESSAGE_ARGS_ATTR, true );
+
+ if ( messageArgs != null )
+ {
+ boolean firstArg = true;
+
+ for ( AnnotationMirror messageArg : messageArgs )
+ {
+ Integer position = CompilerUtils.getInteger( messageArg,
POSITION_ATTR, true );
+
+ if ( ( position == null && firstArg ) || ( position !=
null && position.intValue() == 0 ) )
+ {
+ useDefaultDisplayName = false;
+ break;
+ }
+
+ firstArg = false;
+ }
+ }
+
+ if ( useDefaultDisplayName )
+ {
+ addWarning( annotation, "warning.using-default-display-name",
+ CompilerUtils.getDeclaration(
immediateParent.getAnnotationType() ).getSimpleName() );
+ }
}
-
+
return super.onBeginCheck( annotation, parentAnnotations, classMember
);
}
}
Added:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BundleNameType.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BundleNameType.java?view=auto&rev=154962
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BundleNameType.java
(added)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BundleNameType.java
Tue Feb 22 21:40:51 2005
@@ -0,0 +1,114 @@
+/*
+* 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.AnnotationMemberType;
+import org.apache.beehive.netui.compiler.AnnotationGrammar;
+import org.apache.beehive.netui.compiler.CompilerUtils;
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
+import com.sun.mirror.declaration.AnnotationValue;
+import com.sun.mirror.declaration.ClassDeclaration;
+import com.sun.mirror.declaration.MemberDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+
+
+public class BundleNameType
+ extends AnnotationMemberType
+{
+ public BundleNameType( String requiredRuntimeVersion, AnnotationGrammar
parentGrammar )
+ {
+ super( requiredRuntimeVersion, parentGrammar );
+ }
+
+ @Override
+ public Object onCheck( AnnotationTypeElementDeclaration valueDecl,
AnnotationValue value,
+ AnnotationMirror[] parentAnnotations,
MemberDeclaration classMember,
+ int annotationArrayIndex )
+ {
+ //
+ // Check that the bundle attribute isn't used with commons-validator
v1.0
+ //
+ String bundle = ( String ) value.getValue();
+
+ if ( bundle != null && !bundlesSupported( parentAnnotations,
classMember ) )
+ {
+ AnnotationMirror annotation = parentAnnotations[
parentAnnotations.length - 1 ];
+ addError( value, "error.validation-bundle-support",
BUNDLE_NAME_ATTR, annotation );
+ }
+
+ return null;
+ }
+
+ protected static boolean bundlesSupported( AnnotationMirror[]
parentAnnotations, MemberDeclaration classMember )
+ {
+ //
+ // Find the validator version attribute from the controller.
+ // Look at the annotation parent root for @Jpf.Controller,
+ // @Jpf.Action or @Jpf.ValidatableProperty. If the root is
+ // the Controller then just get the required attribute.
+ // Otherwise, get the controller class declaration then the
+ // attribute.
+ //
+ AnnotationMirror ann = parentAnnotations[0];
+ String validatorVersion = null;
+
+ if ( CompilerUtils.isJpfAnnotation( ann, CONTROLLER_TAG_NAME ) )
+ {
+ validatorVersion = CompilerUtils.getEnumFieldName( ann,
VALIDATOR_VERSION_ATTR, true );
+ }
+ else
+ {
+ TypeDeclaration outerType = null;
+
+ if ( CompilerUtils.isJpfAnnotation( ann, ACTION_TAG_NAME ) )
+ {
+ outerType = CompilerUtils.getOuterClass( classMember );
+ }
+ else if ( CompilerUtils.isJpfAnnotation( ann,
VALIDATABLE_PROPERTY_TAG_NAME ) )
+ {
+ outerType = CompilerUtils.getOutermostClass( classMember );
+ }
+ else
+ {
+ // Should not hit this condition
+ assert false;
+ }
+
+ if ( outerType instanceof ClassDeclaration )
+ {
+ ann = CompilerUtils.getAnnotation( outerType,
CONTROLLER_TAG_NAME );
+
+ if ( ann != null )
+ {
+ validatorVersion = CompilerUtils.getEnumFieldName( ann,
VALIDATOR_VERSION_ATTR, true );
+ }
+ }
+ }
+
+ //
+ // Default is commons-validator v1.0 unless otherwise declared with
the @Jpf.Controller
+ // validator version attribute.
+ if ( validatorVersion == null || validatorVersion.equals(
VALIDATOR_VERSION_ONE_ZERO_STR ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+}
Propchange:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/BundleNameType.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationMessageArgsGrammar.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationMessageArgsGrammar.java?view=diff&r1=154961&r2=154962
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationMessageArgsGrammar.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/ValidationMessageArgsGrammar.java
Tue Feb 22 21:40:51 2005
@@ -61,6 +61,7 @@
// ARG_KEY_ATTR, ARG_ATTR do not need a custom type.
addMemberType( POSITION_ATTR, new UniqueValueType( MESSAGE_ARGS_ATTR,
false, true, null, this ) );
+ addMemberType( BUNDLE_NAME_ATTR, new BundleNameType( null, this ) );
}
@Override
@@ -94,9 +95,9 @@
// a null position attribute from the postion of the arg in the
array.
//
}
- else if ( position.intValue() < 0 )
+ else if ( position.intValue() < 0 || position.intValue() > 3 )
{
- addError( annotation, "error.nonnegative-integer-attribute",
POSITION_ATTR );
+ addError( annotation, "error.integer-attribute-not-in-range",
POSITION_ATTR, 0, 3 );
}
return null;
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?view=diff&r1=154961&r2=154962
==============================================================================
---
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
Tue Feb 22 21:40:51 2005
@@ -518,8 +518,8 @@
{
String arg() default "";
String argKey() default "";
- String bundleName() default ""; // optional
- int position(); // required
+ String bundleName() default "";
+ int position() default -1;
}
public enum ValidatorVersion
Modified:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args/Controller.jpf
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args/Controller.jpf?view=diff&r1=154961&r2=154962
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args/Controller.jpf
(original)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args/Controller.jpf
Tue Feb 22 21:40:51 2005
@@ -17,11 +17,9 @@
*/
package validation.messages.args;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionMapping;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
-import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.PageFlowController;
Modified:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args11/Controller.jpf
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args11/Controller.jpf?view=diff&r1=154961&r2=154962
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args11/Controller.jpf
(original)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/args11/Controller.jpf
Tue Feb 22 21:40:51 2005
@@ -17,11 +17,9 @@
*/
package validation.messages.args11;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionMapping;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
-import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.PageFlowController;
Modified:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge/Controller.jpf
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge/Controller.jpf?view=diff&r1=154961&r2=154962
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge/Controller.jpf
(original)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge/Controller.jpf
Tue Feb 22 21:40:51 2005
@@ -17,11 +17,9 @@
*/
package validation.messages.merge;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionMapping;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
-import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.PageFlowController;
Modified:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge11/Controller.jpf
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge11/Controller.jpf?view=diff&r1=154961&r2=154962
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge11/Controller.jpf
(original)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/validation/messages/merge11/Controller.jpf
Tue Feb 22 21:40:51 2005
@@ -17,11 +17,9 @@
*/
package validation.messages.merge11;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionMapping;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
-import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.PageFlowController;