Package ptolemy.kernel

Examples of ptolemy.kernel.ComponentEntity


        String channelName = insideChannel.stringValue();
        Nameable container = getContainer();

        if (container instanceof CompositeEntity) {
            ComponentEntity entity = ((CompositeEntity) container)
                    .getEntity(channelName);

            if (entity instanceof WirelessChannel) {
                _insideChannel = (WirelessChannel) entity;
            }
View Full Code Here


        if (container != null) {
            Nameable containersContainer = container.getContainer();

            if (containersContainer instanceof CompositeEntity) {
                ComponentEntity channel = ((CompositeEntity) containersContainer)
                        .getEntity(channelName);

                if (channel instanceof WirelessChannel) {
                    _outsideChannel = (WirelessChannel) channel;
                }
View Full Code Here

        e4 = new CompositeEntity(e3, "E4");
        e7 = new CompositeEntity(e0, "E7");
        e10 = new CompositeEntity(e0, "E10");

        // Create component entities
        e1 = new ComponentEntity(e4, "E1");
        e2 = new ComponentEntity(e4, "E2");
        e5 = new ComponentEntity(e3, "E5");
        e6 = new ComponentEntity(e3, "E6");
        e8 = new ComponentEntity(e7, "E8");
        e9 = new ComponentEntity(e10, "E9");

        // Create ports
        p0 = (ComponentPort) e4.newPort("P0");
        p1 = (ComponentPort) e1.newPort("P1");
        p2 = (ComponentPort) e2.newPort("P2");
View Full Code Here

        // Initialize remainingActors to contain all the actors we were given.
        remainingActors.addAll(actorList);

        // Initialize entityToFiringsPerIteration for each actor to -1.
        for (Iterator actors = remainingActors.iterator(); actors.hasNext();) {
            ComponentEntity entity = (ComponentEntity) actors.next();
            entityToFiringsPerIteration.put(entity, _minusOne);
        }

        StaticSchedulingDirector director = (StaticSchedulingDirector) getContainer();

        boolean allowDisconnectedGraphs = false;

        if (director instanceof SDFDirector) {
            allowDisconnectedGraphs = ((SDFDirector) director)._allowDisconnectedGraphs;
        }

        // Ned Stoffel's change to support disconnected graphs:
        // Finally, the schedule can jump from one island to
        // another among the disconnected graphs. There is nothing
        // to force the scheduler to finish executing all actors
        // on one island before firing actors on another
        // island. However, the order of execution within an
        // island should be correct.
        while (!remainingActors.isEmpty()) {
            clusteredActors.clear();
            clusteredExternalPorts.clear();

            ComponentEntity actor = _pickZeroRatePortActor(remainingActors);

            if (actor == null) {
                actor = (ComponentEntity) remainingActors.removeFirst();
            } else {
                remainingActors.remove(actor);
View Full Code Here

     if no actor has a zero rate port.
     */
    private ComponentEntity _pickZeroRatePortActor(List actorList)
            throws IllegalActionException {
        for (Iterator actors = actorList.iterator(); actors.hasNext();) {
            ComponentEntity actor = (ComponentEntity) actors.next();

            // Check if this actor has any ports with rate of zero.
            for (Iterator ports = actor.portList().iterator(); ports.hasNext();) {
                IOPort port = (IOPort) ports.next();

                if (DFUtilities.getRate(port) == 0) {
                    return actor;
                }
View Full Code Here

    private void _propagatePort(CompositeActor container, IOPort currentPort,
            Map entityToFiringsPerIteration, Map externalRates,
            LinkedList remainingActors, LinkedList pendingActors,
            Set clusteredActors, Set clusteredExternalPorts)
            throws NotSchedulableException, IllegalActionException {
        ComponentEntity currentActor = (ComponentEntity) currentPort
                .getContainer();

        // First check to make sure that this port is not connected to
        // any other output ports on the outside.
        // This results in a non-deterministic merge and is illegal.
        // Do not do this test for output ports where we are propagating
        // inwards instead of outwards.
        if (currentPort.isOutput() && (currentPort.getContainer() != container)) {
            Iterator connectedPorts = currentPort.deepConnectedPortList()
                    .iterator();

            // Make sure any connected output ports are connected on
            // the inside.
            while (connectedPorts.hasNext()) {
                IOPort connectedPort = (IOPort) connectedPorts.next();

                // connectedPort might be connected on the inside to the
                // currentPort, which is legal.  The container argument
                // is always the container of the director, so any port
                // that has that container must be connected on the inside.
                if (connectedPort.isOutput()
                        && (connectedPort.getContainer() != container)) {
                    throw new NotSchedulableException(currentPort,
                            connectedPort,
                            "Output ports drive the same relation. "
                                    + "This is not legal in SDF.");
                } else if (connectedPort.isInput()
                        && (connectedPort.getContainer() == container)) {
                    throw new NotSchedulableException(currentPort,
                            connectedPort,
                            "Output port drives the same relation "
                                    + "as the external input port. "
                                    + "This is not legal in SDF.");
                }
            }
        }

        // Next check to make sure that if this port is an external
        // input port, then it does not drive the same relation as some
        // other output port or some other external input port.
        // This results in a non-deterministic merge and is illegal.
        if (currentPort.isInput() && (currentPort.getContainer() == container)) {
            Iterator connectedPorts = currentPort.deepInsidePortList()
                    .iterator();

            // Make sure any connected output ports are connected on
            // the inside.
            while (connectedPorts.hasNext()) {
                IOPort connectedPort = (IOPort) connectedPorts.next();

                // connectPort might be connected on the inside to the
                // currentPort, which is legal.  The container argument
                // is always the container of the director, so any port
                // that has that container must be connected on the inside.
                if (connectedPort.isOutput()
                        && (connectedPort.getContainer() != container)) {
                    throw new NotSchedulableException(currentPort,
                            connectedPort,
                            "External input port drive the same relation "
                                    + "as an output port. "
                                    + "This is not legal in SDF.");
                } else if (connectedPort.isInput()
                        && (connectedPort.getContainer() == container)) {
                    throw new NotSchedulableException(currentPort,
                            connectedPort,
                            "External input port drives the same relation "
                                    + "as another external input port. "
                                    + "This is not legal in SDF.");
                }
            }
        }

        Director director = (Director) getContainer();
        CompositeActor model = (CompositeActor) director.getContainer();

        // Get the rate of this port.
        int currentRate;

        if (currentActor == model) {
            currentRate = 1;
        } else {
            currentRate = DFUtilities.getRate(currentPort);
        }

        // Port rates of less than zero are not valid.
        if (currentRate < 0) {
            throw new NotSchedulableException(currentPort,
                    "Rate cannot be less than zero.  It was: " + currentRate);
        }

        // Propagate to anything that this port is connected to.  For
        // external ports, this is anything that is connected on the
        // inside.  For ports of actors that are being scheduled, this is
        // anything that is connected on the outside.
        Iterator connectedPorts;

        if (currentPort.getContainer() == container) {
            // Find all the ports that are deeply connected to
            // current port on the inside.

            if (_debugging && VERBOSE) {
                // Move this inside and avoid FindBugs Dead Local Store
                connectedPorts = currentPort.deepInsidePortList().iterator();
                _debug("deepInsidePortList of " + currentPort);

                while (connectedPorts.hasNext()) {
                    _debug(connectedPorts.next().toString());
                }
            }

            connectedPorts = currentPort.deepInsidePortList().iterator();
        } else {
            connectedPorts = currentPort.deepConnectedPortList().iterator();
        }

        // For every port we are connected to.
        while (connectedPorts.hasNext()) {
            IOPort connectedPort = (IOPort) connectedPorts.next();

            ComponentEntity connectedActor = (ComponentEntity) connectedPort
                    .getContainer();

            if (_debugging && VERBOSE) {
                _debug("Propagating " + currentPort + " to "
                        + connectedActor.getName());
            }

            int connectedRate;

            if (connectedActor == model) {
View Full Code Here

                    continue;
                }

                SDFReceiver receiver = (SDFReceiver) receivers[channel][copy];
                IOPort connectedPort = receivers[channel][copy].getContainer();
                ComponentEntity connectedActor = (ComponentEntity) connectedPort
                        .getContainer();

                receiver._waitingTokens = count;

                // Update the buffer size, if necessary.
View Full Code Here

                    continue;
                }

                SDFReceiver receiver = (SDFReceiver) receivers[channel][copy];
                IOPort connectedPort = receivers[channel][copy].getContainer();
                ComponentEntity connectedActor = (ComponentEntity) connectedPort
                        .getContainer();

                // Increment the number of waiting tokens.
                receiver._waitingTokens += createdTokens;
View Full Code Here

                    _imports.remove(source);
                }
            }

            if (possibleCandidate instanceof ComponentEntity) {
                ComponentEntity candidate = (ComponentEntity) possibleCandidate;

                // Check that the candidate is a class.
                if (candidate.isClassDefinition()) {
                    // Check that the class name matches.
                    // Only the last part, after any periods has to match.
                    String realClassName = name;
                    int lastPeriod = name.lastIndexOf(".");

                    if ((lastPeriod >= 0) && (name.length() > (lastPeriod + 1))) {
                        realClassName = name.substring(lastPeriod + 1);
                    }

                    String candidateClassName = candidate.getClassName();
                    lastPeriod = candidateClassName.lastIndexOf(".");

                    if ((lastPeriod >= 0)
                            && (candidateClassName.length() > (lastPeriod + 1))) {
                        candidateClassName = candidateClassName
                                .substring(lastPeriod + 1);
                    }

                    if (candidateClassName.equals(realClassName)) {
                        return candidate;
                    }
                }
            }
        }

        // Source has not been previously loaded.
        // Only if the source is null can we have a matching previous instance.
        if (source == null) {
            ComponentEntity candidate = _searchForEntity(name, _current);

            if (candidate != null) {
                // Check that it's a class.
                if (candidate.isClassDefinition()) {
                    return candidate;
                }
            }
        }
View Full Code Here

     */
    private ComponentEntity _attemptToFindMoMLClass(String className,
            String source) throws Exception {
        String classAsFile = null;
        String altClassAsFile = null;
        ComponentEntity reference = null;

        if (source == null) {
            // No source defined.  Use the classpath.
            // First, replace all periods in the class name
            // with slashes, and then append a ".xml".
            // NOTE: This should perhaps be handled by the
            // class loader, but it seems rather complicated to
            // do that.
            // Search for the .xml file before searching for the .moml
            // file.  .moml files are obsolete, and we should probably
            // not bother searching for them at all.
            classAsFile = className.replace('.', '/') + ".xml";

            // RIM uses .moml files, so leave them in.
            altClassAsFile = className.replace('.', '/') + ".moml";
        } else {
            // Source is given.
            classAsFile = source;
        }
        // First check to see whether the object has been previously loaded.
        URL url = null;
        try {
            url = fileNameToURL(classAsFile, _base);
            if (_imports != null) {
                WeakReference possiblePrevious = (WeakReference) _imports
                        .get(url);
                NamedObj previous = null;
                if (possiblePrevious != null) {
                    previous = (NamedObj) possiblePrevious.get();
                    if (previous == null) {
                        _imports.remove(url);
                    }
                }
                if (previous instanceof ComponentEntity) {
                    // NOTE: In theory, we should not even have to
                    // check whether the file has been updated, because
                    // if changes were made to model since it was loaded,
                    // they should have been propagated.
                    return (ComponentEntity) previous;
                }
            }
        } catch (Exception ex) {
            // An exception will be thrown if the class is not
            // found under the specified file name. Below we
            // will try again under the alternate file name.
        }

        // Read external model definition in a new parser,
        // rather than in the current context.
        MoMLParser newParser = new MoMLParser(_workspace, _classLoader);

        NamedObj candidateReference = null;

        try {
            candidateReference = _findOrParse(newParser, _base, classAsFile,
                    className, source);
        } catch (Exception ex2) {
            url = null;
            // Try the alternate file, if it's not null.
            if (altClassAsFile != null) {
                url = fileNameToURL(altClassAsFile, _base);
                // First check to see whether the object has been previously loaded.
                if (_imports != null) {
                    WeakReference possiblePrevious = (WeakReference) _imports
                            .get(url);
                    NamedObj previous = null;
                    if (possiblePrevious != null) {
                        previous = (NamedObj) possiblePrevious.get();
                        if (previous == null) {
                            _imports.remove(url);
                        }
                    }
                    if (previous instanceof ComponentEntity) {
                        // NOTE: In theory, we should not even have to
                        // check whether the file has been updated, because
                        // if changes were made to model since it was loaded,
                        // they should have been propagated.
                        return (ComponentEntity) previous;
                    }
                }
                try {
                    candidateReference = _findOrParse(newParser, _base,
                            altClassAsFile, className, source);
                    classAsFile = altClassAsFile;
                } catch (Exception ex3) {
                    // Cannot find a class definition.
                    // Unfortunately exception chaining does not work here
                    // since we really want to know what ex2 and ex3
                    // both were.
                    throw new XmlException("Could not find '" + classAsFile
                            + "' or '" + altClassAsFile + "' using base '"
                            + _base + "': ", _currentExternalEntity(),
                            _getLineNumber(), _getColumnNumber(), ex2);
                }
            } else {
                // No alternative. Rethrow exception.
                throw ex2;
            }
        }

        if (candidateReference instanceof ComponentEntity) {
            reference = (ComponentEntity) candidateReference;
        } else {
            throw new XmlException("File " + classAsFile
                    + " does not define a ComponentEntity.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        // Check that the classname matches the name of the
        // reference.
        String referenceName = reference.getName();

        if (!className.equals(referenceName)
                && !className.endsWith("." + referenceName)) {
            // The className might reference an inner class defined in
            // the reference.  Try to find that.
View Full Code Here

TOP

Related Classes of ptolemy.kernel.ComponentEntity

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.