全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
运用BeanShell脚本语言进行逻辑判断Wang,XinyuBAS-DIT-JProprietary NoticeThis documentation is the property of, and contains confidential information of, Hewlett-Packard Company or its affiliates. Possession and use of this documentation is authorized only as specified in Exhibit SS5 and the HP Terms and Conditions of Sale and Services, HP Business Terms or HP Global Agreement or pursuant to the license accompanying this documentation. Keyword BeanSshell Category Java Description 运用BeanShell脚本语言进行逻辑判断 How to Use IT 1. 简述: BeanShell是一种脚本语言,一种完全符合Java语法的java脚本语言,并且又拥有自己的一些语法和方法,BeanShell是一种松散类型的脚本语言(这点和JS类似)。实际工程中可以与用BeanShell脚本语言完成所需的简单或复杂对象的逻辑判断下载地址:2. 环境设置: 1)配置BeanShellA. 把;bsh-xx.jar放到$JAVA_HOME/jre/lib/ext文件夹下Bunix: export CLASSPATH=$CLASSPATH:bsh-xx.jarC Windows: set classpath %classpath%;bsh-xx.jar本文中使用的是方法A,将bsh-2.0b4.jar放到C:jdk1.5.0_15jrelibext目录下2)检测配置打开dos窗口,键入:java bsh.Console命令出现BeanShell图片代表设置成功,BeanShell开始运行3. 具体应用: 1)在Eclipse中建立工程TestBeanShell2)添加所需Java类文件建立Bsh1.java,此文件中记录用使用BeanShell编写的方法。建立Person.java,此文件记录一个简单Java类对象。建立ServiceContext.java,此文件记录一个复杂Java类对象。3)BeanShell方法实现详解Person.javapackage bhs.shell;public class Person private String pname;public Person()super();public String getPname() return pname;public void setPname(String pname) this.pname = pname;ServiceContext.javapackage bhs.shell;import java.util.HashMap;import java.util.Map;public class ServiceContext public static final String EVENT_ID = EVENT_ID; public static final String MESSAGE_ID = MESSAGE_ID;private Map context = new HashMap();public void setAttribute(String key, Object value) context.put(key, value);public Object getAttribute(String key) return context.get(key);public void removeAttribute(String key) context.remove(key);Bsh1.javapackage bhs.shell;import java.util.*;import bsh.EvalError;import bsh.Interpreter;import bsh.UtilEvalError;public class Bsh1 public static void main(String args) throws EvalError, UtilEvalError Bsh1.testBshSimpleType();Bsh1.testBshComplexType();Bsh1.testBshComplexExpression(); public static boolean testBshSimpleType() throws EvalError Interpreter i = new Interpreter(); / Construct an interpreterBoolean flag = false;i.set(input, 3);i.set(b, 7);/ Eval a statement and get the resultflag = (Boolean) i.eval(b input);System.out.print(Simple Type result: +flag+n);return flag; public static boolean testBshComplexType()throws EvalError, UtilEvalError ServiceContext context = new ServiceContext();List list= new ArrayList();Person p1=new Person();p1.setPname(eva);Person p2=new Person();p2.setPname(jason);list.add(p1);list.add(p2);context.setAttribute(input, list);Boolean flag = false;flag=(Boolean)validateCondition(Person)context.getAttribute(input).get(1).getPname().equals(jason), context);System.out.print(Complex Type result: +flag+n);return flag; public static boolean testBshComplexExpression()throws EvalError, UtilEvalError ServiceContext context = new ServiceContext(); context.setAttribute(a, 3);context.setAttribute(b, 4);context.setAttribute(c, 6);context.setAttribute(d, null);Boolean flag = false;flag=(Boolean) validateCondition(int)context.getAttribute(a)(int)context.getAttribute(b)&(context.getAttribute(d)=null),context);System.out.print(Complex Expression result: +flag+n);return flag; public static boolean validateCondition(String condition, ServiceContext context) throws EvalError, UtilEvalError Interpreter i = new Interpreter();/ construct an InterpreterBoolean flag = false;/ record the result expression estimatedi.getNameSpace(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小班艺术领域简单教案
- 七年级英语Starter单元同步练习题
- 企业人力资源绩效考核方案全集
- 建筑幕墙知识讲解教案
- 2025锂电回收利用技术突破及环保政策驱动行业发展前景研究报告
- 部编版二年级上册语文阅读练习题集
- 二年级音乐下册卖报歌教案人教新课标版
- 城市雨水花园设计与维护指导
- 六年级科学上册第一单元微小的生物第一课簿教案青岛版六三制
- 企业技术改进年度总结报告
- 2025河北涿州京源热电有限责任公司秋季校园招聘10人笔试历年难易错考点试卷带答案解析2套试卷
- 2025标准个人租房合同范本下载
- 企业节能减排行动计划方案
- 2025中国智能制造软件市场发展现状及未来趋势与投资策略分析报告
- 养老院消防安全培训课件
- 项目阶段性沟通与反馈机制构建方案
- 广药集团校招试题及答案
- 厂房公共抗震支架施工方案
- 英语二2022真题题目文档版
- 雨刮器基础知识培训课件
- 河北省2026届高三年级上学期10月阶段性联合考试英语试卷
评论
0/150
提交评论