Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor

Similar presentations


Presentation on theme: "SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor"— Presentation transcript:

1 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor 1

2 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Javascript object JSON Generated files Template Description file Description file Generated files Template Based Development Environment 2 Expansion Editor / generator Template Enhanced object Specification object Enhancement Source Generation DSL compiler DSL compiler

3 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre The JSON Objects and the Templates (Introduction) 3 1.JSON expansion 2.Templates 3.Specification object 4.Description file

4 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Expansion Principle of the Expansion of the JSON Templates! 4 a: [ {item: "carots", price: 12}, {item: "onions", price: 20}, {item: "spinachs", price: 15} ] a: [ {item: "carots", price: 12}, {item: "onions", price: 20}, {item: "spinachs", price: 15} ] {.repeated section a} The price of {item} is {price} RS {.end} {.repeated section a} The price of {item} is {price} RS {.end} The price of carots is 12 RS The price of onions is 20 RS The price of spinachs is 15 RS The price of carots is 12 RS The price of onions is 20 RS The price of spinachs is 15 RS Resulting page JSON description Template

5 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Template Commands {name} {.section name} {.or} {.end} {.repeated section name} {.or} {.alternates with} {.end} {.include "filename"} 5

6 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre JSON (Javascript) Objects are recursive 6 { create : { id : "customer", inputVar : "customerName", attributes : [ { intAttribute : { varName : "number" } } ] } [... ] array } {... } object

