From: <be...@us...> - 2006-10-27 11:53:03
|
Revision: 140 http://svn.sourceforge.net/pzfilereader/?rev=140&view=rev Author: benoitx Date: 2006-10-27 04:52:52 -0700 (Fri, 27 Oct 2006) Log Message: ----------- Removed some throw Exception Only non-runtime exceptions should be declared and never at the 'Exception' level, which is far too generic and forces every caller to deal with something which is 'unknonwn' Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java 2006-10-27 01:05:51 UTC (rev 139) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java 2006-10-27 11:52:52 UTC (rev 140) @@ -59,7 +59,7 @@ * Name of dataDefinition in the DATAFILE table DATAFILE_DESC * column */ - PZParser newParser(final Connection con, final File dataSource, final String dataDefinition); + PZParser newFixedLengthParser(final Connection con, final File dataSource, final String dataDefinition); /** * Constructs a new DataSet using the database table file layout method. @@ -76,7 +76,7 @@ * Name of dataDefinition in the DATAFILE table DATAFILE_DESC * column */ - PZParser newParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition); + PZParser newFixedLengthParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition); /** * Constructs a new DataSet using the PZMAP XML file layout method. This is @@ -87,7 +87,7 @@ * @param dataSource - * Delimited file to read from */ - PZParser newParser(final File pzmapXML, final File dataSource); + PZParser newFixedLengthParser(final File pzmapXML, final File dataSource); /** * New constructor based on InputStream. Constructs a new DataSet using the @@ -102,7 +102,7 @@ * Delimited file InputStream to read from, user must close them * after use. */ - PZParser newParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream); + PZParser newFixedLengthParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream); // // Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-27 01:05:51 UTC (rev 139) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-27 11:52:52 UTC (rev 140) @@ -581,9 +581,8 @@ * * @param columnMD * @return Map - * @exception Exception */ - public static Map calculateRecordLengths(final Map columnMD) throws Exception { + public static Map calculateRecordLengths(final Map columnMD) { final Map recordLengths = new HashMap(); List cmds = null; @@ -751,19 +750,19 @@ * @param file * The file. * @return the InputStream. - * @throws Exception + * @throws FileNotFoundException */ - public static InputStream createInputStream(final File file) throws Exception { + public static InputStream createInputStream(final File file) throws FileNotFoundException { if (file == null) { throw new IllegalArgumentException("null not allowed"); } - if (!file.exists()) { - throw new FileNotFoundException("file does not exist " + file.getAbsolutePath()); - } - if (!file.canRead()) { - throw new FileNotFoundException("file cannot be read " + file.getAbsolutePath()); - } - return new FileInputStream(file.getAbsolutePath()); +// if (!file.exists()) { +// throw new FileNotFoundException("file does not exist " + file.getAbsolutePath()); +// } +// if (!file.canRead()) { +// throw new FileNotFoundException("file cannot be read " + file.getAbsolutePath()); +// } + return new FileInputStream(file); } /** Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java 2006-10-27 01:05:51 UTC (rev 139) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java 2006-10-27 11:52:52 UTC (rev 140) @@ -15,6 +15,7 @@ package net.sf.pzfilereader.xml; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; @@ -29,6 +30,7 @@ import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; +import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; /** @@ -75,9 +77,10 @@ * @param xmlStream * @return Map * <records> with their corrisponding - * @throws Exception + * @throws IOException + * @throws JDOMException */ - public static Map parse(final InputStream xmlStream) throws Exception { + public static Map parse(final InputStream xmlStream) throws JDOMException, IOException { final SAXBuilder builder = new SAXBuilder(); builder.setValidation(true); // handle the ability to pull DTD from Jar if needed @@ -110,7 +113,7 @@ // value we are using to mark columns specified outside of a // <RECORD> element if (xmlElement.getAttributeValue("id").equals(PZConstants.DETAIL_ID)) { - throw new Exception("The ID 'detail' on the <RECORD> element is reserved, please select another id"); + throw new IllegalArgumentException("The ID 'detail' on the <RECORD> element is reserved, please select another id"); } columns = getColumnChildren(xmlElement); @@ -145,7 +148,7 @@ } // helper to retrieve the "COLUMN" elements from the given parent - private static List getColumnChildren(final Element parent) throws Exception { + private static List getColumnChildren(final Element parent) { final List columnResults = new ArrayList(); final Iterator xmlChildren = parent.getChildren("COLUMN").iterator(); @@ -155,7 +158,7 @@ // make sure the name attribute is present on the column if (xmlColumn.getAttributeValue("name") == null) { - throw new Exception("Name attribute is required on the column tag!"); + throw new IllegalArgumentException("Name attribute is required on the column tag!"); } cmd.setColName(xmlColumn.getAttributeValue("name")); @@ -165,7 +168,7 @@ try { cmd.setColLength(Integer.parseInt(xmlColumn.getAttributeValue("length"))); } catch (final Exception ex) { - throw new Exception("LENGTH ATTRIBUTE ON COLUMN ELEMENT MUST BE AN INTEGER. GOT: " + throw new IllegalArgumentException("LENGTH ATTRIBUTE ON COLUMN ELEMENT MUST BE AN INTEGER. GOT: " + xmlColumn.getAttributeValue("length")); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |