001/* Exception for unweighted graphs or graphs with improper weights.
002
003 Copyright (c) 2002-2014 The University of Maryland.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF MARYLAND BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF MARYLAND HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF MARYLAND SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 MARYLAND HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 */
025package ptolemy.graph;
026
027///////////////////////////////////////////////////////////////////
028//// GraphWeightException
029
030/** Exception for unweighted graphs or graphs with improper weights.
031 This exception can also be thrown due to accessing elements with
032 incorrect weights.
033
034 @author Mingyung Ko
035 @version $Id$
036 @since Ptolemy II 2.1
037 @Pt.ProposedRating Red (myko)
038 @Pt.AcceptedRating Red (ssb)
039 */
040@SuppressWarnings("serial")
041public class GraphWeightException extends GraphException {
042    /** Constructor for a given message.
043     *  @param message The message.
044     */
045    public GraphWeightException(String message) {
046        super(message);
047    }
048
049    /** Constructor with arguments of weight, element, graph,
050     *  and a message.
051     *  This exception is generally thrown because of invalid weight
052     *  association to a specific element. It can also be thrown for
053     *  unspecific elements by setting the <code>element</code> argument
054     *  to <code>null</code>.
055     *
056     *  @param weight The invalid weight.
057     *  @param element The element to associate the invalid weight. Set
058     *         <code>null</code> for unspecific elements.
059     *  @param graph The graph accessed.
060     *  @param message The exception message.
061     */
062    public GraphWeightException(Object weight, Element element, Graph graph,
063            String message) {
064        super(_argumentsToString(weight, element, graph, message));
065    }
066
067    ///////////////////////////////////////////////////////////////////
068    ////                         private methods                   ////
069
070    /*  A method for generating proper string dumps.
071     *  @param weight The invalid weight.
072     *  @param element The element the invalid weight tries to associate.
073     *  @param graph The graph to access.
074     *  @param message The exception message given by users.
075     *  @return The desired exception message.
076     */
077    static private String _argumentsToString(Object weight, Element element,
078            Graph graph, String message) {
079        StringBuffer outputMessage = new StringBuffer(
080                message + weightDump(weight));
081
082        if (element != null) {
083            outputMessage.append(elementDump(element, graph));
084        } else {
085            outputMessage.append(graphDump(graph));
086        }
087
088        return outputMessage.toString();
089    }
090}