Java Code Examples for org.apache.bsf.BSFManager#eval()
The following examples show how to use
org.apache.bsf.BSFManager#eval() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FaenorScriptEngine.java From L2jBrasil with GNU General Public License v3.0 | 6 votes |
public void parsePackages() { BSFManager context = new BSFManager(); try { context.eval("beanshell", "core", 0, 0, "double log1p(double d) { return Math.log1p(d); }"); context.eval("beanshell", "core", 0, 0, "double pow(double d, double p) { return Math.pow(d,p); }"); for (ScriptDocument script : _scripts) { parseScript(script, context); //System.out.println(script.getName()); } } catch (BSFException e) { e.printStackTrace(); } }
Example 2
Source File: BSFReportPreProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public MasterReport performPreDataProcessing( final MasterReport definition, final DefaultFlowController flowController ) throws ReportProcessingException { if ( preDataScript == null || language == null || StringUtils.isEmpty( preDataScript, true ) ) { return definition; } try { final BSFManager interpreter = new BSFManager(); interpreter.declareBean( "definition", definition, MasterReport.class ); //$NON-NLS-1$ interpreter.declareBean( "flowController", flowController, DefaultFlowController.class ); //$NON-NLS-1$ final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, preDataScript ); if ( o instanceof MasterReport == false ) { throw new ReportDataFactoryException( "Not a MasterReport" ); } return (MasterReport) o; //$NON-NLS-1$ } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } }
Example 3
Source File: BSFReportPreProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public MasterReport performPreProcessing( final MasterReport definition, final DefaultFlowController flowController ) throws ReportProcessingException { if ( script == null || language == null || StringUtils.isEmpty( script, true ) ) { return definition; } try { final BSFManager interpreter = new BSFManager(); interpreter.declareBean( "definition", definition, MasterReport.class ); //$NON-NLS-1$ interpreter.declareBean( "flowController", flowController, DefaultFlowController.class ); //$NON-NLS-1$ final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, script ); if ( o instanceof MasterReport == false ) { throw new ReportDataFactoryException( "Not a MasterReport" ); } return (MasterReport) o; //$NON-NLS-1$ } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } }
Example 4
Source File: BSFReportPreProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public SubReport performPreDataProcessing( final SubReport definition, final DefaultFlowController flowController ) throws ReportProcessingException { if ( script == null || language == null ) { return definition; } try { final BSFManager interpreter = new BSFManager(); interpreter.declareBean( "definition", definition, MasterReport.class ); //$NON-NLS-1$ interpreter.declareBean( "flowController", flowController, DefaultFlowController.class ); //$NON-NLS-1$ final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, preDataScript ); if ( o instanceof SubReport == false ) { throw new ReportDataFactoryException( "Not a SubReport" ); } return (SubReport) o; //$NON-NLS-1$ } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } }
Example 5
Source File: BSFReportPreProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public SubReport performPreProcessing( final SubReport definition, final DefaultFlowController flowController ) throws ReportProcessingException { if ( script == null || language == null ) { return definition; } try { final BSFManager interpreter = new BSFManager(); interpreter.declareBean( "definition", definition, SubReport.class ); //$NON-NLS-1$ interpreter.declareBean( "flowController", flowController, DefaultFlowController.class ); //$NON-NLS-1$ final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, script ); if ( o instanceof SubReport == false ) { throw new ReportDataFactoryException( "Not a MasterReport" ); } return (SubReport) o; //$NON-NLS-1$ } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } }
Example 6
Source File: Expression.java From L2jBrasil with GNU General Public License v3.0 | 5 votes |
public static Object eval(BSFManager context, String lang, String code) { try { return context.eval(lang, "eval", 0, 0, code); } catch (Exception e) { e.printStackTrace(); return null; } }
Example 7
Source File: BSFSpecTest.java From groovy with Apache License 2.0 | 5 votes |
@Test public void testSimpleIntegration() throws BSFException { // tag::bsf_simple[] String myScript = "println('Hello World')\n return [1, 2, 3]"; BSFManager manager = new BSFManager(); List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript); assertEquals(3, answer.size()); // end::bsf_simple[] }
Example 8
Source File: BSFSpecTest.java From groovy with Apache License 2.0 | 5 votes |
@Test public void testVariablePassing() throws BSFException { // tag::bsf_variable_passing[] BSFManager manager = new BSFManager(); manager.declareBean("xyz", 4, Integer.class); Object answer = manager.eval("groovy", "test.groovy", 0, 0, "xyz + 1"); assertEquals(5, answer); // end::bsf_variable_passing[] }
Example 9
Source File: AbstractChartExpression.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected JFreeChart postProcessChart( final JFreeChart originalChart ) { if ( postProcessingLanguage == null || postProcessingScript == null ) { return originalChart; } final LegacyDataRowWrapper legacyDataRowWrapper = new LegacyDataRowWrapper(); final WrapperExpressionRuntime runtimeWrapper = new WrapperExpressionRuntime(); runtimeWrapper.update( null, getRuntime() ); legacyDataRowWrapper.setParent( getDataRow() ); try { final BSFManager interpreter = new BSFManager(); interpreter.declareBean( "chartExpression", this, getClass() ); //$NON-NLS-1$ interpreter.declareBean( "chart", originalChart, JFreeChart.class ); //$NON-NLS-1$ interpreter.declareBean( "runtime", runtimeWrapper, ExpressionRuntime.class ); //$NON-NLS-1$ interpreter.declareBean( "dataRow", legacyDataRowWrapper, DataRow.class ); //$NON-NLS-1$ final Object o = interpreter.eval( postProcessingLanguage, "expression", 1, 1, postProcessingScript ); //$NON-NLS-1$ if ( o instanceof JFreeChart ) { return (JFreeChart) o; } return originalChart; } catch ( BSFException e ) { // this is not nice AbstractChartExpression.logger.warn( "Failed to evaluate post processing script", e ); } finally { legacyDataRowWrapper.setParent( null ); runtimeWrapper.update( null, null ); } return originalChart; }