Strategies for Design & Implementation
           of Domain-Specific Languages
                          From Java to WebDS...
ARE YOU RECORDING THIS?




Tuesday, March 16, 2010
Warning: the code fragments in this
                             presentation have been grossly
                          ...
Outline



                -         Language design strategies
                          ★ inductive vs deductive design
...
Design Strategies



Tuesday, March 16, 2010
Designing a Domain-Specific Language




                How does one find domain-specific abstractions?
                -   ...
Deductive (top-down)

                -         Analyze problem domain
                -         Identify elements to spec...
Inductive (bottom-up) design


                -         Consider best practices in solution domain
                -     ...
Designing a Domain-Specific Language



                From JPA/Seam/JSF to WebDSL
                -         JPA to entity...
Compiler Architecture



Tuesday, March 16, 2010
Compiler Architecture

                -         Syntax
                          ★ check syntactic well-formedness

     ...
Compilation by Normalization




Tuesday, March 16, 2010
Data Model



Tuesday, March 16, 2010
object identity
     entity declaration




                               one-to-many




                               ...
Entity Declarations to JPA Entity Classes

                -         Java Persistence API
                -         Entity...
Object Identity


                -         Automatic identity column for all entities
                          ★ UUID
  ...
Entity Class

                                   avoid name clashes




                              symbolic identity sh...
Object Identity




                              object identity equals primary key
Tuesday, March 16, 2010
Value Type Properties




                                                  avoid name clashes




Tuesday, March 16, 2010
Many-to-One Properties
                                                   lazy loading




                               ...
Inverse Properties




                                     update other side of relation
Tuesday, March 16, 2010
HQL Queries




Tuesday, March 16, 2010
Standard Queries




Tuesday, March 16, 2010
Standard Queries




Tuesday, March 16, 2010
Search



                -         Lucene / Hibernate Search
                          ★ annotations indicate fields to in...
Generating Hibernate Search Annotations




Tuesday, March 16, 2010
Page Definitions
                           & Navigation


Tuesday, March 16, 2010
GET | POST

                                   Request       URL

                                              Parameters...
page dispatch




   parameter passing




Tuesday, March 16, 2010
Pages and Templates to Java Classes




