Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.IllegalActionException


            $ASSIGN$_offsets(new double[offsetsValue.length()]);
            double previous = 0.0;
            for (int i = 0; i < offsetsValue.length(); i++) {
                $ASSIGN$_offsets(i, ((DoubleToken)offsetsValue.getElement(i)).doubleValue());
                if (_offsets[i] < previous) {
                    throw new IllegalActionException(this, "Value of offsets is not nondecreasing " + "and nonnegative.");
                }
                previous = _offsets[i];
            }
        } else if (attribute == period) {
            double periodValue = ((DoubleToken)period.getToken()).doubleValue();
            if (periodValue <= 0.0) {
                throw new IllegalActionException(this, "Period is required to be positive.  " + "Period given: "+periodValue);
            }
        } else {
            super.attributeChanged(attribute);
        }
    }
View Full Code Here


        if (_phase >= _offsets.length) {
            $ASSIGN$_phase(0);
            $ASSIGN$_cycleStartTime(_cycleStartTime.add(periodValue));
        }
        if (_offsets[_phase] >= periodValue) {
            throw new IllegalActionException(this, "Offset number " + _phase+" with value "+_offsets[_phase]+" must be less than the "+"period, which is "+periodValue);
        }
        Time nextIterationTime = _cycleStartTime.add(_offsets[_phase]);
        getDirector().fireAt(this, nextIterationTime);
        return true;
    }
View Full Code Here

     * @exception IllegalActionException If there is no director.
     */
    public boolean prefire() throws IllegalActionException  {
        ArrayToken val = (ArrayToken)(values.getToken());
        if ((val == null) || (val.length() <= _phase)) {
            throw new IllegalActionException(this, "Offsets and values parameters lengths do not match.");
        }
        $ASSIGN$_currentValue(val.getElement(_phase));
        return true;
    }
View Full Code Here

            for (int i = 0; i < _dataSize; i++) {
                $ASSIGN$_data(i, Double.valueOf(tokenizer.nextToken()).doubleValue());
            }
            return super.prefire();
        } catch (IOException ex) {
            throw new IllegalActionException(this, ex, "prefire() failed");
        }
    }
