Package ptolemy.moml

Examples of ptolemy.moml.MoMLParser


     *  the value of that parameter is used to set the iterations parameter.
     *  If there is no "copernicus_iterations" parameter, then then
     *  the number of iterations is set to 100000.
     */
    public TestApplication(String xmlFilename) throws Exception {
        MoMLParser parser = new MoMLParser();

        // The test suite calls MoMLSimpleApplication multiple times,
        // and the list of filters is static, so we reset it each time
        // so as to avoid adding filters every time we run an auto test.
        // We set the list of MoMLFilters to handle Backward Compatibility.
        MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());

        // Filter out any graphical classes.
        // We should filter out graphical classes or the
        // treeShakeWithoutCodegen rule will fail when we run it on
        // actor/lib/test/auto/ComplexDivide.
        MoMLParser.addMoMLFilter(new RemoveGraphicalClasses());

        //parser.setErrorHandler(new StreamErrorHandler());
        // We use parse(URL, URL) here instead of parseFile(String)
        // because parseFile() works best on relative pathnames and
        // has problems finding resources like files specified in
        // parameters if the xml file was specified as an absolute path.
        CompositeActor toplevel = null;

        // First, we gc and then print the memory stats
        // BTW to get more info about gc,
        // use java -verbose:gc -Xloggc:filename . . .
        System.gc();
        Thread.sleep(1000);

        Runtime runtime = Runtime.getRuntime();

        try {
            URL url = new URL(null, xmlFilename);
            toplevel = (CompositeActor) parser.parse(url, url.openStream());
        } catch (Exception ex) {
            File f = new File(xmlFilename);
            URL url = f.toURI().toURL();
            System.err.println("Warning: Parsing '" + xmlFilename
                    + "' failed: ");
            ex.printStackTrace();
            System.err.println(" Trying '" + url + "'");

            toplevel = (CompositeActor) parser.parse(null, url);
        }

        // FIXME: nearly duplicate code in kernel/KernelMain.java
        SDFDirector director = (SDFDirector) toplevel.getDirector();

