Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.Attribute


            body.getLocals().add(containerLocal);

            // Invoke the method to compute each attribute, in order.
            for (Iterator attributes = locallyModifiedAttributeList.iterator(); attributes
                    .hasNext();) {
                Attribute attribute = (Attribute) attributes.next();
                Entity attributeContainer = FieldsForEntitiesTransformer
                        .getEntityContainerOfObject(attribute);
                SootClass containerClass = (SootClass) _objectToClassMap
                        .get(attributeContainer);
                SootMethod computeMethod = containerClass
View Full Code Here


            String name = (String) names.next();
            String value = (String) values.next();

            boolean match = false;

            Attribute attribute = _generatorAttribute.getAttribute(name);

            if (attribute instanceof Settable) {
                match = true;
                ((Settable) attribute).setExpression(value);
View Full Code Here

                portFigure.translate(x, y);

                // If the actor contains a variable named "_showRate",
                // with value true, then visualize the rate information.
                // NOTE: Showing rates only makes sense for IOPorts.
                Attribute showRateAttribute = port.getAttribute("_showRate");

                if (port instanceof IOPort
                        && showRateAttribute instanceof Variable) {
                    boolean showRate = false;

                    try {
                        showRate = ((Variable) showRateAttribute).getToken()
                                .equals(BooleanToken.TRUE);
                    } catch (Exception ex) {
                        // Ignore.
                    }

                    if (showRate) {
                        // Infer the rate.  See DFUtilities.
                        String rateString = "";
                        Variable rateParameter = null;

                        if (((IOPort) port).isInput()) {
                            rateParameter = (Variable) port
                                    .getAttribute("tokenConsumptionRate");

                            if (rateParameter == null) {
                                String altName = "_tokenConsumptionRate";
                                rateParameter = (Variable) port
                                        .getAttribute(altName);
                            }
                        } else if (((IOPort) port).isOutput()) {
                            rateParameter = (Variable) port
                                    .getAttribute("tokenProductionRate");

                            if (rateParameter == null) {
                                String altName = "_tokenProductionRate";
                                rateParameter = (Variable) port
                                        .getAttribute(altName);
                            }
                        }

                        if (rateParameter != null) {
                            try {
                                rateString = rateParameter.getToken()
                                        .toString();
                            } catch (KernelException ex) {
                                // Ignore.
                            }
                        }

                        LabelFigure labelFigure = _createPortLabelFigure(
                                rateString, _portLabelFont, x, y, direction);
                        labelFigure.setFillPaint(Color.BLUE);
                        figure.add(labelFigure);
                    }
                }

                // If the port contains an attribute named "_showName",
                // then render the name of the port as well. If the
                // attribute is a boolean-valued parameter, then
                // show the name only if the value is true.
                Attribute showAttribute = port.getAttribute("_showName");
                String toShow = null;
                if (showAttribute != null) {
                    boolean show = true;

                    if (showAttribute instanceof Parameter) {
                        try {
                            Token token = ((Parameter) showAttribute)
                                    .getToken();

                            if (token instanceof BooleanToken) {
                                show = ((BooleanToken) token).booleanValue();
                            }
                        } catch (IllegalActionException e) {
                            // Ignore. Presence of the attribute will prevail.
                        }
                    }

                    if (show) {
                        toShow = port.getDisplayName();
                    }
                }
                // In addition, if the port contains an attribute
                // called "_showInfo", then if that attribute is
                // a variable, then its value is shown. Otherwise,
                // if it is a Settable, then its expression is shown.
                Attribute showInfo = port.getAttribute("_showInfo");
                try {
                    if (showInfo instanceof Variable
                            && !((Variable) showInfo).isStringMode()) {
                        String value = ((Variable) showInfo).getToken()
                                .toString();
View Full Code Here

                        docApplicationSpecializer
                                .handleDocumentationAttributeDoesNotExist(
                                        getFrame(), target);

                    } else { //edit the existing attribute
                        final Attribute docAttribute = (Attribute) docAttributeList
                                .get(docAttributeList.size() - 1);
                        ChangeRequest request = new ChangeRequest(this,
                                "Customize documentation.") {
                            protected void _execute() throws Exception {
                                //_editDocAttribute(getFrame(), docAttribute, target);
View Full Code Here

     @param relation The relation.
     *  @return true if the relation should be ignored in the matching; false
     *   otherwise.
     */
    protected boolean _ignoreRelation(Relation relation) {
        Attribute hideAttribute = relation.getAttribute("_hide");
        if (hideAttribute != null) {
            try {
                BooleanToken token = (BooleanToken) ((Parameter) hideAttribute)
                        .getToken();
                boolean hide = token.booleanValue();
View Full Code Here

                        }
                    }
                } else if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.attributeClass)) {
                    // If we are invoking a method on a parameter.
                    Attribute attribute = (Attribute) _namedObjAnalysis
                            .getObject((Local) r.getBase());

                    if (attribute == null) {
                        // A method invocation with a null base is bogus,
                        // so don't create a type constraint.
View Full Code Here

            boolean match = false;
            Iterator models = _models.iterator();

            while (models.hasNext()) {
                CompositeActor model = (CompositeActor) models.next();
                Attribute attribute = model.getAttribute(name);

                if (attribute instanceof Variable) {
                    match = true;
                    ((Variable) attribute).setExpression(value);
View Full Code Here

                }
                // Find the corresponding ParameterPort and delete it
                if (toDelete != null) {
                    NamedObj container = toDelete.getContainer();
                    if (container != null && container instanceof Entity) {
                        Attribute attribute = ((Entity) container)
                                .getAttribute(portName);
                        if (attribute != null
                                && attribute instanceof PortParameter) {
                            DeleteRequest request = new DeleteRequest(
                                    _DELETE_PROPERTY, attribute.getName(), null);
                            // Only defer if we are in a class, entity, or
                            // model context, which is equivalent to the
                            // _current being an instance of
                            // InstantiableNamedObj.
                            if ((_deleteRequests != null)
                                    && _current instanceof InstantiableNamedObj) {
                                _deleteRequests.add(request);
                            } else {
                                // Very likely, the context is null, in which
                                // case the following will throw an exception.
                                // We defer to it in case somehow a link request
                                // is being made at the top level with a non-null
                                // context (e.g. via a change request).
                                request.execute();
                            }
                        }
                    }
                }

                // Link is stored and processed last, but before deletions.
                DeleteRequest request = new DeleteRequest(_DELETE_PORT,
                        portName, entityName);

                // Only defer if we are in a class, entity, or model context,
                // which is equivalent to the _current being an instance of
                // InstantiableNamedObj.
                if ((_deleteRequests != null)
                        && _current instanceof InstantiableNamedObj) {
                    _deleteRequests.add(request);
                } else {
                    // Very likely, the context is null, in which
                    // case the following will throw an exception.
                    // We defer to it in case somehow a link request
                    // is being made at the top level with a non-null
                    // context (e.g. via a change request).
                    request.execute();
                }

                // NOTE: deletePort is not supposed to have anything
                // inside it, so we do not push the context.
                //////////////////////////////////////////////////////////////
                //// deleteProperty
            } else if (elementName.equals("deleteProperty")) {
                String propName = (String) _attributes.get("name");
                _checkForNull(propName,
                        "No name for element \"deleteProperty\"");

                // Link is stored and processed last, but before deletions.
                DeleteRequest request = new DeleteRequest(_DELETE_PROPERTY,
                        propName, null);

                // We use toDelete to find any PortParameters
                Attribute toDelete = _searchForAttribute(propName);

                // Only defer if we are in a class, entity, or model context,
                // which is equivalent to the _current being an instance of
                // InstantiableNamedObj.
                if ((_deleteRequests != null)
                        && _current instanceof InstantiableNamedObj) {
                    _deleteRequests.add(request);
                } else {
                    // Very likely, the context is null, in which
                    // case the following will throw an exception.
                    // We defer to it in case somehow a link request
                    // is being made at the top level with a non-null
                    // context (e.g. via a change request).
                    request.execute();
                }

                // Find the corresponding PortParameter and delete it
                NamedObj container = toDelete.getContainer();
                if (container != null && container instanceof Entity) {
                    Port port = ((Entity) container).getPort(propName);
                    if (port != null && port instanceof ParameterPort) {
                        request = new DeleteRequest(_DELETE_PORT, port
                                .getName(), container.getFullName());
View Full Code Here

     @return The deleted object, or null if none is found.
     *  @exception Exception If there is no such attribute or if the attribute
     *   is defined in the class definition.
     */
    private Attribute _deleteProperty(String attributeName) throws Exception {
        Attribute toDelete = _searchForAttribute(attributeName);

        if (toDelete == null) {
            return null;
        }

        // Ensure that derived objects aren't changed.
        if (toDelete.getDerivedLevel() < Integer.MAX_VALUE) {
            throw new IllegalActionException(toDelete,
                    "Cannot delete. This attribute is part of the class definition.");
        }

        // Propagate and generate undo MoML.
        // NOTE: not enough to simply record the MoML of the deleted attribute
        // as derived attributes may have overridden the values.
        // Construct the undo MoML as we go to ensure: (1) that
        // the undo occurs in the opposite order of all deletions, and
        // (2) that if a failure to delete occurs at any point, then
        // the current undo only represents as far as the failure got.
        StringBuffer undoMoML = new StringBuffer();

        // Propagate. The name might be absolute and have
        // nothing to do with the current context.  So
        // we look for its derived objects, not the context's derived objects.
        // We have to do this before actually deleting it,
        // which also has the side effect of triggering errors
        // before the deletion.
        try {
            // NOTE: Deletion can occur in the the same order as
            // what appears in the derived list.
            Iterator derivedObjects = toDelete.getDerivedList().iterator();

            String toUndo = _getUndoForDeleteAttribute(toDelete);

            toDelete.setContainer(null);
            undoMoML.append(toUndo);
            while (derivedObjects.hasNext()) {
                Attribute derived = (Attribute) derivedObjects.next();
                // Note that we need to generate undo for the attributes
                // because the attributes may be customized in the instances
                // or derived classes.
                toUndo = _getUndoForDeleteAttribute(derived);
                derived.setContainer(null);
                undoMoML.append(toUndo);
            }
        } finally {
            if (_undoEnabled) {
                undoMoML.insert(0, "<group>");
View Full Code Here

                        List derivedList = _current.getDerivedList();
                        Iterator derivedObjects = derivedList.iterator();

                        while (derivedObjects.hasNext()) {
                            NamedObj derived = (NamedObj) derivedObjects.next();
                            Attribute other = derived
                                    .getAttribute(propertyName);

                            if ((other != null)
                                    && !(other instanceof Singleton)) {
                                throw new IllegalActionException(
View Full Code Here

TOP

Related Classes of ptolemy.kernel.util.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.