Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Strategies for Design & Implementation
      of Domain-Specific Languages
               From Java to WebDSL and Back


   ...
Warning: the code fragments in this
   presentation have been grossly
simplified, even when seemingly bulky.

 Consult actu...
Outline



-   Language design strategies
    ★ inductive vs deductive design

-   Compiler architecture
    ★ compilation...
Design Strategies
Designing a Domain-Specific Language




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

-   Analyze problem domain
-   Identify elements to specify
    ★ language constructs

-   Identify/...
Inductive (bottom-up) design


-   Consider best practices in solution domain
-   Identify coding patterns
-   Identify co...
Designing a Domain-Specific Language



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

-   Syntax
    ★ check syntactic well-formedness

-   Static semantics
    ★ consistency checking

...
Compilation by Normalization
Data Model
object identity
entity declaration




                          one-to-many




                                       in...
Entity Declarations to JPA Entity Classes

-   Java Persistence API
-   Entity declaration to Java POJO
    ★ class with p...
Object Identity


-   Automatic identity column for all entities
    ★ UUID
    ★ primary key
    ★ used as foreign key in...
Entity Class

         avoid name clashes




    symbolic identity should be unique
Object Identity
Object Identity




    object identity equals primary key
Value Type Properties




                        avoid name clashes
Many-to-One Properties
                         lazy loading




                            cascading
Inverse Properties




           update other side of relation
HQL Queries
Standard Queries
Standard Queries
Search



-   Lucene / Hibernate Search
    ★ annotations indicate fields to index




-   Search queries
Generating Hibernate Search Annotations
Page Definitions
 & Navigation
GET | POST

         Request       URL

                    Parameters




Client                           Server

      ...
page dispatch




parameter passing
Pages and Templates to Java Classes
Navigate to URL




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



<a href=”/topic/<%t.id%>”> <%t.name%> </a>



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




request transaction
TopicPage.serv




  handle request
TopicPage.serv




  handle request
TopicPage.initVarsAndArgs
TopicPage.loadArguments
TopicPage.loadArguments
Render Page
Render Page
TopicPage.serv




handle post request
TopicPage.serv




handle post request
class TopicPage extends PageServlet {
  serv(request, response, params) {
    transaction = newTransaction();
    initArgu...
class TopicPage {
  render() {
    s = templateServlet.render();
    response.out(“
      <html>
        <head>
          ...
Templates
Template Lifecycle
                                      for
                                          each
              ...
ren
                                      der


                     section nesting




filter special characters
ren
                              der




                     preventing XSS




rendering WikiText
ren
          der




parameter passing
Forms & Data Binding

   form


                                           input

                                        ...
Data Binding Issues




-   Template control-flow
    ★ template calls: inputs may be nested
    ★ if-then-else: elements n...
Repeated Form Elements




              multiple instances per page
Form Abstraction
ren
<p>
                                                          d   er
  <label for="input221c5e4216d4669e62bee33efc845e...
...
                                                   ren
                                                       d   er
<...
ren
                                                        der
<p>
  <label for="input241c5e4216d4669e62bee33efc845eb627"...
More Template Issues


-   Template calls
    ★ element parameters

-   Nested template definitions
    ★ closures

-   Ema...
Access Control
access control implemented by model-to-model transformation
page dispatch takes care of loading & storing session entities
More Compilation by Normalization




-   Validation
    ★ validation rules translated to exceptions and
    ★ see paper

...
Schedule

Lab this week
  ★ 10 days until deadline Design 1

Cases
  ★ Case 2: web abstractions
  ★ See Case 2 for papers ...
Upcoming SlideShare
Loading in …5
×

Strategies for Design & Implementation of Domain-Specific Languages

1,031 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

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
  2. 2. 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.
  3. 3. Outline - Language design strategies ★ inductive vs deductive design - Compiler architecture ★ compilation by normalization - WebDSL translation schemes (sketch) ★ entities, templates, access control, validation
  4. 4. Design Strategies
  5. 5. Designing a Domain-Specific Language How does one find domain-specific abstractions? - Deductive (top-down) design - Inductive (bottom-up) design
  6. 6. 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
  7. 7. 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
  8. 8. Designing a Domain-Specific Language From JPA/Seam/JSF to WebDSL - JPA to entity declarations - JSF to templates - Seam actions See CodeGen 2008 slides
  9. 9. Compiler Architecture
  10. 10. 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
  11. 11. Compilation by Normalization
  12. 12. Data Model
  13. 13. object identity entity declaration one-to-many inverse relation property
  14. 14. 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
  15. 15. 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
  16. 16. Entity Class avoid name clashes symbolic identity should be unique
  17. 17. Object Identity
  18. 18. Object Identity object identity equals primary key
  19. 19. Value Type Properties avoid name clashes
  20. 20. Many-to-One Properties lazy loading cascading
  21. 21. Inverse Properties update other side of relation
  22. 22. HQL Queries
  23. 23. Standard Queries
  24. 24. Standard Queries
  25. 25. Search - Lucene / Hibernate Search ★ annotations indicate fields to index - Search queries
  26. 26. Generating Hibernate Search Annotations
  27. 27. Page Definitions & Navigation
  28. 28. GET | POST Request URL Parameters Client Server status Page Response mime type body
  29. 29. page dispatch parameter passing
  30. 30. Pages and Templates to Java Classes
  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>
  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
  33. 33. TopicPage.serv
  34. 34. TopicPage.serv request transaction
  35. 35. TopicPage.serv handle request
  36. 36. TopicPage.serv handle request
  37. 37. TopicPage.initVarsAndArgs
  38. 38. TopicPage.loadArguments
  39. 39. TopicPage.loadArguments
  40. 40. Render Page
  41. 41. Render Page
  42. 42. TopicPage.serv handle post request
  43. 43. TopicPage.serv handle post request
  44. 44. class TopicPage extends PageServlet { serv(request, response, params) { transaction = newTransaction(); initArguments(params); if(isPost()) { storeInputs(); validateInputs(); handleAction(); } handleExceptions(); render(); storeSessionEntities(); storeMessages(); transaction.commit(); } }
  45. 45. class TopicPage { render() { s = templateServlet.render(); response.out(“ <html> <head> <%includeCSS()%> <%includeJS()%> <%title()%> </head> <body> <%s.write()%> </body> </html> “); } }
  46. 46. Templates
  47. 47. 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
  48. 48. ren der section nesting filter special characters
  49. 49. ren der preventing XSS rendering WikiText
  50. 50. ren der parameter passing
  51. 51. Forms & Data Binding form input binding submit action issue: bind request parameters to correct binding expressions
  52. 52. 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
  53. 53. Repeated Form Elements multiple instances per page
  54. 54. Form Abstraction
  55. 55. 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
  56. 56. ... 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
  57. 57. ren der <p> <label for="input241c5e4216d4669e62bee33efc845eb627"> Text </label> <textarea id="input241c5e4216d4669e62bee33efc845eb627" class="inputTextarea inputWikiText" name="input251c5e4216d4669e62bee33efc845eb627"> value </textarea> </p>
  58. 58. More Template Issues - Template calls ★ element parameters - Nested template definitions ★ closures - Email templates ★ absolute URLs - AJAX templates ★ accessible directly from client as page
  59. 59. Access Control
  60. 60. access control implemented by model-to-model transformation
  61. 61. page dispatch takes care of loading & storing session entities
  62. 62. More Compilation by Normalization - Validation ★ validation rules translated to exceptions and ★ see paper - Workflow ★ workflow procedures & processes ★ translated to functions, access control, user interface
  63. 63. 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

×