Package bsh

Examples of bsh.Interpreter


        PrintStream origOut = System.out;
        PrintStream origErr = System.err;

        try
        {
            Interpreter engine = new Interpreter();

            if ( scriptOutput != null )
            {
                System.setErr( scriptOutput );
                System.setOut( scriptOutput );
                engine.setErr( scriptOutput );
                engine.setOut( scriptOutput );
            }

            if ( !Capabilities.haveAccessibility() )
            {
                try
                {
                    Capabilities.setAccessibility( true );
                }
                catch ( Exception e )
                {
                    if ( scriptOutput != null )
                    {
                        e.printStackTrace( scriptOutput );
                    }
                }
            }

            if ( classPath != null && !classPath.isEmpty() )
            {
                for ( String path : classPath )
                {
                    try
                    {
                        engine.getClassManager().addClassPath( new File( path ).toURI().toURL() );
                    }
                    catch ( IOException e )
                    {
                        throw new RuntimeException( "bad class path: " + path, e );
                    }
                }
            }

            if ( globalVariables != null )
            {
                for ( String variable : globalVariables.keySet() )
                {
                    Object value = globalVariables.get( variable );
                    try
                    {
                        engine.set( variable, value );
                    }
                    catch ( EvalError e )
                    {
                        throw new RuntimeException( e );
                    }
                }
            }

            try
            {
                return engine.eval( script );
            }
            catch ( TargetError e )
            {
                throw new ScriptEvaluationException( e.getTarget() );
            }
View Full Code Here


        public boolean shouldUse(Map<String, Object> context) {
            boolean shouldUse = true;
            String useWhen = this.getUseWhen(context);
            if (UtilValidate.isNotEmpty(useWhen)) {
                try {
                    Interpreter bsh = (Interpreter) context.get("bshInterpreter");
                    if (bsh == null) {
                        bsh = BshUtil.makeInterpreter(context);
                        context.put("bshInterpreter", bsh);
                    }

                    Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen));

                    // retVal should be a Boolean, if not something weird is up...
                    if (retVal instanceof Boolean) {
                        Boolean boolVal = (Boolean) retVal;
                        shouldUse = boolVal.booleanValue();
View Full Code Here

        String useWhenStr = this.getUseWhen(context);
        if (UtilValidate.isEmpty(useWhenStr)) {
            return true;
        } else {
            try {
                Interpreter bsh = this.modelForm.getBshInterpreter(context);
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr));
                boolean condTrue = false;
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    condTrue = boolVal.booleanValue();
View Full Code Here

            expanderContext = StringUtil.HtmlEncodingMapWrapper.getHtmlEncodingMapWrapper(context, simpleEncoder);
        }

        try {
            // use the same Interpreter (ie with the same context setup) for all evals
            Interpreter bsh = this.getBshInterpreter(context);
            for (AltTarget altTarget: this.altTargets) {
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altTarget.useWhen));
                boolean condTrue = false;
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    condTrue = boolVal.booleanValue();
View Full Code Here

    public void resetBshInterpreter(Map<String, Object> context) {
        context.remove("bshInterpreter");
    }

    public Interpreter getBshInterpreter(Map<String, Object> context) throws EvalError {
        Interpreter bsh = (Interpreter) context.get("bshInterpreter");
        if (bsh == null) {
            bsh = BshUtil.makeInterpreter(context);
            context.put("bshInterpreter", bsh);
        }
        return bsh;
View Full Code Here

     */
    public String getStyleAltRowStyle(Map<String, Object> context) {
        String styles = "";
        try {
            // use the same Interpreter (ie with the same context setup) for all evals
            Interpreter bsh = this.getBshInterpreter(context);
            for (AltRowStyle altRowStyle : this.altRowStyles) {
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altRowStyle.useWhen));
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    if (boolVal.booleanValue()) {
                        styles += altRowStyle.style;
View Full Code Here

            jd.addParameter( p );
            parameterNameToExpressionID.put( parameter.getName(), new Integer(exp.getId()) );
        }

        String bshScript = JRBshGenerator.generateScript( jd );
        Interpreter interpreter = new Interpreter();
        interpreter.setClassLoader(interpreter.getClass().getClassLoader());
        interpreter.eval(new StringReader(bshScript));

        interpreter.eval("bshCalculator = createBshCalculator()");
       
        return interpreter;
    }
View Full Code Here


    synchronized void createInterpreter() {
        // create interpreter just-in-time
        if(interpreter == null) {
            interpreter=new Interpreter();
            try {
                interpreter.set("bsh_prot", this);
            }
            catch(EvalError evalError) {
            }
View Full Code Here

        String useWhenStr = this.getUseWhen(context);
        if (UtilValidate.isEmpty(useWhenStr)) {
            return true;
        } else {
            try {
                Interpreter bsh = this.modelForm.getBshInterpreter(context);
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr));
                boolean condTrue = false;
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    condTrue = boolVal.booleanValue();
View Full Code Here

                throw new ContainerException("Invalid telnet-port defined in container configuration; not a valid int");
            }
        }

        // create the interpreter
        bsh = new Interpreter();

        // configure the interpreter
        if (bsh != null) {
            try {
                bsh.set(name, this);
View Full Code Here

TOP

Related Classes of bsh.Interpreter

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.