001/* Test for port name problems with Entity.clone() 002 003 Copyright (c) 2004-2005 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.test; 029 030import ptolemy.kernel.Entity; 031import ptolemy.kernel.Port; 032import ptolemy.kernel.util.IllegalActionException; 033import ptolemy.kernel.util.NameDuplicationException; 034import ptolemy.kernel.util.Workspace; 035 036/** 037 * Illustrates a problem with port naming and cloning. 038 * <p> In this actor, the Java variable of the port is named 039 * "poorlyNamedInput" but the constructor uses "input", which 040 * is the wrong name. 041 * This used to result in a NullPointerException. 042 * Now, we test for this in Entity.clone(). 043 * @author Christopher Brooks, based on code from Xiaowen Xin and Ilkay Altintas 044 * @version $Id$ 045 * @since Ptolemy II 4.1 046 */ 047public class PortNameProblem extends Entity { 048 public PortNameProblem(Workspace workspace, String name) 049 throws IllegalActionException, NameDuplicationException { 050 super(workspace, name); 051 052 // This port should be oke 053 directoryOrURLPort = new Port(this, "directoryOrURL"); 054 055 // The name of the port should passed to the constructor should 056 // match the name of the variable. Entity.clone() assumes 057 // that the names match. 058 // Right: 059 // poorlyNamedInput = new Port(this, "poorlyNamedInput"); 060 // Wrong: 061 poorlyNamedInput = new Port(this, "input"); 062 } 063 064 // This port, from actor/lib/io/DirectoryListing.java, is ok because 065 // it ends in "Port" 066 public Port directoryOrURLPort; 067 068 //public Port input; 069 public Port poorlyNamedInput; 070}