001/* 002 * Copyright (c) 2005-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.sms; 031 032import java.util.Collection; 033 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036import ptolemy.kernel.util.NamedObj; 037import ptolemy.kernel.util.Settable; 038import ptolemy.kernel.util.StringAttribute; 039import ptolemy.kernel.util.Workspace; 040 041/** 042 * A data structure to hold a semantic property in a MoML file. The container of 043 * a semantic property is currently limited to KeplerIOPortSemanticLinks. 044 * 045 * @author Shawn Bowers 046 * @created June 20, 2005 047 * @see org.kepler.sms.KeplerIOPortSemanticLink 048 */ 049public class SemanticProperty extends StringAttribute { 050 051 /** Constructor */ 052 public SemanticProperty() { 053 super(); 054 } 055 056 /** 057 * Constructor 058 * 059 * @param container 060 * Description of the Parameter 061 * @param name 062 * The value of the property 063 * @exception IllegalActionException 064 * Description of the Exception 065 * @exception NameDuplicationException 066 * Description of the Exception 067 */ 068 public SemanticProperty(NamedObj container, String name) 069 throws IllegalActionException, NameDuplicationException { 070 super(container, name); 071 } 072 073 /** 074 * Constructor 075 * 076 * @param workspace 077 * Description of the Parameter 078 */ 079 public SemanticProperty(Workspace workspace) { 080 super(workspace); 081 } 082 083 /** 084 * Set the container of the semantic property to the given container. This 085 * method fails, in addition to the normal ptolemy constraints for setting 086 * containers, if the given container is not a 087 * org.kepler.sms.KeplerIOPortSemanticLink object. 088 * 089 * @param container 090 * The container for this virtual port. 091 */ 092 public void setContainer(NamedObj container) throws IllegalActionException, 093 NameDuplicationException { 094 if (!(container instanceof KeplerIOPortSemanticLink)) { 095 String msg = "Container not an instance of KeplerIOPortSemanticLink for semantic property '" 096 + getName() + "'"; 097 throw new IllegalActionException(this, msg); 098 } 099 super.setContainer(container); 100 } 101 102 /** 103 * returns the default expression which is null 104 * 105 * @return The defaultExpression value. Currently if not given, then 106 * unknown. 107 */ 108 public String getDefaultExpression() { 109 return null; 110 } 111 112 /** 113 * set the semantic property id value 114 * 115 * @param expression 116 * The new semantic type concept id 117 */ 118 public void setPropertyId(String expr) 119 throws ptolemy.kernel.util.IllegalActionException { 120 setExpression(expr); 121 } 122 123 /** 124 * return the value of the semantic property (the id) 125 * 126 * @return The concept id 127 */ 128 public String getPropertyId() { 129 return getExpression(); 130 } 131 132 /** 133 * SemanticTypes should be invisible to the user 134 * 135 * @return The visibility value 136 */ 137 public Settable.Visibility getVisibility() { 138 // return NONE; // this should be changed? 139 // return ptolemy.kernel.util.Settable.FULL; 140 return ptolemy.kernel.util.Settable.NOT_EDITABLE; 141 } 142 143 /** 144 * this method does not change the visibility. SemanticType should only be 145 * invisible 146 * 147 * @param visibility 148 * The new visibility value 149 */ 150 public void setVisibility(Settable.Visibility visibility) { 151 // do nothing....we don't want the visibility getting changed 152 } 153 154 /** validate the expression. */ 155 public Collection validate() throws IllegalActionException { 156 // ... may want to change this in the future 157 return null; 158 } 159 160 /** 161 * Description of the Method 162 * 163 * @param obj 164 * Description of the Parameter 165 * @return Description of the Return Value 166 */ 167 public boolean equals(Object obj) { 168 if (!(obj instanceof SemanticProperty)) 169 return false; 170 SemanticProperty sempropId = (SemanticProperty) obj; 171 String str = sempropId.getExpression(); 172 if (this.getExpression() == null) { 173 if (str != null) 174 return false; 175 return true; 176 } 177 return this.getExpression().equals(sempropId.getExpression()); 178 } 179 180} // SemanticType