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/09/20 06:46:11 UTC

svn commit: r290355 - in /beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler: genmodel/ grammar/ resources/

Author: rich
Date: Mon Sep 19 21:46:03 2005
New Revision: 290355

URL: http://svn.apache.org/viewcvs?rev=290355&view=rev
Log:
Post-v1 work.

    - Removed our synthesized schemas for Struts and Validator config files, which were used by the NetUI annotation processors.  We now use straight DTD checking.

    - Removed an invalid assert that occurred when a webapp-relative path to a source file could not be inferred, in order to populate a comment in generated XML config files.  We can't assert here since it's the user who determines the sourcepath.

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


Removed:
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/resources/struts-config_1_1.xsd
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/resources/struts-validator_1_1.xsd
Modified:
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ControllerGrammar.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidXmlFileType.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java?rev=290355&r1=290354&r2=290355&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java Mon Sep 19 21:46:03 2005
@@ -489,7 +489,6 @@
             }
         }
         
-        assert false : "could not calculate webapp-relative file from " + file;
         return file.toString();
     }
     

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ControllerGrammar.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ControllerGrammar.java?rev=290355&r1=290354&r2=290355&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ControllerGrammar.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ControllerGrammar.java Mon Sep 19 21:46:03 2005
@@ -37,9 +37,9 @@
         addMemberType( LOGIN_REQUIRED_ATTR, new AnnotationMemberType( null, this ) );
         addMemberType( ROLES_ALLOWED_ATTR, new RolesAllowedType( this ) );
         addMemberType( READONLY_ATTR, new AnnotationMemberType( null, this ) );
-        addMemberType( STRUTSMERGE_ATTR, new ValidXmlFileType( "struts-config_1_1.xsd", null, this, fcInfo ) );
+        addMemberType( STRUTSMERGE_ATTR, new ValidXmlFileType( null, null, this, fcInfo ) );
         addMemberType( VALIDATOR_VERSION_ATTR, new AnnotationMemberType( null, this ) );
-        addMemberType( VALIDATOR_MERGE_ATTR, new ValidXmlFileType( "struts-validator_1_1.xsd", null, this, fcInfo ) );
+        addMemberType( VALIDATOR_MERGE_ATTR, new ValidXmlFileType( null, null, this, fcInfo ) );
         addMemberType( TILES_DEFINITIONS_CONFIGS_ATTR, new TilesDefinitionsConfigsType( null, this, fcInfo ) );
         addMemberType( MULTIPART_HANDLER_ATTR, new AnnotationMemberType( null, this ) );
 

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidXmlFileType.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidXmlFileType.java?rev=290355&r1=290354&r2=290355&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidXmlFileType.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ValidXmlFileType.java Mon Sep 19 21:46:03 2005
@@ -21,20 +21,26 @@
 import org.apache.beehive.netui.compiler.FlowControllerInfo;
 import org.apache.beehive.netui.compiler.LocalFileEntityResolver;
 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.SAXException;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 import org.xml.sax.helpers.DefaultHandler;
+import org.w3c.dom.Document;
 
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.DocumentBuilder;
-import java.util.Map;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.io.File;
-import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 
+/**
+ * A type that requires a valid XML file.  Can accept a specific XML schema, and will fall back to DTD-checking.
+ */
 public class ValidXmlFileType
         extends WebappPathType
 {
@@ -45,7 +51,6 @@
                              FlowControllerInfo fcInfo )
     {
         super( false, requiredRuntimeVersion, parentGrammar, fcInfo );
-        assert schemaFileName != null;
         _schemaFileName = schemaFileName;
     }
 
