Package ptolemy.kernel

Examples of ptolemy.kernel.ComponentEntity


                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        CompositeEntity container = (CompositeEntity) _current;
        ComponentEntity previous = _searchForEntity(entityName, _current);
        Class newClass = null;
        ComponentEntity reference = null;

        if (className != null) {
            // A class name is given.
            reference = searchForClass(className, source);

            // If no source is specified and no reference was found,
            // search for a class definition in context.
            if ((reference == null) && (source == null)) {
                // Allow the class name to be local in the current context
                // or defined in scope. Search for a class definition that
                // matches in the current context.
                reference = _searchForClassInContext(className, /* source*/
                null);
            }

            if (reference == null) {
                // No previously defined class with this name.
                // First attempt to instantiate a Java class.
                // If we throw an error or exception be sure to save the
                // original error message before we go off and try to fix the
                // error.  Sometimes, the original error message is the true
                // cause of the problem, and we should always provide the user
                // with the cause of the original error in the unlikely event
                // that our error correction fails
                try {
                    newClass = Class.forName(className, true, _classLoader);
                } catch (Exception ex) {
                    // NOTE: Java sometimes throws ClassNotFoundException
                    // and sometimes NullPointerException when the class
                    // does not exist.  Hence the broad catch here.
                    try {
                        reference = _attemptToFindMoMLClass(className, source);
                    } catch (Exception ex2) {
                        // If we are running inside an applet, then
                        // we may end up getting a SecurityException,
                        // so we want to be sure to not throw away ex2
                        throw new IllegalActionException(null, ex2,
                                "Cannot find class: " + className);
                    }
                } catch (Error error) {
                    // Java might throw a ClassFormatError, but
                    // we usually get and XmlException
                    // NOTE: The following error message is for
                    // the programmer, not for the user. EAL
                    StringBuffer errorMessage = new StringBuffer();

                    if (error instanceof ExceptionInInitializerError) {
                        // Running a Python applet may cause
                        // an ExceptionInInitializerError
                        // There was a problem in the initializer, but
                        // we can get the original exception that was
                        // thrown.
                        Throwable staticThrowable = ((ExceptionInInitializerError) error)
                                .getCause();

                        // I think we should report the cause and a stack
                        // trace for all the exceptions thrown here,
                        // but it sure makes the output ugly.
                        // Instead, I just debug from here -cxh
                        errorMessage.append("ExceptionInInitializerError: "
                                + "Caused by:\n "
                                + KernelException
                                        .stackTraceToString(staticThrowable));
                    } else {
                        // If there is a class format error in the
                        // code generator, then we may end up obscuring
                        // that error, requiring debugging here.
                        // We use error.toString() here instead of
                        // error.getMessage() so that the name of the
                        // actual class that caused the error is reported.
                        // This is critical if the problem is a class not
                        // found error.  If we use error.getMessage()
                        // and try to open up
                        // actor/lib/comm/demo/SerialPort/SerialPort.xml
                        // when the Java Serial Comm API is not installed,
                        // we get
                        // Error encounted in:
                        // <entity name="SerialComm" class="ptolemy.actor.lib...
                        // -- ptolemy.actor.lib.comm.SerialComm:
                        // javax/comm/SerialPortEventListener
                        // ptolemy.actor.lib.comm.SerialComm: XmlException:
                        // Could not find 'ptolemy/actor/lib/comm/SerialComm.xml'..
                        // If we use toString(), we get:
                        // Error encounted in:
                        // <entity name="SerialComm" class="ptolemy.actor.lib..
                        // -- ptolemy.actor.lib.comm.SerialComm:
                        // java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener
                        // ptolemy.actor.lib.comm.SerialComm: XmlException:
                        // Could not find 'ptolemy/actor/lib/comm/SerialComm.xml'..
                        // It is critical that the error include the
                        // NoClassDefFoundError string -cxh
                        errorMessage.append(className + ": \n "
                                + error.toString() + "\n");
                    }

                    try {
                        reference = _attemptToFindMoMLClass(className, source);
                    } catch (XmlException ex2) {
                        throw new Exception("-- " + errorMessage.toString()
                                + className + ": XmlException:\n"
                                + ex2.getMessage());
                    } catch (ClassFormatError ex3) {
                        throw new Exception("-- :" + errorMessage.toString()
                                + className + ": ClassFormatError: "
                                + "found invalid Java class file.\n"
                                + ex3.getMessage());
                    } catch (Exception ex4) {
                        throw new Exception("-- " + errorMessage.toString()
                                + className + ": Exception:\n"
                                + ex4.getMessage());
                    }
                }
            }
        }

        if (previous != null) {
            if (newClass != null) {
                _checkClass(previous, newClass, "entity named \"" + entityName
                        + "\" exists and is not an instance of " + className);
            }

            return previous;
        }

        // No previous entity.  Class name is required.
        _checkForNull(className, "Cannot create entity without a class name.");

        // Next check to see whether the class extends a named entity.
        if (reference == null) {
            // Not a named entity. Instantiate a Java class.
            if (_current != null) {
                // Not a top-level entity.
                // First check that there will be no name collision
                // when this is propagated. Note that we need to
                // include all derived objects, irrespective of whether
                // they are locally changed.
                List derivedList = container.getDerivedList();
                Iterator derivedObjects = derivedList.iterator();

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

                    if (derived.getEntity(entityName) != null) {
                        throw new IllegalActionException(
                                container,
                                "Cannot create entity because a subclass or instance "
                                        + "contains an entity with the same name: "
                                        + derived.getEntity(entityName)
                                                .getFullName());
                    }
                }

                _checkClass(_current, CompositeEntity.class,
                        "Cannot create an entity inside an element that "
                                + "is not a CompositeEntity. It is: "
                                + _current);

                Object[] arguments = new Object[2];

                arguments[0] = _current;
                arguments[1] = entityName;

                NamedObj newEntity = _createInstance(newClass, arguments);

                newEntity.propagateExistence();

                _loadIconForClass(className, newEntity);

                _addParamsToParamsToParse(newEntity);

                return newEntity;
            } else {
                // Top-level entity.  Instantiate in the workspace.
                // Note that there cannot possibly be any propagation here.
                Object[] arguments = new Object[1];
                arguments[0] = _workspace;

                NamedObj result = _createInstance(newClass, arguments);
                result.setName(entityName);
                _loadIconForClass(className, result);
                return result;
            }
        } else {
            // Extending a previously defined entity.  Check to see that
            // it was defined to be a class definition.
            if (!reference.isClassDefinition()) {
                throw new MissingClassException(
                        "Attempt to extend an entity that "
                                + "is not a class: " + reference.getFullName(),
                        reference.getFullName(), _currentExternalEntity(),
                        _getLineNumber(), _getColumnNumber());
            }

            // First check that there will be no name collision
            // when this is propagated. Note that we need to
            // include all derived objects, irrespective of whether
            // they are locally changed.
            // If the container is null, then we can't possibly get
            // a name collision.
            List derivedList = null;

            if (container != null) {
                derivedList = container.getDerivedList();

                Iterator derivedObjects = derivedList.iterator();

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

                    if (derived.getEntity(entityName) != null) {
                        throw new IllegalActionException(
                                container,
                                "Cannot create entity because a subclass or instance "
                                        + "contains an entity with the same name: "
                                        + derived.getEntity(entityName)
                                                .getFullName());
                    }
                }
            }

            // Instantiate it.
            ComponentEntity newEntity = (ComponentEntity) reference
                    .instantiate(container, entityName);

            // If we are keeping track of objects created...
            if ((_topObjectsCreated != null) && (container == _originalContext)) {
                _topObjectsCreated.add(newEntity);
            }

            // The original reference object may have had a URIAttribute,
            // but the new one should not. The clone would have copied
            // it.  The URIAttribute refers to the file in which the
            // component is defined, but the new entity is defined
            // in whatever file its container is defined. Leaving the
            // URIAttribute in the clone results in "look inside"
            // opening the clone but making it look as if it is the
            // original.
            // FIXME: This violates the derivation invariant.
            URIAttribute modelURI = (URIAttribute) newEntity.getAttribute(
                    "_uri", URIAttribute.class);

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

            // Mark contents as needing evaluation.
            _markParametersToParse(newEntity);

            // Set the class name as specified in this method call.
            // This overrides what InstantiableNamedObj does.  The reason
            // we want to do that is that InstantiableNamedObj uses the
            // name of the object that we cloned as the classname.
            //  But this may not provide enough information to
            // instantiate the class.
            newEntity.setClassName(className);

            // Propagate.
            Iterator propagatedInstances = newEntity.propagateExistence()
                    .iterator();

            while (propagatedInstances.hasNext()) {
                ComponentEntity propagatedEntity = (ComponentEntity) propagatedInstances
                        .next();

                // Get rid of URI attribute that may have been cloned.
                // FIXME: Should that be done in the clone method
                // for URIAttribute?  Doesn't this violate the
                // derivation invariant?
                URIAttribute propagatedURI = (URIAttribute) propagatedEntity
                        .getAttribute("_uri", URIAttribute.class);

                if (propagatedURI != null) {
                    propagatedURI.setContainer(null);
                }
View Full Code Here


            while (inPortsOutside.hasNext()) {
                IOPort inputPortOutside = (IOPort) inPortsOutside.next();

                // Check if the current port is contained by the
                // container of the current refinement.
                ComponentEntity thisPortContainer = (ComponentEntity) inputPortOutside
                        .getContainer();

                if (thisPortContainer.getFullName().equals(
                        refineInPortContainer.getFullName())) {
                    // set the outside port rate equal to the port rate
                    // of the refinement.
                    int previousPortRate = DFUtilities
                            .getTokenConsumptionRate(inputPortOutside);
View Full Code Here

            while (outPortsOutside.hasNext()) {
                IOPort outputPortOutside = (IOPort) outPortsOutside.next();

                // Check if the current port is contained by the
                // container of the current refinment.
                ComponentEntity thisPortContainer = (ComponentEntity) outputPortOutside
                        .getContainer();

                if (thisPortContainer.getFullName().equals(
                        refineOutPortContainer.getFullName())) {
                    // set the outside port rate equal to the port rate
                    // of the refinement.
                    int previousPortRate = DFUtilities
                            .getTokenProductionRate(outputPortOutside);
View Full Code Here

     @return The deleted object, or null if none was found.
     *  @exception Exception If there is no such entity or if the entity
     *   is defined in the class definition.
     */
    private NamedObj _deleteEntity(String entityName) throws Exception {
        ComponentEntity toDelete = _searchForEntity(entityName, _current);

        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 entity is part of the class definition.");
        }

        // NOTE: not enough to simply record the MoML of the deleted entity
        // as any links connected to its ports will also be deleted.
        // 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, so we first create the undo in the order given
        // by the derived list, then do the deletion 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 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()) {
                ComponentEntity derived = (ComponentEntity) derivedObjects
                        .next();

                // Generate Undo commands. Note that despite the
                // fact that the entity will get created by propagation
                // on undo, we still have to record it in the undo record
                // because it may have overridden parameter values (in
                // a derived class).
                // However, we have to be careful to not re-establish
                // links, as these will duplicate the original links
                // (and, in fact, will throw an exception saying
                // that establishing links between ports defined
                // in the base class is not allowed).
                // Have to get this _before_ deleting.
                String toUndo = _getUndoForDeleteEntity(derived);
                derived.setContainer(null);

                // Put at the _start_ of the undo MoML, to ensure
                // reverse order from the deletion.
                undoMoML.insert(0, toUndo);
            }
View Full Code Here

     @exception Exception If a source is specified and it cannot
     *   be opened.
     */
    private ComponentEntity _searchForClassInContext(String name, String source)
            throws Exception {
        ComponentEntity candidate = _searchForEntity(name, _current);

        // Search upwards in the hierarchy if necessary.
        NamedObj context = _current;

        // Make sure we get a real candidate, which is a
        // class definition. The second term in the if will
        // cause the search to continue up the hierarchy.
        // NOTE: There is still an oddness, in that
        // the class scoping results in a subtle (and
        // maybe incomprehensible) identification of
        // the base class, particularly when pasting
        // an instance or subclass into a new context.
        while (((candidate == null) || !candidate.isClassDefinition())
                && (context != null)) {
            context = context.getContainer();

            if (context instanceof CompositeEntity) {
                candidate = ((CompositeEntity) context).getEntity(name);
            }
        }

        if (candidate != null) {
            // Check that its source matches.
            String candidateSource = candidate.getSource();

            if ((source == null) && (candidateSource == null)) {
                return candidate;
            } else if ((source != null) && (candidateSource != null)) {
                // Have to convert to a URL to check whether the
View Full Code Here

                     }
                     */
                    return (ComponentEntity) _toplevel;
                } else {
                    if (name.length() > (nextPeriod + 1)) {
                        ComponentEntity result = ((CompositeEntity) _toplevel)
                                .getEntity(name.substring(nextPeriod + 1));

                        if (result != null) {
                            /* NOTE: This is too restrictive.
                             * With an absolute name, there is no
                             * reason to disallow setting the context.
                             * This is useful in particular when deleting
                             * ports to make sure undo works.  The undo
                             * code has to execute in a context that may
                             * be higher than that in which the port
                             * was deleted in order for the connections
                             * to be re-established.
                             */
                            /*
                             if (context != null
                             && !context.deepContains(result)) {
                             throw new XmlException(
                             "Reference to an existing entity: "
                             + result.getFullName()
                             + " in an inappropriate context: "
                             + context.getFullName(),
                             _currentExternalEntity(),
                             _getLineNumber(),
                             _getColumnNumber());
                             }
                             */
                            return result;
                        }
                    }
                }
            }

            return null;
        } else {
            // Name is relative.
            if (context instanceof CompositeEntity) {
                ComponentEntity result = ((CompositeEntity) context)
                        .getEntity(name);
                return result;
            }

            if (context == null) {
View Full Code Here

        _createInsideBufferReferences();

        // Loop over all the _model instance classes.
        for (Iterator entities = _model.deepEntityList().iterator(); entities
                .hasNext();) {
            ComponentEntity entity = (ComponentEntity) entities.next();
            String className = ModelTransformer.getInstanceClassName(entity,
                    _options);
            SootClass entityClass = Scene.v().loadClassAndSupport(className);

            _createBufferReferences(entity, entityClass);
View Full Code Here

            _createTokenAndExpressionFields(theClass, context, attribute,
                    attributeToValueFieldMap, constantAnalysis, debug);
        }

        if (container instanceof ComponentEntity) {
            ComponentEntity entity = (ComponentEntity) container;

            for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
                Port port = (Port) ports.next();
                _createTokenAndExpressionFields(theClass, context, port,
                        attributeToValueFieldMap, constantAnalysis, debug);
            }
        }

        if (container instanceof CompositeEntity
                && !(container instanceof FSMActor)) {
            CompositeEntity model = (CompositeEntity) container;

            // Loop over all the actor instance classes.
            for (Iterator entities = model.deepEntityList().iterator(); entities
                    .hasNext();) {
                ComponentEntity entity = (ComponentEntity) entities.next();
                String className = ModelTransformer.getInstanceClassName(
                        entity, _options);
                SootClass entityClass = Scene.v()
                        .loadClassAndSupport(className);
View Full Code Here

                _connectedBoundaryCacheIsOn = false;
                _isConnectedBoundaryValue = false;
                return _isConnectedBoundaryValue;
            }

            ComponentEntity contEntity = (ComponentEntity) contPort
                    .getContainer();
            IOPort connectedPort = null;
            ComponentEntity connectedEntity = null;

            Iterator ports = contPort.connectedPortList().iterator();

            while (ports.hasNext()) {
                connectedPort = (IOPort) ports.next();
                connectedEntity = (ComponentEntity) connectedPort
                        .getContainer();

                if ((connectedEntity == contEntity.getContainer())
                        && connectedPort.isInput() && connectedPort.isOpaque()) {
                    // The port container of this receiver is
                    // connected to the inside of a boundary port.
                    // Now determine if this receiver's channel is
                    // connected to the boundary port.
                    Receiver[][] receivers = connectedPort.deepGetReceivers();

                    for (int i = 0; i < receivers.length; i++) {
                        for (int j = 0; j < receivers[i].length; j++) {
                            if (_receiver == receivers[i][j]) {
                                _connectedBoundaryCacheIsOn = true;
                                _isConnectedBoundaryValue = true;
                                return true;
                            }
                        }
                    }
                } else if (connectedPort.isOpaque()
                        && !connectedEntity.isAtomic()
                        && connectedPort.isOutput()) {
                    // The port container of this receiver is
                    // connected to the outside of a boundary port.
                    // Now determine if this receiver's channel is
                    // connected to the boundary port.
View Full Code Here

                _connectedInsideOfBoundaryCacheIsOn = false;
                _isConnectedInsideOfBoundaryValue = false;
                return _isConnectedInsideOfBoundaryValue;
            }

            ComponentEntity contEntity = (ComponentEntity) contPort
                    .getContainer();
            IOPort connectedPort = null;
            ComponentEntity connectedEntity = null;

            Iterator ports = contPort.connectedPortList().iterator();

            while (ports.hasNext()) {
                connectedPort = (IOPort) ports.next();
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.