001/* A composite actor that serves as container of the contents of a configurable 002 entity. 003 004 Copyright (c) 2008-2018 The Regents of the University of California. 005 All rights reserved. 006 Permission is hereby granted, without written agreement and without 007 license or royalty fees, to use, copy, modify, and distribute this 008 software and its documentation for any purpose, provided that the above 009 copyright notice and the following two paragraphs appear in all copies 010 of this software. 011 012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 016 SUCH DAMAGE. 017 018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023 ENHANCEMENTS, OR MODIFICATIONS. 024 025 PT_COPYRIGHT_VERSION_2 026 COPYRIGHTENDKEY 027 028 */ 029package ptolemy.domains.modal.kernel; 030 031import ptolemy.actor.CompositeActor; 032import ptolemy.kernel.util.Attribute; 033import ptolemy.kernel.util.IllegalActionException; 034import ptolemy.kernel.util.InternalErrorException; 035import ptolemy.kernel.util.KernelException; 036import ptolemy.kernel.util.NameDuplicationException; 037import ptolemy.kernel.util.NamedObj; 038import ptolemy.kernel.util.Workspace; 039 040/////////////////////////////////////////////////////////////////// 041//// Configurer 042 043/** 044 A composite actor that serves as container of the contents of a configurable 045 entity. 046 047 @author Thomas Huining Feng 048 @version $Id$ 049 @since Ptolemy II 8.0 050 @Pt.ProposedRating Red (tfeng) 051 @Pt.AcceptedRating Red (tfeng) 052 */ 053public class Configurer extends CompositeActor { 054 055 /** Construct a configurer in the given workspace. 056 * 057 * @param workspace The workspace. 058 */ 059 public Configurer(Workspace workspace) { 060 super(workspace); 061 062 try { 063 new ContainmentExtender(this, "_containmentExtender"); 064 } catch (KernelException e) { 065 throw new InternalErrorException(e); 066 } 067 } 068 069 /** Clone the actor into the specified workspace. The new object is 070 * <i>not</i> added to the directory of that workspace (you must do this 071 * yourself if you want it there). 072 * The result is a composite actor with clones of the ports of the 073 * original actor, the contained actors, and the contained relations. 074 * The ports of the returned actor are not connected to anything. 075 * The connections of the relations are duplicated in the new composite, 076 * unless they cross levels, in which case an exception is thrown. 077 * The local director is cloned, if there is one. 078 * The executive director is not cloned. 079 * NOTE: This will not work if there are level-crossing transitions. 080 * 081 * @param workspace The workspace for the cloned object. 082 * @exception CloneNotSupportedException If the actor contains 083 * level crossing transitions so that its connections cannot be cloned, 084 * or if one of the attributes cannot be cloned. 085 * @return A new CompositeActor. 086 */ 087 @Override 088 public Object clone(Workspace workspace) throws CloneNotSupportedException { 089 Configurer newObject = (Configurer) super.clone(workspace); 090 newObject._configured = null; 091 return newObject; 092 } 093 094 /** Get the object that this configurer configures. 095 * 096 * @return The object that this configurer configures. 097 * @see #setConfiguredObject(NamedObj) 098 */ 099 public NamedObj getConfiguredObject() { 100 return _configured; 101 } 102 103 /** Set the object that this configurer configures. 104 * 105 * @param configured The object that this configurer configures. 106 * @see #getConfiguredObject() 107 */ 108 public void setConfiguredObject(NamedObj configured) { 109 _configured = configured; 110 } 111 112 /////////////////////////////////////////////////////////////////// 113 //// ContainmentExtender 114 115 /** 116 The containment extender that returns the configured object as the 117 container of this configurer. 118 119 @author Thomas Huining Feng 120 @version $Id$ 121 @since Ptolemy II 8.0 122 @Pt.ProposedRating Red (tfeng) 123 @Pt.AcceptedRating Red (tfeng) 124 */ 125 public static class ContainmentExtender extends Attribute 126 implements ptolemy.data.expr.ContainmentExtender { 127 128 /** Construct a containment extender. 129 * 130 * @param container The container. 131 * @param name The name of this attribute. 132 * @exception IllegalActionException If the attribute is not of an 133 * acceptable class for the container, or if the name contains a 134 * period. 135 * @exception NameDuplicationException If the name coincides with 136 * an attribute already in the container. 137 */ 138 public ContainmentExtender(Configurer container, String name) 139 throws IllegalActionException, NameDuplicationException { 140 super(container, name); 141 } 142 143 /** Get an object with the given name within the container. 144 * 145 * @param name The name of the object. 146 * @return The object, or null if not found. 147 * @exception IllegalActionException If exception occurs when trying to get 148 * the contained object. 149 */ 150 @Override 151 public NamedObj getContainedObject(String name) 152 throws IllegalActionException { 153 return ((Configurer) getContainer()).getEntity(name); 154 } 155 156 /** Get the extended container. 157 * 158 * @return The container. 159 * @exception IllegalActionException If exception occurs when trying to get 160 * the container. 161 */ 162 @Override 163 public NamedObj getExtendedContainer() throws IllegalActionException { 164 return ((Configurer) getContainer()).getConfiguredObject(); 165 } 166 167 } 168 169 // The object that this configurer configures. 170 private NamedObj _configured; 171}