@@ -88,28 +93,36 @@
         {
             try
             {
-                LocalFileEntityResolver entityResolver = LocalFileEntityResolver.getInstance();
-                InputSource schemaInput =  entityResolver.resolveLocalEntity(_schemaFileName);
-                assert schemaInput != null : "could not get schema resource for " + _schemaFileName;
                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                factory.setNamespaceAware(true);
+                LocalFileEntityResolver entityResolver = LocalFileEntityResolver.getInstance();
+                
+                // If a schema was specified, we'll validate against that; otherwise, we'll just use the DTD.
+                if (_schemaFileName != null) {
+                    InputSource schemaInput =  entityResolver.resolveLocalEntity(_schemaFileName);
+                    assert schemaInput != null : "could not get schema resource for " + _schemaFileName;
+                    factory.setNamespaceAware(true);
+                    factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
+                                          "http://www.w3.org/2001/XMLSchema");
+                    factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource", schemaInput);
+                }
                 factory.setValidating(true);
-                factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
-                                      "http://www.w3.org/2001/XMLSchema");
-                factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource", schemaInput);
                 DocumentBuilder builder = factory.newDocumentBuilder();
                 builder.setEntityResolver(LocalFileEntityResolver.getInstance());
-                Validator handler = new Validator(lastModTime, file, value);
+                ParseResults results = new ParseResults(lastModTime);
+                Validator handler = new Validator(results);
                 builder.setErrorHandler(handler);
-                builder.parse(file);
-                if (handler.hadErrors()) {
-                    return;
+                Document doc = builder.parse(file);
+                if (doc.getDoctype() == null && _schemaFileName == null) {
+                    // If the doctype is null, then we don't want to add errors -- there was no DTD identified.
+                    results = new ParseResults(lastModTime);
                 }
+                _parseResults.put(file.getPath(), results);
+                addErrorDiagnostics(file, results, value);
             }
             catch ( SAXParseException e )
             {
-                addErrorDiagnostic( file, e, value );
                 _parseResults.put( file.getPath(), new ParseResults( lastModTime, e ) );
+                addDiagnostic(file, e, value, true);
                 return;
             }
             catch ( Exception e )
@@ -119,23 +132,37 @@
                           new Object[]{ file.getPath(), e.getClass().getName(), e.getMessage() } );
                 return;
             }
-
-            _parseResults.put( file.getPath(), new ParseResults( lastModTime, null ) );
         }
         else
         {
-            Exception e = prevResults.getException();
+            addErrorDiagnostics(file, prevResults, value);
+        }
+    }
+
+    private void addErrorDiagnostics(File file, ParseResults results, AnnotationValue value) {
+        List errors = results.getErrors();
 
+        for (Iterator i = errors.iterator(); i.hasNext();) {
+            Exception e = (Exception) i.next();
+            
             if (e instanceof SAXParseException) {
-                addErrorDiagnostic(file, (SAXParseException) e, value);
-            } else if (e != null) {
+                addDiagnostic(file, (SAXParseException) e, value, true);
+            } else {
                 addError( value, "error.xml-read-error",
-                          new Object[]{ file.getPath(), e.getClass().getName(), e.getMessage() } );
+                        new Object[]{ file.getPath(), e.getClass().getName(), e.getMessage() } );
             }
         }
-    }
+        
+        List warnings = results.getWarnings();
 
-    private void addErrorDiagnostic( File file, SAXParseException err, AnnotationValue value )
+        for (Iterator i = warnings.iterator(); i.hasNext();) {
+            Exception e = (Exception) i.next();
+            assert e instanceof SAXParseException : e.getClass().getName();
+            addDiagnostic(file, (SAXParseException) e, value, false);
+        }
+    }
+    
+    private void addDiagnostic(File file, SAXParseException err, AnnotationValue value, boolean isError)
     {
         if ( err.getColumnNumber() != -1 && err.getLineNumber() != -1 )
         {
@@ -147,7 +174,11 @@
                         err.getMessage()
                     };
 
-            addError( value, "error.xml-parse-error", args );
+            if (isError) {
+                addError( value, "error.xml-parse-error", args );
+            } else {
+                addWarning( value, "error.xml-parse-error", args );
+            }
         }
         else if ( err.getLineNumber() != -1 )
         {
@@ -158,7 +189,11 @@
                 err.getMessage()
             };
 
