Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.IllegalActionException


            throws IllegalActionException {
        // NOTE: Do not react to changes in _windowProperties.
        // Those properties are only used when originally opening a window.
        if (attribute == startingDataset) {
            if (((IntToken) startingDataset.getToken()).intValue() < 0) {
                throw new IllegalActionException(this,
                        "startingDataset: negative value is not allowed.");
            }
        } else {
            super.attributeChanged(attribute);
        }
View Full Code Here


        if ((_frame == null) && (_container == null)) {
            // Need an effigy and a tableau so that menu ops work properly.
            Effigy containerEffigy = Configuration.findEffigy(toplevel());

            if (containerEffigy == null) {
                throw new IllegalActionException(this,
                        "Cannot find effigy for top level: "
                                + toplevel().getFullName());
            }

            try {
                PlotEffigy plotEffigy = new PlotEffigy(containerEffigy,
                        containerEffigy.uniqueName("plot"));

                // The default identifier is "Unnamed", which is no good for
                // two reasons: Wrong title bar label, and it causes a save-as
                // to destroy the original window.
                plotEffigy.identifier.setExpression(getFullName());

                PlotWindowTableau tableau = new PlotWindowTableau(plotEffigy,
                        "tableau");
                _frame = tableau.frame;
            } catch (Exception ex) {
                throw new IllegalActionException(this, null, ex,
                        "Error creating effigy and tableau");
            }

            _windowProperties.setProperties(_frame);
            _implementDeferredConfigurations();
View Full Code Here

            if (file.exists()) {
                if (((BooleanToken) confirmOverwrite.getToken()).booleanValue()) {
                    if (!MessageHandler.yesNoQuestion("OK to overwrite " + file
                            + "?")) {
                        throw new IllegalActionException(this,
                                "Please select another file name.");
                    }
                }
            }

            FileOutputStream stream = null;

            try {
                try {
                    stream = new FileOutputStream(fileRoot);
                } catch (FileNotFoundException ex) {
                    throw new IllegalActionException(this, ex,
                            "Could not create stream '" + fileRoot + "'");
                }

                ImageEncoder encoder = ImageCodec.createImageEncoder(
                        _imageEncoderName, stream, _imageEncodeParam);

                if (encoder == null) {
                    throw new IllegalActionException(this,
                            "Could not create encoder for \""
                                    + _imageEncoderName + "\", to \""
                                    + fileRoot
                                    + "\". Perhaps the encoder name is wrong?"
                                    + "encoder was: " + _imageEncodeParam);
                }

                try {
                    encoder.encode(_image);
                } catch (IOException ex) {
                    throw new IllegalActionException(this, ex,
                            "Couldn't encode image");
                }
            } finally {
                if (stream != null) {
                    try {
View Full Code Here

            throws IllegalActionException {
        if (attribute == length) {
            int lengthValue = ((IntToken) length.getToken()).intValue();

            if (lengthValue < 0) {
                throw new IllegalActionException(this,
                        "length: value is required to be positive.");
            }

            if (lengthValue != _previousLengthValue) {
                _previousLengthValue = lengthValue;
View Full Code Here

            } else if (natureName.equals("complexToReal")) {
                _dataNature = _COMPLEX_TO_REAL;
            } else if (natureName.equals("realToComplex")) {
                _dataNature = _REAL_TO_COMPLEX;
            } else {
                throw new IllegalActionException(this,
                        "Unrecognized dataNature type: " + natureName);
            }
        } else if (attribute == scalingType) {
            String typeName = scalingType.getExpression();

            if (typeName.equals("dimensions")) {
                _scalingType = _DIMENSIONS;
            } else if (typeName.equals("unitary")) {
                _scalingType = _UNITARY;
            } else if (typeName.equals("none")) {
                _scalingType = _NONE;
            } else {
                throw new IllegalActionException(this,
                        "Unrecognized scaling type: " + typeName);
            }
        } else {
            super.attributeChanged(attribute);
        }
View Full Code Here

        case _UNITARY:
            dftParameters.add(DFTDescriptor.SCALING_UNITARY);
            break;

        default:
            throw new IllegalActionException("Invalid value for scaling type");
        }

        switch (_dataNature) {
        case _COMPLEX_TO_COMPLEX:
            dftParameters.add(DFTDescriptor.COMPLEX_TO_COMPLEX);
            break;

        case _COMPLEX_TO_REAL:
            dftParameters.add(DFTDescriptor.COMPLEX_TO_REAL);
            break;

        case _REAL_TO_COMPLEX:
            dftParameters.add(DFTDescriptor.REAL_TO_COMPLEX);
            break;

        default:
            throw new IllegalActionException("Invalid data natures");
        }

        RenderedOp newImage = JAI.create("dft", dftParameters);
        output.send(0, new JAIImageToken(newImage));
    }
View Full Code Here

            throws IllegalActionException {
        if (attribute == maxWindowSize) {
            _maxWindowSize = ((IntToken) maxWindowSize.getToken()).intValue();

            if ((_maxWindowSize % 2) == 0) {
                throw new IllegalActionException(this,
                        "Window Size must be odd!!");
            }
        } else {
            super.attributeChanged(attribute);
        }
View Full Code Here

                // a directory.
                if (url.getProtocol().equals("file")) {
                    File asFile = modelFileOrURL.asFile();

                    if (!asFile.isFile()) {
                        throw new IllegalActionException(this, "Not a file: "
                                + url);
                    }
                }

                // By specifying no workspace argument to the parser, we
                // are asking it to create a new workspace for the referenced
                // model.  This is necessary because the execution of that
                // model will proceed through its own sequences, and it
                // will need to get write permission on the workspace.
                // Particularly if it is executing in a new thread, then
                // during the fire() method of this actor it would be
                // inappropriate to grant write access on the workspace
                // of this actor.
                MoMLParser parser = new MoMLParser();

                try {
                    _model = parser.parse(null, url);
                } catch (Exception ex) {
                    throw new IllegalActionException(this, ex,
                            "Failed to read model from: " + url);
                }

                // Create a manager, if appropriate.
                if (_model instanceof CompositeActor) {
                    _manager = new Manager(_model.workspace(), "Manager");
                    ((CompositeActor) _model).setManager(_manager);

                    if (_debugging) {
                        _debug("** Created new manager.");
                    }
                }
            } else {
                // URL is null... delete the current model.
                _model = null;
                _manager = null;
                _throwable = null;
            }
        } else if (attribute == executionOnFiring) {
            String executionOnFiringValue = executionOnFiring.stringValue();

            if (executionOnFiringValue.equals("run in calling thread")) {
                _executionOnFiringValue = _RUN_IN_CALLING_THREAD;
            } else if (executionOnFiringValue.equals("run in a new thread")) {
                _executionOnFiringValue = _RUN_IN_A_NEW_THREAD;
            } else if (executionOnFiringValue.equals("do nothing")) {
                _executionOnFiringValue = _DO_NOTHING;
            } else {
                throw new IllegalActionException(this,
                        "Unrecognized option for executionOnFiring: "
                                + executionOnFiringValue);
            }
        } else if (attribute == postfireAction) {
            String postfireActionValue = postfireAction.stringValue();

            if (postfireActionValue.equals("do nothing")) {
                _postfireActionValue = _DO_NOTHING;
            } else if (postfireActionValue.equals("stop executing")) {
                _postfireActionValue = _STOP_EXECUTING;
            } else {
                throw new IllegalActionException(this,
                        "Unrecognized value for postfireAction: "
                                + postfireActionValue);
            }
        } else {
            super.attributeChanged(attribute);
View Full Code Here

        super.fire();

        if (_throwable != null) {
            Throwable throwable = _throwable;
            _throwable = null;
            throw new IllegalActionException(this, throwable,
                    "Run in a new thread threw an exception "
                            + "on the previous firing.");
        }

        // Read the inputs. This should be done even if there is
        // no model.
        // Derived classes may need to read inputs earlier in their
        // fire() method, before calling this class, in which case
        // they are expected to set this flag to true.
        if (!_alreadyReadInputs) {
            // Iterate over input ports and read any available values
            // into the referenced model parameters and validate
            // settable attributes.
            _readInputsAndValidateSettables();
        }

        // Set the flag to false for the next firing.
        _alreadyReadInputs = false;

        if (_model instanceof CompositeActor) {
            CompositeActor executable = (CompositeActor) _model;

            _manager = executable.getManager();

            if (_manager == null) {
                throw new InternalErrorException("No manager!");
            }

            if (_debugging) {
                _manager.addDebugListener(this);

                Director director = executable.getDirector();

                if (director != null) {
                    director.addDebugListener(this);
                }
            } else {
                _manager.removeDebugListener(this);

                Director director = executable.getDirector();

                if (director != null) {
                    director.removeDebugListener(this);
                }
            }

            // If there is a previous execution, then wait for it to finish.
            // Avoid the synchronize block if possible.
            if (_executing) {
                synchronized (this) {
                    while (_executing) {
                        try {
                            if (_debugging) {
                                _debug("** Waiting for previous execution to finish.");
                            }

                            // Use workspace version of wait to release
                            // read permission on the workspace.
                            workspace().wait(this);
                        } catch (InterruptedException ex) {
                            // Cancel subsequent execution.
                            getManager().finish();
                            return;
                        }
                    }

                    if (_debugging) {
                        _debug("** Previous execution has finished.");
                    }
                }
            }

            if (_executionOnFiringValue == _RUN_IN_CALLING_THREAD) {
                if (_debugging) {
                    _debug("** Executing referenced model in the calling thread.");
                }

                try {
                    _manager.execute();
                } catch (KernelException ex) {
                    throw new IllegalActionException(this, ex,
                            "Execution failed.");
                }

                _writeOutputs();
            } else if (_executionOnFiringValue == _RUN_IN_A_NEW_THREAD) {
                // Listen for exceptions. The listener is
                // removed in the listener methods, executionError()
                // and executionFinished().
                if (_debugging) {
                    _debug("** Creating a new thread to execute the model.");
                }

                _manager.addExecutionListener(this);

                // Create a thread.  Can't directly use _manager.startRun()
                // because we need to write outputs upon completion.
                if (_manager.getState() != Manager.IDLE) {
                    throw new IllegalActionException(this,
                            "Cannot start an execution. "
                                    + "Referenced model is "
                                    + _manager.getState().getDescription());
                }

View Full Code Here

        _alreadyReadInputs = false;

        if (_throwable != null) {
            Throwable throwable = _throwable;
            _throwable = null;
            throw new IllegalActionException(this, throwable,
                    "Background run threw an exception");
        }
    }
View Full Code Here

TOP

Related Classes of ptolemy.kernel.util.IllegalActionException

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.