ptolemy.kernel.attributes
Class URIAttribute

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.util.Attribute
          extended byptolemy.kernel.util.SingletonAttribute
              extended byptolemy.kernel.attributes.URIAttribute
All Implemented Interfaces:
Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable, Singleton

public class URIAttribute
extends SingletonAttribute

An attribute that identifies the URI from which the container was read. This attribute is not persistent by default. That is, it exports no MoML description. This makes sense because it should be set by the code that reads the container's specification. It is also a singleton, meaning that it will replace any previous attribute that has the same name and is an instance of the base class, SingletonAttribute.

In most cases, this URI will specify a URL. The difference between a URL and a URI is that a URI is unevaluated. That is, it is a string representation of a resource, without any assurance or indication of a file, stream, or other associated network resource. To access a URI, it is common to create a URL from its specification.

Unfortunately, URLs are not necessarily valid URIs. For example, a URL that has a space in it is not a valid URI, the space must be quoted (converted) to %20.

Since:
Ptolemy II 2.1
Version:
$Id: URIAttribute.java,v 1.23 2004/04/13 03:42:07 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (cxh)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
URIAttribute(NamedObj container, java.lang.String name)
          Construct an attribute with the given name contained by the specified container.
 
Method Summary
static java.net.URI getModelURI(NamedObj container)
          Return the URI from which the specified model was read, or null if there is no such URI.
 java.net.URI getURI()
          Get the URI that has been set by setURI(), or null if there is none.
 java.net.URL getURL()
          Get a URL representation of the URI that has been set by setURI(), or null if there is none.
 void setURI(java.net.URI uri)
          Set the value of the URI, and call the attributeChanged() method of the container.
 void setURL(java.net.URL url)
          Set the value of the URI by specifying a URL, and call the attributeChanged() method of the container.
 
Methods inherited from class ptolemy.kernel.util.SingletonAttribute
setContainer
 
Methods inherited from class ptolemy.kernel.util.Attribute
_getContainedObject, _propagateExistence, clone, getContainer, setName
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URIAttribute

public URIAttribute(NamedObj container,
                    java.lang.String name)
             throws IllegalActionException,
                    NameDuplicationException
Construct an attribute with the given name contained by the specified container. The container argument must not be null, or a NullPointerException will be thrown. This attribute will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. The object is added to the directory of the workspace if the container is null. Increment the version of the workspace.

Parameters:
container - The container.
name - The name of this attribute.
Throws:
IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
NameDuplicationException - If the name coincides with an attribute already in the container.
Method Detail

getModelURI

public static java.net.URI getModelURI(NamedObj container)
Return the URI from which the specified model was read, or null if there is no such URI. This is obtained by finding a URIAttribute in the first container above this attribute in the hierarchy that has such an attribute. Note that this URI may represent a file on the local filesystem, in which case it will use the "file" scheme.

Returns:
A URI, or null if none can be found.

getURI

public java.net.URI getURI()
Get the URI that has been set by setURI(), or null if there is none.

Returns:
The URI.

getURL

public java.net.URL getURL()
                    throws java.net.MalformedURLException
Get a URL representation of the URI that has been set by setURI(), or null if there is none. For this to succeed, it is necessary that the URI be absolute or an IllegalArgumentException will be thrown.

Returns:
A new URL.
Throws:
java.net.MalformedURLException - If the URI cannot be converted to a URL.
java.lang.IllegalArgumentException - If the URI is not absolute.

setURI

public void setURI(java.net.URI uri)
            throws IllegalActionException
Set the value of the URI, and call the attributeChanged() method of the container.

Parameters:
uri - The new URI.
Throws:
IllegalActionException - If the change is not acceptable to the container.

setURL

public void setURL(java.net.URL url)
            throws IllegalActionException
Set the value of the URI by specifying a URL, and call the attributeChanged() method of the container.

Parameters:
url - The URL.
Throws:
IllegalActionException - If the change is not acceptable to the container.