View Full Code Here


     @param args The command line arguments
     *  @exception Exception If there was a problem parsing
     *  or running the model.
     */
    public MoMLSimpleStatisticalApplication(String[] args) throws Exception {
        _parser = new MoMLParser();

        MoMLParser.setErrorHandler(new StreamErrorHandler());

        // First, we gc and then print the memory stats
        // BTW to get more info about gc,
View Full Code Here

                    // The context in which to execute the request.
                    NamedObj context = _actor;

                    // The MoMLParser.
                    MoMLParser momlParser = null;

                    // Check to see whether there is a parser...
                    if (context != null) {
                        momlParser = ParserAttribute.getParser(context);
                        momlParser.reset();
                    }

                    if (momlParser == null) {
                        // There is no previously associated parser
                        // (can only happen if context is null).
                        momlParser = new MoMLParser();
                    }

                    if (context != null) {
                        momlParser.setContext(context);
                    }

                    // MoML description for actor declaration.
                    String description = "<entity name =\"" + uniqueName
                            + "\" class =\"" + actor + "\"/>";
                    momlParser.parse(null, description);

                    ComponentEntity entity = null;
                    if (_actor != null) {
                        entity = _actor.getEntity(uniqueName);
                    }
View Full Code Here

         @exception Exception If the parsing is not successful.
         */
        private NamedObj _parse(Reader reader, NamedObj container)
                throws Exception {
            if (_parser == null) {
                _parser = new MoMLParser();
            }

            _parser.setContext(container);
            NamedObj result = _parser.parse(null, reader);
            MoMLParser.setModified(true);
View Full Code Here

            }

            CodeGenerator codeGenerator = null;

            // See MoMLSimpleApplication for similar code
            MoMLParser parser = new MoMLParser();
            MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());
            MoMLParser.addMoMLFilter(new RemoveGraphicalClasses());

            // Reset the list each time we parse a parameter set.
            // Otherwise two calls to this method will share params!
            _parameterNames = new LinkedList<String>();
            _parameterValues = new LinkedList<String>();
            for (int i = 0; i < args.length; i++) {
                if (parseArg(args[i])) {
                    continue;
                }
                if (args[i].trim().startsWith("-")) {
                    if (i >= (args.length - 1)) {
                        throw new IllegalActionException("t set "
                                + "parameter " + args[i] + " when no value is "
                                + "given.");
                    }

                    // Save in case this is a parameter name and value.
                    _parameterNames.add(args[i].substring(1));
                    _parameterValues.add(args[i + 1]);
                    i++;
                    continue;
                }
                // Note: the code below uses explicit try catch blocks
                // so we can provide very clear error messages about what
                // failed to the end user.  The alternative is to wrap the
                // entire body in one try/catch block and say
                // "Code generation failed for foo", which is not clear.
                URL modelURL;

                try {
                    modelURL = new File(args[i]).toURI().toURL();
                } catch (Exception ex) {
                    throw new Exception("Could not open \"" + args[i] + "\"",
                            ex);
                }

                CompositeActor toplevel = null;

                try {
                    try {
                        // Reset the parser and reload so that if
                        // we run the model and then generate code,
                        // we get the same results when generating code.
                        // If we don't do this, then the nightly tests
                        // fail because the results don't match.
                        parser.reset();
                        MoMLParser.purgeModelRecord(modelURL);
                        toplevel = (CompositeActor) parser
                                .parse(null, modelURL);
                    } catch (Exception ex) {
                        throw new Exception("Failed to parse \"" + args[i]
                                + "\"", ex);
                    }
View Full Code Here

                // Only do this if the library hasn't been set above
                // by a LibraryBuilder
                // No previous libraryEffigy exists that is identified
                // by this URL.  Parse the user library into the
                // workspace of the actor library.
                MoMLParser parser = new MoMLParser(libraryContainer.workspace());

                // Set the ErrorHandler so that if we have
                // compatibility problems between devel and production
                // versions, we can skip that element.
                //MoMLParser.setErrorHandler(new VergilErrorHandler());
                parser.parse(fileURL, fileURL);

                library = (CompositeEntity) parser.getToplevel();
            }

            //library.setContainer(libraryContainer); //i don't know if this is needed
            // Now create the effigy with no tableau.
            final PtolemyEffigy finalLibraryEffigy = new PtolemyEffigy(
View Full Code Here

            throws IllegalActionException {
        StringWriter moml = new StringWriter();
        try {
            model.exportMoML(moml, 0);

            MoMLParser parser = new MoMLParser();
            RenameClassMoMLFilter filter = new RenameClassMoMLFilter();
            MoMLParser.addMoMLFilter(filter);
            NamedObj topLevel = parser.parse(null, moml.toString());
            MoMLParser.getMoMLFilters().remove(filter);

            Iterator entitiesToRename = filter.entitiesChanged();
            while (entitiesToRename.hasNext()) {
                NamedObj entity = (NamedObj) entitiesToRename.next();

                // Add a little visual effect to the transformed entity.
                String imageMoML = "<property name=\"_decorate\" "
                        + "class=\"ptolemy.data.expr.FileParameter\" "
                        + "value=\"$CLASSPATH/ptolemy/backtrack/manual/ptolemy/"
                        + "actor/lib/BacktrackIconSmall.gif\">\n"
                        + "</property>";
                parser.setContext(entity);
                try {
                    parser.parse(null, imageMoML);
                    MoMLParser.setModified(true);
                } catch (Exception ex) {
                    throw new IllegalActionException("Unable to parse\n"
                            + imageMoML);
                }
View Full Code Here

                // Create a blank effigy.
                PtolemyEffigy effigy = _newEffigy(container, container
                        .uniqueName("effigy"));

                MoMLParser parser = new MoMLParser();

                // Make sure that the MoMLParser._modified flag is reset
                // If we don't call reset here, then the second time
                // the code generator is run, we will be prompted to
                // save the model because the first time we ran
                // the code generator the model was marked as modified.
                parser.reset();

                NamedObj toplevel = null;

                try {
                    try {
                        long startTime = 0;
                        long endTime = 0;
                        // If the following fails, we should remove the effigy.
                        try {
                            //                          Report on the time it takes to open the model.
                            startTime = System.currentTimeMillis();
                            toplevel = parser.parse(base, input);
                            endTime = System.currentTimeMillis();
                        } catch (IOException io) {
                            // If we are running under Web Start, we
                            // might have a URL that refers to another
                            // jar file.
                            URL anotherURL = ClassUtilities
                                    .jarURLEntryResource(input.toString());

                            if (anotherURL != null) {
                                startTime = System.currentTimeMillis();
                                toplevel = parser.parse(base, anotherURL);
                                endTime = System.currentTimeMillis();
                            } else {
                                throw io;
                            }
                        }
View Full Code Here

     *  a relative pathname.
     *  @exception Throwable If there was a problem parsing
     *  or running the model.
     */
    public MoMLSimpleApplication(String xmlFileName) throws Throwable {
        MoMLParser parser = new MoMLParser();

        // The test suite calls MoMLSimpleApplication multiple times,
        // and the list of filters is static, so we reset it each time
        // so as to avoid adding filters every time we run an auto test.
        // We set the list of MoMLFilters to handle Backward Compatibility.
        MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());

        // Filter out any graphical classes.
        MoMLParser.addMoMLFilter(new RemoveGraphicalClasses());

        // If there is a MoML error, then throw the exception as opposed
        // to skipping the error.  If we call StreamErrorHandler instead,
        // then the nightly build may fail to report MoML parse errors
        // as failed tests
        //parser.setErrorHandler(new StreamErrorHandler());
        // We use parse(URL, URL) here instead of parseFile(String)
        // because parseFile() works best on relative pathnames and
        // has problems finding resources like files specified in
        // parameters if the xml file was specified as an absolute path.
        CompositeActor toplevel = (CompositeActor) parser.parse(null, new File(
                xmlFileName).toURI().toURL());

        _manager = new Manager(toplevel.workspace(), "MoMLSimpleApplication");
        toplevel.setManager(_manager);
        toplevel.addChangeListener(this);
View Full Code Here

        } catch (Exception e) {
            // Ignore exceptions, which only result in the wrong look and feel.
        }

        // Create a parser to use.
        _parser = new MoMLParser();

        // We set the list of MoMLFilters to handle Backward Compatibility.
        MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());

        // 2/03: Moved the setMessageHandler() to before parseArgs() so
View Full Code Here

TOP

Related Classes of ptolemy.moml.MoMLParser

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.