




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
运用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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 坝坡砌石修复施工方案
- 高中口语考试题目及答案
- 2025机械设备购销合同
- 临朐立柱宣传栏施工方案
- 铁路退让补偿方案范本
- 工程桩基引孔施工方案
- 2025年计算机面试试题及答案
- 六安毕业活动策划方案模板
- 2025-2030中国乳品废弃物资源化利用技术及环保效益评估报告
- 2025-2030中国临床试验CRO行业集中度提升及服务创新研究
- ICU患者的早期活动
- 型钢混凝土结构钢筋施工
- 石群邱关源电路(第1至7单元)白底课件
- JJF 1338-2012相控阵超声探伤仪校准规范
- GB/T 40529-2021船舶与海洋技术起货绞车
- GB 31603-2015食品安全国家标准食品接触材料及制品生产通用卫生规范
- 关于公布2016年度中国电力优质工程奖评审结果的通知
- 港口集团绩效考核方案
- 送达地址确认书(诉讼类范本)
- 三坐标测量基础知识(基础教育)
- 宜家战略分析(课堂PPT)
评论
0/150
提交评论