本文整理汇总了Java中org.apache.bsf.BSFEngine类的典型用法代码示例。如果您正苦于以下问题:Java BSFEngine类的具体用法?Java BSFEngine怎么用?Java BSFEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BSFEngine类属于org.apache.bsf包,在下文中一共展示了BSFEngine类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeBusinessLogic
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
/**
* Invokes the service by calling the script function
*/
public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault {
try {
log.debug("invoking script service");
outMC.setEnvelope(getSOAPFactory(inMC).getDefaultEnvelope());
BSFEngine engine = getBSFEngine(inMC);
OMElementConvertor convertor = (OMElementConvertor) inMC.getServiceContext().getProperty(CONVERTOR_PROP);
Parameter scriptFunctionParam = inMC.getAxisService().getParameter(FUNCTION_ATTR);
String scriptFunction = scriptFunctionParam == null ? DEFAULT_FUNCTION : (String) scriptFunctionParam.getValue();
ScriptMessageContext inScriptMC = new ScriptMessageContext(inMC, convertor);
ScriptMessageContext outScriptMC = new ScriptMessageContext(outMC, convertor);
Object[] args = new Object[] { inScriptMC, outScriptMC };
engine.call(null, scriptFunction, args);
} catch (BSFException e) {
throw AxisFault.makeFault(e);
}
}
示例2: initEngine
import org.apache.bsf.BSFEngine; //导入依赖的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);
}
}
示例3: processFileOrScript
import org.apache.bsf.BSFEngine; //导入依赖的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);
}
}
}
示例4: evalFileOrScript
import org.apache.bsf.BSFEngine; //导入依赖的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);
}
}
}
示例5: testAccess
import org.apache.bsf.BSFEngine; //导入依赖的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[]
}
示例6: testCall
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
public void testCall() throws Exception {
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[]{});
assertEquals("olleh", result);
}
示例7: createManager
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
private BSFManager createManager() throws BSFException {
if (manager != null) {
return manager;
}
BSFManager m = new BSFManager();
m.setClassLoader(getScriptClassLoader());
if (getKeepEngine()) {
BSFEngine e = manager.loadScriptingEngine(getLanguage());
this.manager = m;
this.engine = e;
}
return m;
}
示例8: isMethodDefined
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
public boolean isMethodDefined(String method, String scriptName, BSFEngine engine, BSFManager manager)
throws BSFException
{
String script = "this.namespace.getMethod(\"" + method + "\", new Class[0])";
Object res =
engine.eval(scriptName, 1, 1, script);
return res != null;
}
示例9: testVersion
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
public void testVersion() throws Exception {
//System.out.println("BSFManager.getVersion() = " + BSFManager.getVersion());
BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
assertEquals(CACHING_ENGINE, bsfEngine.getClass());
}
示例10: initScript
import org.apache.bsf.BSFEngine; //导入依赖的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);
}
}
示例11: setEngine
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
public void setEngine(BSFEngine e) {
}
示例12: setEngine
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
public void setEngine(BSFEngine e) {
this.bsfEngine = e;
}
示例13: setEngine
import org.apache.bsf.BSFEngine; //导入依赖的package包/类
public void setEngine(BSFEngine e);