Package ptolemy.kernel

Examples of ptolemy.kernel.ComponentRelation


        // Creation des ports
        Iterator relations = model.relationList().iterator();

        StringBuffer relationsMoML = new StringBuffer();
        while (relations.hasNext()) {
            ComponentRelation relation = (ComponentRelation) relations.next();
            relationsMoML.append(relation.exportMoML());
            relation.unlinkAll();
        }

        actor.removeAllPorts();
        actor.createPorts();
        //actor.updatePorts();
View Full Code Here


                            // Do this only if they are not already connected.
                            List connectedPorts = insidePort
                                    .connectedPortList();

                            if (!connectedPorts.contains(newPort)) {
                                ComponentRelation relation = newRelation(uniqueName("relation"));
                                newPort.link(relation);
                                insidePort.link(relation);
                            }
                        }
                    } finally {
View Full Code Here

                            List connectedPorts = insidePort
                                    .connectedPortList();

                            if (!connectedPorts.contains(castPort)) {
                                // There is no connection. Create one.
                                ComponentRelation newRelation = newRelation(uniqueName("relation"));
                                insidePort.link(newRelation);
                                castPort.link(newRelation);
                            }
                        }
                    } finally {
View Full Code Here

        // This is because _addPort() will take care of that.
        // The cast is safe because all my ports are instances of IOPort.
        Iterator relations = ((IOPort) port).insideRelationList().iterator();

        while (relations.hasNext()) {
            ComponentRelation relation = (ComponentRelation) relations.next();

            try {
                relation.setContainer(null);
            } catch (KernelException ex) {
                throw new InternalErrorException(ex);
            }
        }
View Full Code Here

                        }
                    }
                }

                // Remove the relation as well.
                ComponentRelation relation = model.getRelation(getName()
                        + "Relation");

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

            super.setContainer(container);
        } finally {
View Full Code Here

                    // then the publisher will not have created
                    // its relation.
                    publisher._updateLinks();
                }
            }
            ComponentRelation relation = publisher._relation;
            if (!input.isLinked(relation)) {
                // The Publisher._updateLinks() may have already linked us.
                input.liberalLink(relation);
            }
            _relations.add(relation);
