001/* An attribute used for testing that is never valid. 002 003 Copyright (c) 2006-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.test; 029 030import java.util.Collection; 031 032import ptolemy.kernel.util.IllegalActionException; 033import ptolemy.kernel.util.KernelRuntimeException; 034import ptolemy.kernel.util.NameDuplicationException; 035import ptolemy.kernel.util.NamedObj; 036import ptolemy.kernel.util.StringAttribute; 037import ptolemy.kernel.util.Workspace; 038 039/////////////////////////////////////////////////////////////////// 040//// InvalidStringAttribute 041 042/** 043 An attribute used for testing that is never valid. 044 045 @author Christopher Brooks 046 @version $Id$ 047 @since Ptolemy II 5.2 048 @Pt.ProposedRating Red (cxh) 049 @Pt.AcceptedRating Red (cxh) 050 */ 051public class InvalidStringAttribute extends StringAttribute { 052 /** Construct an attribute in the default workspace with an empty string 053 * as its name. 054 * The object is added to the directory of the workspace. 055 * Increment the version number of the workspace. 056 */ 057 public InvalidStringAttribute() { 058 super(); 059 } 060 061 /** Construct an attribute in the specified workspace with an empty 062 * string as a name. You can then change the name with setName(). 063 * If the workspace argument 064 * is null, then use the default workspace. 065 * The object is added to the directory of the workspace. 066 * Increment the version number of the workspace. 067 * @param workspace The workspace that will list the attribute. 068 */ 069 public InvalidStringAttribute(Workspace workspace) { 070 super(workspace); 071 } 072 073 /** Construct an attribute with the given name contained by the specified 074 * entity. The container argument must not be null, or a 075 * NullPointerException will be thrown. This attribute will use the 076 * workspace of the container for synchronization and version counts. 077 * If the name argument is null, then the name is set to the empty string. 078 * Increment the version of the workspace. 079 * @param container The container. 080 * @param name The name of this attribute. 081 * @exception IllegalActionException If the attribute is not of an 082 * acceptable class for the container, or if the name contains a period. 083 * @exception NameDuplicationException If the name coincides with 084 * an attribute already in the container. 085 */ 086 public InvalidStringAttribute(NamedObj container, String name) 087 throws IllegalActionException, NameDuplicationException { 088 super(container, name); 089 } 090 091 /////////////////////////////////////////////////////////////////// 092 //// public methods //// 093 094 /** Throw either a KernelRuntimeException or an IllegalActionException. 095 * @exception IllegalActionException If the expression is not valid, or 096 * its value is not acceptable to the container or the listeners. 097 */ 098 @Override 099 public Collection validate() throws IllegalActionException { 100 if (getName().equals("KernelRuntimeException")) { 101 throw new KernelRuntimeException(this, 102 "Name was \"KernelRuntimeException\", so we throw it"); 103 } 104 throw new IllegalActionException(this, 105 "InvalidStringAttributeAlways throws an exception in validate()"); 106 } 107 108 /////////////////////////////////////////////////////////////////// 109 //// private members //// 110}