Author: rich
Date: Tue Apr 12 23:49:36 2005
New Revision: 161160

URL: http://svn.apache.org/viewcvs?view=rev&rev=161160
Log:
Fixes for:
    - http://issues.apache.org/jira/browse/BEEHIVE-465 : PageFlows that do not 
use annotations to declare SharedFlows should not compile
    - http://issues.apache.org/jira/browse/BEEHIVE-492 : Global.app is no 
longer handling exceptions
    - http://issues.apache.org/jira/browse/BEEHIVE-496 : 
java.lang.ClassCastException: java.lang.String is thrown when compiling a 
PageFlow with an invalid value for the "redirect" attribute

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


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/JpfLanguageConstants.java
    
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java
    
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties
    
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/TypeNameType.java
    incubator/beehive/trunk/netui/src/pageflow-jdk14/build.xml
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultExceptionsHandler.java

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?view=diff&r1=161159&r2=161160
==============================================================================
--- 
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
 Tue Apr 12 23:49:36 2005
@@ -47,6 +47,9 @@
 public class CompilerUtils
         implements JpfLanguageConstants
 {
+    private static final String ERROR_STRING = "<error>";
+    private static final TypeDeclaration ERROR_TYPE_DECLARATION = new 
ErrorTypeDeclaration();
+    
     public static boolean isJpfAnnotation( AnnotationInstance annotation, 
String unqualifiedName )
     {
         String annotationName = getDeclaration( annotation.getAnnotationType() 
).getQualifiedName();
@@ -186,7 +189,7 @@
         AnnotationValue value = getAnnotationValue( annotation, memberName, 
defaultIsNull );
         
         // If the type is the string "", it means that there is already an 
error related to the type itself.
-        if ( value != null && ERROR_TYPE_STR.equals( value.getValue() ) ) 
return null;
+        if ( value != null && isErrorString( value.getValue() ) ) return null;
         
         assert value == null || value.getValue() instanceof DeclaredType : 
value.getValue().getClass().getName();
         return value != null ? ( DeclaredType ) value.getValue() : null;
@@ -201,31 +204,81 @@
     public static Integer getInteger( AnnotationInstance annotation, String 
memberName, boolean defaultIsNull )
     {
         AnnotationValue value = getAnnotationValue( annotation, memberName, 
defaultIsNull );
-        return value != null ? ( Integer ) value.getValue() : ( defaultIsNull 
? null : new Integer( 0 ) );
+        if ( value == null ) return defaultIsNull ? null : new Integer( 0 );
+        Object result = value.getValue();
+        
+        if ( result instanceof String )
+        {
+            assert isErrorString( result ) : result;
+            return new Integer( 0 );
+        }
+        
+        return ( Integer ) value.getValue();
+    }
+    
+    public static boolean isErrorString( Object str )
+    {
+        return ERROR_STRING.equals( str );
     }
     
     public static Long getLong( AnnotationInstance annotation, String 
memberName, boolean defaultIsNull )
     {
         AnnotationValue value = getAnnotationValue( annotation, memberName, 
defaultIsNull );
-        return value != null ? ( Long ) value.getValue() : ( defaultIsNull ? 
null : new Long( 0 ) );
+        if ( value == null ) return defaultIsNull ? null : new Long( 0 );
+        Object result = value.getValue();
+        
+        if ( result instanceof String )
+        {
+            assert result.equals( ERROR_STRING ) : result;
+            return new Long( 0 );
+        }
+        
+        return ( Long ) value.getValue();
     }
     
     public static Float getFloat( AnnotationInstance annotation, String 
memberName, boolean defaultIsNull )
     {
         AnnotationValue value = getAnnotationValue( annotation, memberName, 
defaultIsNull );
-        return value != null ? ( Float ) value.getValue() : ( defaultIsNull ? 
null : new Float( 0 ) );
+        if ( value == null ) return defaultIsNull ? null : new Float( 0 );
+        Object result = value.getValue();
+        
+        if ( result instanceof String )
+        {
+            assert result.equals( ERROR_STRING ) : result;
+            return new Float( 0 );
+        }
+        
+        return ( Float ) value.getValue();
     }
     
     public static Double getDouble( AnnotationInstance annotation, String 
memberName, boolean defaultIsNull )
     {
         AnnotationValue value = getAnnotationValue( annotation, memberName, 
defaultIsNull );
-        return value != null ? ( Double ) value.getValue() : ( defaultIsNull ? 
null : new Double( 0 ) );
+        if ( value == null ) return defaultIsNull ? null : new Double( 0 );
+        Object result = value.getValue();
+        
+        if ( result instanceof String )
+        {
+            assert result.equals( ERROR_STRING ) : result;
+            return new Double( 0 );
+        }
+        
+        return ( Double ) value.getValue();
     }
     
     public static Boolean getBoolean( AnnotationInstance annotation, String 
memberName, boolean defaultIsNull )
     {
         AnnotationValue value = getAnnotationValue( annotation, memberName, 
defaultIsNull );
-        return value != null ? ( Boolean ) value.getValue() : ( defaultIsNull 
? null : Boolean.FALSE );
+        if ( value == null ) return defaultIsNull ? null : Boolean.FALSE;
+        Object result = value.getValue();
+        
+        if ( result instanceof String )
+        {
+            assert result.equals( ERROR_STRING ) : result;
+            return Boolean.FALSE;
+        }
+        
+        return ( Boolean ) value.getValue();
     }
     
     public static Object getValue( Declaration element, String annotationName, 
String memberName, boolean defaultIsNull )
@@ -277,7 +330,7 @@
         {
             Object i = ii.next();
             Object value = i instanceof AnnotationValue ? ( ( AnnotationValue 
) i ).getValue() : i;
-            if ( ! weedOutErrorType || ! ERROR_TYPE_STR.equals( value ) ) 
translatedValues.add( value );
+            if ( ! weedOutErrorType || ! isErrorString( value ) ) 
translatedValues.add( value );
         }
     }
     
@@ -972,7 +1025,7 @@
     
     public static TypeDeclaration getDeclaration( DeclaredType type )
     {
-        return type.getDeclaration();
+        return type != null ? type.getDeclaration() : ERROR_TYPE_DECLARATION;
     }
     
     private static class ErrorTypeDeclaration
@@ -991,7 +1044,7 @@
 
         public String getQualifiedName()
         {
-            return ERROR_TYPE_STR;
+            return ERROR_STRING;
         }
 
         /*

Modified: 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java?view=diff&r1=161159&r2=161160
==============================================================================
--- 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
 Tue Apr 12 23:49:36 2005
@@ -250,8 +250,6 @@
         }
     }
 
-    public static final String ERROR_TYPE_STR = "";
-    
     /**
      * When this APT option is set, the logic that warns about missing files 
looks here for web files, like .jsps.
      */

Modified: 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java?view=diff&r1=161159&r2=161160
==============================================================================
--- 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java
 Tue Apr 12 23:49:36 2005
@@ -94,6 +94,14 @@
                                            SHARED_FLOW_REF_TAG_NAME, 
sharedFlowName );
             }
         }
