SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
Using Stratego/XT for
Generation of Software
    Connectors

        Michal Malohlava
   Supervisor: RNDr. Tomáš Bureš, Ph. D.

 DISTRIBUTED SYSTEMS RESEARCH GROUP
           http://dsrg.mff.cuni.cz/

    CHARLES UNIVERSITY IN PRAGUE
     Faculty of Mathematics and Physics
Outline
    Connector generation
●


    Existing connector generator overview
●


    Stratego/XT overview
●


    Proposed solution
●


    Conclusion
●




                                            2
Connectors? Generation? Why?
    Why should be component interested in communication?
●


         It should just implement business logic
     –

    => Connectors
●


         Displace communication matters from components
     –

         Design time view
     –

              Model component interaction (communication style, NFP)
          ●



         Run-time view
     –

              Implements interaction with help of some middleware
          ●


              Additional services (e.g. Logging)
          ●



    Preparation of connectors
●



         During deployment time
     –

              complete info about application and its distribution
          ●

                                                                        3
              Automatic generation (component interface, depl. docks,
          ●

              requirements, code template)
General goal
    Define and implement simple method of
●

    defining connectors implementations
        Template based system
    –

        Source code generation
    –

        Integrate new solution with existing solution
    –

             Non-invasively (preserve original functionality)
         ●




                                                                4
Connector architecture
    Connector
●


        Connector units
    –

             Connector elements
         ●




                                  5
Existing connector generator
    Architecture resolver
●



         Find architecture of connector in according to described
     –
         requirements (HLCS)
    Source code generation
●



         Driven by generation script
     –

         Generates Java code
     –

              Per conn. element
          ●


              Simple templates
          ●


         Compile java code
     –

         Package binaries
     –



                                                                    6
Existing connector generator
    Simple code templates which are processed by Java class
●



         Class just substitutes parts enclosed in % by Java code
     –

    Sufficient for primitive connector elements, but composite
●

    element looks like this:
    package %PACKAGE%;
    imports org...runtime.*;
    public class %CLASS% implements
           ElementLocalServer ,
           ElementLocalClient ,
           ElementRemoteServer ,
           ElementRemoteClient {
           protected Element[] subElements ;
           protected UnitReferenceBundle[] boundedToRRef;
           public %CLASS%( ) {
           }
          %INIT METHODS% // this part processed by special
                             Java class
    }                                                              7
Existing connector generator
    Simple code templates which are processed by Java class
●



         Class just substitutes parts enclosed in % by Java code
     –

    Sufficient for primitive connector elements, but composite
●

    element looks like this:
    package %PACKAGE%;
    imports org...runtime.*;
    public class %CLASS% implements This variable is unfolded
                                       into into 200LOC by
           ElementLocalServer ,
                                          Java class with
           ElementLocalClient ,
                                             1200LOC!
           ElementRemoteServer ,
           ElementRemoteClient {
           protected Element[] subElements ;
           protected UnitReferenceBundle[] boundedToRRef;
           public %CLASS%( ) {
           }
          %INIT METHODS% // this part processed by special
                             Java class
    }                                                              8
Stratego/XT
    Developed at Delft University of Technology,
●

    Netherlands (Eelco Visser, Martin Bravenboer)
    Tool set
●


        Grammar tools
    –

             SDF – Syntax Definition Formalism
         ●


             Pretty printers
         ●


             Grammar definitions (Java, C/C++, XML, ...)
         ●



        Program transformation language Stratego
    –

             Based on AST rewriting via strategies
         ●




                                                           9
Stratego/XT - architecture
    How does it work?
●




                             10
Stratego/XT - SDF
    Modular, one grammar defines:
●



        Lexical tokens
    –

        Context-free rules
    –

    Generation of parser (scannerless generalized LR parser)
●



        Generates “a forest of Abstract Syntax Trees (AST)”
    –

             ambiguous parts are explicitly marked
         ●



        AST represented by ATerm
    –




                                                               11
