当前位置: 首页>>代码示例>>Java>>正文


Java BSFManager.loadScriptingEngine方法代码示例

本文整理汇总了Java中org.apache.bsf.BSFManager.loadScriptingEngine方法的典型用法代码示例。如果您正苦于以下问题:Java BSFManager.loadScriptingEngine方法的具体用法?Java BSFManager.loadScriptingEngine怎么用?Java BSFManager.loadScriptingEngine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bsf.BSFManager的用法示例。


在下文中一共展示了BSFManager.loadScriptingEngine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initEngine

import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
protected void initEngine() {
	try {

		String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
		BSFManager bsfManager = new BSFManager();
		bsfManager.setClassLoader(BSFManager.class.getClassLoader());
		// bsfManager.declareBean("_AxisService", axisService,
		// AxisService.class);

		BSFEngine bsfEngine = bsfManager
				.loadScriptingEngine(scriptLanguage);
		Object scriptSrc = readScript();
		bsfEngine.exec(scriptName, 0, 0, scriptSrc);

	} catch (BSFException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:ScriptInvoker.java

示例2: processFileOrScript

import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
protected void processFileOrScript(BSFManager mgr) throws BSFException{
    BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
    if (scriptFile.length() == 0) {
        bsfEngine.exec("[script]",0,0,getScript());
    } else {// we have a file, read and process it
        try {
            String script=FileUtils.readFileToString(new File(scriptFile));
            bsfEngine.exec(scriptFile,0,0,script);
        } catch (IOException e) {
            log.warn(e.getLocalizedMessage());
            throw new BSFException(BSFException.REASON_IO_ERROR,"Problem reading script file",e);
        }
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:16,代码来源:BSFTestElement.java

示例3: evalFileOrScript

import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
protected Object evalFileOrScript(BSFManager mgr) throws BSFException{
    BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
    if (scriptFile.length() == 0) {
        return bsfEngine.eval("[script]",0,0,getScript());
    } else {// we have a file, read and process it
        try {
            String script=FileUtils.readFileToString(new File(scriptFile));
            return bsfEngine.eval(scriptFile,0,0,script);
        } catch (IOException e) {
            log.warn(e.getLocalizedMessage());
            throw new BSFException(BSFException.REASON_IO_ERROR,"Problem reading script file",e);
        }
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:16,代码来源:BSFTestElement.java

示例4: testAccess

import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
@Test
public void testAccess() throws BSFException {
    // tag::bsf_access[]
    BSFManager manager = new BSFManager();
    BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
    manager.declareBean("myvar", "hello", String.class);
    Object myvar = manager.lookupBean("myvar");
    String result = (String) bsfEngine.call(myvar, "reverse", new Object[0]);
    assertEquals("olleh", result);
    // end::bsf_access[]
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:BSFSpecTest.java

示例5: initScript

import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
/**
 * Initializes the script service by finding the script source code,
 * compiling it in a BSFEngine, and creating an OMElementConvertor
 * for the script.
 */
protected BSFEngine initScript(MessageContext mc) throws AxisFault {
    log.debug("initializing script service");

    AxisService axisService = mc.getAxisService();

    String scriptName = null;
    String scriptSrc = null;
    Parameter scriptFileParam = axisService.getParameter(SCRIPT_ATTR);
    if (scriptFileParam != null) {
        // the script is defined in a seperate file
        scriptName = ((String) scriptFileParam.getValue()).trim();
        Parameter scriptSrcParam = axisService.getParameter(SCRIPT_SRC_PROP);
        if (scriptSrcParam != null) {
            scriptSrc = (String) scriptSrcParam.getValue();
        } else {
            scriptSrc = readScript(axisService.getClassLoader(), scriptName);
        }
    } else {
        // the script is defined inline within the services.xml
        ArrayList parameters = axisService.getParameters();
        for (int i=0; scriptFileParam == null && i<parameters.size(); i++) {
            Parameter p = (Parameter) parameters.get(i);
            if (p.getName().startsWith("script.")) {
                scriptFileParam = p;
                scriptName = p.getName();
                scriptSrc = (String) p.getValue();
            }
        }
    }
    if (scriptName == null) {
        throw new AxisFault("Missing script parameter");
    }
    
    try {

        String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
        BSFManager bsfManager = new BSFManager();
        bsfManager.setClassLoader(BSFManager.class.getClassLoader());
        bsfManager.declareBean("_AxisService", axisService, AxisService.class);

        BSFEngine bsfEngine = bsfManager.loadScriptingEngine(scriptLanguage);
        bsfEngine.exec(scriptName, 0, 0, scriptSrc);

        ServiceContext serviceContext = mc.getServiceContext();
        serviceContext.setProperty(BSFENGINE_PROP, bsfEngine);

        OMElementConvertor convertor = ConvertorFactory.createOMElementConvertor(axisService, scriptName);
        serviceContext.setProperty(CONVERTOR_PROP, convertor);

        return bsfEngine;

    } catch (BSFException e) {
        throw AxisFault.makeFault(e);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:61,代码来源:ScriptReceiver.java


注:本文中的org.apache.bsf.BSFManager.loadScriptingEngine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。