db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henn...@apache.org
Subject cvs commit: db-torque/src/generator/src/java/org/apache/torque/engine/database/transform DTDResolver.java XmlToAppData.java XmlToData.java
Date Fri, 25 Jul 2003 16:39:08 GMT
henning     2003/07/25 09:39:08

  Modified:    src/generator/src/java/org/apache/torque/engine/database/transform
                        DTDResolver.java XmlToAppData.java XmlToData.java
  Log:
  Clean up error handling in the Parser classes. Let all the classes throw
  SAX Errors up the calling chain.
  
  Remove unnecessary callback handlers and error message fields.
  
  Make sure that the callers get exceptions to handle.
  
  Revision  Changes    Path
  1.7       +11 -12    db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/DTDResolver.java
  
  Index: DTDResolver.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/DTDResolver.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DTDResolver.java	29 Jun 2003 13:38:36 -0000	1.6
  +++ DTDResolver.java	25 Jul 2003 16:39:07 -0000	1.7
  @@ -63,6 +63,9 @@
   
   import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
  +import org.apache.torque.engine.EngineException;
   
   /**
    * A resolver to get the database.dtd file for the XML parser from the jar.
  @@ -88,6 +91,7 @@
        * constructor
        */
       public DTDResolver()
  +            throws SAXException
       {
           try
           {
  @@ -108,7 +112,7 @@
           }
           catch (Exception ex)
           {
  -            log.error("Could not get stream for database.dtd", ex);
  +            throw new SAXException("Could not get stream for database.dtd", ex);
           }
       }
   
  @@ -120,6 +124,7 @@
        * @return an InputSource for the database.dtd file
        */
       public InputSource resolveEntity(String publicId, String systemId)
  +            throws IOException
       {
           if (databaseDTD != null && WEB_SITE_DTD.equals(systemId))
           {
  @@ -150,16 +155,10 @@
        * @return <code>InputSource</code> for the URL.
        */
       private InputSource getInputSource(String urlString)
  +            throws IOException
       {
  -        try
  -        {
  -            URL url = new URL(urlString);
  -            return new InputSource(url.openStream());
  -        }
  -        catch (IOException ex)
  -        {
  -            log.error("Couldn't read DTD specified in XML schema: ", ex);
  -            return new InputSource();
  -        }
  +        URL url = new URL(urlString);
  +        InputSource src = new InputSource(url.openStream());
  +        return src;
       }
   }
  
  
  
  1.4       +15 -58    db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
  
  Index: XmlToAppData.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XmlToAppData.java	18 Jul 2003 20:24:38 -0000	1.3
  +++ XmlToAppData.java	25 Jul 2003 16:39:07 -0000	1.4
  @@ -57,6 +57,7 @@
   import java.io.BufferedReader;
   import java.io.FileReader;
   import java.io.FileNotFoundException;
  +import java.io.IOException;
   import java.io.File;
   import java.util.Vector;
   import java.util.Stack;
  @@ -64,6 +65,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import org.apache.torque.engine.EngineException;
   import org.apache.torque.engine.database.model.AppData;
   import org.apache.torque.engine.database.model.Column;
   import org.apache.torque.engine.database.model.Database;
  @@ -79,6 +81,7 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXParseException;
   import org.xml.sax.helpers.DefaultHandler;
  +import org.xml.sax.SAXException;
   
   /**
    * A Class that is used to parse an input xml schema file and creates an AppData
  @@ -104,7 +107,6 @@
       private Unique currUnique;
   
       private boolean firstPass;
  -    private String errorMessage;
       private boolean isExternalSchema;
       private String currentPackage;
       private String currentXmlFile;
  @@ -138,7 +140,6 @@
           app = new AppData(databaseType, basePropsFilePath);
           this.defaultPackage = defaultPackage;
           firstPass = true;
  -        errorMessage = "";
       }
   
       /**
  @@ -149,6 +150,7 @@
        * @return AppData populated by <code>xmlFile</code>.
        */
       public AppData parseFile(String xmlFile)
  +            throws EngineException
       {
           try
           {
  @@ -167,14 +169,14 @@
               {
                   alreadyReadFiles = new Vector(3, 1);
               }
  -
  +            
               // remember the file to avoid looping
               alreadyReadFiles.add(xmlFile);
  -
  +            
               currentXmlFile = xmlFile;
  -
  +            
               SAXParser parser = saxFactory.newSAXParser();
  -
  +            
               FileReader fr = null;
               try
               {
  @@ -200,19 +202,15 @@
           }
           catch (Exception e)
           {
  -            log.error(e, e);
  +            throw new EngineException(e);
           }
           if (!isExternalSchema)
           {
               firstPass = false;
           }
  -        if (errorMessage.length() > 0)
  -        {
  -            log.error("Error in XML schema: " + errorMessage);
  -        }
           return app;
       }
  -
  +    
       /**
        * EntityResolver implementation. Called by the XML parser
        *
  @@ -221,6 +219,8 @@
        * @return an InputSource for the database.dtd file
        */
       public InputSource resolveEntity(String publicId, String systemId)
  +            throws SAXException,
  +                   IOException
       {
           return new DTDResolver().resolveEntity(publicId, systemId);
       }
  @@ -238,6 +238,7 @@
        */
       public void startElement(String uri, String localName, String rawName,
                                Attributes attributes)
  +            throws SAXException
       {
           try
           {
  @@ -326,7 +327,7 @@
           }
           catch (Exception e)
           {
  -            log.error(e, e);
  +            throw new SAXException(e);
           }
       }
   
  @@ -346,50 +347,6 @@
               log.debug("endElement(" + uri + ", " + localName + ", "
                       + rawName + ") called");
           }
  -    }
  -
  -    /**
  -     * Warning callback.
  -     *
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    public void warning(SAXParseException spe)
  -    {
  -        printParseError("Warning", spe);
  -    }
  -
  -    /**
  -     * Error callback.
  -     *
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    public void error(SAXParseException spe)
  -    {
  -        printParseError("Error", spe);
  -    }
  -
  -    /**
  -     * Fatal error callback.
  -     *
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    public void fatalError(SAXParseException spe)
  -    {
  -        printParseError("Fatal Error", spe);
  -    }
  -
  -    /**
  -     * Write an error to System.err.
  -     *
  -     * @param type error type
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    private final void printParseError(String type, SAXParseException spe)
  -    {
  -        log.error(type + "[file '" + (new File(currentXmlFile)).getName() 
  -                + "', line " + spe.getLineNumber() 
  -                + ", row " + spe.getColumnNumber()
  -                + "]: " + spe.getMessage());
       }
   
       /**
  
  
  
  1.4       +19 -72    db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/XmlToData.java
  
  Index: XmlToData.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/XmlToData.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XmlToData.java	26 Jun 2003 06:59:56 -0000	1.3
  +++ XmlToData.java	25 Jul 2003 16:39:07 -0000	1.4
  @@ -76,6 +76,7 @@
   import org.xml.sax.Attributes;
   import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
   import org.xml.sax.SAXParseException;
   import org.xml.sax.helpers.DefaultHandler;
   
  @@ -95,7 +96,6 @@
       /** Logging class from commons.logging */
       private static Log log = LogFactory.getLog(XmlToData.class);
       private Database database;
  -    private String errorMessage;
       private List data;
       private String dtdFileName;
       private File dtdFile;
  @@ -119,42 +119,29 @@
           dtdFile = new File(dtdFilePath);
           this.dtdFileName = "file://" + dtdFile.getName();
           dataDTD = new InputSource(dtdFile.toURL().openStream());
  -        errorMessage = "";
       }
   
       /**
        *
        */
       public List parseFile(String xmlFile)
  +            throws Exception
       {
  -        try
  -        {
  -            data = new ArrayList();
  +        data = new ArrayList();
   
  -            SAXParser parser = saxFactory.newSAXParser();
  +        SAXParser parser = saxFactory.newSAXParser();
   
  -            FileReader fr = new FileReader (xmlFile);
  -            BufferedReader br = new BufferedReader (fr);
  -            try
  -            {
  -                InputSource is = new InputSource (br);
  -                parser.parse(is, this);
  -            }
  -            finally
  -            {
  -                br.close();
  -            }
  -        }
  -        catch (Exception e)
  +        FileReader fr = new FileReader (xmlFile);
  +        BufferedReader br = new BufferedReader (fr);
  +        try
           {
  -            //System.out.println("Error : "+e);
  -            log.error(e, e);
  +            InputSource is = new InputSource (br);
  +            parser.parse(is, this);
           }
  -        if (errorMessage.length() > 0)
  +        finally
           {
  -            log.error("ERROR in data file!!!\n" + errorMessage);
  +            br.close();
           }
  -
           return data;
       }
   
  @@ -163,6 +150,7 @@
        */
       public void startElement(String uri, String localName, String rawName,
                                Attributes attributes)
  +            throws SAXException
       {
           try
           {
  @@ -186,52 +174,17 @@
           }
           catch (Exception e)
           {
  -            log.error(e, e);
  +            throw new SAXException(e);
           }
       }
   
       /**
  -     * Warning callback.
  -     *
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    public void warning(SAXParseException spe)
  -    {
  -        log.warn("Warning Line: " + spe.getLineNumber()
  -                + " Row: " + spe.getColumnNumber()
  -                + " Msg: " + spe.getMessage());
  -    }
  -
  -    /**
  -     * Error callback.
  -     *
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    public void error(SAXParseException spe)
  -    {
  -        log.error("Error Line: " + spe.getLineNumber()
  -                + " Row: " + spe.getColumnNumber()
  -                + " Msg: " + spe.getMessage());
  -    }
  -
  -    /**
  -     * Fatal error callback.
  -     *
  -     * @param spe The parse exception that caused the callback to be invoked.
  -     */
  -    public void fatalError(SAXParseException spe)
  -    {
  -        log.fatal("Fatal Error Line: " + spe.getLineNumber()
  -                + " Row: " + spe.getColumnNumber()
  -                + " Msg: " + spe.getMessage());
  -    }
  -
  -    /**
        * called by the XML parser
        *
        * @return an InputSource for the database.dtd file
        */
       public InputSource resolveEntity(String publicId, String systemId)
  +            throws IOException
       {
           if (dataDTD != null && dtdFileName.equals(systemId))
           {
  @@ -252,17 +205,11 @@
        * @return an InputSource for the URL String
        */
       public InputSource getInputSource(String urlString)
  +            throws IOException
       {
  -        try
  -        {
  -            URL url = new URL(urlString);
  -            return new InputSource(url.openStream());
  -        }
  -        catch (IOException ex)
  -        {
  -            log.error(ex, ex);
  -        }
  -        return new InputSource();
  +        URL url = new URL(urlString);
  +        InputSource src = new InputSource(url.openStream());
  +        return src;
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message