View Full Code Here

            $ASSIGN$_denominator(denominatorValue.arrayValue());
            if (!_denominator[0].isEqualTo(_denominator[0].one()).booleanValue()) {
                try {
                    MessageHandler.warning("First denominator value is required to be 1. " + "Using 1.");
                } catch (CancelException ex) {
                    throw new IllegalActionException(this, "Canceled parameter change.");
                }
                $ASSIGN$_denominator(0, _denominator[0].one());
            }
        } else {
            super.attributeChanged(attribute);
View Full Code Here

                                        + "</port>");
                        request.setUndoable(true);
                        requestChange(request);

                    } catch (Exception ex) {
                        throw new IllegalActionException(this, ex,
                                "Unable to construct port "
                                        + "port for argument \""
                                        + argument.getName() + "\"");
                    }
                } else if (argument.isInput() && argument.isOutput()) {
                    try {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<group>\n"
                                        + " <port name=\""
                                        + argument.getName()
                                        + "in"
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"input\"/>\n"
                                        + " </port>\n"
                                        + " <port name=\""
                                        + argument.getName()
                                        + "out"
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"output\"/>\n"
                                        + " </port>\n" + "</group>");
                        request.setUndoable(true);
                        requestChange(request);
                    } catch (Exception ex) {
                        throw new IllegalActionException(this, ex,
                                "Unable to construct " + "input or output "
                                        + "port for argument \""
                                        + argument.getName() + "\"");
                    }
                } else {
                    try {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + (argument.isInput() ? "    <property name=\"input\"/>\n"
                                                : "")
                                        + (argument.isOutput() ? "    <property name=\"output\"/>\n"
                                                : "") + "</port>");
                        request.setUndoable(true);
                        requestChange(request);
                    } catch (Exception ex) {
                        throw new IllegalActionException(this, ex,
                                "Unable to construct " + "port for argument \""
                                        + argument.getName() + "\"");
                    }
                }
            } else {
View Full Code Here

                        + "property 'java.library.path' " + "which is:\n"
                        + libraryPath + "\nError message was: "
                        + error.getMessage(), error);
            }
        } catch (Exception ex) {
            throw new IllegalActionException(this, ex,
                    "Class cannot be instantiated");
        }

        try {
            ret = _methods[_methodIndex].invoke(obj, args.toArray());
        } catch (Throwable ex) {
            StringBuffer argumentsDescription = new StringBuffer("");

            try {
                if (args.size() >= 1) {
                    argumentsDescription.append(args.elementAt(0).toString());

                    for (int i = 1; i < args.size(); i++) {
                        argumentsDescription.append(", "
                                + args.elementAt(i).toString());
                    }
                }
            } catch (Throwable throwable) {
                // Ignore
            }

            throw new IllegalActionException(this, ex,
                    "Native operation call failed." + "Failed to invoke '"
                            + obj + "' with " + args.size() + " arg(s) "
                            + argumentsDescription.toString());
        }

        ports = portList().iterator();

        while (ports.hasNext()) {
            TypedIOPort port = (TypedIOPort) ports.next();

            //if the argument is return
            if (getArgumentReturn() == null) {
                System.err.println("Warning: GenericJNIActor.java: "
                        + "getArgumentReturn() returns null?");
            }

            if ((port != null)
                    && (port.getName() != null)
                    && (getArgumentReturn() != null)
                    && port.getName()
                            .equals(this.getArgumentReturn().getName())) {
                String typ = "";
                Field field = null;

                try {
                    field = _class.getDeclaredField("_" + port.getName());
                    typ = field.getType().toString();
                } catch (NoSuchFieldException e) {
                    try {
                        throw new IllegalActionException(this, e,
                                "No return type field '_" + port.getName()
                                        + "'");
                    } catch (Throwable throwable) {
                        getDirector().stop();
                    }
                }

                if (typ.equals("boolean")) {
                    port.send(0, new BooleanToken(((Boolean) ret)
                            .booleanValue()));
                } else if (typ.equals("double")) {
                    port.send(0, new DoubleToken(((Double) ret).doubleValue()));
                } else if (typ.equals("int")) {
                    port.send(0, new IntToken(((Integer) ret).intValue()));
                } else if (typ.equals("char")) {
                    port.send(0,
                            new UnsignedByteToken(((Byte) ret).byteValue()));
                } else {
                    System.out.println("The return type is not convertible "
                            + "with Ptolemy II types.");
                }
            }
            //if the argument is output
            else if ((port != null)
                    && port.isOutput()
                    && (port.getName() != null)
                    && (getArgumentReturn() != null)
                    && !(port.getName().equals(this.getArgumentReturn()
                            .getName()))) {
                String typ = "";
                Field field = null;

                try {
                    field = _class.getDeclaredField("_" + port.getName());
                    typ = field.getType().toString();
                } catch (NoSuchFieldException ex) {
                    try {
                        field = _class.getDeclaredField("_"
                                + port.getName().substring(0,
                                        port.getName().length() - 3));
                        typ = field.getType().toString();
                    } catch (Throwable throwable) {
                        try {
                            throw new IllegalActionException(this, throwable,
                                    "No '+" + port.getName() + "' field !");
                        } catch (Throwable throwable2) {
                            getDirector().stop();
                        }
                    }
                }

                if (field == null) {
                    throw new InternalErrorException("Field '" + port.getName()
                            + "' in '" + _class + "' is null?");
                } else {
                    if (typ.equals("boolean")) {
                        try {
                            port.send(0,
                                    new BooleanToken(field.getBoolean(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("double")) {
                        try {
                            port.send(0, new DoubleToken(field.getDouble(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("int")) {
                        try {
                            port.send(0, new IntToken(field.getInt(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("char")) {
                        try {
                            port.send(0, new UnsignedByteToken(field
                                    .getChar(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("class [I")) {
                        try {
                            if (field == null) {
                                throw new InternalErrorException(
                                        "field == null?");
                            }
                            if (obj == null) {
                                throw new InternalErrorException("obj == null?");
                            }
                            if (field.get(obj) == null) {
                                throw new InternalErrorException(
                                        "field.get(obj)  == null? (field = "
                                                + field + " obj = " + obj);
                            }
                            Token[] toks = new Token[((int[]) field.get(obj)).length];

                            for (int j = 0; j < ((int[]) field.get(obj)).length; j++) {
                                toks[j] = new IntToken(
                                        ((int[]) field.get(obj))[j]);
                            }

                            port.send(0, new ArrayToken(BaseType.INT, toks));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("class [D")) {
                        try {
                            Token[] toks = new Token[((double[]) field.get(obj)).length];

                            for (int j = 0; j < ((double[]) field.get(obj)).length; j++) {
                                toks[j] = new DoubleToken(((double[]) field
                                        .get(obj))[j]);
                            }

                            port.send(0, new ArrayToken(toks));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else {
                        // FIXME: for char[] and boolean[], there is
                        // no corresponding Token type.
View Full Code Here

        try {
            File userDirAsFile = new File(StringUtilities
                    .getProperty("user.dir"));
            tab[0] = userDirAsFile.toURI().toURL();
        } catch (Exception ex) {
            throw new IllegalActionException(this, ex, "Could not create URL "
                    + "from user.dir ("
                    + StringUtilities.getProperty("user.dir") + ")");
        }

        try {
            ClassLoader cl = new URLClassLoader(tab);
            _class = cl.loadClass(className);
        } catch (Throwable ex) {
            throw new IllegalActionException(this, ex,
                    "Could not load JNI C class '" + className
                            + "' relative to " + tab[0]);
        }

        if (_class == null) {
            throw new IllegalActionException(this, "Could load JNI C class, '"
                    + className + "' relative to " + tab[0]);
        }

        _methods = null;

        try {
            _methods = _class.getMethods();
        } catch (Exception ex) {
            throw new IllegalActionException(this, ex,
                    "Interface C _methods not found " + "class was: " + _class);
        }

        if (_methods == null) {
            throw new IllegalActionException(this,
                    "getMethods() returned null?, " + "class was: " + _class);
        }

        //getting the fire _method
        _methodIndex = -1;

        for (int i = 0; i < _methods.length; i++) {
            if (_methods[i].getName().equals("fire")) {
                _methodIndex = i;
                break;
            }
        }

        if (_methodIndex == -1) {
            StringBuffer methodNames = new StringBuffer();

            try {
                for (int i = 0; i < _methods.length; i++) {
                    if (i > 0) {
                        methodNames.append(", ");
                    }

                    methodNames.append(_methods[i].getName());
                }
            } catch (Exception ex) {
                methodNames.append("Failed to get method names: " + ex);
            }

            throw new IllegalActionException(this, "After looking at "
                    + _methods.length + " method(s),"
                    + "did not find fire method in '" + _class
                    + "', method names were: " + methodNames.toString());
        }
    }
View Full Code Here

                    }
                    request.setUndoable(true);
                    requestChange(request);
                } catch (Throwable throwable) {
                    throw new IllegalActionException(this, throwable,
                            "MoMLChangeRequest for \"" + argument.getName()
                                    + "\" failed. Request was:\n" + request);
                }
            } else {
                // We have a preexisting port, synchronized the
View Full Code Here

            $ASSIGN$_indexes(new int[indexesValue.length()]);
            int previous = 0;
            for (int i = 0; i < indexesValue.length(); i++) {
                $ASSIGN$_indexes(i, ((IntToken)indexesValue.getElement(i)).intValue());
                if (_indexes[i] < previous) {
                    throw new IllegalActionException(this, "Value of indexes is not nondecreasing " + "and nonnegative.");
                }
                previous = _indexes[i];
            }
        } else if (attribute == values) {
            try {
                ArrayToken valuesArray = (ArrayToken)values.getToken();
                Token prototype = valuesArray.getElement(0);
                $ASSIGN$_zero(prototype.zero());
            } catch (ArrayIndexOutOfBoundsException ex) {
                throw new IllegalActionException(this, "Cannot set values to an empty array.");
            } catch (ClassCastException ex) {
                throw new IllegalActionException(this, "Cannot set values to something that is not an array: " + values.getToken());
            }
        } else if (attribute == repeat) {
            $ASSIGN$_repeatFlag(((BooleanToken)repeat.getToken()).booleanValue());
        } else {
            super.attributeChanged(attribute);
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.