Technology modeling with MegaL in software development

138
© 2014-2015, Ralf Lämmel, [email protected] 1 Technology modeling with MegaL in software development Ralf Lämmel Software Languages Team University of Koblenz-Landau

Transcript of Technology modeling with MegaL in software development

Page 1: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 1

Technology modeling with MegaLin software development

Ralf Lämmel Software Languages Team

University of Koblenz-Landau

Page 2: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 2

EMF

SQL

TENEO

Java

XSD

DOM

Antlr

OWL

UML

XMI

Ecore

SQL DDL

XLSTSaxon

Hibernate

Awk

Json

Yacc

JAXP

RestOWL

RDF

ATOM

SparQLXSLT

DTD

BNF

XSD

OCL

Prolog

grep

MOF

OMG

QVT

jDOMRose

Protegé

XQuery

ODM

XMLSpy

JPA

JAXB

JDBC

ODBC

MySQLArgoUML

Jean

Jena

Jena

Ralf

Dragan

TXL

VLDB

EMF.gen

ORACLE

TCS

XText

Teneo

Jersey

GWT

Sesame

Stratego

XPATH

JeanBeans

UTF8

ASCII

RDFa

RDF(S)

RDFS

CFG

LALR

ER

SLE2010xerces

xalan

saxonsax

sed

XSD

JMI JMF

SBVR

Acknowledgement: Jean-Marie Favre designed this (such a) slide.

We have a problem!Too many technologies.

Too little time.

Page 3: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 3

Technological spaces

Source: http://upload.wikimedia.org/wikipedia/en/thumb/6/66/E_t_the_extra_terrestrial_ver3.jpg/220px-E_t_the_extra_terrestrial_ver3.jpg

Page 4: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Technological space = Technology and community context

in software engineering• UMLware — Mainstream software modeling • MDEware — Model Driven Engineering • Javaware — Mainstream OO programming • XMLware — Interoperability in data exchange • SQLware — Mainstream database management • Pythonware — Scripting and frameworks • RDFware — Semantic Web and Linked Data • JSONware — Modern interoperability • COBOLware — Legacy programming technology

4

What’s a technological space?

Page 5: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 5

Page 6: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 6

A technological space is a working context with a set of associated concepts, body of knowledge,tools, required skills, and possibilities. It is often associated to a given user community with shared know-how, educational support, common literature and even workshop and conference meetings. It is at the same time a zone of established expertise and ongoing research and a repository for abstract and concrete resources.

Page 7: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 7

More technological spaces ...

Data driven journalism

CSVware

Lambdaware

Javaware

Rubyware

TOOLS 2007-2012 ✟

Specware

???

Page 8: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 8

http://upload.wikimedia.org/wikipedia/commons/4/48/Data_driven_journalism_process.jpg

Ralf’s favorite technological space (in his next life)

Page 9: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Constituents of a technological space

• Application scenarios

• Programming languages

• Data representation formats

• Development tools such as IDEs and compilers

• Runtime tools such as libraries and frameworks

• Query and transformation languages

• Textbooks and other knowledge resources

• Conferences and other community resources

• …

9

Page 10: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Space exploration

with 101companies

10

http://101companies.org/

101companies: a community project on software technologies and software languages by Jean-Marie Favre, Ralf Lämmel, Thomas Schmorleiz, Andrei Varanovich. In Proceedings of TOOLS 2012. http://softlang.uni-koblenz.de/101companies/inauguration/

Page 11: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 11

What’s 101companies?It is ...

The Hitchhiker's Guide to the Software Galaxy

Page 12: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 12

Company X: Swing + JDBC

Company Y: SWT + Hibernate

Company Z: GWT + MongoDB

...

A community project aiming at a

knowledge base about software

technologies and languages based on

implementations of a human-resources

management system.

What’s 101companies?

Page 13: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 13

Company X: Swing + JDBC

Company Y: SWT + Hibernate

Company Z: GWT + MongoDB

...

101 ways of building a HRMS.

Building a HRMS for 101 companies.

Why is it called “101companies”?

Page 14: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 14

A Human Resources Management System

• Total salaries

• Increase salaries

• Cut salaries

• Edit employee data