Stratego/XT – SDF example
module Expr−literals                module Expr−expressions

                                    imports Expr−literals
exports

                                    exports
      sorts Int
lexical syntax                            sorts Exp
                                    context−free syntax
      ”0” −> Int
      [1−9][0−9]* −> Int             I n t −> Exp { cons ( ” I n t ” )}
lexical restrictions                 Exp ”+” Exp −> Exp { cons ( ”Add” ) , assoc}
      Int −/− [0−9]                  Exp ”−” Exp −> Exp { cons ( ”Sub” ) , left }

                                     Exp ” *” Exp −> Exp { cons ( ”Mul ” ) , assoc}

                                     Exp ” / ” Exp −> Exp { cons ( ” Div ” ) , assoc}

                                     Exp ” ˆ ” Exp −> Exp { cons ( ”Pow” ) , right }

                                     ” ( ” Exp ” ) ” −> Exp { bracket }


    SDF grammar for simple language describing numerical expressions
●

                                                                                        12
Stratego/XT – Stratego language
    Based on strategies manipulating with AST
●



         Input/Output: AST represented by ATerms
     –

    Rewriting strategies and rules
●



         Strategy
     –

              Describes how is AST traversed and rewrited
          ●


         Rule
     –

              simple rewrite strategy ( Rule: A -> B <=> ?A; !B)
          ●


              Many predefined strategies and rules for AST traversing (id, fail,
          ●

              bottomup, topdown, try,...), system access strategies (e.g. ls,
              chmod, open_file,...)
         Dynamic rules
     –

              Allows creating rewrite rules on the fly in according to context
          ●


    Program in Stratego language is translated into C and compiled 13
●
Stratego/XT – Stratego example
module EExpr
imports liblib Expr−eval
strategies
   io−EExpr = io−wrap ( expr−eval )


imports Expr
strategies
  expr-eval = innermost(EvalAdd <+ EvalMul <+ EvalSub
                        <+ EvalDiv <+ EvalPow)
rules
  EvalAdd: Add(Int(i), Int(j)) -> Int(<addS>(i,j))
  EvalSub: Sub(Int(i), Int(j)) -> Int(<subtS>(i,j))
  EvalMul: Mul(Int(i), Int(j)) -> Int(<mulS>(i,j))
  EvalDiv: Div(Int(i), Int(j)) -> Int(<divS>(i,j))
  EvalPow: Pow(Int(i), Int(j)) -> Int(<powS>(i,j))
strategies
  powS = (string-to-int, string-to-int); pow; int-to-string
                                                               14
  pow = ?(A,B); <copy>(B, A); foldr(!1, mul) // à la Haskell
Goals revisited
    Rebuild source code generator
●


        Design more sophisticated templates based on DSL
    –

        Implement source code generator
    –

        Test eligibility of Stratego/XT for this purposes
    –

        Incorporate the developed connector element code
    –
        generator into the existing solution




                                                            15
Solution – DSL
    Designed new Domain Specific Language
●



        Mixture of meta-language ElLang and target language (Java)
    –

             MetaBorg method developed by Stratego/XT group
         ●


                  Allows embedding language into another language
              –

                  Connecting selected nonterminals of both languages
              –
                    ● Defined via SDF


    Meta-language ElLang
●



        Meta-variables
    –

             ${a}, ${a[index]}
         ●


        Meta-queries
    –

             ${a.b.c}
         ●


        Meta-statements
    –

             $set, $if, $include, $foreach, $rforeach                  16
         ●
Solution – DSL
    Designed new Domain Specific Language