View Full Code Here

     @return The deleted object, or null if none is found.
     *  @exception Exception If there is no such relation or if the relation
     *   is defined in the class definition.
     */
    private Relation _deleteRelation(String relationName) throws Exception {
        ComponentRelation toDelete = _searchForRelation(relationName);

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

        if (toDelete.getDerivedLevel() < Integer.MAX_VALUE) {
            throw new IllegalActionException(toDelete,
                    "Cannot delete. This relation is part of the class definition.");
        }

        // Propagate and generate undo MoML.
        // NOTE: not enough to simply record the MoML of the deleted relation
        // as any links connected to it will also be deleted
        // and derived relations will have to have similar undo MoML
        // so that connections get remade.
        // 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.
        // Note that deletion and undo need to occur in the opposite
        // order.
        try {
            Iterator derivedObjects = toDelete.getDerivedList().iterator();

            // NOTE: Deletion needs to occur in the reverse order from
            // what appears in the derived objects list. So first we construct
            // a reverse order list.
            List reverse = new LinkedList();

            while (derivedObjects.hasNext()) {
                reverse.add(0, derivedObjects.next());
            }

            derivedObjects = reverse.iterator();

            while (derivedObjects.hasNext()) {
                ComponentRelation derived = (ComponentRelation) derivedObjects
                        .next();

                // Since the Relation can't be a
                // class itself (currently), it has derived objects
                // only if its container has derived objects.
                // Thus, we do not need to create undo MoML
                // for the derived objects. The undo MoML for
                // the principal relation will propagate when
                // executed.
                // FIXME: The above is not true, since a propagated
                // relation may contain parameter values that are
                // not in the original.  Need to carefully choose
                // the level at which the exportMoML is done.
                derived.setContainer(null);
            }

            // Have to get this _before_ deleting.
            String toUndo = _getUndoForDeleteRelation(toDelete);
            toDelete.setContainer(null);
View Full Code Here

        }

        CompositeEntity context = (CompositeEntity) _current;

        // Get relations.
        ComponentRelation relation1 = context.getRelation(relation1Name);
        _checkForNull(relation1, "No relation named \"" + relation1Name
                + "\" in " + context.getFullName());

        // Get relations.
        ComponentRelation relation2 = context.getRelation(relation2Name);
        _checkForNull(relation2, "No relation named \"" + relation2Name
                + "\" in " + context.getFullName());

        // Ensure that derived objects aren't changed.
        // We have to prohit adding links between class
        // elements because this operation cannot be undone, and
        // it will not be persistent.
        if (_isLinkInClass(context, relation1, relation2)) {
            throw new IllegalActionException(relation1, relation2,
                    "Cannot link relations when both"
                            + " are part of the class definition.");
        }

        relation1.link(relation2);

        // Propagate. Get the derived list for relation1,
        // then use its container as the context in which to
        // find relation2.
        Iterator derivedObjects = relation1.getDerivedList().iterator();

        while (derivedObjects.hasNext()) {
            ComponentRelation derivedRelation1 = (ComponentRelation) derivedObjects
                    .next();
            CompositeEntity derivedContext = (CompositeEntity) derivedRelation1
                    .getContainer();
            ComponentRelation derivedRelation2 = derivedContext
                    .getRelation(relation2Name);
            derivedRelation1.link(derivedRelation2);
        }

        // Handle the undo aspect.
View Full Code Here

        // Save to help generate undo MoML
        int origNumOutsideLinks = port.numLinks();
        int origNumInsideLinks = port.numInsideLinks();

        // Get relation if given
        ComponentRelation relation = null;

        if (relationName != null) {
            Relation tmpRelation = context.getRelation(relationName);
            _checkForNull(tmpRelation, "No relation named \"" + relationName
                    + "\" in " + context.getFullName());
            relation = (ComponentRelation) tmpRelation;
        }

        // Ensure that derived objects aren't changed.
        // We have to prohibit adding links between class
        // elements because this operation cannot be undone, and
        // it will not be persistent.
        if (_isLinkInClass(context, port, relation)) {
            throw new IllegalActionException(port,
                    "Cannot link a port to a relation when both"
                            + " are part of the class definition.");
        }

        // Get the index if given
        int insertAt = -1;

        if (insertAtSpec != null) {
            insertAt = Integer.parseInt(insertAtSpec);
        }

        // Get the inside index if given
        int insertInsideAt = -1;

        if (insertInsideAtSpec != null) {
            insertInsideAt = Integer.parseInt(insertInsideAtSpec);
        }

        if (insertAtSpec != null) {
            port.insertLink(insertAt, relation);
        } else if (insertInsideAtSpec != null) {
            port.insertInsideLink(insertInsideAt, relation);
        } else {
            port.link(relation);
        }

        // Propagate. Get the derived list for the relation,
        // then use its container as the context in which to
        // find the port. NOTE: The relation can be null
        // (to insert an empty link in a multiport), so
        // we have two cases to consider.
        if (relation != null) {
            Iterator derivedObjects = relation.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                ComponentRelation derivedRelation = (ComponentRelation) derivedObjects
                        .next();
                CompositeEntity derivedContext = (CompositeEntity) derivedRelation
                        .getContainer();
                ComponentPort derivedPort = _getPort(portName, derivedContext);

                // NOTE: Duplicate the above logic exactly.
                if (insertAtSpec != null) {
View Full Code Here

        }

        CompositeEntity context = (CompositeEntity) _current;

        // Get relations.
        ComponentRelation relation1 = context.getRelation(relation1Name);
        _checkForNull(relation1, "No relation named \"" + relation1Name
                + "\" in " + context.getFullName());

        // Get relations.
        ComponentRelation relation2 = context.getRelation(relation2Name);
        _checkForNull(relation2, "No relation named \"" + relation2Name
                + "\" in " + context.getFullName());

        // Ensure that derived objects aren't changed.
        // We have to prohit adding links between class
        // elements because this operation cannot be undone, and
        // it will not be persistent.
        if (_isLinkInClass(context, relation1, relation2)) {
            throw new IllegalActionException(relation1, relation2,
                    "Cannot unlink relations when both"
                            + " are part of the class definition.");
        }

        relation1.unlink(relation2);

        // Propagate. Get the derived list for relation1,
        // then use its container as the context in which to
        // find relation2.
        Iterator derivedObjects = relation1.getDerivedList().iterator();

        while (derivedObjects.hasNext()) {
            ComponentRelation derivedRelation1 = (ComponentRelation) derivedObjects
                    .next();
            CompositeEntity derivedContext = (CompositeEntity) derivedRelation1
                    .getContainer();
            ComponentRelation derivedRelation2 = derivedContext
                    .getRelation(relation2Name);
            derivedRelation1.unlink(derivedRelation2);
        }

        // Handle the undo aspect.
View Full Code Here

TOP

Related Classes of ptolemy.kernel.ComponentRelation

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.