presentation

Download Report

Transcript presentation

SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Bottom Up Creation of a DSL
Using JSON Templates
An workbench with a novel editor
http://ltiwww.epfl.ch/BUDE
1
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
2
Template Based Development Environment
Specification object
Enhancement
Generation
Source
DSL
compiler
Template
Template
Template
Javascript object
Enhanced
Editor / generator
Description
JSON
file
Expansion
Generatedfiles
files
Generated
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
The JSON Objects and the Templates
(Introduction)
1. JSON expansion
2. Templates
3. Specification object
4. Description file
3
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Principle of the Expansion of
the JSON Templates!
JSON description
Template
a: [
{item: "carots", price: 12},
{item: "onions", price: 20},
{item: "spinachs", price: 15}
{.repeated section a}
The price of {item} is {price} RS
{.end}
]
Expansion
Resulting page
The price of carots is 12 RS
The price of onions is 20 RS
The price of spinachs is 15 RS
http://json.org
4
SPLASH-DSM'11
Template
Commands
Faculté I&C, Claude Petitpierre
{name}
{.section name}
{.or}
{.end}
{.repeated section name}
{.or}
{.alternates with}
{.end}
{.include "filename"}
5
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
JSON (Javascript) Objects are recursive
{
create : {
id : "customer",
inputVar : "customerName",
attributes : [ {
intAttribute : {
varName : "number"
}
}]
}
[ . . . ] array
}
{ . . . } object
6
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Empty Attribute: conditional generation
{
{
create : {
id : "customer",
selector: { },
inVar : "cName"
}
create : {
selector: {
id : "customer",
inVar : "cName"
}
}
}
}
{.section selector}
String {inVar};
{.end}
// same code generated
// with both objects
7
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Ordered Sequence
attributes : [ {
stringAttribute: {
varName : "name"
}
}, {
intAttribute: {
varName : "number"
}
}]
{.repeated section attributes}
{.section intAttribute}
int {varName} = 0;
{.end}
{.section stringAttribute}
String {varName} = "";
{.end}
{.end}
Expansion
public class Customer {
String name = "";
int number = 0;
}
8
SPLASH-DSM'11
dataTables : [ {
id : "customer",
attributes : [ {
stringAttribute: {
varName : "name",
finder: { }
}
}, {
intAttribute: {
varName : "number"
}
} ],
relationships : [ {
OneToMany : {
to : "confirmedOrder"
}
}]
}
Faculté I&C, Claude Petitpierre
9
Other Example
Result of the expansion
public class Customer {
String name = "";
int number = 0;
public static findByName(String name) {
query = "select * from customer where
name='"+name+"'";
result = execute(query);
}
@OneToMany
public Collection confirmedOrder;
}
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
10
Generation of an Application
(requires a set of files)
{
{.section create}
class {Id} {
String {inpVar}
}
{.end}
dataTables: [ {
id : "customer",
inpVar : "custName"
}]
}
File description
foreach dataTables
expand "dataTemplate.java"
to "src/data/"+Id+".java"
for whole
expand "taskTemplate.java"
to "src/data/Task.java"
Expansion
aaa
aaa
aaa
class bbb
Customer
{
bbbabcd
abcdccc
ccc
abcd
ccc
bbb
String
customerName;
ddd
ddd
ddd
}
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Our Enhancements to
the Specification Object
11
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
12
Computation of the Object Arguments
Specification object
Enhancement
Template
Template
Templates
Description
file
Extended specification object
Expansion
Generatedfiles
files
Generated
Computations are made
in the specification object,
not in the templates
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
13
Computation of Object Arguments
{
create : {
id : "customer",
Id : "Customer",
uppercase {equals (id, inputVar)}
{
create : {
inputVar : "customerName",
InputVar : "CustomerName",
id : "customer",
attributes : [ {
intAttribute : {
varName : "number"
},
_index : "0"
} ],
inputVar : "customerName",
#attributes :
"dataTables[customer].attributes",
#myObject : "myMethod(inputVar)"
}
myObject : "CUSTOMER_NAME"
}
}
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
BUDE: an Eclipse Plugin
Double-click: selection of a file
14
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
15
BUDE
selection
marked if found
highlighted if error
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
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
More Examples
1. Tutorial , tutorial file
2. Menus and submenus in a GUI (intra-file)
3. General Ressort (application level)
4. The DSL compiler itself
17
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
2) Menus of a GUI
{
menus : [ {
id : "Files",
items : [ {
itemId: "Load"
}, {
itemId: "Save"
}]
},{
...
}]
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}
{.end}
}
Expansion
18
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
3) A Workflow: Company General Ressort
create
not
Customer
order
enter
Customer
name
found
Customer
record
createR
(paper)
enter
Customer
part id
found
Confirmed
order
Part record
not
Task
create
Preconditions
(work with A.Wegmann and B.Bajic)
19
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Implementation
x
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
21
List of the Entity Names
roles
actions
temporary variables
data tables
secretary
enterCustomerName
customerName
Customer
findCustomer
customerPartId
name
createCustomer
enterCustomerData
enterCustomerPartId
findPart
engineer
number
Part
partID
ConfirmedOrder
createPart
comment
enterPartData
ManyToOne customer
ManyToOne part
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Specification Object
{
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\")"
}, {
...
22
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Specification Object: Continuation
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]"
}]
}]
23
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Architecture
enterInputVar.jsp
IdRole.jsp
createIdRecord.jsp
logicServlet.java
HomePage.jsp
EnterIdData.jsp
Manager.jsp
logicData.java
jump to
task.java
calls
dataTable.java
24
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
25
Description File
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"
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
26
4) DSL : tables
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"
}
}]
}, {
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Creation of the DSL
Specification
Object
Source
Linear
Object
AST
Compiler
DSL
Template
27
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Compiler – JavaCC
(generated by templates)
{
optimisation of the language
"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; }
}
28
SPLASH-DSM'11
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 { . . . }
}
Faculté I&C, Claude Petitpierre
General Ressort DSL:
actions and roles
roles secretary {
enterAndFind customer
enterAndFind part
create customer
createRecord confirmedOrder
}
roles engineer {
create part
}
29
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Remarks About the Approach
• 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
30
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
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
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
SPLASH-DSM'11
Faculté I&C, Claude Petitpierre
Demo ?
(Eclipse/TutorialExample)
34