●


     – Recursive foreach – designed ElLang of Java grammar constraints
       Mixture of meta-language because and target language (Java)
               MetaBorg method developed by Stratego/XT group
           ●

         $rforeach(PORT in ${ports.port(type=PROVIDED)} )$
          if (quot;${PORT.name}quot;.equals(portName)) {into another language
                 – Allows embedding language

            ObjectConnecting selected neterminals of both languages
                 – result = ((ElementLocalServer) subElements[${el[PORT....]}]);

                        Defined via SDF
                    ●
         if (isTopLevel) {
    Meta-language ElLang
●
           dcm.reregisterConnectorUnitReference(parentUnit, portName, result);
         }
     – Meta-variables
         return result;
       } else $recpoint$
         ● ${a}, ${a[index]}
       $final$
          throw new ElementLinkException(quot;Invalid port 'quot;+portName+quot;'.quot;);
     – Meta-queries
       $end$
               ${a.b.c}
           ●


         Meta-statements
     –

               $set, $if, $include, $foreach, $rforeach                            17
           ●
Solution - DSL
    Special meta-statements
●


        Simple templates inheritance (extends)
    –

        Extension points ($extPoint$)
    –

             Allow define points in template which can be extended in a
         ●

             child template
        Method templates
    –

             Important for implementing component interfaces
         ●


                  ! component iface is not known when template is designing !
              –

             Language should provides information about iface
         ●

             methods
                  ${method.name}, ${method.variables}, ...
              –
                                                                                18
Solution - DSL
    Special meta-statements
      element console_log extends quot;primitive_default.ellangquot; {
●
          implements interface ${ports.port(name=in).signature} {
         Simplemethod template inheritance (extends)
                templates {
     –             ${method.declareReturnValue}

         ExtensionSystem.out.println(quot;method > ${method.name} < calledquot;);
                   points ($extPoint$)
     –

              Allow define points in template which can be extended in a
                       $if (method.returnVar) $
          ●

              child template${method.returnVar}
                      = this.target.${method.name}(${method.variables});
     – Method templates
                 $else$
                      this.target.${method.name}(${method.variables});
        ● Important for implementing component interfaces
                 $end$
                   ! component iface is not known when needed
                        //generates return statemene if it is templates is designing !
               –

              Language should provides information about iface
                     ${method.returnStm}
          ●
                  }
              methods
               }
          }        ${method.name}, ${method.variables}, ...
               –
                                                                                         19
Solution – template structure
    ElLang-J = mixture of ElLang and Java
