Updated the parser exceptions to give more details. * Now the VXQueryCollectionOperatorDescriptor adds the file and node to the exception message. * Re-architected the exceptions in the XMLParser to help with new exception messages.
Project: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/commit/98f95975 Tree: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/tree/98f95975 Diff: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/diff/98f95975 Branch: refs/heads/master Commit: 98f95975adee9ab975a76ca15ba20fc89c6c40cf Parents: 215d9e1 Author: Preston Carman <[email protected]> Authored: Mon Apr 7 16:11:47 2014 -0700 Committer: Preston Carman <[email protected]> Committed: Mon Apr 7 16:11:47 2014 -0700 ---------------------------------------------------------------------- .../VXQueryFileNotFoundException.java | 35 ++++++++++++++++++++ .../exceptions/VXQueryParseException.java | 35 ++++++++++++++++++++ .../VXQueryCollectionOperatorDescriptor.java | 24 +++++++++++--- .../runtime/functions/util/FunctionHelper.java | 30 +++++------------ .../org/apache/vxquery/xmlparser/XMLParser.java | 27 +++++++++++++-- 5 files changed, 122 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/98f95975/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryFileNotFoundException.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryFileNotFoundException.java b/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryFileNotFoundException.java new file mode 100644 index 0000000..27a0a2e --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryFileNotFoundException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2009-2013 by The Regents of the University of California + * 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 from + * + * 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. + */ +package org.apache.vxquery.exceptions; + +import edu.uci.ics.hyracks.api.exceptions.HyracksDataException; + +public class VXQueryFileNotFoundException extends HyracksDataException { + + private static final long serialVersionUID = 1L; + + public VXQueryFileNotFoundException() { + super(); + } + + public VXQueryFileNotFoundException(Exception ex) { + super(ex); + } + + public VXQueryFileNotFoundException(String msg) { + super(msg); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/98f95975/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryParseException.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryParseException.java b/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryParseException.java new file mode 100644 index 0000000..f1b4155 --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/exceptions/VXQueryParseException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2009-2013 by The Regents of the University of California + * 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 from + * + * 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. + */ +package org.apache.vxquery.exceptions; + +import edu.uci.ics.hyracks.api.exceptions.HyracksDataException; + +public class VXQueryParseException extends HyracksDataException { + + private static final long serialVersionUID = 1L; + + public VXQueryParseException() { + super(); + } + + public VXQueryParseException(Exception ex) { + super(ex); + } + + public VXQueryParseException(String msg) { + super(msg); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/98f95975/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java index 5cc2276..54007c8 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java @@ -27,8 +27,9 @@ import org.apache.vxquery.datamodel.accessors.PointablePool; import org.apache.vxquery.datamodel.accessors.PointablePoolFactory; import org.apache.vxquery.datamodel.accessors.TaggedValuePointable; import org.apache.vxquery.exceptions.SystemException; +import org.apache.vxquery.exceptions.VXQueryFileNotFoundException; +import org.apache.vxquery.exceptions.VXQueryParseException; import org.apache.vxquery.runtime.functions.step.ChildPathStepOperatorDescriptor; -import org.apache.vxquery.runtime.functions.util.FunctionHelper; import org.apache.vxquery.xmlparser.ITreeNodeIdProvider; import org.apache.vxquery.xmlparser.TreeNodeIdProvider; import org.apache.vxquery.xmlparser.XMLParser; @@ -121,9 +122,24 @@ public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityO // Now add new field. abvsFileNode.reset(); try { - FunctionHelper.readInDocFromString(file, in, abvsFileNode, parser); - } catch (Exception e) { - throw new HyracksDataException(e); + parser.parseFile(file, in, abvsFileNode); + } catch (VXQueryFileNotFoundException e) { + String message = "The file (" + nodeId + ":" + file.getAbsolutePath() + ") can not be found."; + HyracksDataException hde = new HyracksDataException(message, e.getCause()); + hde.setNodeId(nodeId); + throw hde; + } catch (VXQueryParseException e) { + String message = "The file (" + nodeId + ":" + file.getAbsolutePath() + + ") throw a SAXException durring parsing."; + HyracksDataException hde = new HyracksDataException(message, e.getCause()); + hde.setNodeId(nodeId); + throw hde; + } catch (HyracksDataException e) { + String message = "The file (" + nodeId + ":" + file.getAbsolutePath() + + ") throw the following error during parsing: " + e.getMessage(); + HyracksDataException hde = new HyracksDataException(message, e.getCause()); + hde.setNodeId(nodeId); + throw hde; } TaggedValuePointable tvp = ppool.takeOne(TaggedValuePointable.class); http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/98f95975/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java index a7d7186..d732145 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java @@ -19,13 +19,9 @@ package org.apache.vxquery.runtime.functions.util; import java.io.DataInputStream; import java.io.DataOutput; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStreamReader; import java.nio.ByteBuffer; import java.util.Arrays; -import java.util.zip.GZIPInputStream; import org.apache.vxquery.context.DynamicContext; import org.apache.vxquery.datamodel.accessors.SequencePointable; @@ -60,6 +56,7 @@ import org.apache.vxquery.types.BuiltinTypeRegistry; import org.apache.vxquery.xmlparser.XMLParser; import org.xml.sax.InputSource; +import edu.uci.ics.hyracks.api.exceptions.HyracksDataException; import edu.uci.ics.hyracks.data.std.api.IPointable; import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable; import edu.uci.ics.hyracks.data.std.primitive.BytePointable; @@ -1237,26 +1234,15 @@ public class FunctionHelper { } public static void readInDocFromPointable(UTF8StringPointable stringp, InputSource in, ByteBufferInputStream bbis, - DataInputStream di, ArrayBackedValueStorage abvs, XMLParser parser) throws SystemException { - String fName = getStringFromPointable(stringp, bbis, di); - File file = new File(fName); - readInDocFromString(file, in, abvs, parser); - } - - public static void readInDocFromString(File file, InputSource in, ArrayBackedValueStorage abvs, XMLParser parser) - throws SystemException { + DataInputStream di, ArrayBackedValueStorage abvs, XMLParser parser) throws HyracksDataException { + String fName; try { - if (file.getName().toLowerCase().endsWith(".xml.gz")) { - in.setCharacterStream(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)))); - } else { - in.setCharacterStream(new InputStreamReader(new FileInputStream(file))); - } - parser.parseInputSource(in, abvs); - } catch (FileNotFoundException e) { - throw new RuntimeException("The file (" + file.getName() + ") does not exist."); - } catch (IOException e) { - throw new SystemException(ErrorCode.SYSE0001, e); + fName = getStringFromPointable(stringp, bbis, di); + } catch (SystemException e) { + throw new HyracksDataException(e); } + File file = new File(fName); + parser.parseFile(file, in, abvs); } public static boolean transformThenCompareMinMaxTaggedValues(AbstractValueComparisonOperation aOp, http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/98f95975/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/XMLParser.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/XMLParser.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/XMLParser.java index d73dd12..125557b 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/XMLParser.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/XMLParser.java @@ -14,7 +14,17 @@ */ package org.apache.vxquery.xmlparser; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.zip.GZIPInputStream; + +import org.apache.vxquery.exceptions.VXQueryFileNotFoundException; +import org.apache.vxquery.exceptions.VXQueryParseException; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; @@ -36,12 +46,23 @@ public class XMLParser { } } - public void parseInputSource(InputSource in, ArrayBackedValueStorage abvs) throws HyracksDataException { + + public void parseFile(File file, InputSource in, ArrayBackedValueStorage abvs) throws HyracksDataException { try { + if (file.getName().toLowerCase().endsWith(".xml.gz")) { + in.setCharacterStream(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)))); + } else { + in.setCharacterStream(new InputStreamReader(new FileInputStream(file))); + } parser.parse(in); handler.write(abvs); - } catch (Exception e) { - throw new HyracksDataException(e.toString()); + } catch (FileNotFoundException e) { + throw new VXQueryFileNotFoundException(e); + } catch (SAXException e) { + throw new VXQueryParseException(e); + } catch (IOException e) { + throw new HyracksDataException(e); } } + } \ No newline at end of file