• Import / export company data

Page 15: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 15

Demo http://101companies.org/wiki/Contribution:pyjson

Page 16: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 16

The 101companies Repository

8

442

#Files per implementation Technologies

Languages LOC per implementation

Page 17: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 17

Explorable facets of a contribution

Page 18: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 18

Page 19: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 19

Page 20: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 20

Page 21: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 21

Page 22: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The 101companies Wiki

• Classification (e.g., languages, technologies)

• Feature modeling for the 101system

• Documentation of each contribution

• Collections of contributions in themes

• Tracking of semantic metadata

• Languages, technologies, developers, …

22

Extended demo

Page 23: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 23

• 101companies contribution X ...

• ... uses (‚is written in‘) language L

• ... uses technology T

• ... implements feature F

• ... uses (‚exercises‘) concept C

• 101companies developer D ...

• ... has skills regarding language L

• ... has skills regarding technology T

• ...

The 101companies Ontology

Page 24: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The SQLware technological space

24

Remember the course slot on data modeling?

Page 25: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The XMLware technological space

25

Page 26: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 26

Elevator speech

Consider the following realities: – Applications are built in Cobol, C#, Java, Python, etc. – “Messages” have to be send over the “wire”. – Configuration data has to be represented somehow. – Objects have to be persisted in an human-readable way.

Conclusions: – We need to model data in a language-independent manner. – We need a comprehensive method for exchange/storage formats.

We need (something like) XML. XML stands for eXtensible Markup Language.

Page 27: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 27

Example XML document

<?xml version="1.0"?> <weatherReport> <date>7/14/97</date> <city>North Place</city>, <state>NX</state> <country>USA</country> High Temp: <high scale="F">103</high> Low Temp: <low scale="F">70</low> Morning: <morning>Partly cloudy, Hazy</morning> Afternoon: <afternoon>Sunny &amp; hot</afternoon> Evening: <evening>Clear and Cooler</evening> </weatherReport>

XML declaration at the beginning

Root element; there is one!

Start tagEnd tag

Attribute

Text

Entity

From: XML: A Primer, by Simon St. Laurent

Page 28: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 28

Page 29: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Well-formedness of XML

• A document has exactly one root element. • There is an end tag for each start tag: <name>….</name> • Empty elements can be abbreviated: <noname/> • Elements must be properly nested. • Attribute values must be enclosed into “…”. • …

29

Page 30: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 30

Tree shape of XML

<?xml version="1.0"?> <!DOCTYPE menu SYSTEM "menu.dtd"> <menu> <meal name="breakfast"> <food>Scrambled Eggs</food> <food>Hash Browns</food> <drink>Orange Juice</drink> </meal> <meal name="snack"> <food>Chips</food> </meal> </menu>

menu

meal

name

"breakfast"

food

"Scrambled Eggs"

food

"Hash Browns"

drink

"Orange Juice"

meal

There are techniques for referring from one location in the tree to another. Hence, essentially one can go beyond tree shape. However, the serialized format, no matter what, is of tree shape.

Page 31: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

XML-based languages - Some examples -

• FpML – Financial products Markup Language

• HL7 – Standards in Healthcare

• MathML – Mathematical Markup Language

• XHTML – HTML defined in XML

• … and countless others …

31

Page 32: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

XML-related technologies and standards

• XML is a standard; there is 1.0 and 1.1.

• XML elements & attributes are qualified by XML namespaces.

• DTD (Document Type Definition; part of XML standard) and XML Schema and Relax

NG (both separate standards) are used to define legal XML tags and their attributes for

particular XML languages.

• CSS (Cascading Style Sheets) and XSL (eXtensible Stylesheet Language) are used to

map HTML or XML for presentation in a browser.

• XPath, XSLT and XQuery are used to program queries on transformations on XML

data. In fact, XPath is part of XSLT and XQuery.

• DOM (Document Object Model), SAX (Simple API for XML), and JAXP (Java API for

XML Processing) are all Java APIs for XML processing. In fact, DOM is language-

independent.

32

Page 33: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 33

XML queries with XPath

• XPath is an XML query language.

• Queries are composed from query axes.

• Children, Ancestors, Descendants, ...

