001/*
002 * BioJava development code
003 * 
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 * 
009 * http://www.gnu.org/copyleft/lesser.html
010 * 
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 * 
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 * 
018 * http://www.biojava.org
019 */
020
021package org.biojava.utils;
022
023/**
024 *  
025 * Exception which is thrown when a ChangeListener does not
026 * wish a change to take place. Since BioJava 1.5 the <code>ChangeVetoException</code>
027 * has been changed to extend <code>RuntimeException</code>. It is therefore an
028 * unchecked exception.
029 *
030 * @author     Thomas Down
031 * @author     Matthew Pocock
032 * @author     Mark Schreiber
033 * @since      1.1 
034 */
035
036public class ChangeVetoException extends RuntimeException {
037  private final ChangeEvent change;
038
039  public ChangeVetoException() {
040    super();
041    change = null;
042  }
043  
044  /**
045   *  Construct an exception to veto a change without explanation. 
046   *
047   * @param  change  An event which is being vetoed. 
048   */
049
050  public ChangeVetoException(ChangeEvent change) {
051    super();
052    this.change = change;
053  }
054
055  /**
056   *  Create an exception with a detail message 
057   *
058   * @param  reason  A detail message. 
059   */
060
061  public ChangeVetoException(
062    String reason
063  ) {
064    super(reason);
065    this.change = null;
066  }
067
068  /**
069   *  Construct an exception to veto a change for a specified reason. 
070   *
071   * @param  change  An event which is being vetoed. 
072   * @param  reason  A detail message.
073   */
074
075  public ChangeVetoException(ChangeEvent change, String reason) {
076    super(reason);
077    this.change = change;
078  }
079
080  /**
081   *  Propogate an exception without (additional) explanation. 
082   *
083   * @param  ex      A parent exception 
084   * @param  change  An event which is being vetoed.
085   */
086
087  public ChangeVetoException(Throwable ex, ChangeEvent change) {
088    super(ex);
089    this.change = change;
090  }
091  
092  /**
093   *  Propogate an exception, giving a detail message 
094   *
095   * @param  ex      A parent exception 
096   * @param  reason  A detail message. 
097   * @deprecated use new ChangeVetoException(reason, ex);
098   */
099
100   public ChangeVetoException(Throwable ex, String reason) {
101    this(ex, null, reason);
102  }
103  
104  public ChangeVetoException(String reason, Throwable cause) {
105    this(cause, null, reason);
106  }
107
108  /**
109   *  Propogate an exception, giving a detail message 
110   *
111   * @param  ex      A parent exception 
112   * @param  change  An event which is being vetoed. 
113   * @param  reason  A detail message. 
114   */
115
116  public ChangeVetoException(
117    Throwable ex, 
118    ChangeEvent change, 
119    String reason
120  ) {
121    super(reason, ex);
122    this.change = change;
123  }
124
125  /**
126   *  Return the ChangeEvent which is being vetoed. 
127   *
128   * @return    The ChangeEvent value 
129   */
130
131  public ChangeEvent getChangeEvent() {
132    return change;
133  }
134}
135