-            addError( value, "error.xml-parse-error-nocolumn", args );
+            if (isError) {
+                addError( value, "error.xml-parse-error-nocolumn", args );
+            } else {
+                addWarning( value, "error.xml-parse-error-nocolumn", args );
+            }
         }
         else
         {
@@ -168,79 +203,85 @@
                 err.getMessage()
             };
 
-            addError( value, "error.xml-parse-error-nolinecolumn", args );
+            if (isError) {
+                addError( value, "error.xml-parse-error-nolinecolumn", args );
+            } else {
+                addWarning( value, "error.xml-parse-error-nolinecolumn", args );
+            }
         }
     }
 
     private static class ParseResults
     {
         private long _fileModTime;
-        private Exception _exception;
+        private List _errors = null;
+        private List _warnings = null;
 
-        public ParseResults( long fileModTime, Exception exception )
-        {
+        public ParseResults(long fileModTime) {
             _fileModTime = fileModTime;
-            _exception = exception;
+        }
+        
+        public ParseResults(long fileModTime, Exception ex) {
+            _fileModTime = fileModTime;
+            addError(ex);
         }
 
-        public long getFileModTime()
-        {
+        public long getFileModTime() {
             return _fileModTime;
         }
 
-        public void setFileModTime( long fileModTime )
-        {
+        public void setFileModTime(long fileModTime) {
             _fileModTime = fileModTime;
         }
 
-        public Exception getException()
-        {
-            return _exception;
+        public void addError(Exception e) {
+            if (_errors == null) {
+                _errors = new ArrayList();
+            }
+            _errors.add(e);
         }
-
-        public void setException( Exception exception )
-        {
-            _exception = exception;
+        
+        public void addWarning(Exception e) {
+            if (_warnings == null) {
+                _warnings = new ArrayList();
+            }
+            _warnings.add(e);
+        }
+        
+        public List getErrors() {
+            return _errors != null ? _errors : Collections.EMPTY_LIST;
+        }
+        
+        public List getWarnings() {
+            return _warnings != null ? _warnings : Collections.EMPTY_LIST;
         }
     }
 
-    private class Validator extends DefaultHandler {
+    private static class Validator extends DefaultHandler {
 
-        private long _fileModTime;
-        private File _file;
-        private AnnotationValue _value;
-        private boolean _hadErrors = false;
+        private ParseResults _results;
 
-        public Validator(long fileModTime, File file, AnnotationValue value) {
-            _fileModTime = fileModTime;
-            _file = file;
-            _value = value;
+        public Validator(ParseResults results) {
+            _results = results;
+        }
+
+        public ParseResults getResults() {
+            return _results;
         }
 
         public void error(SAXParseException ex)
                 throws SAXException {
-            ParseResults results = new ParseResults(_fileModTime, ex);
-            addErrorDiagnostic(_file, ex, _value );
-            _parseResults.put(_file.getPath(), results);
-            _hadErrors = true;
+            _results.addError(ex);
         }
 
         public void fatalError(SAXParseException ex)
                 throws SAXException {
-            error(ex);
+            _results.addError(ex);
         }
 
-        public void warning(SAXParseException exception)
+        public void warning(SAXParseException ex)
                 throws SAXException {
-            // TODO: add a compiler warning?
-        }
-
-        public boolean hadErrors() {
-            return _hadErrors;
-        }
-
-        public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException {
-            return super.resolveEntity(publicId, systemId);
+            _results.addWarning(ex);
         }
     }
 }

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java?rev=290355&r1=290354&r2=290355&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java Mon Sep 19 21:46:03 2005
@@ -232,7 +232,7 @@
                 }
             }
             
-            if ( fileToCheck != null && ! fileToCheck.exists() && ! ( ignoreDirectories && fileToCheck.isDirectory() ) )
+            if ( (fileToCheck == null || ! fileToCheck.exists()) && ! ( ignoreDirectories && fileToCheck.isDirectory() ) )
             {
                 fileExists = false;
             }