• XPath is embedded into Java et al. by APIs.

• XPath queries are encoded as strings.

• Examples: “//salary” “//manager/salary”

All salary nodes below all manager nodes anywhere

Page 34: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 34

XPath axesAxisName Resultancestor Selects all ancestors (parent, grandparent, etc.) of the current node

ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself

attribute Selects all attributes of the current node

child Selects all children of the current nodedescendant Selects all descendants (children, grandchildren, etc.) of the current node

descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself

following Selects everything in the document after the closing tag of the current node

following-sibling Selects all siblings after the current node

namespace Selects all namespace nodes of the current node

parent Selects the parent of the current nodepreceding Selects everything in the document that is before the start tag of the current node

preceding-sibling Selects all siblings before the current node

self Selects the current node

“/” “//”

Page 35: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 35

XML transformations with XSLT

• XSLT is an XML transformation language.

• XSLT leverages XPath for node selection.

• XSLT is an XML-based language.

• XSLT is a functional programming language.

Page 36: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 36

Cutting salaries with XSLT

<xsl:stylesheet> <xsl:template match="salary"> <xsl:copy> <xsl:value-of select=". div 2"/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>

Type-specific template

Generic default

Recursion into kids

Page 37: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

XML languages (defined by XML schemas)

37

Page 38: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 38

<employee> <name>Ralf</name> <address>Koblenz</address> <salary>1234</salary></employee>

<employee> <name>Ralf</name> <salary>1234 Euro</salary></employee>

OK

Not OK!

Address missing

Not a number

Page 39: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 39

XML Schema (XSD)

http://www.w3.org/XML/Schema: “XML Schemas express shared vocabularies and

allow machines to carry out rules made by people. They provide a means for defining the structure, content and semantics of XML documents. […] XML Schema was approved as a W3C Recommendation on 2 May 2001.”

Page 40: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 40

XSD for 101

<xs:element name="company"><xs:complexType>

<xs:sequence><xs:element ref="name"/><xs:element maxOccurs="unbounded"

minOccurs="0" ref="department"/>

</xs:sequence></xs:complexType>

</xs:element>

<xs:element name="department"> ... </xs:element>

<xs:complexType name="employee"> ... </xs:complexType>

Page 41: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 41

XML validation

Well-formed XML as a prerequisite

Input

XML document

XML schema

Output

“valid”: document valid w.r.t. schema

“invalid” + violations

Page 42: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 42

XSD – schema components

• Element declarations

• Complex type definitions

• Model-group definitions

• Simple type definitions

• Attribute declarations

• Attribute-group definitions

• Redefinitions

• Annotations Comments and hints for schema processors

Deprecated

Types of leafs in XML trees (both elements and attributes).

Nonrecursive macros without subtyping

Recursive macros with subtyping

Sets of XML trees rooted by a certain element name

Page 43: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 43

Sketch of the company schema

<xs:schema …> <xs:element name="company“> … </xs:element> <xs:element name="department“> … </xs:element> <xs:complexType name="employee"> … </xs:complexType> <xs:element name="name"> … </xs:element> <xs:element name="address"> … </xs:element> <xs:element name="salary"> … </xs:element>

</xs:schema>

Page 44: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 44

<sequence><xs:complexType name="employee"> <xs:sequence> <xs:element ref="name" /> <xs:element ref="address" /> <xs:element ref="salary" /> </xs:sequence> </xs:complexType>

An employee element has children for name, address, and salary.

Page 45: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 45

<choice><xs:element name="subunit"> <xs:complexType> <xs:choice> <xs:element name="employee" type="employee" /> <xs:element ref="department" /> </xs:choice> </xs:complexType> </xs:element>

In a variation of our preferred schema, a subunit (of a department) is either an

employee or a department.

Page 46: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 46

“*” (i.e., many)<xs:element name="company">

<xs:complexType><xs:sequence>

<xs:element ref="name"/><xs:element maxOccurs="unbounded"

minOccurs="0" ref="department"/>

</xs:sequence></xs:complexType>

</xs:element> A company element has any number of

department elements as its children.

Page 47: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 47

XSD simple types• Comparable to primitive types in a programming.

