《unit12 Bean Markup Language (BML)知识讲解》由会员分享,可在线阅读,更多相关《unit12 Bean Markup Language (BML)知识讲解(31页珍藏版)》请在金锄头文库上搜索。
1、Nov. 2000,Unit 12.Bean Markup Language(BML),What This Unit Is About This unit will describe Bean markup Language,what it is,how to use it,and its components. What You Should Be Able to Do After completing this unit,you should be able to: Define and write a BML script Interpret a BML script Compile a
2、 BML script Embed a BML script into an application How You Will Check Your Progress Accountability: Lab exercise,Nov. 2000,Unit 12.Bean Markup Language(BML),References Tutorial and Users Guide Objectives After completing this unit,you should be able to: Define and write a BML script Interpret a BML
3、script Compile a BML script Embed a BML script in an application,Nov. 2000,Unit 12.Bean Markup Language(BML),What is BML? An instance of an XML-based component configuration, or A wiring language customized for the JavaBeans component model Consists of three components: -BML,the Language Directly ex
4、ecutable BML Player -Interprets a BML script BML Compiler Translates a BML script into Java source code,Nov. 2000,BML,The Language(Cont), Useful in cases: -You want to configure a set of beans in a non-interactive setting (for example ,if you are using XSL to generate Java) -You want to dynamically
5、modify or create new components and wire them into the running application -High-level,textual abstraction to capture the structure of component-based applications Required user background: -Working knowledge of XML and a good understanding of JavaBeans component model,Nov. 2000,BML,The Language(Con
6、t), Visual builders could use BML as an import/export format and also as a builder- to-builder exchange format Since BML is XML-based,it opens up application development to all the tools now being developed to work with XML Practical example: -You can start to think about using XSL to style“ applica
7、tions,starting from an XML description of the programs functions(or an individual users needs) and an XSL description of a user-interface framework,and generating BML to produce a running application,Nov. 2000,BML,The Language(Cont), BML allows one to specify the desired configuration of a set of be
8、ans Expressed in terms of standard bean operations -Creation,event bindings,method calls and containment,Nov. 2000,BML,The Language(Cont), A brief description:,Nov. 2000,Unit 12.Bean Markup Language(BML),Language-Bean Creation and Access -Used to create new beans or to look up beans by name -Once cr
9、eated or looked up,the children are processed with this bean as the default target of their operations,Nov. 2000,Language-Bean Creation and Access(Cont),Example: -If a were present as a child,the call would occur on the bean identified by the containing element.If there are no children elements,then
10、 processing the element simply results in that bean would result in the p1 property of bar-bean being set to the value of the potato property of foo-bean,Nov. 2000,Unit 12.Bean Markup Language(BML),Language-Creating a Bean Bean resurrected from a serialized file (.ser),or A new instance of a class M
11、ay optionally be registered into BMLs object registry case 1 (instantiating a class using its no-args constructor or by resurrection and optionally registering it) Syntax: .other BML elements to configure bean. ,Nov. 2000,Language-Creating a Bean(Cont),Case 2 (creating a bean by instantiating a clas
12、s with a specific constructor and optionally registering it) Syntax: constructor-arg-1 . constructor-arg-n .other BML elements to configure bean. ,Nov. 2000,Unit 12.Bean Markup Language(BML),Language-Looking Up a Bean Allows one to look up beans previously registered in object registry A special fea
13、ture allows one to look up the java.lang.Class object representing some Java class Case 1 (looking up a previously registered bean) Syntax: Case 2 (looking up a class bean) Syntax: .other BML elements to configure bean. .,Nov. 2000,Unit 12.Bean Markup Language(BML),Language-Creating String Beans Ins
14、tances of java.lang.String Have to be treated specially because Java strings are immutable and XML is white space-sensitive For more information on the motivation behind,see the BML Users Guide Case 1 (creating a string with a non-empty value) Syntax: value-of-string Case 2 (creating an empty string
15、) Syntax: ,Nov. 2000,Unit 12.Bean Markup Language(BML),Language-Bean Property Configuration Allows one to get the value of a property,or To set the value of a property to some value Value may be immediate or the return value of some other appropriate BML element Setting or getting performed on the d
16、efault target bean,unless otherwise specified Case 1 (setting with an immediate value) Syntax: ,Nov. 2000,Language-Bean Property Configuration (Cont),Case 2 (setting with an indirect value) Syntax: .a bean,string,field,property,call-method,cast or script element. Case 3 (getting a property value) Syntax: ,Nov. 2000,Unit 12.Bean Markup Language(BML)