001/* Return a list containing all the backward compatibility filters
002
003 Copyright (c) 2002-2016 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.filter;
029
030import java.util.LinkedList;
031import java.util.List;
032
033import ptolemy.moml.MoMLFilter;
034
035//////////////////////////////////////////////////////////////////////////
036//// BackwardCompatibility
037
038/** Return a list where each element is a backward compatibility filter
039 to be applied by the MoMLParser.
040
041 <p>When this class is registered with</p>
042 <pre>
043 MoMLParser.addMoMLFilters(BackwardCompatibility.allFilters())
044 </pre>
045 <p>method, it will cause MoMLParser to filter so that models from
046 earlier releases will run in the current release.</p>
047
048 @see ptolemy.moml.MoMLFilter
049 @author Christopher Hylands, Edward A. Lee
050 @version $Id$
051 @since Ptolemy II 2.0
052 @Pt.ProposedRating Red (cxh)
053 @Pt.AcceptedRating Red (cxh)
054 */
055public class BackwardCompatibility {
056
057    /** Add a MoMLFilter to the list of filters.
058     *  @param filter The filter to be added.
059     */
060    public static void addFilter(MoMLFilter filter) {
061        _filterList.add(filter);
062    }
063
064    /** Return a shallow copy of the list where each element of the
065     *  list is a MoMLFilter to be applied to handle backward
066     *  compatibility.
067     *
068     *  @return a list of all the filters.
069     */
070    public static List allFilters() {
071        // Return a clone of the list and not the list itself.
072        // The reason is that callers might add to the list
073        // and we don't want to modify the base list.
074        // To replicate, use:
075        //  cd moml/filter/test
076        //  $PTII/bin/ptjacl
077        //  source ActorIndex.tcl
078        //  source GRColorChanges.tcl
079        return (List) ((LinkedList) _filterList).clone();
080    }
081
082    /** Clear the list of filters.
083     */
084    public static void clear() {
085        _filterList = new LinkedList();
086    }
087
088    /** Return a string that describes all the filters.
089     *  @return the String that describes all the filters and that ends with a
090     *  newline.
091     */
092    @Override
093    public String toString() {
094        // This is a little strange because when we call
095        // BackwardCompatibility.allFilters(), we add the individual filters
096        // so when we iterate through the filters and call toString, we never
097        // actually call BackwardCompatibility.toString().
098        // Ideally, we would like to make toString() static, but we
099        // can't do that because Object.toString() is not static
100        StringBuffer results = new StringBuffer(
101                "This filter contains the following filters:\n");
102
103        for (MoMLFilter filter : _filterList) {
104            results.append(filter.toString() + "\n");
105        }
106
107        return results.toString();
108    }
109
110    // List of MoMLFilters to be applied.
111    private static List<MoMLFilter> _filterList;
112
113    static {
114        _filterList = new LinkedList<MoMLFilter>();
115        // AddEditorFactory is deprecated, use AddMissingParameter instead.
116        //_filterList.add(new AddEditorFactory());
117        _filterList.add(new AddMissingParameter());
118        _filterList.add(new AddIcon());
119        _filterList.add(new ClassChanges());
120        _filterList.add(new DocAttributeChanges());
121        //_filterList.add(new UpdateAnnotations());
122        _filterList.add(new HideAnnotationNames());
123
124        // JavaScriptThisUpdate is temporary while we add "this." to certain keywords.
125        // _filterList.add(new JavaScriptThisUpdate());
126
127        _filterList.add(new MultiportToSinglePort());
128        _filterList.add(new ParameterNameChanges());
129        _filterList.add(new PortClassChanges());
130        _filterList.add(new PortNameChanges());
131        _filterList.add(new PropertyClassChanges());
132        _filterList.add(new GRColorChanges());
133        _filterList.add(new RemoveProperties());
134        //System.out.println("Filtering and converting to LazyTypedCompositeActors");
135        //_filterList.add(new LazyTypedCompositeActorChanges());
136        _filterList.add(new RelationWidthChanges());
137    }
138}