●



         package ${package};
         import org . . . runtime .* ;

         element console_log extends “primitive_default.ellang” {
           public ${classname} { / / constructor
           }

           implements interface ElementLocalClient {
             public void bindElPort(String portName , Object target ) {
               /* ... */
             }
           }
          implements interface ${ ports.port (name=line).signature} {
            method template {
            }
          }
                                                                          20
Solution – generator architecture
    Java part
●


        Prepares low-level connector configuration
    –

             Description of connector element internals
         ●



    Stratego part
●


        Generates source code
    –

             From template written in ElLang-J
         ●


             From L-LCC passed from Java part of generator
         ●




                                                             21
Solution - Java part
    Implementing action interface
●

    JimplGeneratorInterface

         rewrites Low-Level
     –
         Connector configuration
         into XML and passed it to
         Stratego part
         Just defines new action for
     –
         script controlling
         generation
    Bridge between Java and
●

    Stratego:
         JNI
     –

         Shell (execute connector
     –
                                       22
         generator)
Solution – Java v. Stratego part
    low-level connector
●

    configuration
            Describes ports
        ●


                 Name
             –

                 Type (provided, required,
             –
                 remote)
                 Resolved port signature
             –

            List of subelements
        ●


                 Name
             –

                 Implementing class
             –

            Bindings between
        ●

            subelements
            Selects template for
        ●

            implementation

                                             23
Solution – Stratego part
    Pipe line of several small
●

    transformation components
        Input XML preprocessor
    –

        Template parser
    –

        Template evaluation
    –

        Target code gen.
    –

        Query component
    –

    All of them transform and
●

    produce AST (in ATerms)


                                 24
Solution – Query module
    Provides access to input XML (contains L-LCC)
●


        Simple queries à la XPath
    –

             Traversing XML
         ●


                  ${ports.port.name}
              –
                   ●


             conditions
         ●


                ${ports.port(name=call).signature}
              –
                  ● Returns signature of port called “call”


             Count operator
         ●


              – ${elements.element#count}
                  ● Returns number of sub-elements




                                                              25
Solution – evaluation module
    Pipe-line of evaluation modules
●


        Processing extends
    –

        Processing imports
    –

        Template adjustment
    –

             Normalization of statements with different notations
         ●


                  e.g. If -> If-Else ( in ATerms: If(cond,body) -> If(cond, body, []))
              –

        Queries evaluation
    –

        Meta-statements evaluation
    –




                                                                                         26
Evaluation (pro-and-con)
    Advantages
●



        Simple template which has at least the same power as the
    –
        previous solution
             Shown by implementing all connectors elements into new
         ●

             templates
        Extensible template language (e.g. ElLang-C#)
    –

        New generator can be used just by modifying script
    –
        controlling connector generation
    Disadvantages
●



        Stratego/XT is C-based, rest of generator is in Java
    –

             ? Java implementation of Stratego ?
         ●



        Annoying long-time compilation of longer Stratego programs
    –

             Should be fixed in new release of Stratego
         ●
                                                                      27
Future work
    Byte code manipulation
●


        To avoid need of javac (~SDK) during deployment
    –
        process
        Templates are precompiled into binary form
    –

        Presented and implemented in master thesis
    –
        “Optimizing performance of software connectors
        code generator”, Pavel Petřek
    Simplifying connectors
●


        Merging generated Java classes
    –

    Implements ElLang-C#
●

                                                          28
    Improve method templates
●
Results
    T. Bureš, M. Malohlava, P. Hnětynka “Using
●

    DSL for Automatic Generation of Software
    Connector”
        Accepted at 7th IEEE International Conference on
    –
        Composition Based Software Systems (ICCBSS),
        Madrid, February 2008




                                                           29

Mais conteúdo relacionado

Mais procurados (20)

Gdb cheat sheet
Gdb cheat sheetGdb cheat sheet
Gdb cheat sheet
 
Core java
Core javaCore java
Core java
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Code generating beans in Java
Code generating beans in JavaCode generating beans in Java
Code generating beans in Java
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 
Clojure A Dynamic Programming Language for the JVM
Clojure A Dynamic Programming Language for the JVMClojure A Dynamic Programming Language for the JVM
Clojure A Dynamic Programming Language for the JVM
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Basics
Java BasicsJava Basics
Java Basics
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
 
Java Basics
Java BasicsJava Basics
Java Basics
 

Semelhante a Generate Software Connectors Using Stratego/XT

[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cooljavablend
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
Using DSL for generation of software connectors
Using DSL for generation of software connectorsUsing DSL for generation of software connectors
Using DSL for generation of software connectorsMichal Malohlava
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDTBastian Feder
 
Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)Robin Fernandes
 
The Lumber Mill Xslt For Your Templates
The Lumber Mill   Xslt For Your TemplatesThe Lumber Mill   Xslt For Your Templates
The Lumber Mill Xslt For Your TemplatesThomas Weinert
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017Ayush Sharma
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPSVaclav Pech
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Bastian Feder
 

Semelhante a Generate Software Connectors Using Stratego/XT (20)

[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
Using DSL for generation of software connectors
Using DSL for generation of software connectorsUsing DSL for generation of software connectors
Using DSL for generation of software connectors
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
55j7
55j755j7
55j7
 
Extending and scripting PDT
Extending and scripting PDTExtending and scripting PDT
Extending and scripting PDT
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDT
 
Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)
 
The Lumber Mill Xslt For Your Templates
The Lumber Mill   Xslt For Your TemplatesThe Lumber Mill   Xslt For Your Templates
The Lumber Mill Xslt For Your Templates
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
XML parsing using jaxb
XML parsing using jaxbXML parsing using jaxb
XML parsing using jaxb
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009
 

Último

B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxpriyanshujha201
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...anilsa9823
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
Best Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaBest Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaShree Krishna Exports
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Roland Driesen
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...Suhani Kapoor
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst SummitHolger Mueller
 
Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...
Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...
Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...lizamodels9
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
 

Último (20)

B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
Best Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaBest Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in India
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst Summit
 
Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...
Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...
Call Girls In Holiday Inn Express Gurugram➥99902@11544 ( Best price)100% Genu...
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 

Generate Software Connectors Using Stratego/XT

  • 1. Using Stratego/XT for Generation of Software Connectors Michal Malohlava Supervisor: RNDr. Tomáš Bureš, Ph. D. DISTRIBUTED SYSTEMS RESEARCH GROUP http://dsrg.mff.cuni.cz/ CHARLES UNIVERSITY IN PRAGUE Faculty of Mathematics and Physics
  • 2. Outline Connector generation ● Existing connector generator overview ● Stratego/XT overview ● Proposed solution ● Conclusion ● 2
  • 3. Connectors? Generation? Why? Why should be component interested in communication? ● It should just implement business logic – => Connectors ● Displace communication matters from components – Design time view – Model component interaction (communication style, NFP) ● Run-time view – Implements interaction with help of some middleware ● Additional services (e.g. Logging) ● Preparation of connectors ● During deployment time – complete info about application and its distribution ● 3 Automatic generation (component interface, depl. docks, ● requirements, code template)
  • 4. General goal Define and implement simple method of ● defining connectors implementations Template based system – Source code generation – Integrate new solution with existing solution – Non-invasively (preserve original functionality) ● 4
  • 5. Connector architecture Connector ● Connector units – Connector elements ● 5
  • 6. Existing connector generator Architecture resolver ● Find architecture of connector in according to described – requirements (HLCS) Source code generation ● Driven by generation script – Generates Java code – Per conn. element ● Simple templates ● Compile java code – Package binaries – 6
  • 7. Existing connector generator Simple code templates which are processed by Java class ● Class just substitutes parts enclosed in % by Java code – Sufficient for primitive connector elements, but composite ● element looks like this: package %PACKAGE%; imports org...runtime.*; public class %CLASS% implements ElementLocalServer , ElementLocalClient , ElementRemoteServer , ElementRemoteClient { protected Element[] subElements ; protected UnitReferenceBundle[] boundedToRRef; public %CLASS%( ) { } %INIT METHODS% // this part processed by special Java class } 7
  • 8. Existing connector generator Simple code templates which are processed by Java class ● Class just substitutes parts enclosed in % by Java code – Sufficient for primitive connector elements, but composite ● element looks like this: package %PACKAGE%; imports org...runtime.*; public class %CLASS% implements This variable is unfolded into into 200LOC by ElementLocalServer , Java class with ElementLocalClient , 1200LOC! ElementRemoteServer , ElementRemoteClient { protected Element[] subElements ; protected UnitReferenceBundle[] boundedToRRef; public %CLASS%( ) { } %INIT METHODS% // this part processed by special Java class } 8
  • 9. Stratego/XT Developed at Delft University of Technology, ● Netherlands (Eelco Visser, Martin Bravenboer) Tool set ● Grammar tools – SDF – Syntax Definition Formalism ● Pretty printers ● Grammar definitions (Java, C/C++, XML, ...) ● Program transformation language Stratego – Based on AST rewriting via strategies ● 9
  • 10. Stratego/XT - architecture How does it work? ● 10
  • 11. Stratego/XT - SDF Modular, one grammar defines: ● Lexical tokens – Context-free rules – Generation of parser (scannerless generalized LR parser) ● Generates “a forest of Abstract Syntax Trees (AST)” – ambiguous parts are explicitly marked ● AST represented by ATerm – 11
  • 12. Stratego/XT – SDF example module Expr−literals module Expr−expressions imports Expr−literals exports exports sorts Int lexical syntax sorts Exp context−free syntax ”0” −> Int [1−9][0−9]* −> Int I n t −> Exp { cons ( ” I n t ” )} lexical restrictions Exp ”+” Exp −> Exp { cons ( ”Add” ) , assoc} Int −/− [0−9] Exp ”−” Exp −> Exp { cons ( ”Sub” ) , left } Exp ” *” Exp −> Exp { cons ( ”Mul ” ) , assoc} Exp ” / ” Exp −> Exp { cons ( ” Div ” ) , assoc} Exp ” ˆ ” Exp −> Exp { cons ( ”Pow” ) , right } ” ( ” Exp ” ) ” −> Exp { bracket } SDF grammar for simple language describing numerical expressions ● 12
  • 13. Stratego/XT – Stratego language Based on strategies manipulating with AST ● Input/Output: AST represented by ATerms – Rewriting strategies and rules ● Strategy – Describes how is AST traversed and rewrited ● Rule – simple rewrite strategy ( Rule: A -> B <=> ?A; !B) ● Many predefined strategies and rules for AST traversing (id, fail, ● bottomup, topdown, try,...), system access strategies (e.g. ls, chmod, open_file,...) Dynamic rules – Allows creating rewrite rules on the fly in according to context ● Program in Stratego language is translated into C and compiled 13 ●
  • 14. Stratego/XT – Stratego example module EExpr imports liblib Expr−eval strategies io−EExpr = io−wrap ( expr−eval ) imports Expr strategies expr-eval = innermost(EvalAdd <+ EvalMul <+ EvalSub <+ EvalDiv <+ EvalPow) rules EvalAdd: Add(Int(i), Int(j)) -> Int(<addS>(i,j)) EvalSub: Sub(Int(i), Int(j)) -> Int(<subtS>(i,j)) EvalMul: Mul(Int(i), Int(j)) -> Int(<mulS>(i,j)) EvalDiv: Div(Int(i), Int(j)) -> Int(<divS>(i,j)) EvalPow: Pow(Int(i), Int(j)) -> Int(<powS>(i,j)) strategies powS = (string-to-int, string-to-int); pow; int-to-string 14 pow = ?(A,B); <copy>(B, A); foldr(!1, mul) // à la Haskell
  • 15. Goals revisited Rebuild source code generator ● Design more sophisticated templates based on DSL – Implement source code generator – Test eligibility of Stratego/XT for this purposes – Incorporate the developed connector element code – generator into the existing solution 15
  • 16. Solution – DSL Designed new Domain Specific Language ● Mixture of meta-language ElLang and target language (Java) – MetaBorg method developed by Stratego/XT group ● Allows embedding language into another language – Connecting selected nonterminals of both languages – ● Defined via SDF Meta-language ElLang ● Meta-variables – ${a}, ${a[index]} ● Meta-queries – ${a.b.c} ● Meta-statements – $set, $if, $include, $foreach, $rforeach 16 ●
  • 17. Solution – DSL Designed new Domain Specific Language ● – Recursive foreach – designed ElLang of Java grammar constraints Mixture of meta-language because and target language (Java) MetaBorg method developed by Stratego/XT group ● $rforeach(PORT in ${ports.port(type=PROVIDED)} )$ if (quot;${PORT.name}quot;.equals(portName)) {into another language – Allows embedding language ObjectConnecting selected neterminals of both languages – result = ((ElementLocalServer) subElements[${el[PORT....]}]); Defined via SDF ● if (isTopLevel) { Meta-language ElLang ● dcm.reregisterConnectorUnitReference(parentUnit, portName, result); } – Meta-variables return result; } else $recpoint$ ● ${a}, ${a[index]} $final$ throw new ElementLinkException(quot;Invalid port 'quot;+portName+quot;'.quot;); – Meta-queries $end$ ${a.b.c} ● Meta-statements – $set, $if, $include, $foreach, $rforeach 17 ●
  • 18. Solution - DSL Special meta-statements ● Simple templates inheritance (extends) – Extension points ($extPoint$) – Allow define points in template which can be extended in a ● child template Method templates – Important for implementing component interfaces ● ! component iface is not known when template is designing ! – Language should provides information about iface ● methods ${method.name}, ${method.variables}, ... – 18
  • 19. Solution - DSL Special meta-statements element console_log extends quot;primitive_default.ellangquot; { ● implements interface ${ports.port(name=in).signature} { Simplemethod template inheritance (extends) templates { – ${method.declareReturnValue} ExtensionSystem.out.println(quot;method > ${method.name} < calledquot;); points ($extPoint$) – Allow define points in template which can be extended in a $if (method.returnVar) $ ● child template${method.returnVar} = this.target.${method.name}(${method.variables}); – Method templates $else$ this.target.${method.name}(${method.variables}); ● Important for implementing component interfaces $end$ ! component iface is not known when needed //generates return statemene if it is templates is designing ! – Language should provides information about iface ${method.returnStm} ● } methods } } ${method.name}, ${method.variables}, ... – 19
  • 20. Solution – template structure ElLang-J = mixture of ElLang and Java ● package ${package}; import org . . . runtime .* ; element console_log extends “primitive_default.ellang” { public ${classname} { / / constructor } implements interface ElementLocalClient { public void bindElPort(String portName , Object target ) { /* ... */ } } implements interface ${ ports.port (name=line).signature} { method template { } } 20
  • 21. Solution – generator architecture Java part ● Prepares low-level connector configuration – Description of connector element internals ● Stratego part ● Generates source code – From template written in ElLang-J ● From L-LCC passed from Java part of generator ● 21
  • 22. Solution - Java part Implementing action interface ● JimplGeneratorInterface rewrites Low-Level – Connector configuration into XML and passed it to Stratego part Just defines new action for – script controlling generation Bridge between Java and ● Stratego: JNI – Shell (execute connector – 22 generator)
  • 23. Solution – Java v. Stratego part low-level connector ● configuration Describes ports ● Name – Type (provided, required, – remote) Resolved port signature – List of subelements ● Name – Implementing class – Bindings between ● subelements Selects template for ● implementation 23
  • 24. Solution – Stratego part Pipe line of several small ● transformation components Input XML preprocessor – Template parser – Template evaluation – Target code gen. – Query component – All of them transform and ● produce AST (in ATerms) 24
  • 25. Solution – Query module Provides access to input XML (contains L-LCC) ● Simple queries à la XPath – Traversing XML ● ${ports.port.name} – ● conditions ● ${ports.port(name=call).signature} – ● Returns signature of port called “call” Count operator ● – ${elements.element#count} ● Returns number of sub-elements 25
  • 26. Solution – evaluation module Pipe-line of evaluation modules ● Processing extends – Processing imports – Template adjustment – Normalization of statements with different notations ● e.g. If -> If-Else ( in ATerms: If(cond,body) -> If(cond, body, [])) – Queries evaluation – Meta-statements evaluation – 26
  • 27. Evaluation (pro-and-con) Advantages ● Simple template which has at least the same power as the – previous solution Shown by implementing all connectors elements into new ● templates Extensible template language (e.g. ElLang-C#) – New generator can be used just by modifying script – controlling connector generation Disadvantages ● Stratego/XT is C-based, rest of generator is in Java – ? Java implementation of Stratego ? ● Annoying long-time compilation of longer Stratego programs – Should be fixed in new release of Stratego ● 27
  • 28. Future work Byte code manipulation ● To avoid need of javac (~SDK) during deployment – process Templates are precompiled into binary form – Presented and implemented in master thesis – “Optimizing performance of software connectors code generator”, Pavel Petřek Simplifying connectors ● Merging generated Java classes – Implements ElLang-C# ● 28 Improve method templates ●
  • 29. Results T. Bureš, M. Malohlava, P. Hnětynka “Using ● DSL for Automatic Generation of Software Connector” Accepted at 7th IEEE International Conference on – Composition Based Software Systems (ICCBSS), Madrid, February 2008 29