Package org.apache.commons.jelly

Examples of org.apache.commons.jelly.JellyException


    public void invokeCommandLineJelly(String[] args) throws JellyException {
        CommandLine cmdLine = null;
        try {
            cmdLine = parseCommandLineOptions(args);
        } catch (ParseException e) {
            throw new JellyException(e);
        }
       
        // check for -h or -v
        if (cmdLine.hasOption("h")) {
            new HelpFormatter().printHelp("jelly [scriptFile] [-script scriptFile] [-o outputFile] [-Dsysprop=syspropval] [-awt]",
                cmdLineOptions);
            System.exit(1);
        }
        if (cmdLine.hasOption("v")) {
            System.err.println("Jelly " + Jelly.getJellyVersion());
            System.err.println(" compiled: " + Jelly.getJellyBuildDate());
            System.err.println("");
            System.exit(1);
        }

        // get the -script option. If there isn't one then use args[0]
        String scriptFile = null;
        if (cmdLine.hasOption("script")) {
            scriptFile = cmdLine.getOptionValue("script");
        } else {
            scriptFile = args[0];
        }
       
        // check the -awt option.
        boolean runInSwingThread = cmdLine.hasOption("awt") || cmdLine.hasOption("swing");

        //
        // Use classloader to find file
        //
        URL url = ClassLoaderUtils.getClassLoader(getClass()).getResource(scriptFile);
        // check if the script file exists
        if (url == null && !(new File(scriptFile)).exists()) {
            throw new JellyException("Script file " + scriptFile + " not found");
        }

        try {
            // extract the -o option for the output file to use
            final XMLOutput output = cmdLine.hasOption("o") ?
                    XMLOutput.createXMLOutput(new FileWriter(cmdLine.getOptionValue("o"))) :
                    XMLOutput.createXMLOutput(System.out);

            Jelly jelly = new Jelly();
            jelly.setScript(scriptFile);

            final Script script = jelly.compileScript();

            // add the system properties and the command line arguments
            final JellyContext context = jelly.getJellyContext();
            context.setVariable("args", args);
            context.setVariable("commandLine", cmdLine);
            if (runInSwingThread) {
                javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() {
                    try {
                        script.run(context, output);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
            } } ); } else {
                script.run(context, output);
            }

            // now lets wait for all threads to close
            Runtime.getRuntime().addShutdownHook(new Thread() {
                    public void run() {
                        try {
                            output.close();
                        }
                        catch (Exception e) {
                            // ignore errors
                        }
                    }
                }
            );

        } catch (Exception e) {
            throw new JellyException(e);
        }

    }
View Full Code Here


    //-------------------------------------------------------------------------
    public Tag createTag(String name, Attributes attributes) throws JellyException {
        try {
          return (Tag) tagClass.newInstance();
        } catch (InstantiationException e) {
            throw new JellyException(e.toString());
        } catch (IllegalAccessException e) {
            throw new JellyException(e.toString());
        }
    }
View Full Code Here

        }

        int endIndex = text.indexOf( "}", startIndex+2 );

        if ( endIndex < 0 ) {
            throw new JellyException( "Missing '}' character at the end of expression: " + text );
        }
        if ( startIndex == 0 && endIndex == len - 1 ) {
            return factory.createExpression(text.substring(2, endIndex));
        }
View Full Code Here

    {
        ProcessTag processTag = (ProcessTag) findAncestorWithClass( ProcessTag.class );

        if ( processTag == null )
        {
            throw new JellyException( "Not within a process element" );
        }
       
        Process process = processTag.getProcess();

        return process;
View Full Code Here

    {
        StateTag stateTag = (StateTag) findAncestorWithClass( StateTag.class );

        if ( stateTag == null )
        {
            throw new JellyException( "Not within a state element" );
        }
       
        State state = stateTag.getState();

        return state;
View Full Code Here

    {
        DescribedTag describedTag = (DescribedTag) findAncestorWithClass( DescribedTag.class );

        if ( describedTag == null )
        {
            throw new JellyException( "Unable to locate an element to describe" );
        }

        Described described = describedTag.getDescribed();

        return described;
View Full Code Here

        ProcessContext context = getProcessContext();

        if ( context == null )
        {
            throw new JellyException( "No process context" );
        }
        ProcessEngine  engine  = context.getProcessEngine();

        engine.call( getProcess(),
                     context );
View Full Code Here

        Transition transition = transitionTag.getTransition();

        if ( transition.getGuard() != null )
        {
            throw new JellyException( "Guard already defined for transition" );
        }

        transition.setGuard( guard );
    }
View Full Code Here

        State fromState = process.getState( this.from );

        if ( fromState == null )
        {
            throw new JellyException( "No such state \"" + this.from  + "\"" );
        }

        State toState = process.getState( this.to );

        if ( toState == null )
        {
            throw new JellyException( "No such state \"" + this.to  + "\"" );
        }

        this.transition = fromState.addTransition( toState,
                                                   this.description );
View Full Code Here

        State startState = this.process.getState( getStart() );

        if ( startState == null )
        {
            throw new JellyException( "Start state \"" + getStart() + "\" not found." );
        }

        this.process.setStartState( startState );

        String var = getVar();
View Full Code Here

TOP

Related Classes of org.apache.commons.jelly.JellyException

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.