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/06/16 21:51:29 UTC

svn commit: r190993 - in /incubator/beehive/trunk/netui: src/compiler-core/org/apache/beehive/netui/compiler/ src/compiler-core/org/apache/beehive/netui/compiler/genmodel/ src/compiler-core/org/apache/beehive/netui/compiler/processor/ src/pageflow/org/apache/beehive/netui/pageflow/annotations/ test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/ test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/ test/webapps/drt/testRecorder/config/

Author: rich
Date: Thu Jun 16 12:51:28 2005
New Revision: 190993

URL: http://svn.apache.org/viewcvs?rev=190993&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/BEEHIVE-823 : @Jpf.FormBean annotation is not inherited

tests: bvt in netui (WinXP)
BB: self (linux)


Added:
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/BaseMessages.properties   (with props)
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/OverrideMessages.properties   (with props)
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/Controller.jpf   (with props)
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/index.jsp   (with props)
Modified:
    incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java
    incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FormBeanChecker.java
    incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
    incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/FormBeanAnnotationProcessor.java
    incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java
    incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml

Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java?rev=190993&r1=190992&r2=190993&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java (original)
+++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java Thu Jun 16 12:51:28 2005
@@ -55,6 +55,22 @@
         return annotationName.equals( ANNOTATION_QUALIFIER + unqualifiedName );
     }
     