• Example:

<xs:element name="salary" type="xs:double"/>

• All attributes are of simple types.

• New simple types can be defined by: – Restriction – Union – List

Page 48: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 48

Page 49: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Technological space travel

49

Source: http://www.nasa.gov/images/content/63114main_highway_med.jpg

Page 50: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 50

Sesame

XMIModelwareXMLware

JavawareJDBC

Dataware

JDOM

Ontoware

JenaHibernate

EMF.genJMITeneo JAXB

JPA

Some bridges exercised by such space travel

Page 51: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 51

Why is space travel a burden?

• Terminology, notation, conventions, culture

• Computational models, data models, type systems

• Concrete technologies and languages

• Accidental complexity

• …This also goes by the name

O/R/X/… impedance mismatch

Page 52: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

XML data binding (aka O/X mapping)

52

Page 53: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 53

X-to-O mappingX-to-O

mapping tool

XML types

OO types

Page 54: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 54

O/X type mapping<element name=“point"> <complexType> <sequence> <element name="x" type=“xs:int"/> <element name="y" type="xs:int"/> </sequence> </complexType> </element>

Maps to public class Point { public int x; public int y; }

Maps to

Page 55: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 55

Object model for 101system

public class Company {private String name;private List<Department> depts = new LinkedList<Department>();public String getName() { return name; }public void setName(String name) { this.name = name; }public List<Department> getDepts() { return depts; }

}

public class Department { ... }

public class Employee { ... }

Page 56: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 56

XSD for 101system

<xs:element name="company"><xs:complexType>

<xs:sequence><xs:element ref="name"/><xs:element maxOccurs="unbounded"

minOccurs="0" ref="department"/>

</xs:sequence></xs:complexType>

</xs:element>

<xs:element name="department"> ... </xs:element>

<xs:complexType name="employee"> ... </xs:complexType>

XML too

Grammar-like

OO types-like

Page 57: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

XML data binding• Directions for XML data binding

• Generate classes from XML schemas.

• Generate XML schemas from classes.

• Describe mapping only without generation.

• Motivations for XML data binding

• Support valid XML output.

• Hide XML in OO programming.

• Use XML-based object serialization.

57

Page 58: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 58

Demo

http://101companies.org/wiki/Contribution:jaxbComposition

Page 59: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The O/X impedance mismatch

59

Page 60: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 60

How to map this element declaration?