+        else if ( CompilerUtils.isAssignableFrom( SHARED_FLOW_BASE_CLASS, 
field.getType(), getEnv() ) )
+        {
+            // Output a warning if the field type extends SharedFlowController 
but there's no @Jpf.SharedFlowField
+            // annotation (in which case the field won't get auto-initialized 
at runtime.
+            getDiagnostics().addWarning( field, 
"warning.shared-flow-field-no-annotation",
+                                         field.getSimpleName(), 
SHARED_FLOW_BASE_CLASS,
+                                         ANNOTATION_INTERFACE_PREFIX + 
SHARED_FLOW_FIELD_TAG_NAME );
+        }
         
         super.checkField( field, jclass );
     }

Modified: 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties?view=diff&r1=161159&r2=161160
==============================================================================
--- 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties
 (original)
+++ 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties
 Tue Apr 12 23:49:36 2005
@@ -207,3 +207,6 @@
 the annotation, {1}.
 
 error.attr-depends-on-attr-value = The {0} attribute requires a value of {1} 
for attribute {2}.
+
+warning.shared-flow-field-no-annotation = \
+Field {0} is of a type that extends {1}, but it has no @{2} annotation.  It 
will not be initialized automatically.

Modified: 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/TypeNameType.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/TypeNameType.java?view=diff&r1=161159&r2=161160
==============================================================================
--- 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/TypeNameType.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/TypeNameType.java
 Tue Apr 12 23:49:36 2005
@@ -20,7 +20,6 @@
 import org.apache.beehive.netui.compiler.AnnotationMemberType;
 import org.apache.beehive.netui.compiler.CompilerUtils;
 import org.apache.beehive.netui.compiler.AnnotationGrammar;
-import org.apache.beehive.netui.compiler.JpfLanguageConstants;
 import 
org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
 import 
org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
 import 
