001/* An attribute that represents an external file reference.
002
003 Copyright (c) 1998-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
027 */
028package ptolemy.moml;
029
030import java.io.IOException;
031import java.io.Writer;
032
033import ptolemy.kernel.util.Attribute;
034import ptolemy.kernel.util.IllegalActionException;
035import ptolemy.kernel.util.NameDuplicationException;
036import ptolemy.kernel.util.NamedObj;
037
038///////////////////////////////////////////////////////////////////
039//// ImportAttribute
040
041/**
042 This attribute represents an external file reference.
043
044 @author  Edward A. Lee
045 @version $Id$
046 @since Ptolemy II 1.0
047 @Pt.ProposedRating Red (eal)
048 @Pt.AcceptedRating Red (reviewmoderator)
049 @deprecated The 'import' MoML element is deprecated, use the 'source'
050 attribute instead.
051 */
052@Deprecated
053public class ImportAttribute extends Attribute {
054    /** Construct an attribute with the specified container and name.
055     *  @param container The container.
056     *  @param name The name of this attribute.
057     *  @exception IllegalActionException If the attribute is not of an
058     *   acceptable class for the container, or if the name contains a period.
059     *  @exception NameDuplicationException If the name coincides with
060     *   an attribute already in the container.
061     */
062    public ImportAttribute(NamedObj container, String name)
063            throws IllegalActionException, NameDuplicationException {
064        super(container, name);
065    }
066
067    ///////////////////////////////////////////////////////////////////
068    ////                         public methods                    ////
069
070    /** Set the name of the external file being referenced.
071     *  @param source The name of the external file.
072     */
073    @Override
074    public void setSource(String source) {
075        _source = source;
076    }
077
078    /** Write a MoML description of this object, which in this case is
079     *  an "import" element. If this object is not persistent, then
080     *  write nothing.
081     *  @param name The name to use instead of the name of this object.
082     *   This argument is ignored.
083     *  @param output The output stream to write to.
084     *  @param depth The depth in the hierarchy, to determine indenting.
085     *  @exception IOException If there is a problem writing the MoML.
086     */
087    @Override
088    public void exportMoML(Writer output, int depth, String name)
089            throws IOException {
090        if (_isMoMLSuppressed(depth)) {
091            return;
092        }
093
094        String moml = "<import source=\"" + _source + "\"/>";
095        output.write(_getIndentPrefix(depth) + moml + "\n");
096    }
097
098    ///////////////////////////////////////////////////////////////////
099    ////                         private variables                 ////
100    // The external file name;
101    private String _source;
102}