001/* Some object or set of objects has a state that is not permitted. 002 003 Copyright (c) 1997-2014 The Regents of the University of California. 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 CALIFORNIA 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 CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA 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 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.kernel.util; 029 030import java.util.ArrayList; 031import java.util.Collection; 032import java.util.Enumeration; 033import java.util.List; 034 035/////////////////////////////////////////////////////////////////// 036//// InvalidStateException 037 038/** 039 Some object or set of objects has a state that is not 040 permitted. E.g., a NamedObj has a null name. Or a topology has 041 inconsistent or contradictory information in it, e.g. an entity 042 contains a port that has a different entity as it container. Our 043 design should make it impossible for this exception to ever occur, 044 so occurrence is a bug. 045 046 @author Edward A. Lee, Jie Liu 047 @version $Id$ 048 @since Ptolemy II 0.2 049 @Pt.ProposedRating Green (cxh) 050 @Pt.AcceptedRating Green (cxh) 051 */ 052@SuppressWarnings("serial") 053public class InvalidStateException extends KernelRuntimeException { 054 /** Construct an exception with only a detail message. 055 * @param detail The message. 056 */ 057 public InvalidStateException(String detail) { 058 this(null, null, null, detail); 059 } 060 061 /** Construct an exception with a detail message that includes the 062 * name of the first argument, the cause and the third argument string. 063 * @param object The nameable object involved in the exception 064 * @param cause The cause of this exception. 065 * @param detail The message. 066 */ 067 public InvalidStateException(Nameable object, Throwable cause, 068 String detail) { 069 super(object, null, cause, detail); 070 } 071 072 /** Construct an exception with a detail message that includes the 073 * name of the first argument and the second argument string. 074 * @param object The object. 075 * @param detail The message. 076 */ 077 public InvalidStateException(Nameable object, String detail) { 078 this(object, null, null, detail); 079 } 080 081 /** Construct an exception with a detail message that includes the 082 * names of the first two arguments plus the third argument string. 083 * @param object1 The first object. 084 * @param object2 The second object. 085 * @param detail The message. 086 */ 087 public InvalidStateException(Nameable object1, Nameable object2, 088 String detail) { 089 this(object1, object2, null, detail); 090 } 091 092 /** Construct an exception with a detail message that includes the 093 * names of the first two arguments plus the third argument string. 094 * @param object1 The first object. 095 * @param object2 The second object. 096 * @param cause The cause of this exception. 097 * @param detail The message. 098 */ 099 public InvalidStateException(Nameable object1, Nameable object2, 100 Throwable cause, String detail) { 101 super(object1, object2, cause, detail); 102 } 103 104 /** Construct an exception with a detail message that includes the 105 * names of an enumeration of nameable object plus the argument string. 106 * 107 * @deprecated Use InvalidStateException(Collection, String) instead. 108 * @param objects The enumeration of Nameable objects 109 * @param detail The message. 110 */ 111 @Deprecated 112 public InvalidStateException(Enumeration objects, String detail) { 113 this(_list(objects), null, detail); 114 } 115 116 /** Constructs an exception with a detail message that includes the 117 * names of a collection of nameable objects plus the argument string. 118 * @param objects The Collection of Nameable objects 119 * @param detail The message. 120 */ 121 public InvalidStateException(Collection objects, String detail) { 122 this(objects, null, detail); 123 } 124 125 /** Constructs an exception with a detail message that includes the 126 * names of a collection of nameable objects plus the argument string. 127 * @param objects The Collection of Nameable objects 128 * @param cause The cause of this exception. 129 * @param detail The message. 130 */ 131 public InvalidStateException(Collection objects, Throwable cause, 132 String detail) { 133 super(objects, cause, detail); 134 } 135 136 /////////////////////////////////////////////////////////////////// 137 //// private methods //// 138 // Convert from an Enumeration to a List. 139 // 140 // JDK1.4 has a Collections.list(Enumeration) method 141 // that would be good to use. 142 // For suggestions about converting from Enumerations to Lists, 143 // see 144 // http://download.oracle.com/javase/tutorial/collections/interoperability/compatibility.html 145 private static List _list(Enumeration objects) { 146 List list = new ArrayList(); 147 148 while (objects.hasMoreElements()) { 149 list.add(objects.nextElement()); 150 } 151 152 return list; 153 } 154}