001/* Container for decorator attributes that are provided to actors by 002 * a resource scheduler. 003 004@Copyright (c) 2008-2018 The Regents of the University of California. 005All rights reserved. 006 007Permission is hereby granted, without written agreement and without 008license or royalty fees, to use, copy, modify, and distribute this 009software and its documentation for any purpose, provided that the 010above copyright notice and the following two paragraphs appear in all 011copies of this software. 012 013IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 014FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 015ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 016THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 017SUCH DAMAGE. 018 019THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 020INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 021MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 022PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 023CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 024ENHANCEMENTS, OR MODIFICATIONS. 025 026 PT_COPYRIGHT_VERSION_2 027 COPYRIGHTENDKEY 028 029 030 */ 031package ptolemy.actor; 032 033import ptolemy.data.BooleanToken; 034import ptolemy.data.expr.Parameter; 035import ptolemy.data.type.BaseType; 036import ptolemy.kernel.util.Attribute; 037import ptolemy.kernel.util.Decorator; 038import ptolemy.kernel.util.DecoratorAttributes; 039import ptolemy.kernel.util.IllegalActionException; 040import ptolemy.kernel.util.InternalErrorException; 041import ptolemy.kernel.util.KernelException; 042import ptolemy.kernel.util.NameDuplicationException; 043import ptolemy.kernel.util.NamedObj; 044 045/** 046Container for decorator attributes that are provided to actors by 047a ExecutionAspect. The resource scheduler decorates actors 048in a model with the attributes contained by this object. 049 050This provides an "enable" attribute. 051 052 @author Patricia Derler 053 @author Edward A. Lee 054 @version $Id$ 055 @since Ptolemy II 10.0 056 @Pt.ProposedRating Yellow (eal) 057 @Pt.AcceptedRating Red (eal) 058 */ 059public class ExecutionAttributes extends DecoratorAttributes { 060 061 /** Constructor to use when editing a model. 062 * @param target The object being decorated. 063 * @param decorator The decorator. 064 * @exception IllegalActionException If the superclass throws it. 065 * @exception NameDuplicationException If the superclass throws it. 066 */ 067 public ExecutionAttributes(NamedObj target, Decorator decorator) 068 throws IllegalActionException, NameDuplicationException { 069 super(target, decorator); 070 _init(); 071 } 072 073 /** Constructor to use when parsing a MoML file. 074 * @param target The object being decorated. 075 * @param name The name of this attribute. 076 * @exception IllegalActionException If the superclass throws it. 077 * @exception NameDuplicationException If the superclass throws it. 078 */ 079 public ExecutionAttributes(NamedObj target, String name) 080 throws IllegalActionException, NameDuplicationException { 081 super(target, name); 082 _init(); 083 } 084 085 /////////////////////////////////////////////////////////////////// 086 //// parameters //// 087 088 /** The enable parameter specifies whether the decorated actor uses 089 * the resource scheduler decorator. 090 * This is a boolean that defaults to false. 091 */ 092 public Parameter enable; 093 094 /////////////////////////////////////////////////////////////////// 095 //// public methods //// 096 097 /** React to a change in an attribute. If the attribute is 098 * <i>enable</i>, remember the value. 099 * @param attribute The attribute that changed. 100 * @exception IllegalActionException If the change is not acceptable 101 * to this container (not thrown in this base class). 102 */ 103 @Override 104 public void attributeChanged(Attribute attribute) 105 throws IllegalActionException { 106 if (attribute == enable) { 107 _enabled = ((BooleanToken) enable.getToken()).booleanValue(); 108 } 109 super.attributeChanged(attribute); 110 } 111 112 /** Return whether the decorator associated with this attribute is 113 * enabled. 114 * @return True if enabled. 115 */ 116 public boolean enabled() { 117 return _enabled; 118 } 119 120 /////////////////////////////////////////////////////////////////// 121 //// private methods //// 122 123 /** Create the parameters. 124 */ 125 private void _init() { 126 try { 127 enable = new Parameter(this, "enable"); 128 enable.setExpression("false"); 129 enable.setTypeEquals(BaseType.BOOLEAN); 130 } catch (KernelException ex) { 131 // This should not occur. 132 throw new InternalErrorException(ex); 133 } 134 } 135 136 private boolean _enabled; 137}