Package ptolemy.moml

Class LibraryAttribute

  • All Implemented Interfaces:
    java.lang.Cloneable, Changeable, Configurable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable

    public class LibraryAttribute
    extends ConfigurableAttribute
    This class is a configurable singleton attribute that associates a component library with a model. By convention, it is typically named "_library". A visual editor that opens a model containing this attribute will offer the contents of its library as the component library for editing the model. "Singleton" means that if this attribute is placed in a model, it will replace any previous singleton attribute that has the same name. "Configurable" means that the contents of the library can be set in a configure element in MoML, or via the configure() method. The library can also be set by calling setLibrary(); this will override any library specified by configure.

    When creating a library to associate with this attribute, the library should be created in the same workspace as this attribute (as returned by the workspace() method). Normally, it will have no container. The text specified in the configure element (or a call to the configure() method) is not parsed until the getLibrary() method is called. Thus, the overhead of creating the library is avoided if the library is not used.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (janneck)
    Pt.ProposedRating:
    Yellow (eal)
    • Constructor Detail

      • LibraryAttribute

        public LibraryAttribute()
        Construct a new attribute with no container and an empty string as its name. Add the attribute to the workspace directory. Increment the version number of the workspace.
      • LibraryAttribute

        public LibraryAttribute​(Workspace workspace)
        Construct a new attribute with no container and an empty string as a name. You can then change the name with setName(). If the workspace argument is null, then use the default workspace. Add the attribute to the workspace directory. Increment the version number of the workspace.
        Parameters:
        workspace - The workspace that will list the attribute.
      • LibraryAttribute

        public LibraryAttribute​(NamedObj container,
                                java.lang.String name)
                         throws NameDuplicationException,
                                IllegalActionException
        Construct an attribute with the given container and name. If an attribute already exists with the same name as the one specified here, that is an instance of class LibraryAttribute (or a derived class), then that attribute is removed before this one is inserted in the container.
        Parameters:
        container - The container.
        name - The name of this attribute.
        Throws:
        IllegalActionException - If the attribute cannot be contained by the proposed container.
        NameDuplicationException - If the container already has an attribute with this name, and the class of that container is not LibraryAttribute.
    • Method Detail

      • getLibrary

        public CompositeEntity getLibrary()
                                   throws java.lang.Exception
        Return the library specified by the configure() method or the setLibrary() method, or null if it has not been set. If the configure() method has defined the library, then calling this method will parse the MoML in specified in the configure() call to create the library. The parser for the top-level container of this attribute will be used, if there is one. Otherwise, a new parser will be used. Note that the library will be reparsed each time this is called. This method ensures that the library that is returned contains an attribute called "_libraryMarker" so that a user interface recognizes it as a library.
        Returns:
        The library, or null if none.
        Throws:
        java.lang.Exception - If the library specification is invalid, for example because the MoML cannot be parsed, or because it does not define an instance of CompositeEntity.
        See Also:
        setLibrary(CompositeEntity)
      • setLibrary

        public void setLibrary​(CompositeEntity library)
        Specify the library, overriding any library that might have been or might later be specified by a call to configure(). This method ensures that the library contains an attribute named "_libraryMarker" by creating one if it is not there.
        Parameters:
        library - The library.
        See Also:
        getLibrary()