001/* For Testing NamedObjs with null names 002 003 Copyright (c) 1999-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 ptolemy.kernel.util.IllegalActionException; 031import ptolemy.kernel.util.NameDuplicationException; 032import ptolemy.kernel.util.NamedObj; 033import ptolemy.kernel.util.Workspace; 034 035/////////////////////////////////////////////////////////////////// 036//// TestNullNamedObj.java 037 038/** 039 TestNullNamedObj is like NamedObj, except that null names are permissible. 040 This class is used to test some of the assertions in classes such 041 as NamedList. 042 043 @author Christopher Hylands 044 @version $Id$ 045 @since Ptolemy II 0.3 046 @Pt.ProposedRating Green (cxh) 047 @Pt.AcceptedRating Red (cxh) 048 */ 049public class TestNullNamedObj extends NamedObj { 050 /** Construct an object in the default workspace with an empty string 051 * as its name. The object is added to the list of objects in 052 * the workspace. Increment the version number of the workspace. 053 * @exception IllegalActionException Not thrown. 054 */ 055 public TestNullNamedObj() throws IllegalActionException { 056 super(_defaultWorkspace, ""); 057 } 058 059 /** Construct an object in the default workspace with an empty string 060 * as its name. The object is added to the list of objects in 061 * the workspace. Increment the version number of the workspace. 062 * @exception IllegalActionException If the name has a period. 063 */ 064 public TestNullNamedObj(String name) throws IllegalActionException { 065 super(_defaultWorkspace, name); 066 } 067 068 /** Get an object with the specified name in the specified container. 069 * The type of object sought is an instance of the same class as 070 * this object. In this base class, return null, as there 071 * is no containment mechanism. Derived classes should override this 072 * method to return an object of their same type. 073 * @param relativeName The name relative to the container. 074 * @param container The container expected to contain the object. 075 * @return null. 076 * @exception IllegalActionException If the object exists 077 * and has the wrong class. Not thrown in this base class. 078 */ 079 public NamedObj getContainedObject(NamedObj container, String relativeName) 080 throws IllegalActionException { 081 return _getContainedObject(container, relativeName); 082 } 083 084 /** Get the name. If no name has been given, or null has been given, 085 * then return an empty string, "". 086 * @return The name of the object. 087 */ 088 @Override 089 public String getName() { 090 return _name; 091 } 092 093 /** Set or change the name. If a null argument is given the 094 * name is set to an empty string. 095 * Increment the version of the workspace. 096 * This method is write-synchronized on the workspace. 097 * @param name The new name. 098 * @exception NameDuplicationException Not thrown in this base 099 * class. May be thrown by derived classes if the container 100 * already contains an object with this name. 101 */ 102 @Override 103 public void setName(String name) throws NameDuplicationException { 104 //if (name == null) { 105 // name = new String(""); 106 //} 107 try { 108 workspace().getWriteAccess(); 109 _name = name; 110 } finally { 111 workspace().doneWriting(); 112 } 113 } 114 115 /////////////////////////////////////////////////////////////////// 116 //// private variables //// 117 // Instance of a workspace that can be used if no other is specified. 118 private static Workspace _defaultWorkspace = new Workspace(); 119 120 /** @serial The name. */ 121 private String _name; 122}