Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.Attribute


            String[] resultLabels) throws IllegalActionException {
        Token[] value = new Token[resultLabels.length];

        for (int i = 0; i < resultLabels.length; i++) {
            String label = resultLabels[i];
            Attribute attribute = model.getAttribute(label);

            if (attribute instanceof Variable) {
                value[i] = ((Variable) attribute).getToken();
            }
        }
View Full Code Here


    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////
    private String _deletesIfNecessary(NamedObj obj) {
        String retv = null;
        Attribute color = obj.getAttribute("_color");
        Attribute explanation = obj.getAttribute("_explanation");

        if ((color != null) && (explanation != null)) {
            retv = "<deleteProperty name=\"_color\"/>"
                    + "<deleteProperty name=\"_explanation\"/>";
        }
View Full Code Here

                    boolean removed = false;
                    Port port = (Port) portInfo
                            .get(ColumnNames.COL_ACTUAL_PORT);

                    if (port != null) {
                        Attribute attribute = port.getAttribute("_showName");

                        if (!(attribute instanceof Parameter)) {
                            momlUpdate.append(_momlDeleteProperty("_showName"));
                            removed = true;
                        }
                    }

                    if (!removed) {
                        momlUpdate.append(_momlProperty("_showName",
                                _SINGLETON_PARAMETER, "false"));
                    }
                }
            }
        }

        if (updates.containsKey(ColumnNames.COL_HIDE)) {
            Boolean updateValue = (Boolean) updates.get(ColumnNames.COL_HIDE);

            if (updateValue.booleanValue()) {
                if (((Boolean) portInfo.get(ColumnNames.COL_HIDE))
                        .booleanValue()) {
                    momlUpdate.append(_momlProperty("_hide",
                            _SINGLETON_PARAMETER, "true"));
                } else {
                    // NOTE: If there is already a property that is not
                    // a boolean-valued parameter, then remove it rather
                    // than setting it to false.  This is done for more
                    // robust backward compatibility.
                    boolean removed = false;
                    Port port = (Port) portInfo
                            .get(ColumnNames.COL_ACTUAL_PORT);

                    if (port != null) {
                        Attribute attribute = port.getAttribute("_hide");

                        if (!(attribute instanceof Parameter)) {
                            momlUpdate.append(_momlDeleteProperty("_hide"));
                            removed = true;
                        }
View Full Code Here

     @param object The object.
     *  @param name The property name.
     *  @return True if the property is set.
     */
    private boolean _isPropertySet(NamedObj object, String name) {
        Attribute attribute = object.getAttribute(name);

        if (attribute == null) {
            return false;
        }

View Full Code Here

            NamedList scope = new NamedList();
            NamedObj container = object.getContainer();

            while (container != null) {
                Iterator level1 = container.attributeList().iterator();
                Attribute var = null;

                while (level1.hasNext()) {
                    // add the variables in the same NamedObj to scope,
                    // excluding this
                    var = (Attribute) level1.next();

                    if ((var instanceof Variable) && (var != object)) {
                        if (var.workspace() != object.workspace()) {
                            continue;
                        }

                        try {
                            scope.append(var);
                        } catch (NameDuplicationException ex) {
                            // This occurs when a variable is shadowed by one
                            // that has been previously entered in the scope.
                        } catch (IllegalActionException ex) {
                            // This should not happen since we are dealing with
                            // variables which are Nameable.
                        }
                    }
                }

                level1 = container.attributeList(ScopeExtender.class)
                        .iterator();

                while (level1.hasNext()) {
                    ScopeExtender extender = (ScopeExtender) level1.next();
                    Iterator level2 = extender.attributeList().iterator();

                    while (level2.hasNext()) {
                        // add the variables in the scope extender to scope,
                        // excluding this
                        var = (Attribute) level2.next();

                        if ((var instanceof Variable) && (var != object)) {
                            if (var.workspace() != object.workspace()) {
                                continue;
                            }

                            try {
                                scope.append(var);
View Full Code Here

        //                 copyAttributesOtherThanVariable(port);
        //             }
        //         }
        if ((object instanceof Attribute)
                && !(object instanceof SharedParameter)) {
            Attribute attribute = (Attribute) object;

            // Ignore attributes that are ignorable.
            if (ModelTransformer._isIgnorableAttribute(attribute)) {
                return;
            }

            // PortParameters are handled specially.
            //  if (attribute instanceof PortParameter) {
            //                 continue;
            //             }
            // If we have an attribute that derives from
            // stringAttribute, or Parameter then we need to grab some
            // code for it. (i.e. FileParameter, and FileParameter)
            if ((attribute instanceof StringAttribute && !attribute.getClass()
                    .equals(StringAttribute.class))
                    || (attribute instanceof Parameter && !attribute.getClass()
                            .equals(Parameter.class))) {
                String className = attribute.getClass().getName();

                if (_debug) {
                    System.out.println("ComplexAttribute = " + attribute
                            + " Class = " + className);
                }

                SootClass attributeClass = Scene.v().loadClassAndSupport(
                        className);
                attributeClass.setLibraryClass();

                String newClassName = ModelTransformer.getInstanceClassName(
                        attribute, _options);

                // Create a new class for the attribute.
                SootClass newClass = SootUtilities.copyClass(attributeClass,
                        newClassName);

                // Make sure that we generate code for the new class.
                newClass.setApplicationClass();

                // Associate the new class with the attribute.
                ModelTransformer.addAttributeForClass(newClass, attribute);

                // Fold the copied class up to StringAttribute, or parameter
                SootClass superClass = newClass.getSuperclass();

                while ((superClass != PtolemyUtilities.objectClass)
                        && (superClass != PtolemyUtilities.stringAttributeClass)
                        && (superClass != PtolemyUtilities.parameterClass)) {
                    superClass.setLibraryClass();
                    SootUtilities.foldClass(newClass);
                    superClass = newClass.getSuperclass();
                }

                // Remove problematic methods for PortParameter
                if (newClass.declaresMethodByName("setContainer")) {
                    SootMethod method = newClass
                            .getMethodByName("setContainer");
                    newClass.removeMethod(method);
                }

                if (newClass.declaresMethodByName("setName")) {
                    SootMethod method = newClass.getMethodByName("setName");
                    newClass.removeMethod(method);
                }

                if (newClass.declaresMethodByName("attributeChanged")) {
                    SootMethod method = newClass
                            .getMethodByName("attributeChanged");
                    newClass.removeMethod(method);
                }

                if (newClass.declaresFieldByName("_port")) {
                    SootField field = newClass.getFieldByName("_port");
                    Port port = ((PortParameter) attribute).getPort();
                    field.addTag(new ValueTag(port));
                }

                // Add a container field to the generated class.
                // FIXME: this doesn't work for UnitSystems, e.g.,
                // since their container isn't associated with a class.
                FieldsForEntitiesTransformer._createContainerField(newClass);

                HashMap oldSignatureToFieldMap = new HashMap();

                // Loop over all the methods and replace the old class
                // wherever it appears with the copied class.
                for (Iterator classes = Scene.v().getApplicationClasses()
                        .iterator(); classes.hasNext();) {
                    SootClass theClass = (SootClass) classes.next();

                    if (theClass != newClass) {
                        _replaceObjectTypesInClassMethods(theClass, attribute,
                                attributeClass, newClass);
                    }
                }
                for (Iterator classes = Scene.v().getApplicationClasses()
                        .iterator(); classes.hasNext();) {
                    SootClass theClass = (SootClass) classes.next();

                    if (theClass != newClass) {
                        _replaceObjectTypesInClassFields(theClass, attribute,
                                attributeClass, newClass,
                                oldSignatureToFieldMap);
                    }
                }
                for (Iterator classes = Scene.v().getApplicationClasses()
                        .iterator(); classes.hasNext();) {
                    SootClass theClass = (SootClass) classes.next();

                    if (theClass != newClass) {
                        _fixFieldTypesInClassMethods(theClass, attribute,
                                attributeClass, newClass,
                                oldSignatureToFieldMap);
                    }
                }
            }
        }

        // Loop over all the attributes of the actor
        for (Iterator attributes = object.attributeList(Attribute.class)
                .iterator(); attributes.hasNext();) {
            Attribute attribute = (Attribute) attributes.next();

            copyAttributesOtherThanVariable(attribute);
        }
    }
View Full Code Here

     *   an attribute with the name of this attribute that is of class
     *   SingletonConfigurableAttribute.
     */
    public void setContainer(NamedObj container) throws IllegalActionException,
            NameDuplicationException {
        Attribute previous = null;

        if (container != null) {
            previous = container.getAttribute(getName());

            if (previous != null) {
                previous.setContainer(null);
            }
        }

        try {
            super.setContainer(container);
        } catch (IllegalActionException ex) {
            // Restore previous.
            if (previous != null) {
                previous.setContainer(container);
            }

            throw ex;
        } catch (NameDuplicationException ex) {
            // Restore previous.
            if (previous != null) {
                previous.setContainer(container);
            }

            throw ex;
        }
    }
View Full Code Here

                if (_model != null) {
                    Iterator attributes = _model.attributeList(Attribute.class)
                            .iterator();

                    while (attributes.hasNext()) {
                        Attribute attribute = (Attribute) attributes.next();
                        attribute.updateContent();
                    }
                }

                // Ensure that if we do ever try to call this method,
                // that it is the top effigy that is written.
View Full Code Here

        // give the object access to attributes and ports of this actor
        Iterator attributes = attributeList().iterator();

        while (attributes.hasNext()) {
            Attribute attribute = (Attribute) attributes.next();
            String mangledName = _mangleName(attribute.getName());

            if (_debugging) {
                _debug("set up reference to attribute \"" + attribute.getName()
                        + "\" as \"" + mangledName + "\"");
            }

            object.__setattr__(new PyString(mangledName), new PyJavaInstance(
                    attribute));
View Full Code Here

        IOPort port = (IOPort) fsm.getPort(name);

        if (port == null) {
            // No port found.  Try for a variable.
            Attribute variable = fsm.getAttribute(name);

            if (variable == null) {
                // Try for a refinement variable.
                int period = name.indexOf(".");

                if (period > 0) {
                    String refinementName = name.substring(0, period);
                    String entryName = name.substring(period + 1);

                    // FIXME: Look in the container of the fsm???
                    // Below we look for an attribute only in the fsm
                    // itself.
                    Nameable fsmContainer = fsm.getContainer();

                    if (fsmContainer instanceof CompositeEntity) {
                        Entity refinement = ((CompositeEntity) fsmContainer)
                                .getEntity(refinementName);

                        if (refinement != null) {
                            Attribute entry = refinement
                                    .getAttribute(entryName);

                            if (entry instanceof Variable) {
                                return entry;
                            }
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.