7 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Empty Attribute: conditional generation 7 { create : { id : "customer", selector: { }, inVar : "cName" } {.section selector} String {inVar}; {.end} { create : { selector: { id : "customer", inVar : "cName" } // same code generated // with both objects

8 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Ordered Sequence 8 attributes : [ { stringAttribute: { varName : "name" } }, { intAttribute: { varName : "number" } } ] public class Customer { String name = ""; int number = 0; } {.repeated section attributes} {.section intAttribute} int {varName} = 0; {.end} {.section stringAttribute} String {varName} = ""; {.end} Expansion

9 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Other Example 9 dataTables : [ { id : "customer", attributes : [ { stringAttribute: { varName : "name", finder: { } } }, { intAttribute: { varName : "number" } } ], relationships : [ { OneToMany : { to : "confirmedOrder" } } ] } public class Customer { String name = ""; int number = 0; public static findByName(String name) { query = "select * from customer where name='"+name+"'"; result = execute(query); public Collection confirmedOrder; } Result of the expansion

10 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Generation of an Application (requires a set of files) 10 { dataTables: [ { id : "customer", inpVar : "custName" } ] } { dataTables: [ { id : "customer", inpVar : "custName" } ] } aaa bbb abcd ccc ddd aaa bbb abcd ccc ddd aaa bbb abcd ccc ddd aaa bbb abcd ccc ddd aaa bbb abcd ccc ddd aaa bbb abcd ccc ddd class Customer { String customerName; } class Customer { String customerName; } Expansion {.section create} class {Id} { String {inpVar} } {.end} {.section create} class {Id} { String {inpVar} } {.end} File description foreach dataTables expand "dataTemplate.java" to "src/data/"+Id+".java" for whole expand "taskTemplate.java" to "src/data/Task.java"

11 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Our Enhancements to the Specification Object 11

12 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Computation of the Object Arguments 12 Template Generated files Expansion Description file Description file Extended specification object Templates Generated files Specification object Enhancement Computations are made in the specification object, not in the templates

13 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Computation of Object Arguments 13 { create : { id : "customer", Id : "Customer", inputVar : "customerName", InputVar : "CustomerName", attributes : [ { intAttribute : { varName : "number" }, _index : "0" } ], myObject : "CUSTOMER_NAME" } { create : { id : "customer", inputVar : "customerName", #attributes : "dataTables[customer].attributes", #myObject : "myMethod(inputVar)" } uppercase {equals (id, inputVar)}

14 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre BUDE: an Eclipse Plugin 14 Double-click: selection of a file

15 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre BUDE 15 selection marked if found highlighted if error

16 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Scope of the approach Intra-file level duplication of parts such as menus and sub-menus in a GUI Application level duplication of files and repetitive components within the files Architecture level extension of an application, creation of another application from a set of predefined components 16

17 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre More Examples 17 1.Tutorial, tutorial fileTutorialtutorial file 2.Menus and submenus in a GUI (intra-file) 3.General Ressort (application level) 4.The DSL compiler itself

18 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre 2) Menus of a GUI 18 private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JMenuBar GUIMenuBar = null; {.repeated section menus} private JMenu j{id}Menu = null; {.repeated section items} private JMenuItem j{itemId}Item = null; {.end} { menus : [ { id : "Files", items : [ { itemId: "Load" }, { itemId: "Save" } ] }, {... } ] } Expansion

19 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Task 3) A Workflow: Company General Ressort 19 Customer name Customer record Customer part id Part record Confirmed order Customer order (paper) found create found create enter createR not Preconditions (work with A.Wegmann and B.Bajic)

20 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Implementation x

21 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre List of the Entity Names 21 rolesactionstemporary variablesdata tables secretaryenterCustomerNamecustomerNameCustomer findCustomercustomerPartId name createCustomer number enterCustomerDataPart enterCustomerPartId partID findPartConfirmedOrder engineercreatePart comment enterPartData ManyToOne customer ManyToOne part

22 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Specification Object 22 { application : { version_id : "memory", memory: { }, database : "test", username : "" }, dataTables : [ { id : "customer", attributes : [ { stringAttribute: { }, varName : "name", finder }, { intAttribute: { }, varName : "number" } ], relationships : [ { OneToMany : { to : "confirmedOrder" } } ] }, {... actions : [ { enterAndFind, inputVar : "customerName", #insert : "dataTables[customer]" precondition : [ { stringNotAvailable : "customerPartId" } ] }, { create, inputVar : "customerName", #insert : "dataTables[customer]", transfers : [ { fromAttribute : "customerName", toAttribute : "name" } ], precondition : [ { stringAvailable : "customerName" }, { recordNotAvailable : "customer" } ], #enterAttr : "setSubtract(attributes,\"varName\",attributes,\"finder.varName\")" }, {...

23 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Specification Object: Continuation 23 roles : [ { id : "secretary", roleActionList : [ { #enterAndFind : "actions[enterAndFind.customer]" }, { #create : "actions[create.customer]" }, { #enterAndFind : "actions[enterAndFind.part]" }, { confirmed : { #dataTables : "dataTables" } } ] }, { id : "engineer", roleActionList : [ { #create : "actions[create.part]" } ]

24 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Architecture 24 dataTable.java task.java HomePage.jsp createIdRecord.jsp logicData.java enterInputVar.jsp EnterIdData.jsp IdRole.jsp Manager.jsp jump to calls logicServlet.java

25 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Description File 25 output directory ".." // relative to the directory of this file uppercase {equals (id, tableName, inputVar, varName, to)} foreach dataTables, application expand application.version_id + "/Customer.java" to "src/data/"+Id+".java" for whole expand application.version_id+"/Task.java" to "src/data/Task.java" for whole expand "business/LogicServlet.java" to "src/business/LogicServlet.java" for whole expand "business/LogicData.java" to "src/business/LogicData.java" foreach roles, actions, dataTables expand "WebContent/SecretaryRole.jsptmpl" to "WebContent/"+Id+"Role.jsp" for whole expand "WebContent/ERP.jsptmpl" to "WebContent/ERP.jsp" foreach actions where enterAndFind != null expand "WebContent/Enter.jsptmpl" to "WebContent/Enter"+InputVar+".jsp" foreach actions where createRecord != null expand "WebContent/CreateRecord.jsptmpl" to "WebContent/Create"+Id+".jsp" foreach actions where create != null expand "WebContent/EnterData.jsptmpl" to "WebContent/Enter"+Id+"Data.jsp" for whole expand "WebContent/Manager.jspTmpl" to "WebContent/Manager.jsp" for application, dataTables where JPA!=null expand "JPA/persistence.xmlTmpl" to "src/META-INF/persistence.xml" copyfile "WebContent/web.xml" "WebContent/WEB-INF/web.xml" copyfile "JPA/Manager.java" "src/weblangUtils/Manager.java" copyfile "SQL/DBConnection.java" "src/weblangUtils/DBConnection.java" copydir "lib" "/WebContent/WEB-INF/lib"

26 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre 4) DSL : tables 26 dataTable customer { finder string name; int number; OneToMany to confirmedOrder } dataTable part { finder string partId; string grPartInfo; OneToMany to confirmedOrder } dataTable confirmedOrder { string comment; ManyToOne to customer ManyToOne to part } dataTables : [ { id : "customer", attributes : [ { stringAttribute, varName : "name", finder }, { intAttribute, varName : "number" } ], relationships : [ { OneToMany : { to : "confirmedOrder" } } ] }, {

27 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Creation of the DSL 27 Specification Object Linear Object DSL Template Source AST Compiler

28 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Compiler – JavaCC (generated by templates) 28 { "attributes" "{" ( // guarded object obj = stringAttributeProd() { ((JSONObject)obj).names.add(0,"stringAttribute"); ((JSONObject)obj).objects.add(0,new Highlight()); } { attributes.put(obj); } | obj = intAttributeProd() { ((JSONObject)obj).names.add(0,"intAttribute"); ((JSONObject)obj).objects.add(0,new Highlight()); } { attributes.put(obj); } )+ "}" { return attributes; } } optimisation of the language

29 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre actions { enterAndFind { inputVar customerName table customer precondition { stringNotAvailable customerPartId } enterAndFind {... } create { inputVar customerName tableToCreate customer transfers { from customerName to name; } precondition { stringAvailable customerName recordNotAvailable customer } create {... } createRecord {... } } General Ressort DSL: actions and roles 29 roles secretary { enterAndFind customer enterAndFind part create customer createRecord confirmedOrder } roles engineer { create part }

30 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Remarks About the Approach 30 The description file provides the list of all the kinds of components and defines thus the architecture The specification object gives the customer's view The templates implement the platform view

31 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Generation of Web Applications RAD tools: Eclipse/WTP, Ruby on Rails, Spring Roo, Tutorials (quick start + copy and paste) Successful former experience with WebLang A Web application built with our approach and using either SQL, JPA, JSF or PHP from the same object 31

32 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Conclusions The approach only uses elementary statements (like if then else or inherit) No specific library or package required – only (visible) templates Templates have been pulled out of the RAD tool and transferred into the developer's space These templates are highly customizable and reusable 32

33 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Conclusion's Conclusion Programming languages have been developed layer after layer: Modula, Java, Scala ( procedure, object, inheritance, genericity, annotations ) A simple version of DSM can be developed from the JSON templates and make a greater leap forward 33

34 SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Demo ? (Eclipse/TutorialExample) 34


Download ppt "SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor"

Similar presentations


Ads by Google