org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
@@ -55,7 +54,7 @@
     {
         Object val = value.getValue();
         
-        if ( JpfLanguageConstants.ERROR_TYPE_STR.equals( val ) )
+        if ( CompilerUtils.isErrorString( val ) )
         {
             // This means that there is already an error related to the type 
itself.
             return null;
@@ -69,6 +68,12 @@
         else if ( val instanceof VoidType )
         {
             addError( value, "error.void-type-not-allowed" );
+            return null;
+        }
+        
+        if ( val instanceof String ) 
+        {
+            assert CompilerUtils.isErrorString( val ) : val;
             return null;
         }
         

Modified: incubator/beehive/trunk/netui/src/pageflow-jdk14/build.xml
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow-jdk14/build.xml?view=diff&r1=161159&r2=161160
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow-jdk14/build.xml (original)
+++ incubator/beehive/trunk/netui/src/pageflow-jdk14/build.xml Tue Apr 12 
23:49:36 2005
@@ -53,7 +53,12 @@
         </jar>
 
         <!-- Update the jar with all the other classes (etc.) from 
beehive-netui-pageflow.jar -->
-        <jar jarfile="${build.lib.dir}/beehive-netui-pageflow-jdk14.jar" 
basedir="${classes.dir}/pageflow" update="true" duplicate="fail" 
excludes="**/JavaControlUtils*.class"/>
+        <jar
+            jarfile="${build.lib.dir}/beehive-netui-pageflow-jdk14.jar"
+            basedir="${classes.dir}/pageflow"
+            update="true"
+            duplicate="fail"
+            excludes="**/JavaControlUtils*.class,**/Jpf*.class"/>
     </target>
 
     <target name="clean">

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java?view=diff&r1=161159&r2=161160
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
 Tue Apr 12 23:49:36 2005
@@ -442,7 +442,7 @@
         }
         
         //
-        // Legacy behavior: if there's no page flow for the request, 
initialize a GlobalApp instance.
+        // Legacy behavior: if there's no shared flow for the request, 
initialize a GlobalApp instance.
         //
         SharedFlowController ga = PageFlowUtils.getGlobalApp( request );
         

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultExceptionsHandler.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultExceptionsHandler.java?view=diff&r1=161159&r2=161160
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultExceptionsHandler.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultExceptionsHandler.java
 Tue Apr 12 23:49:36 2005
@@ -43,6 +43,7 @@
 import java.lang.reflect.Method;
 import java.util.Locale;
 import java.util.Collection;
+import java.util.Iterator;
 import java.io.IOException;
 
 import org.apache.beehive.netui.pageflow.config.PageFlowExceptionConfig;
@@ -53,6 +54,8 @@
 import org.apache.beehive.netui.pageflow.PageFlowManagedObjectException;
 import org.apache.beehive.netui.pageflow.PageFlowEventReporter;
 import org.apache.beehive.netui.pageflow.ExpressionMessage;
+import org.apache.beehive.netui.pageflow.PageFlowUtils;
+import org.apache.beehive.netui.pageflow.GlobalApp;
 import org.apache.beehive.netui.pageflow.handler.ExceptionsHandler;
 import org.apache.beehive.netui.pageflow.handler.FlowControllerHandlerContext;
 import org.apache.beehive.netui.util.Bundle;
@@ -239,27 +242,37 @@
             Collection/*< SharedFlowController >*/ sharedFlows =
                     ( ( PageFlowController ) originalFlowController 
).getSharedFlows().values();
             
-            for ( java.util.Iterator ii = sharedFlows.iterator(); 
ii.hasNext(); )  
+            for ( Iterator ii = sharedFlows.iterator(); ii.hasNext(); )  
             {
                 SharedFlowController sf = ( SharedFlowController ) ii.next();
-                ModuleConfig mc = sf.getModuleConfig();
-                ExceptionConfig ec = getExceptionConfig( exClass, mc );
-                
-                if ( ec != null )
-                {
-                    if ( _log.isDebugEnabled() )
-                    {
-                        _log.debug( "Found exception-config for " + 
exClass.getName() + " in SharedFlowController "
-                                    + sf.getDisplayName() );
-                    }                    
-                    
-                    InternalUtils.setCurrentModule( mc, request );
-                    return sf;
-                }
+                if ( checkForExceptionConfig( sf, exClass, request ) ) return 
sf;
             }
         }
         
+        assert request instanceof HttpServletRequest : 
request.getClass().getName();
+        SharedFlowController globalApp = PageFlowUtils.getGlobalApp( ( 
HttpServletRequest ) request );
+        if ( globalApp != null && checkForExceptionConfig( globalApp, exClass, 
request ) ) return globalApp;
         return null;
+    }
+    
+    private boolean checkForExceptionConfig( SharedFlowController sf, Class 
exClass, ServletRequest request )
+    {
+        ModuleConfig mc = sf.getModuleConfig();
+        ExceptionConfig ec = getExceptionConfig( exClass, mc );
+        
+        if ( ec != null )
+        {
+            if ( _log.isDebugEnabled() )
+            {
+                _log.debug( "Found exception-config for " + exClass.getName() 
+ " in SharedFlowController "
+                            + sf.getDisplayName() );
+            }                    
+            
+            InternalUtils.setCurrentModule( mc, request );
+            return true;
+        }
+        
+        return false;
     }
     
     protected ActionForward invokeExceptionHandlerClass( 
FlowControllerHandlerContext context, Throwable throwable,


Reply via email to