Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 3a765e0dfd10ed9b02ed6b864748c7ebe83148cb Mon Sep 17 00:00:00 2001
- From: Egon Willighagen <egonw@users.sourceforge.net>
- Date: Sat, 30 Jan 2010 11:54:31 +0100
- Subject: [PATCH 1/2] Added a new IO API for reporting file format errors.
- * introducing a IChemObjectReaderErrorHandler
- * handleError() methods for IChemObjectReader's to report problems
- * these handleErrors() method throw an CDKException when
- in STRICT mode
- * line and column number support, useful for MDL V2000 molfile text
- editors in, e.g. Bioclipse
- ---
- .../cdk/io/DefaultChemObjectReader.java | 46 ++++++++++++++++--
- .../org/openscience/cdk/io/IChemObjectReader.java | 52 ++++++++++++++++++-
- .../iterator/DefaultIteratingChemObjectReader.java | 49 ++++++++++++++++--
- 3 files changed, 134 insertions(+), 13 deletions(-)
- diff --git a/src/main/org/openscience/cdk/io/DefaultChemObjectReader.java b/src/main/org/openscience/cdk/io/DefaultChemObjectReader.java
- index 1807005..1015c49 100644
- --- a/src/main/org/openscience/cdk/io/DefaultChemObjectReader.java
- +++ b/src/main/org/openscience/cdk/io/DefaultChemObjectReader.java
- @@ -1,6 +1,5 @@
- -/* $Revision$ $Author$ $Date$
- - *
- - * Copyright (C) 2002-2007 The Jmol Development Team
- +/* Copyright (C) 2002-2007 The Jmol Development Team
- + * 2010 Egon Willighagen <egonw@users.sf.net>
- *
- * Contact: cdk-devel@lists.sourceforge.net
- *
- @@ -23,6 +22,7 @@ package org.openscience.cdk.io;
- import java.util.ArrayList;
- import java.util.List;
- +import org.openscience.cdk.exception.CDKException;
- import org.openscience.cdk.io.listener.IChemObjectIOListener;
- import org.openscience.cdk.io.listener.IReaderListener;
- import org.openscience.cdk.io.setting.IOSetting;
- @@ -42,6 +42,7 @@ public abstract class DefaultChemObjectReader implements ISimpleChemObjectReader
- private ReaderEvent frameReadEvent = null;
- protected IChemObjectReader.Mode mode = IChemObjectReader.Mode.RELAXED;
- + protected IChemObjectReaderErrorHandler errorHandler = null;
- /**
- * Holder of reader event listeners.
- @@ -88,5 +89,42 @@ public abstract class DefaultChemObjectReader implements ISimpleChemObjectReader
- public void setReaderMode(ISimpleChemObjectReader.Mode mode) {
- this.mode = mode;
- }
- -
- +
- + /** {@inheritDoc} */
- + public void setErrorHandler(IChemObjectReaderErrorHandler handler) {
- + this.errorHandler = handler;
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message) throws CDKException {
- + if (this.errorHandler != null) this.errorHandler.handleError(message);
- + if (this.mode == Mode.STRICT) throw new CDKException(message);
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message, Exception exception)
- + throws CDKException {
- + if (this.errorHandler != null)
- + this.errorHandler.handleError(message, exception);
- + if (this.mode == Mode.STRICT) {
- + throw new CDKException(message, exception);
- + }
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message, int row, int col) throws CDKException {
- + if (this.errorHandler != null)
- + this.errorHandler.handleError(message, row, col);
- + if (this.mode == Mode.STRICT) throw new CDKException(message);
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message, int row, int col, Exception exception)
- + throws CDKException {
- + if (this.errorHandler != null)
- + this.errorHandler.handleError(message, row, col, exception);
- + if (this.mode == Mode.STRICT) {
- + throw new CDKException(message, exception);
- + }
- + }
- }
- diff --git a/src/main/org/openscience/cdk/io/IChemObjectReader.java b/src/main/org/openscience/cdk/io/IChemObjectReader.java
- index d9a29bc..8709fa4 100644
- --- a/src/main/org/openscience/cdk/io/IChemObjectReader.java
- +++ b/src/main/org/openscience/cdk/io/IChemObjectReader.java
- @@ -1,6 +1,4 @@
- -/* $Revision$ $Author$ $Date$
- - *
- - * Copyright (C) 2000-2007 Egon Willighagen <egonw@users.sf.net>
- +/* Copyright (C) 2000-2007,2010 Egon Willighagen <egonw@users.sf.net>
- *
- * Contact: cdk-devel@lists.sourceforge.net
- *
- @@ -66,5 +64,53 @@ public interface IChemObjectReader extends IChemObjectIO {
- * @param mode
- */
- public void setReaderMode(Mode mode);
- +
- + /**
- + * Sets an error handler that is sent events when file format issues occur.
- + *
- + * @param handler {@link IChemObjectReaderErrorHandler} to send error
- + * messages to.
- + */
- + public void setErrorHandler(IChemObjectReaderErrorHandler handler);
- +
- + /**
- + * Redirects an error message to the {@link IChemObjectReaderErrorHandler}.
- + * Throws an {@link CDKException} when in STRICT {@link Mode}.
- + *
- + * @param message the error message.
- + */
- + public void handleError(String message) throws CDKException;
- +
- + /**
- + * Redirects an error message to the {@link IChemObjectReaderErrorHandler}.
- + * Throws an {@link CDKException} when in STRICT {@link Mode}.
- + *
- + * @param message the error message.
- + * @param exception the corresponding {@link Exception}.
- + */
- + public void handleError(String message, Exception exception)
- + throws CDKException;
- +
- + /**
- + * Redirects an error message to the {@link IChemObjectReaderErrorHandler}.
- + * Throws an {@link CDKException} when in STRICT {@link Mode}.
- + *
- + * @param message the error message.
- + * @param row Row in the file where the error is found.
- + * @param col Column in the file where the error is found.
- + */
- + public void handleError(String message, int row, int col) throws CDKException;
- +
- + /**
- + * Redirects an error message to the {@link IChemObjectReaderErrorHandler}.
- + * Throws an {@link CDKException} when in STRICT {@link Mode}.
- + *
- + * @param message the error message.
- + * @param exception the corresponding {@link Exception}.
- + * @param row Row in the file where the error is found.
- + * @param col Column in the file where the error is found.
- + */
- + public void handleError(String message, int row, int col, Exception exception)
- + throws CDKException;
- }
- diff --git a/src/main/org/openscience/cdk/io/iterator/DefaultIteratingChemObjectReader.java b/src/main/org/openscience/cdk/io/iterator/DefaultIteratingChemObject
- Reader.java
- index 8b79efd..6131481 100644
- --- a/src/main/org/openscience/cdk/io/iterator/DefaultIteratingChemObjectReader.java
- +++ b/src/main/org/openscience/cdk/io/iterator/DefaultIteratingChemObjectReader.java
- @@ -1,9 +1,5 @@
- -/* $RCSfile$
- - * $Author$
- - * $Date$
- - * $Revision$
- - *
- - * Copyright (C) 2003-2007 The Jmol Development Team
- +/* Copyright (C) 2003-2007 The Jmol Development Team
- + * 2010 Egon Willighagen <egonw@users.sf.net>
- *
- * Contact: cdk-devel@lists.sourceforge.net
- *
- @@ -26,8 +22,11 @@ package org.openscience.cdk.io.iterator;
- import java.util.ArrayList;
- import java.util.List;
- +import org.openscience.cdk.exception.CDKException;
- import org.openscience.cdk.io.IChemObjectReader;
- +import org.openscience.cdk.io.IChemObjectReaderErrorHandler;
- import org.openscience.cdk.io.ISimpleChemObjectReader;
- +import org.openscience.cdk.io.IChemObjectReader.Mode;
- import org.openscience.cdk.io.listener.IChemObjectIOListener;
- import org.openscience.cdk.io.setting.IOSetting;
- @@ -41,6 +40,7 @@ import org.openscience.cdk.io.setting.IOSetting;
- public abstract class DefaultIteratingChemObjectReader implements IIteratingChemObjectReader {
- protected IChemObjectReader.Mode mode = IChemObjectReader.Mode.RELAXED;
- + protected IChemObjectReaderErrorHandler errorHandler = null;
- /**
- * Holder of reader event listeners.
- @@ -83,4 +83,41 @@ public abstract class DefaultIteratingChemObjectReader implements IIteratingChem
- this.mode = mode;
- }
- + /** {@inheritDoc} */
- + public void setErrorHandler(IChemObjectReaderErrorHandler handler) {
- + this.errorHandler = handler;
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message) throws CDKException {
- + if (this.errorHandler != null) this.errorHandler.handleError(message);
- + if (this.mode == Mode.STRICT) throw new CDKException(message);
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message, Exception exception)
- + throws CDKException {
- + if (this.errorHandler != null)
- + this.errorHandler.handleError(message, exception);
- + if (this.mode == Mode.STRICT) {
- + throw new CDKException(message, exception);
- + }
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message, int row, int col) throws CDKException {
- + if (this.errorHandler != null)
- + this.errorHandler.handleError(message, row, col);
- + if (this.mode == Mode.STRICT) throw new CDKException(message);
- + }
- +
- + /** {@inheritDoc} */
- + public void handleError(String message, int row, int col, Exception exception)
- + throws CDKException {
- + if (this.errorHandler != null)
- + this.errorHandler.handleError(message, row, col, exception);
- + if (this.mode == Mode.STRICT) {
- + throw new CDKException(message, exception);
- + }
- + }
- }
- --
- 1.6.6.1
Add Comment
Please, Sign In to add comment