1、A SOA Approach for Domain-Specific Language Implementation,Shih-Hsi “Alex” Liu1, Adam Cardenas1, Xang Xiong1, Marjan Mernik2, Barrett R. Bryant3, Jeff Gray4 1California State University, Fresno, USA 2University of Maribor, Slovenia 3University of Alabama at Birmingham, USA 4University of Alabama, US
2、A,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Outlines,Background: Domain-Specific Languages (DSLs) Challenges of DSL Implementation Existing DSL Implementation methodologies and tools A SOA Approach for DSL Implementation Case Studies Robot language PPCea FDL Discussions Co
3、nclusions,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Background,A Domain-Specific Language (DSL) is a programming/modeling language that shields accidental complexity by uplifting the abstraction layer to a higher level. A DSL introduces domain-specific constructs and notat
4、ions to facilitate productivity, reliability, maintainability and portability. Up to 510 times productivity improvement Decision, analysis, design and implementation patterns have been identified to assist DSL developers in when and how to develop a DSL.,IEEE 6th World Congress on Services. Miami, F
5、L, USA. July 5-10, 2010,Background (cont.),Example DSLs include: Robot language: An imperative DSL that controls a (Lego Mindstorm NXT) robot to move in different directions and distances. PPCea: An imperative DSL that controls parameter settings to balance an evolution process toward optimization a
6、nd convergence. Feature description language (FDL): A declarative DSL to configure combinations of features. And many others.(e.g., SQL, UNIX shell script, MediaWiki templates etc.),IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Challenges of DSL Impl.,Kosar et al. investigated
7、 that DSL implementation using a compiler or interpreter pattern may suffer from extension/evolution problem Gray et al. also pointed out that DSLs are usually unstable and syntactically and/or semantically evolve due to their frequent need to represent changes in domain concepts. E.g., A DSL for te
8、sting automobile breaks,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Extension/Evolution: When domain concepts change, then the lexical, syntactical and/or semantic domain constructs need to evolve. Tedious and error-prone. E.g., one new domain statement or one new grammar pr
9、oduction introduced will affect an existing DSL implementation at the lexical, syntactical, and semantic levels in different magnitudes. Interoperability: A DSL is usually implemented by one base language (e.g., Java). What if it is desired to implement a DSL in several different base languages? How
10、 would these base languages communicate with each other? Tool Support: When a new DSL is introduced, corresponding DSL tools should be supported (e.g., DSL debugger). Otherwise, the DSL will have fewer opportunities to be adopted. It requires a great amount of endeavor and promotion.,Challenges of D
11、SL Impl. (cont.),IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,AMMA is a platform to implement text-based DSLs using a Model-Driven Engineering approach that is focused on model transformations. Need to describe abstract syntax, concrete syntax and transformation rules of a DS
12、L CoCloRep is a DSL for code clone representation The Generic Modeling Environment (GME) is a metamodeling toolkit for developing graphical DSLs. Metamodel defines a domains syntax, semantics, constraints, and presentation A model is an instance (namely, a DSL program) that conforms to metamodel Int
13、erpreter generates source code from a model or executes a model TCPN is a modeling language for time-colored Petri net,Existing DSL Impl. Methodologies,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Existing DSL Impl. Methodologies (cont.),Six DSL implementation patterns are id
14、entified: Interpreter/compiler patterns utilize compiler/interpreter techniques; Embedding patterns introduce new DSL constructs from an existing General-Purpose Language (GPL); Preprocessor patterns translate DSL constructs into a base language; Extensible compiler/interpreter patterns add DSL opti
15、mization rules and code generation in the existing compiler/interpreter of a GPL; Commercial off-the-shelf patterns utilize existing tools and/or notations for a specific domain; and A Hybrid pattern is the combination of all of the above. There are many other implementation methodologies/tools for
16、DSLs (e.g., Visual Studio DSL tools, Eclipse GMF, MetaEdit+). These methodologies (not tools) still suffer from the aforementioned three challenges,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,A SOA Approach for DSL Impl.,IEEE 6th World Congress on Services. Miami, FL, USA. J
17、uly 5-10, 2010,Case Study: Robot Language,An imperative DSL that controls a (Lego Mindstorm NXT) robot to move in different directions and distances. The implementation utilizes preprocessing pattern that translates its program into leJOS, a base language for controlling and communicating w/ NXT. NX
18、T allows two types of communication: USB and Bluetooth between two robots or between one robot and one controlling device (a desktop or a laptop).,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: Robot Language (cont.),The SOA-based Robot Language is implemented in tw
19、o ways: First Way: A web service is introduced: Each movement control (e.g., Move Up, Move Down, Move Left, or Move Right) is encapsulated in an WebMethod Each WebMethod invokes the corresponding leJOS APIs. The invocations then send the directions and distances to another NXT robot, which preloads
20、a receiver that performs movement commands accordingly Second Way: A web service performs leJOS code generation at runtime using Java Reflection. The code is then loaded to a robot connected w/ the desktop via USB. Both ways utilize WS-BPEL to express a sequence of movements (i.e., a Robot language
21、program) for the robot,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: Robot Language (cont.),Experiment 1: A robot is controlled by a desktop/laptop using bluetooth/USB connection. The robot follows a square and then stops.,IEEE 6th World Congress on Services. Miami
22、, FL, USA. July 5-10, 2010,Case Study: Robot Language (cont.),Experiment 2: One robot is controlled by a desktop and a laptop using USB and Bluetooth connections, respectively. The two devices send controls to the robot in turns. The robot moves following the commands from both devices.,USB,Bluetoot
23、h,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: Robot Language (cont.),Evolution/Extension: If a new command/control is needed, it can be added to a new WebMethod or a new web service E.g., Make Bell Sound If an existing command needs: Semantic evolution, we concen
24、trate on editing the web service. Lexical and/or syntactical evolution, we concentrate on WSDL. Good modularization and good decoupling: Developers not need to worry too much about coordination among lexical, syntactical, semantic levels. SOA tools coordinate it for you. Traditional DSL implementati
25、on will need to revise lexical, syntactical/grammatical, and/or semantic levels in different magnitudes.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea,An imperative DSL for Evolutionary Algorithms. It controls parameter settings to balance an evolution proces
26、s toward optimization and convergence.,1 genetic 2 Round := 50; 3 r := 0; 4 while ( r Round ) do 5 g :=0; 6 tmp := 1.0; 7 init; 8 while ( g Maxgen ) do 9 pm := (1.0 / 1250.0) + (0.0042 / tmp); 10 callGA; 11 tmp := tmp * 2.0; 12 g := g + Epoch 13 end; 14 r := r + 1 15 end 16 end genetic,IEEE 6th Worl
27、d Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea (cont.),The SOA-based PPCea is implemented as follows: WSDL is an XML-based language to describe a service. It specifies data types, messages, operations, port types, bindings, port, and service. For a SOA-based DSL, WSDL can
28、assist with lexical analysis and syntax analysis It comprises lexical and syntactical information and semantic specification of a web service.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea (cont.),IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10
29、, 2010,Case Study: PPCea (cont.),An XML schema describes the structure and (domain-specific) data types of an XML message. It is utilized to validate if an XML message consumed by a web service follows the specified structure and data types. For a SOA-based DSL, XML schema is used to validate if XML
30、 messages contain valid data.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea (cont.),W3C defines a web service as “a software system designed to support interoperable machine-to-machine interaction over a network.” For a SOA-based DSL, a web service describes
31、the semantics of a DSL statement. SOA-based PPCea introduces the web services shown on the right.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,PPCea (cont.),WS-BPEL is an executable language that has various programming constructs to describe the execution flow of a business
32、process. For a SOA-based DSL, WS-BPEL describes a DSL program as well as primitive domain-specific parameters within.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea (cont.),Four experiments/ implementation alternatives are introduced: Exp. (0) is for interpret
33、er-based PPCea Exp. (1) utilizes JAXB to marshal and unmarshal messages passed among web services. Symbol tables used to store DSL parameters are public to all web services. (Note: it does Not conform to SOA ideology.) Exp. (2) utilizes StAX to marshal and unmarshal messages. Symbol table impl. is t
34、he same Exp. (1),IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea (cont.),Exp. (3) is implemented as follows: Interoperability between Java-based and C#-based web services all but the “Init” web service is implemented in Java. These web services are partner link
35、ed by WS- BPEL under the Oracle BPEL Process Manager. Symbol tables are replaced by XML message passing. The experiment shows that interoperability and tooling support challenges can be overcome by using the SOA approach. Oracle BPM provides a very good debugging functionality.,IEEE 6th World Congre
36、ss on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCea (cont.),Evolution/Extension: If a new DSL statement is needed, it can be added to a new WebMethod or a new web service can be created. E.g., Introduce N-point mutation WS (currently it is one-point mutation), and N-point crossover WS
37、(currently it is one-point crossover) If an existing DSL statement needs: Semantic evolution, we concentrate on editing the web service. (E.g., fixed point mutation - random point mutation) Lexical and/or syntactical evolution, we concentrate on editing WSDL if needed. PPCeas grammar evolution will
38、not affect WSDL and/or web services SOA-based PPCea has the same implementation advantages on evolution and extension as SOA-based Robot language. It also shows the solution of interoperability and tooling support.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: PPCe
39、a (cont.),Experimental Results (Exp. 0 is interpreter-based PPCea :,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL,Different from imperative languages that utilize DSL control constructs to determine how a DSL program is executed, domain-specific declarative lan
40、guages instead describe what a program should do when executed and the relationships between DSL statements A Feature Description Language (FDL) is a declarative language that textually describes feature diagrams for domain analysis.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 20
41、10,Case Study: FDL (cont.),The language introduces all-of, one-of, more-of and optional feature operations to explore all possible configurations along with requires, excludes, include and exclude constraints to reduce the possibilities,1 Car : all (carbody, Transmission, Engine, Horsepower, opt(pul
42、lsTrailer) 2 Transmission : one-of (automatic, manual) 3 Engine : more-of (electric, gasoline) 4 Horsepower : one-of (lowPower, mediumPower,highPower) 5 include pullsTrailer 6 pullsTrailer requires highPower,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL (cont.)
43、,A SOA-based FDL language introduces two web services as DSL statements: FeatureWS comprises the aforementioned eight operations, each of which consumes previously generated and current (input) XML messages and returns a new combinatory XML message based on normalization, variability, expansion and
44、satisfaction rules. CompileWS prints out the final combinatory result of all possible alternatives. A preprocessing step is also needed to convert the example program to XML messages line-by-line.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL (cont.),FeatureWS
45、WSDL,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL (cont.),2 Transmission : one-of (automatic, manual),A Transmission XML input for FeatureWS,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL (cont.),A SOA-based FDL program wr
46、itten in WS-BPEL,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL (cont.),Output of the FDL program: Six constrained car alternatives,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Case Study: FDL (cont.),Evolution/Extension: none-of operatio
47、n: identically acts as an exclude constraint. For syntactic (but not semantic) evolution, SOA-based FDL can be evolved easily by utilizing a newly generated WSDL without affecting other parts of the implementation. two-of operation: Syntactic evolution is done by automatically generated WSDL of a ne
48、w web service. For semantic evolution, most of the rules for the all-of operation are reused. A new rule that can be realized as a web service is introduced to generate a set of two combinatory atomic features out of a feature list. Semantic evolution may be considered as introduction and/or composi
49、tion of web services, which reflects SOAs advantages.,IEEE 6th World Congress on Services. Miami, FL, USA. July 5-10, 2010,Discussions: Lexical Analysis,Traditionally, lexical analyzer tokenizes a DSL program into lexemes For SOA approach, there is no need to perform lexical analysis: WSDL can be re
50、garded as a lexeme to represent the web service acting as a domain-specific statement. XML schema within WSDL (or listed separately) can be regarded as the data type of domain-specific parameters (e.g., population XML schema) For DSL constructs, a number of XML tags and XML schema used for SOA-based DSL programs have been defined in the WS-BPEL (e.g., if-else, while) For CoCloRep and TCPN, lexemes are defined in metamodel.,