<xs:element name="s"> <xs:complexType> <xs:sequence> <xs:element name="a" type="x"/> <xs:sequence maxOccurs="unbounded"> <xs:element name="b" type="y" maxOccurs="unbounded"/> <xs:element name="c" type="z"/> </xs:sequence> </xs:sequence> </xs:complexType> </xs:element>`

1..*

1..*

Page 61: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 61

How to map “s = a:x (b:y1..* c:z)1..* ”?

Grouping of b’s and c’s is lost.

This may be Ok for read access.

This is not Ok for round-tripping.

Occurrence constraints not enforced:

Mandatory a, b, c

class s { x a; y[] b; z[] c; }

Page 62: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 62

XML data binding is difficult becauseXML are parented trees whereas …

<Add>

<Add> <Const>

element

<Const><Const>

Thanks to Erik Meijer for contributing this slide or part thereof.

Page 63: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 63

Objects are freewheeling graphs.

1

.Value

.right.left

.right

.left

Add

Add Const

Thanks to Erik Meijer for contributing this slide or part thereof.

Page 64: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 64

Its also difficult becauseXML trees are node-labeled whereas …

element

<Add>

<Add> <IConst>1 2

Thanks to Erik Meijer for contributing this slide or part thereof.

Page 65: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 65

Object graphs are edge-labeled.

1

.Value

.right.left

.right

.left

ConstAdd

<Add>

Const

Thanks to Erik Meijer for contributing this slide or part thereof.

Page 66: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Object/relational mapping „likewise“ Let’s do demos, if time permits.

66

Page 67: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 67

Technology models

A technology model is a structural as well as behavioral model of a technology such that the roles of involved languages, typical artifacts of

usage, and technology application are modeled.

Page 68: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Different kinds of software models

• Data models (to be implemented in a database)

• Structural models (to be implemented in software)

• Class diagrams (to model state and relationships)

• Package diagrams (to group classes)

• Behavioral models (to be implemented in software)

• Sequence diagrams (to define specific „scenarios“)

• Activity diagrams (to define general „workflows“)

• State diagrams (to define object states and transitions)

68

Page 69: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

A structural model for a metro’s turnstile

69

Page 70: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

A behavioral model for a metro’s turnstile

70

Page 71: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Software models vs. technology models

• Software models

• Structure and behavior of the software system

• Technology models

• Entities related to technology usage

• Relationships between those entities

71

Page 72: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Examples of technology models

• Population of a mySQL database

• Compilation with Java’s javac compiler

• XML data binding with Java’s JAXB technology

72

Page 73: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 73

Compilation with Java’s javac compilerhttp://en.wikipedia.org/wiki/Javac

Given a source file (a Java program), the compiler produces bytecode (a .class file). The bytecode could be executed directly by the JVM (Java Virtual Machine), but our technology model is not going to cover the execution aspect.

Explanation

Page 74: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 74

$ ls HelloWorld.* HelloWorld.java $ more HelloWorld.java public class HelloWorld {

public static void main(String[] args) { System.out.println("Hello, World"); }

} $ javac HelloWorld.java $ ls HelloWorld.* HelloWorld.class HelloWorld.java

Compilation with Java’s javac compiler

Illustration

Page 75: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Compilation with Java’s javac compiler

• Java : Language

• JavaByteCode : Language

• Compiler < Technology

• javac : Compiler

• aJavaProgram : Artifact

• aJavaByteCodeProgram : Artifact

• aJavaProgram elementOf Java

• aJavaByteCodeProgram elementOf JavaByteCode

• compilation : Function<Java, JavaByteCode>

• javac defines compilation

• compilation(aJavaProgram) |-> aJavaByteCodeProgram

75

Model

Page 76: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Population of a MySQL database

76

https://www.mysql.com/ https://www.mysql.com/products/workbench/

Given a MySQL database, the MySQL workbench is used to populate the database. To this end, the database schema (some CREATE TABLE statements) are executed as a script, followed by another script with sample data (some INSERT statements).

Explanation

Page 77: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 77

Page 78: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 78

Page 79: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 79

Page 80: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Population of a MySQL database

• SQL : Language

• RDBMS < Technology

• MySQL : RDBMS

• someCreateStatements : Artifact

• someInsertStatements : Artifact

• someCreateStatements elementOf SQL

• someInsertStatements elementOf SQL

• MySQL Workbench : Technology

• creation : Action

• insertion : Action

• creation precedes insertion

• creation reads someCreateStatements

• creation modifies database

• insertion reads someInsertStatements

• insertion modifies database

• MySQL Workbench executes creation

• MySQL Workbench executes insertion

80

Page 81: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 81

XML data binding with Java’s JAXB technologyhttp://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding

Explanation

Source: http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JAXBWorks2.html

Page 82: Technology modeling with MegaL in software development

© 2014 Software Languages Team, University of Koblenz-Landau

82

A technology model for JAXB(XML-data binding of the Java platform)

Part 1: Technology break-down and concepts

Page 83: Technology modeling with MegaL in software development

© 2014 Software Languages Team, University of Koblenz-Landau

83

A technology model for JAXB(XML-data binding of the Java platform)

Part 2: Type-level mapping

Page 84: Technology modeling with MegaL in software development

© 2014 Software Languages Team, University of Koblenz-Landau

84

A technology model for JAXB(XML-data binding of the Java platform)

Part 3: Instance-level

mapping

Page 85: Technology modeling with MegaL in software development

© 2014 Software Languages Team, University of Koblenz-Landau

85

A technology model for JAXB(XML-data binding of the Java platform)

Part 4: Conformance

Page 86: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Summary of technology modeling• Entities in software development

• e.g.: Java, Python, J2EE, Django, Testing, Inheritance • Entity types in software development

• e.g.: Language, Technology, Artifact, Concept • Relationships in software development

• e.g.: • HelloWorld.java elementOf Java • Django uses Python

• Relationship types in software development • e.g., „elementOf“ or „uses“

86

Page 87: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Entities in technology models

87

Page 88: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Entity types I / II

• Language — e.g., Python

• Technology — e.g., Django web framework

• Artifact

• System < Artifact — e.g., an information system

• File < Artifact — e.g., a Python script

• Fragment < Artifact — e.g., a Python function

• Function — e.g., the I/O behavior of a compiler

• Action — e.g., the execution of a script

• Concept — e.g., Composition or inheritance

88

Page 89: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Entity types II / II

• Resource < Artifact — e.g., Wikipedia pages

• Request < Artifact — e.g., the invocation of a certain service, tool, or script

• Request < Response — e.g., the response returned upon a request

• Specification < Resource — e.g., Java Language Specification

• Protocol < Resource — e.g., HTTP

• Standard < Resource — e.g., DVI

• Organization — e.g., IBM or Siemens

• People — e.g., „Joe Programmer“ (at Siemens)

• Role — e.g., Developer, Tester, or Manager

89

Page 90: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) language entities• Definition:

• An artificial language used in software development

• Examples

• Programming languages: Java, Python, Ruby, …

• Query languages: XPath, SQL, XQuery, …

• Transformation languages: XSLT, SQL, ATL, …

• Modeling languages: UML, SDL, BPMN, …

90

Page 91: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

More categories of software languages

• Hypertext languages (HTML)

• Markup languages (XML)

• Configuration languages

• Annotation languages

• Template languages

• …

91

Page 92: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) technology entities• Definition:

• A tool (in a very general sense) used in software development

• Examples

• APIs and libraries: JDOM, JQuery, Swing, Tkinter, Twitter, …

• Frameworks: JPA, Hibernate, Spring, Django, …

• IDEs: Visual Studio, Eclipse, NetBeans, …

• Platforms: .NET, Android, J2EE, Java, JRE, …

• Language processors: javac, python, gcc, …

92

Page 93: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

More categories of software technologies

• Server, e.g., Web server

• Web browser

• Plugins

• Office software

• Operating systems

• Package portals, package manager

• App stores

• …

93

We should always try to define each new entitty type as a

subtype („<) of an existing type.

Page 94: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) system entities• Definition:

• A deployed, implemented, or designed software system

• Examples

• An information system for a specific startup

• A web application complementing said information system

• A web service making said system available through an API

• A smartphone app complementing said web application

94

Page 95: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) artifact entities• Definition:

• A physical artifact as part of a software system

• Examples

• Files: source code, byte code, markup, …

• Directories as shallow or deep collections of files

• Packages as logical collections

95

Page 96: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) fragment entities• Definition:

• A part of a software artifact

• Examples

• Classes in a Python script collecting many classes

• Methods in a class of a Python script

• A CREATE TABLE statement in SQL/DDL script

• A method call in a Python script

96

Page 97: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Source code as a nested container

97

def search(l, x): return searchInRange(l, x, 0, len(l)-1)

def searchInRange(l, x, min, max): if min>max: return False else: middle = min+(max-min)/2 if x > l[middle]: # Search in right half return searchInRange(l, x, middle+1, max) elif x < l[middle]: # Search in left half return searchInRange(l, x, min, middle-1) else: # Found in the middle return True

Page 98: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) meaning entities• Definition:

• The meaning of an artifact, a technology, or a part thereof

• Examples

• Functions

• The semantics of a Python function

• The I/O behavior of a program

• The I/O behavior of a tool as part of a technology

• Actions

• The meaning of a specific method call in a program

• The meaning of a database update

98

Page 99: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) concept entities• Definition:

• A concept from the broad domain of software development

• Examples

• A programming technique such as iteration or recursion

• A modeling principle such inheritance or composition

• A design pattern such as Composite or Visitor

• A classifier for software languages or technologies

• A general capability of a software system, e.g., persistence

99

Page 100: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

(Software) resource entities• Definition:

• A resource for any entity above in the sense of Linked Data

• Examples

• A Wikipedia page for a software language

• A portal for a software technology

• A repository URI for a system

• A fragment locator URI for a source code fragement

• A LinkedIn URI for a developer

100

Page 101: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationships in technology models

101

Page 102: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationship types ‚part of‘

• An artifact (a file) is part of a system.

• A fragment is part of an artifact.

• A language is part of another language.

• A technology is part of another technology.

• A concept is part of a concept.

102

Page 103: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationship types ‚uses‘

• A system (an artifact) uses a language.

• A system (an artifact) uses a technology.

• A system (an artifact) uses a concept.

103

Page 104: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationship types for languages and models thereof

• An artifact is an element of a language.

• A language is a subset of another language.

• An artifact conforms to an artifact.

• An artifact defines a language.

• An artifact corresponds to another artifact.

104

Page 105: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 105

Model of technology usage for .NET’s xsd.exehttp://worker.101companies.org/MegaModels/implementations/xsdClasses/

Page 106: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationship types for meanings & Co.

• An artifact (a fragment) defines a function.

• A technology defines a meaning.

• A technology supports a protocol.

• A technology implements a specification.

• An artifact (a fragment) implements a concept.

106

Page 107: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationship types for data flow & access

• An artifact is transformed into another artifact.

• A request yields a response.

• A language is the domain of a function.

• A language is the co-domain of a function.

• A function maps one artifact to another.

• An action reads an artifact.

• An action writes an artifact.

• An action modifies an artifact.

107

As a shortcut, we may use the artifact right in place of its meaning.

Page 108: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Relationship types for persons

• A person has developed a system.

• A person knows of a language.

• A person knows of a technology.

• A person knows of a concept.

108

Page 109: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Benefits of technology modeling

• Raise the level of abstraction compared to …

• file system view

• build management view

• Recognize all technologies and languages explicitly

• Understand concepts behind artifacts

• Understand relationships between artifacts

• Link model elements to artifacts or resources

109

Page 110: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

An extended example: A technology model for Django

110

We use the Polls app as the running example.

Find the code here:

https://github.com/rlaemmel/mysite

Page 111: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Python Web frameworks

• Django

• web2py

• Flask

• Bottle

111

Page 112: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 112112

A database

The modelThe view

Python code,

HTML, and templates

Templates for views

A low-level view on the Polls app

Page 113: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

• db_sqlite3 : File • mysite : Directory

• __init__.py : File • manage.py : File • media : Directory • polls : Directory

• __init__.py : File • admin.py : File • models.py : File • tests.py : File • views.py : File

• settings.py : File • templates : Directory

• admin : Directory • polls : Directory

• detail.html : File • index.html : File • results.html : File

• urls.py : File113

Types of artifacts: How useful is that?

Page 114: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 114

• db_sqlite3 : File ∈ SQLITE3-IMAGE (a language we made up) • mysite : Directory

• __init__.py : File ∈ Python • manage.py : File ∈ Python • media : Directory • polls : Directory

• __init__.py : File ∈ Python • admin.py : File ∈ Python • models.py : File ∈ Python • tests.py : File ∈ Python • views.py : File ∈ Python

• settings.py : File ∈ Python • templates : Directory

• admin : Directory • polls : Directory

• detail.html : File ∈ HTML • index.html : File ∈ HTML • results.html : File ∈ HTML

• urls.py : File ∈ Python

Languages of artifacts: How useful is that?

Is this HTML, proper?

„∈“ shortcut for „element of“

Page 115: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Issues

• What is the schema underlying the database image?

• What are the roles of the different python scripts?

• How do code and database relate to each other?

• The HTML files are not plain HTML files, actually.

• What technologies are used by the app?

115

Page 116: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Issues

• What is the schema underlying the database image?

• What are the roles of the different python scripts?

• How do code and database relate to each other?

• The HTML files are not plain HTML files, actually.

• What technologies are used by the app?

116

Page 117: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

In need of new entities: request and response for DB schema

• schemaRequ : Request # for database schema

• schemaResp : Response # for database schema

• schemaRequ ∈ Bash # a shell script

• schemaResp ∈ SQL # CREATE TABLE statements

• schemaRequ yields schemaResp

117

Page 118: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 118

schemaRequ : Request # for database schema

schemaResp : Response # for database schema

~ $ pwd/home/rlaemmel/mysite~ $ python manage.py sql polls

Page 119: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Issues

• What is the schema underlying the database image?

• What are the roles of the different python scripts?

• How do code and database relate to each other?

• The HTML files are not plain HTML files, actually.

• What technologies are used by the app?

119

Page 120: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Concepts behind the many Python scripts

120

• mysite• __init__.py implements initialization • manage.py implements administration • polls

• __init__.py implements initialization • admin.py implements view • models.py implements model • tests.py implements testing • views.py implements view

• settings.py implements configuration• urls.py implements router

Page 121: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Concepts

• Model: the data / business logics part MVC

• View: the user interface part of MVC

• Router: a variation of a controller (part of MVC)

• Configuration: configuration of a component or a system

• Initialization: initialization of a component or a system

• Administration: administration of a system

• Testing: test of an artifact or a system

121

MVC = Model View Controller

Page 122: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The model

122

Don’t bother about details: these are Python (Django) classes for the

business data of the Polls app.

Page 123: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The view for „end users“

123

Don’t bother about details, but a typical view loads or saves

data, and renders data as HTML via a template.

Page 124: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The view for „admins“ according to Django

124

These views are standardized by Django: they allow us to do basic

data management for polls and choices.

Page 125: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The router (map URLs to views)

125

Regular expression for URLs with parameters

Python function for a particular view

Page 126: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Issues

• What is the schema underlying the database image?

• What are the roles of the different python scripts?

• How do code and database relate to each other?

• The HTML files are not plain HTML files, actually.

• What technologies are used by the app?

126

Page 127: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

In need of new entities: request and response for DB synchronization

• syncRequ : Request # for database sync

• syncResp : Response # for database sync

• syncRequ ∈ Bash # a shell script

• syncResp ∈ Text # verbose log

• syncRequ yields syncResp

127

Page 128: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected] 128

syncRequ : Request # for database sync

syncResp : Response # for database sync

~ $ pwd/home/rlaemmel/mysite~ $ python manage.py syncdb

Creating tables ... Creating table auth_permission … Creating table django_admin_log Creating table polls_poll Creating table polls_choice

You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'rlaemmel'): rlaemmel … Superuser created successfully. Installing custom SQL ... Installing indexes ... No fixtures found.

Page 129: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

How do code and database relate to each other?

129

Relationships: • syncRequ reads mysite/polls/models.py • syncRequ reads db.sqlite3 • syncRequ modifies db.sqlite3 • schemaResp corresponds to mysite/polls/models.py

CREATE TABLE "polls_poll" ( … ) ; CREATE TABLE "polls_choice" ( … )

schemaResp:class Poll(models.Model): ...

class Choice(models.Model): …

mysite/polls/models.py:

Page 130: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

A hidden language for administration

• Remember

• python manage.py sql polls

• python manage.py syncdb

• There exist more such administrative commands.

• We designate a language DjangoAdmin ⊂ Bash.

130

Page 131: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Issues

• What is the schema underlying the database image?

• What are the roles of the different python scripts?

• How do code and database relate to each other?

• The HTML files are not plain HTML files, actually.

• What technologies are used by the app?

131

Page 132: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The template for the index view

132

Page 133: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The template for the detail view

133

Page 134: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The template for the results view

134

Page 135: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

A language for templates

• We designate a language DjangoTempl ⊃ HTML.

• Extra constructs:

• Python expressions {{ … }} evaluating to HMTL

• Loops over Python data to return HTML

135

Page 136: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Issues

• What is the schema underlying the database image?

• What are the roles of the different python scripts?

• How do code and database relate to each other?

• The HTML files are not plain HTML files, actually.

• What technologies are used by the app?

136

Page 137: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

Referenced python modules

• webapp uses django.db is part of Django and implements database access

• webapp uses django.test is part of Django and implements testing

• webapp uses django.template is part of Django and implements DjangoTempl

• webapp uses django.http is part of Django and supports (the) HTTP (protocol)

• webapp uses django.…

• webapp uses datetime is part of PythonRuntime

• webapp uses os is part of PythonRuntime

137

Page 138: Technology modeling with MegaL in software development

© 2014-2015, Ralf Lämmel, [email protected]

The End

138