Tuesday, March 16, 2010
Navigate to URL




                          navigate(topic(t){output(t.name)}



       <a href=”/topic/<%t.id%>”> <%t.n...
GET | POST                                  name    class
      Request               URL         Dispatch                ...
TopicPage.serv




                          request transaction
Tuesday, March 16, 2010
TopicPage.serv




                            handle request
Tuesday, March 16, 2010
TopicPage.initVarsAndArgs




Tuesday, March 16, 2010
TopicPage.loadArguments




Tuesday, March 16, 2010
Render Page




Tuesday, March 16, 2010
TopicPage.serv




                          handle post request
Tuesday, March 16, 2010
class TopicPage extends PageServlet {
                            serv(request, response, params) {
                      ...
class TopicPage {
                            render() {
                              s = templateServlet.render();
     ...
Templates



Tuesday, March 16, 2010
Template Lifecycle
                                                            for
                                       ...
ren
                                                                der


                                               s...
ren
                                             der




                                    preventing XSS




          ...
ren
                                    der




                          parameter passing




Tuesday, March 16, 2010
Forms & Data Binding

                   form


                                                      input

             ...
Data Binding Issues




                -         Template control-flow
                          ★ template calls: inputs ...
Repeated Form Elements




                                        multiple instances per page




Tuesday, March 16, 2010
Form Abstraction




Tuesday, March 16, 2010
ren
      <p>
                                                                d   er
        <label for="input221c5e4216d4...
...
                                                                 ren
                                                 ...
ren
                                                                    der
            <p>
              <label for="inpu...
More Template Issues


                -         Template calls
                          ★ element parameters

          ...
Access Control



Tuesday, March 16, 2010
access control implemented by model-to-model transformation
Tuesday, March 16, 2010
page dispatch takes care of loading & storing session entities


Tuesday, March 16, 2010
More Compilation by Normalization




                -         Validation
                          ★ validation rules tr...
Schedule

                Lab this week
                          ★ 10 days until deadline Design 1

                Cases...
Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages
Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages
Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages
Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages
Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages
Upcoming SlideShare
Loading in …5
×

Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages

1,745 views

Published on

Lecture 5 of course on Model-Driven Software Development about Strategies for Design & Implementation of Domain-Specific Languages, discussing design and implementation of WebDSL

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,745
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
45
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Model-Driven Software Development - Strategies for Design & Implementation of Domain-Specific Languages

  1. 1. Strategies for Design & Implementation of Domain-Specific Languages From Java to WebDSL and Back Lecture 5 Course IN4308 Eelco Visser Master Computer Science http://eelcovisser.org Delft University of Technology Tuesday, March 16, 2010
  2. 2. ARE YOU RECORDING THIS? Tuesday, March 16, 2010
  3. 3. Warning: the code fragments in this presentation have been grossly simplified, even when seemingly bulky. Consult actual code generated by WebDSL compiler to get the full story. Tuesday, March 16, 2010
  4. 4. Outline - Language design strategies ★ inductive vs deductive design - Compiler architecture ★ compilation by normalization - WebDSL translation schemes (sketch) ★ entities, templates, access control, validation Tuesday, March 16, 2010
  5. 5. Design Strategies Tuesday, March 16, 2010
  6. 6. Designing a Domain-Specific Language How does one find domain-specific abstractions? - Deductive (top-down) design - Inductive (bottom-up) design Tuesday, March 16, 2010
  7. 7. Deductive (top-down) - Analyze problem domain - Identify elements to specify ★ language constructs - Identify/design solution domain ★ architecture, technology, - Investigate implementation ★ code generation templates - Risk ★ design language that is hard to implement Tuesday, March 16, 2010
  8. 8. Inductive (bottom-up) design - Consider best practices in solution domain - Identify coding patterns - Identify commonality ★ code generation templates - Identify variability ★ language constructs - Risk ★ design language that is too low-level Tuesday, March 16, 2010
  9. 9. Designing a Domain-Specific Language From JPA/Seam/JSF to WebDSL - JPA to entity declarations - JSF to templates - Seam actions See CodeGen 2008 slides Tuesday, March 16, 2010
  10. 10. Compiler Architecture Tuesday, March 16, 2010
  11. 11. Compiler Architecture - Syntax ★ check syntactic well-formedness - Static semantics ★ consistency checking - Model-to-model transformation ★ desugaring: express constructs in core language ★ add higher-level abstractions - Code generation ★ translate core language models to implementation Tuesday, March 16, 2010
  12. 12. Compilation by Normalization Tuesday, March 16, 2010
  13. 13. Data Model Tuesday, March 16, 2010
  14. 14. object identity entity declaration one-to-many inverse relation property Tuesday, March 16, 2010
  15. 15. Entity Declarations to JPA Entity Classes - Java Persistence API - Entity declaration to Java POJO ★ class with private fields, getters, and setters ★ annotations • values • relations: one-to-many, many-to-one ★ object identity - Object-relational mapping ★ entity classes to database tables ★ properties to columns Tuesday, March 16, 2010
  16. 16. Object Identity - Automatic identity column for all entities ★ UUID ★ primary key ★ used as foreign key in relations - Custom symbolic id property ★ key :: String (id) ★ can be changed without compromising foreign keys ★ symbolic id used in URL Tuesday, March 16, 2010
  17. 17. Entity Class avoid name clashes symbolic identity should be unique Tuesday, March 16, 2010
  18. 18. Object Identity object identity equals primary key Tuesday, March 16, 2010
  19. 19. Value Type Properties avoid name clashes Tuesday, March 16, 2010
  20. 20. Many-to-One Properties lazy loading cascading Tuesday, March 16, 2010
  21. 21. Inverse Properties update other side of relation Tuesday, March 16, 2010
  22. 22. HQL Queries Tuesday, March 16, 2010
  23. 23. Standard Queries Tuesday, March 16, 2010
  24. 24. Standard Queries Tuesday, March 16, 2010
  25. 25. Search - Lucene / Hibernate Search ★ annotations indicate fields to index - Search queries Tuesday, March 16, 2010
  26. 26. Generating Hibernate Search Annotations Tuesday, March 16, 2010
  27. 27. Page Definitions & Navigation Tuesday, March 16, 2010
  28. 28. GET | POST Request URL Parameters Client Server status Page Response mime type body Tuesday, March 16, 2010
  29. 29. page dispatch parameter passing Tuesday, March 16, 2010
  30. 30. Pages and Templates to Java Classes Tuesday, March 16, 2010
  31. 31. Navigate to URL navigate(topic(t){output(t.name)} <a href=”/topic/<%t.id%>”> <%t.name%> </a> <a href=”/topic/FooBar”>FooBar</a> Tuesday, March 16, 2010
  32. 32. GET | POST name class Request URL Dispatch topic Parameters edittopic page dispatch table param value t Foobar param map TopicPage status Response mime type serv body Tuesday, March 16, 2010
  33. 33. TopicPage.serv request transaction Tuesday, March 16, 2010
  34. 34. TopicPage.serv handle request Tuesday, March 16, 2010
  35. 35. TopicPage.initVarsAndArgs Tuesday, March 16, 2010
  36. 36. TopicPage.loadArguments Tuesday, March 16, 2010
  37. 37. Render Page Tuesday, March 16, 2010
  38. 38. TopicPage.serv handle post request Tuesday, March 16, 2010
  39. 39. class TopicPage extends PageServlet { serv(request, response, params) { transaction = newTransaction(); initArguments(params); if(isPost()) { storeInputs(); validateInputs(); handleAction(); } handleExceptions(); render(); storeSessionEntities(); storeMessages(); transaction.commit(); } } Tuesday, March 16, 2010
  40. 40. class TopicPage { render() { s = templateServlet.render(); response.out(“ <html> <head> <%includeCSS()%> <%includeJS()%> <%title()%> </head> <body> <%s.write()%> </body> </html> “); } } Tuesday, March 16, 2010
  41. 41. Templates Tuesday, March 16, 2010
  42. 42. Template Lifecycle for each tem - Store inputs plat e ★ bind request parameters to form inputs - Validate inputs ★ check validation rules - Handle action ★ execute selected action - Render ★ print markup ★ render properties of objects Tuesday, March 16, 2010
  43. 43. ren der section nesting filter special characters Tuesday, March 16, 2010
  44. 44. ren der preventing XSS rendering WikiText Tuesday, March 16, 2010
  45. 45. ren der parameter passing Tuesday, March 16, 2010
  46. 46. Forms & Data Binding form input binding submit action issue: bind request parameters to correct binding expressions Tuesday, March 16, 2010
  47. 47. Data Binding Issues - Template control-flow ★ template calls: inputs may be nested ★ if-then-else: elements not always present ★ for-loop: multiple occurrences of same form Tuesday, March 16, 2010
  48. 48. Repeated Form Elements multiple instances per page Tuesday, March 16, 2010
  49. 49. Form Abstraction Tuesday, March 16, 2010
  50. 50. ren <p> d er <label for="input221c5e4216d4669e62bee33efc845eb627"> Title </label> <input type="text" value="LoremIpsum" class="inputString" id="input221c5e4216d4669e62bee33efc845eb627" name="input231c5e4216d4669e62bee33efc845eb627"> </p> stor e inpu ts Tuesday, March 16, 2010
  51. 51. ... ren d er <form onsubmit="return clickFirstButton(this);" method="POST" accept-charset="UTF-8" action="http://localhost:8080/wiki/editpage2/LoremIpsum" id="form51c5e4216d4669e62bee33efc845eb627" name="form51c5e4216d4669e62bee33efc845eb627"> <input type="hidden" value="1" name="form51c5e4216d4669e62bee33efc845eb627"> <input type="hidden" value="LoremIpsum" name="p"> ... <input type="submit" class="button" value="Save" name="action61c5e4216d4669e62bee33efc845eb627"> </form> handle action bind action to action code Tuesday, March 16, 2010
  52. 52. ren der <p> <label for="input241c5e4216d4669e62bee33efc845eb627"> Text </label> <textarea id="input241c5e4216d4669e62bee33efc845eb627" class="inputTextarea inputWikiText" name="input251c5e4216d4669e62bee33efc845eb627"> value </textarea> </p> Tuesday, March 16, 2010
  53. 53. More Template Issues - Template calls ★ element parameters - Nested template definitions ★ closures - Email templates ★ absolute URLs - AJAX templates ★ accessible directly from client as page Tuesday, March 16, 2010
  54. 54. Access Control Tuesday, March 16, 2010
  55. 55. access control implemented by model-to-model transformation Tuesday, March 16, 2010
  56. 56. page dispatch takes care of loading & storing session entities Tuesday, March 16, 2010
  57. 57. More Compilation by Normalization - Validation ★ validation rules translated to exceptions and ★ see paper - Workflow ★ workflow procedures & processes ★ translated to functions, access control, user interface Tuesday, March 16, 2010
  58. 58. Schedule Lab this week ★ 10 days until deadline Design 1 Cases ★ Case 2: web abstractions ★ See Case 2 for papers to read Next ★ Lecture 6: language workbenches, modeling languages ★ Lecture 7: basic code generation Tuesday, March 16, 2010

×