001/* A property that specifies the category of a base unit. 002 003 Copyright (c) 2001-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 */ 027package ptolemy.data.unit; 028 029import ptolemy.kernel.util.Attribute; 030import ptolemy.kernel.util.IllegalActionException; 031import ptolemy.kernel.util.NameDuplicationException; 032import ptolemy.kernel.util.NamedObj; 033import ptolemy.kernel.util.Workspace; 034 035////////////////////////////////////////////////////////////////////////// 036//// UnitCategory 037 038/** 039 A property that specifies the category of a base unit. For example, in the 040 International System of Units, the base unit meter has the category length. 041 042 @author Xiaojun Liu 043 @version $Id$ 044 @since Ptolemy II 2.0 045 @Pt.ProposedRating Red (liuxj) 046 @Pt.AcceptedRating Red (liuxj) 047 @see ptolemy.data.unit.BaseUnit 048 */ 049public class UnitCategory extends Attribute { 050 /** Construct a unit category in the default workspace with an empty string 051 * as its name. 052 * The object is added to the directory of the workspace. 053 * Increment the version number of the workspace. 054 */ 055 public UnitCategory() { 056 super(); 057 } 058 059 /** Construct an attribute in the specified workspace with an empty 060 * string as a name. You can then change the name with setName(). 061 * If the workspace argument 062 * is null, then use the default workspace. 063 * The object is added to the directory of the workspace. 064 * Increment the version number of the workspace. 065 * @param workspace The workspace that will list the attribute. 066 */ 067 public UnitCategory(Workspace workspace) { 068 super(workspace); 069 } 070 071 /** Construct a unit category property with the given name contained by 072 * the specified 073 * entity. The container argument must not be null, or a 074 * NullPointerException will be thrown. This attribute will use the 075 * workspace of the container for synchronization and version counts. 076 * If the name argument is null, then the name is set to the empty string. 077 * Increment the version of the workspace. 078 * 079 * <p>This constructor adds the created object to the system wide 080 * UnitSystem by calling 081 * {@link UnitUtilities#registerUnitCategory(String)} 082 * 083 * @param container The container. 084 * @param name The name of this attribute. 085 * @exception IllegalActionException If the attribute is not of an 086 * acceptable class for the container, or if the name contains a period. 087 * @exception NameDuplicationException If the name coincides with 088 * an attribute already in the container. 089 */ 090 public UnitCategory(NamedObj container, String name) 091 throws IllegalActionException, NameDuplicationException { 092 super(container, name); 093 UnitUtilities.registerUnitCategory( 094 ((BaseUnit) this.getContainer()).getName()); 095 } 096 097 /** Return the base unit. 098 * @return The base unit. 099 */ 100 public BaseUnit getBaseUnit() { 101 return (BaseUnit) getContainer(); 102 } 103 104 /** Set the container and register this object in to the system wide 105 * unit system by calling 106 * {@link UnitUtilities#registerUnitCategory(String)}. 107 * @param container The container to attach this attribute to. 108 * The type of the container must be an instances of BaseUnit. 109 * @exception IllegalActionException If Attribute.setContainer() 110 * throws it. 111 * @exception NameDuplicationException If Attribute.setContainer() 112 * throws it. 113 */ 114 @Override 115 public void setContainer(NamedObj container) 116 throws IllegalActionException, NameDuplicationException { 117 super.setContainer(container); 118 UnitUtilities.registerUnitCategory( 119 ((BaseUnit) this.getContainer()).getName()); 120 } 121}