+    public static AnnotationInstance getAnnotation( ClassDeclaration decl, String unqualifiedName, boolean inherited )
+    {
+        if ( ! inherited ) return getAnnotation( decl, unqualifiedName );
+        
+        do
+        {
+            AnnotationInstance ann = getAnnotation( decl, unqualifiedName );
+            if ( ann != null ) return ann;
+            ClassType superType = decl.getSuperclass();
+            TypeDeclaration superTypeDecl = getDeclaration( superType );
+            decl = superTypeDecl instanceof ClassDeclaration ? ( ClassDeclaration ) superTypeDecl : null;
+        } while ( decl != null );
+        
+        return null;
+    }
+    
     public static AnnotationInstance getAnnotation( Declaration element, String unqualifiedName )
     {
         return getAnnotationFullyQualified( element, ANNOTATION_QUALIFIER + unqualifiedName );

Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FormBeanChecker.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FormBeanChecker.java?rev=190993&r1=190992&r2=190993&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FormBeanChecker.java (original)
+++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FormBeanChecker.java Thu Jun 16 12:51:28 2005
@@ -43,7 +43,7 @@
             throws FatalCompileTimeException
     {
         GetterValidatablePropertyGrammar validatablePropertyGrammar = new GetterValidatablePropertyGrammar();
-        boolean isFormBeanClass = CompilerUtils.getAnnotation( jclass, FORM_BEAN_TAG_NAME ) != null;
+        boolean isFormBeanClass = CompilerUtils.getAnnotation( jclass, FORM_BEAN_TAG_NAME, true ) != null;
         
         //
         // Look for ValidationField annotations on the methods; if there are some present, then we consider this

Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java?rev=190993&r1=190992&r2=190993&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java (original)
+++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java Thu Jun 16 12:51:28 2005
@@ -297,35 +297,29 @@
         
         ClassDeclaration formClassDecl = ( ClassDeclaration ) formTypeDecl;
         
-        while ( true )
+        AnnotationInstance ann = CompilerUtils.getAnnotation( formClassDecl, FORM_BEAN_TAG_NAME, true );
+        
+        if ( ann != null )
         {
-            AnnotationInstance ann = CompilerUtils.getAnnotation( formClassDecl, FORM_BEAN_TAG_NAME );
+            String defaultMessageResources = CompilerUtils.getString( ann, MESSAGE_BUNDLE_ATTR, true );
             
-            if ( ann != null )
+            if ( defaultMessageResources != null )
             {
-                String defaultMessageResources = CompilerUtils.getString( ann, MESSAGE_BUNDLE_ATTR, true );
+                String key = "formMessages:" + CompilerUtils.getLoadableName( formClassDecl );
                 
-                if ( defaultMessageResources != null )
+                for ( Iterator ii = getMessageResourcesList().iterator(); ii.hasNext(); )  
                 {
-                    for ( Iterator ii = getMessageResourcesList().iterator(); ii.hasNext(); )  
-                    {
-                        MessageResourcesModel i = ( MessageResourcesModel ) ii.next();
-                        if ( i.getParameter().equals( defaultMessageResources ) ) return;
-                    }
-                    
-                    MessageResourcesModel mrm = new MessageResourcesModel( this );
-                    String key = "formMessages:" + CompilerUtils.getLoadableName( formClassDecl );
-                    mrm.setKey( key );
-                    mrm.setParameter( defaultMessageResources );
-                    mrm.setReturnNull( true );
-                    addMessageResources( mrm );
-                    if ( actionModel != null ) actionModel.setFormBeanMessageResourcesKey( key );
+                    MessageResourcesModel i = ( MessageResourcesModel ) ii.next();
+                    if ( key.equals( i.getKey() ) && i.getParameter().equals( defaultMessageResources ) ) return;
                 }
+                
+                MessageResourcesModel mrm = new MessageResourcesModel( this );
+                mrm.setKey( key );
+                mrm.setParameter( defaultMessageResources );
+                mrm.setReturnNull( true );
+                addMessageResources( mrm );
+                if ( actionModel != null ) actionModel.setFormBeanMessageResourcesKey( key );
             }
-            
-            ClassType superType = formClassDecl.getSuperclass();
-            if ( superType == null ) break;
-            formClassDecl = superType.getClassTypeDeclaration();
         }
     }
     

Modified: incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/FormBeanAnnotationProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/FormBeanAnnotationProcessor.java?rev=190993&r1=190992&r2=190993&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/FormBeanAnnotationProcessor.java (original)
+++ incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/FormBeanAnnotationProcessor.java Thu Jun 16 12:51:28 2005
@@ -37,7 +37,7 @@
     
     protected BaseChecker getChecker( ClassDeclaration decl, Diagnostics diagnostics )
     {
-        if ( CompilerUtils.getAnnotation( decl, FORM_BEAN_TAG_NAME ) != null )
+        if ( CompilerUtils.getAnnotation( decl, FORM_BEAN_TAG_NAME, true ) != null )
         {
             return new FormBeanChecker( getAnnotationProcessorEnvironment(), diagnostics );
         }

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=190993&r1=190992&r2=190993&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 Thu Jun 16 12:51:28 2005
@@ -19,6 +19,8 @@
 
 import java.lang.annotation.Target;
 import java.lang.annotation.Retention;
+import java.lang.annotation.Inherited;
+
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.ElementType.FIELD;
@@ -1699,6 +1701,7 @@
      */
     @Target( TYPE )
     @Retention( RUNTIME )
+    @Inherited
     public @interface FormBean
     {
         /**

Added: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/BaseMessages.properties
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/BaseMessages.properties?rev=190993&view=auto
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/BaseMessages.properties (added)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/BaseMessages.properties Thu Jun 16 12:51:28 2005
@@ -0,0 +1 @@
+msg=Got the message!

Propchange: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/BaseMessages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/OverrideMessages.properties
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/OverrideMessages.properties?rev=190993&view=auto
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/OverrideMessages.properties (added)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/OverrideMessages.properties Thu Jun 16 12:51:28 2005
@@ -0,0 +1 @@
+msg=Got the <i>override</i> message!

Propchange: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/inheritFormBeanMessages/OverrideMessages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/Controller.jpf
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/Controller.jpf?rev=190993&view=auto
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/Controller.jpf (added)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/Controller.jpf Thu Jun 16 12:51:28 2005
@@ -0,0 +1,121 @@
+/*
+ * 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 miniTests.inheritFormBeanMessages;
+
+import org.apache.beehive.netui.pageflow.*;
+import org.apache.beehive.netui.pageflow.annotations.*;
+
+@Jpf.Controller(
+    simpleActions={
+        @Jpf.SimpleAction(name="begin", path="index.jsp")
+    }
+)
+public class Controller extends PageFlowController
+{
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(name="index", path="index.jsp")
+        },
+        validationErrorForward=@Jpf.Forward(name="failure", path="index.jsp")
+    )
+    public Forward submitBaseFormBean( BaseFormBean form )
+    {
+        return new Forward( "index" );
+    }
+
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(name="index", path="index.jsp")
+        },
+        validationErrorForward=@Jpf.Forward(name="failure", path="index.jsp")
+    )
+    public Forward submitDerivedFormBean( DerivedFormBean form )
+    {
+        return new Forward( "index" );
+    }
+
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(name="index", path="index.jsp")
+        },
+        validationErrorForward=@Jpf.Forward(name="failure", path="index.jsp")
+    )
+    public Forward submitOverridingFormBean( OverridingFormBean form )
+    {
+        return new Forward( "index" );
+    }
+
+    @Jpf.FormBean(messageBundle="miniTests.inheritFormBeanMessages.BaseMessages")
+    public static class BaseFormBean
+        implements java.io.Serializable
+    {
+        private String _foo;
+
+        @Jpf.ValidatableProperty(
+            validateRequired=@Jpf.ValidateRequired(messageKey="msg")
+        )
+        public String getFoo()
+        {
+            return _foo;
+        }
+
+        public void setFoo( String foo )
+        {
+            _foo = foo;
+        }
+    }
+
+    public static class DerivedFormBean
+        extends BaseFormBean
+    {
+        private String _bar;
+
+        @Jpf.ValidatableProperty(
+            validateRequired=@Jpf.ValidateRequired(messageKey="msg")
+        )
+        public String getBar()
+        {
+            return _bar;
+        }
+
+        public void setBar( String bar )
+        {
+            _bar = bar;
+        }
+    }
+
+    @Jpf.FormBean(messageBundle="miniTests.inheritFormBeanMessages.OverrideMessages")
+    public static class OverridingFormBean
+        extends BaseFormBean
+    {
+        private String _baz;
+
+        @Jpf.ValidatableProperty(
+            validateRequired=@Jpf.ValidateRequired(messageKey="msg")
+        )
+        public String getBaz()
+        {
+            return _baz;
+        }
+
+        public void setBaz( String baz )
+        {
+            _baz = baz;
+        }
+    }
+}

Propchange: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/Controller.jpf
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/index.jsp?rev=190993&view=auto
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/index.jsp (added)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/index.jsp Thu Jun 16 12:51:28 2005
@@ -0,0 +1,56 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+
+
+<netui:html>
+    <head>
+        <netui:base/>
+    </head>
+    <netui:body>
+        <h3>${pageFlow.URI}</h3>
+
+        This test verifies that a <code>@Jpf.FormBean</code> annotation is inherited from a superclass
+        if none is provided on the derived class, and that it is overridden if the derived class has one.
+        
+        <ul>
+            <li>
+                The first <code>netui:form</code> uses the base class, which defines message resources
+                in its <code>@Jpf.FormBean</code> annotation.
+            </li>
+            <li>
+                The second <code>netui:form</code> uses a derived class, which simply inherits the
+                <code>@Jpf.FormBean</code> annotation.
+            </li>
+            <li>
+                The second <code>netui:form</code> uses a derived class, which overrides the
+                <code>@Jpf.FormBean</code> annotation.
+            </li>
+        </ul>
+
+        In each case, leave the text box empty when you press Submit.
+        <br/>
+        <br/>
+        <netui:form action="submitBaseFormBean">
+            foo: <netui:textBox dataSource="actionForm.foo"/><netui:error key="foo"/>
+            <br/>
+            <netui:button value="Submit BaseFormBean"/>
+        </netui:form>
+        <netui:form action="submitDerivedFormBean">
+            bar: <netui:textBox dataSource="actionForm.bar"/><netui:error key="bar"/>
+            <netui:hidden dataSource="actionForm.foo" dataInput="something"/>
+            <br/>
+            <netui:button value="Submit DerivedFormBean"/>
+        </netui:form>
+        <netui:form action="submitOverridingFormBean">
+            baz: <netui:textBox dataSource="actionForm.baz"/><netui:error key="baz"/>
+            <netui:hidden dataSource="actionForm.foo" dataInput="something"/>
+            <br/>
+            <netui:button value="Submit OverridingFormBean"/>
+        </netui:form>
+    </netui:body>
+</netui:html>
+
+  
+

Propchange: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/inheritFormBeanMessages/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml?rev=190993&r1=190992&r2=190993&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml (original)
+++ incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml Thu Jun 16 12:51:28 2005
@@ -4266,6 +4266,21 @@
          </features>
       </test>
       <test>
+         <name>InheritFormBeanMessages</name>
+         <description>Test to ensure that a @Jpf.FormBean annotation is inherited from a superclass if none is provided on the derived class, and that it is overridden if the derived class has one.</description>
+         <webapp>coreWeb</webapp>
+         <categories>
+            <category>bvt</category>
+            <category>bvt.struts11</category>
+            <category>corePageFlow</category>
+         </categories>
+         <features>
+            <feature>PageFlow</feature>
+            <feature>Inheritance</feature>
+            <feature>Form</feature>
+         </features>
+      </test>
+      <test>
          <name>InitFormBeanInterface</name>
          <description>Test to ensure that we can initialize the form bean on a JSP even when the destination action accepts an interface as its form bean argument, and the previous action passes a concrete implementation of that interface on the Forward. </description>
          <webapp>coreWeb</webapp>