<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Peter Friese &#187; EMF</title>
	<atom:link href="http://www.peterfriese.de/category/emf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peterfriese.de</link>
	<description>Xtext, DSLs, Eclipse, iPhone</description>
	<lastBuildDate>Tue, 27 Jul 2010 21:36:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting started with Code Generation with Xpand</title>
		<link>http://www.peterfriese.de/getting-started-with-code-generation-with-xpand/</link>
		<comments>http://www.peterfriese.de/getting-started-with-code-generation-with-xpand/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 14:05:05 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[EMF]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>
		<category><![CDATA[xpand]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=390</guid>
		<description><![CDATA[Have you heard about model driven software development (MDD / MDSD) and are thinking "what's all this fuzz about models"? "Why should models help me to be more productive," might be another thought you have.
People have been asking how to leverage models on and off on the web and in meetings I attended, so I[...]]]></description>
			<content:encoded><![CDATA[<p>Have you heard about model driven software development (MDD / MDSD) and are thinking "what's all this fuzz about models"? "Why should models help me to be more productive," might be another thought you have.</p>
<p>People have been asking how to leverage models on and off on the web and in meetings I attended, so I thought I might share this little tutorial with you. In this tutorial, we will develop a little code generator that helps you to create (HTML) forms from models. </p>
<h2>A short Overview</h2>
<p>Xpand is a template engine, similar to FreeMarker, Velocity, JET and JSP. However, it features some very unique properties that makes using Xpand very well suited for generating code from models, such as <strong><a href="http://en.wikipedia.org/wiki/Type_safety">type safety</a></strong> and <strong>polymorphic dispatch</strong>. If you haven't heard those terms before, fear not! I'll show you how to use Xpand by way of an easy-to-follow example.</p>
<p><span id="more-390"></span></p>
<p>The usual process of writing a code generator with Xpand is as follows:</p>
<ol>
<li>Define the structure of the model you want to process. This is called a <em>metamodel</em></li>
<li>Define one or more template(s) that teach the code generator how to translate your model into code.</li>
</ol>
<p>Easy, isn't it?</p>
<p>Using the code generator is even easier:</p>
<ol>
<li>Create a model</li>
<li>Start the code generator</li>
</ol>
<p>It is worth mentioning that you can use Xpand to generate code for almost any known programming language. Everything you can express in text can be generated using Xpand. So, while we will be generating HTML and Java code in the following example, you can easily write code templates that generate code for C#, Basic, Lua, SmallTalk, ABAP, or any other programming language. You can also generate manuals and other documentation artifacts from your models using Xpand. I've successfully used Xpand to create DocBook files from models. Those DocBook files have then been converted to PDF files and online help files.</p>
<h2>Preparing your IDE</h2>
<ol>
<li>Grab and install a recent copy of Eclipse. At the time of writing, I am using <a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.6M6-201003121448/index.php">Eclipse 3.6 M6</a>.</li>
<li>Install the latest version of Xpand (<em>Help -> Install New Software ...</em>)
<li>Add the Xpand update site (at the time of this writing, I am using Xpand 1.0 nightly builds from <a href="http://download.eclipse.org/modeling/m2t/xpand/updates/nightly/">http://download.eclipse.org/modeling/m2t/xpand/updates/nightly/</a>)</li>
<li>Add the MWE update site (<a href="http://download.eclipse.org/modeling/emft/mwe/updates/nightly/">http://download.eclipse.org/modeling/emft/mwe/updates/nightly/</a>)</li>
<li>Select MWE and Xpand:
<div style="text-align:center;"><a href="http://www.flickr.com/photos/81029262@N00/4439298864" title="View 'Install MWE and Xpand' on Flickr.com"><img border="0" width="488" alt="Install MWE and Xpand" src="http://farm5.static.flickr.com/4001/4439298864_40b913f0e5.jpg" height="500"/></a></div>
</li>
<li>After the obligatory restart, do yourself the favour and set the platform encoding to <strong>UTF-8</strong>!</li>
</ol>
<h2>Creating a Generator Project</h2>
<p>Xpand code generators are hosted in Eclipse plug-ins, mainly because this makes handling the classpath a lot easier. People have reportedly used Maven to run Xpand code generators, but we won't go down this road today. Let's create a simple generator project:</p>
<ol>
<li>Open the new project wizard and choose <em>Xpand Project</em> from the list</li>
<li>Choose a meaningful name for your project (e.g. <em>org.xpand.example.gettingstarted</em></li>
<li>Select <em>Create a sample EMF based Xpand project</em></li>
</ol>
<p>After clicking <em>Finish</em>, the wizard will create an sample generator project for you:</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/81029262@N00/4439735747" title="View 'Xpand project layout' on Flickr.com"><img border="0" width="556" alt="Xpand project layout" src="http://farm3.static.flickr.com/2794/4439735747_e7385b2cef_o.png" height="394"/></a></div>
<p>Before we can start working with this project, we need to perform some clean-up actions:</p>
<ol>
<li>Open <em>src/metamodel/Checks.chk</em> and delete all its contents</li>
<li>Open <em>src/metamodel/Extensions.chk</em> and delete all its contents</li>
<li>Open <em>src/template/GeneratorExtensions.ext</em> and delete all its contents</li>
<li>Delete <em>src/Model.xmi</em></li>
<li>Don't forget to save all modified files</li>
</ol>
<h2>Creating the Metamodel</h2>
<p>As mentioned before, we need to define the structure of our models before we can actually start writing the code template.<br />
Xpand is capable of understanding a variety of metamodel types. For example, if you have an XML schema file, you can use this as a metamodel and thereby enable Xpand to use XML files which are compliant to your schema as input models. Or, if you already have a bunch of Java files making up your data model, you can use those to drive Xpand code generation. In this tutorial, however, we will be using an Ecore metamodel to define the structure of our models. The project has already been configured to support Ecore metamodels, so all we need to do is open <em>metamodel.ecore</em> and define the structure:</p>
<ol>
<li>Please open <em>src/metamodel/metamodel.ecore</em></li>
<p>.</p>
<li>Remove the following elements from the metamodel: <em>Feature</em>, <em>Entity</em>, <em>Datatype</em>, <em>Type</em>, <em>Model</em>. The metamodel should now be empty:
<div style="text-align:center;"><a href="http://www.flickr.com/photos/81029262@N00/4439788989" title="View 'Empty metamodel' on Flickr.com"><img border="0" width="500" alt="Empty metamodel" src="http://farm3.static.flickr.com/2555/4439788989_42665597db.jpg" height="105"/></a></div>
</li>
<li>Select package <em>metamodel</em> (as depicted in the screenshot above) and add a new <em>EClass</em> (<em>context menu -> New Child -> EClass</em>). Use the properties view to change the name of the newly created EClass to <em>Model</em>.</li>
<li>Create a new EClass <em>Form</em></li>
<li>Select the newly created EClass <em>Form</em> and add the following <em>EAttribute</em>s:
<ul>
<li><em>name</em>, set the EType to <em>EString</em></li>
<li><em>description</em>, EType = <em>EString</em></li>
<li><em>title</em>, EType = <em>EString</em></li>
</ul>
</li>
<li>Select EClass <em>Model</em> and add a new <em>EReference</em>, setting its attributes as follows:
<ul>
<li>name = <em>forms</em></li>
<li>EType = <em>Form</em></li>
<li>Containment = <em>true</em></li>
<li>Upperbound = <em>-1</em> (meaning: unlimited)</li>
</ul>
</li>
<li>Create a new EClass <em>Field</em> and add the following EAttributes to it:
<ul>
<li><em>name</em>, EType = <em>EString</em></li>
<li><em>label</em>, EType = <em>Estring</em></li>
</ul>
</li>
<li>Create another EClass <em>TextField</em>, setting its properties as follows:
<ul>
<li>name = <em>TextField</em></li>
<li>ESuper Types = <em>Field</em></li>
</ul>
</li>
<li>Add one EAttribute <em>text</em> to <em>Textfield</em>:
<ul>
<li>name = <em>text</em>, EType = <em>EString</em></li>
</ul>
</li>
<li>Add an EClass <em>MultiLineTextField</em> to the metamodel:
<ul>
<li>name = <em>MultiLineTextTield</em></li>
<li>ESuper Types = <em>TextField</em></li>
</ul>
</li>
<li>Now that we have everything in place, we finally need to add a reference from <em>Form</em> to <em>Field</em> so we can later add fields to a form. Select EClass <em>Form</em> and add an EReference to it, setting its properties as follows:
<ul>
<li>name = <em>fields</em></li>
<li>EType = <em>Field</em></li>
<li>Containment = <em>true</em></li>
<li>Upperbound = <em>-1</em> (meaning: unlimited)</li>
</ul>
</li>
</ol>
<h2>Creating a Model</h2>
<p>Let's now create a model that follows the structure of the metamodel:</p>
<ol>
<li>In <em>metamodel.ecore</em>, select EClass <em>Model</em></li>
<li>Create a model instance by choosing <em>Create Dynamic Instance...</em> from the context menu</li>
<li>Save the model file to <em>src/Model.xmi</em></li>
</ol>
<p>The model file editor will now open and you can use the tree editor to input the following model:</p>
<ul>
<li>Add a <em>Form</em> to the model, seeting the following properties:
<ul>
<li>Name: <em>context</em></li>
<li>Description: <em>Send your feedback</em></li>
<li>Title: <em>Contact form</em></li>
</ul>
</li>
<li>Add a <em>TextField</em> to the <em>Form</em>, setting the following properties:
<ul>
<li>Name: <em>name</em></li>
<li>Label: <em>Name</em></li>
</ul>
</li>
<li>Add another <em>TextField</em> to the <em>Form</em>, setting the following properties:
<ul>
<li>Name: <em>email</em></li>
<li>Label: <em>EMail</em></li>
</ul>
</li>
<li>Add a <em>MultiLineTextField</em> to the <em>Form</em>, setting the following properties:
<ul>
<li>Name: <em>message</em></li>
<li>Label: <em>Message</em></li>
</ul>
</li>
</ul>
<p>Your model should now look like this:</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/81029262@N00/4440711442" title="View 'Contact model' on Flickr.com"><img border="0" width="500" alt="Contact model" src="http://farm3.static.flickr.com/2719/4440711442_354f817303.jpg" height="167"/></a></div>
<h2>Creating a Code Generator</h2>
<p>As mentioned before, we will create a code generator for simple forms. Nothing too fancy, but enough to give you an idea of how to create generator templates.</p>
<p>The result will look like this:</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/81029262@N00/4440844786" title="View 'Contact Form' on Flickr.com"><img border="0" width="500" alt="Contact Form" src="http://farm3.static.flickr.com/2745/4440844786_46824ce7ea.jpg" height="403"/></a></div>
<p>Open <em>src/template/Template.xpt</em> and replace its contents with the following text:</p>
<pre>
«IMPORT metamodel»
«DEFINE main FOR Model»
«EXPAND form FOREACH forms»
«ENDDEFINE»
</pre>
<p>On the first line, we import the metamodel so that the generator (and the editor as well) knows about the structure of our model. On line 2 - 4 we define a code template named <em>main</em>, making sure it is bound to model elements of type <em>Model</em>. The template doesn't do much, except to call another template (which we will define in a minute) named <em>form</em> with the collection of <em>Form</em>s, contained in the reference <em>forms</em> of the current form.</p>
<p>Add the following lines to the template file, defining the template for the HTML file:</p>
<pre>
«DEFINE form FOR Form»
«FILE name + ".html"»
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>«this.title»</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../static/style.css" />
</head>
</pre>
<p>In the first line, we start the template by specifying its name (<em>form</em>) and the type it is bound to (<em>Form</em>). On the next line, we use the <em>FILE</em> statement to specify the file the output is going to be written to. The name of the file is derived by concatenating the attribute <em>name</em> of the current <em>Form</em> and the string literal <em>".html"</em>.</p>
<p>Continue the template by appending the following text:</p>
<pre>
<body>
<div id="page-wrap">
<h1>«this.title»</h1>

«this.description»
<div id="form-area">
</pre>
<p>Obviously, this piece of template code will create part of the body of the HTML page. Again, we will access attributes of the current <em>Form</em> (as read from the model) and insert their values into the template (in this case, the title and the description). By the way, you can omit the <em>this.</em> prefix in front of the variable names.</p>
<p>The template goes on with the following text:</p>
<pre>
<form method="post" action="form.php">
        «EXPAND field FOREACH this.fields»
<input type="submit" name="submit" value="Submit" class="submit-button" />
      </form>
<div style="clear: both;"></div>
</div>
</div>

</body>
</html>
«ENDFILE»
«ENDDEFINE»
</pre>
<p>The <em>EXPAND</em> statement will invoke yet another subtemplate with the name <em>field</em>. This sub template will be called for each element in the <em>fields</em> attribute (reference) of the current <em>Form</em>.</p>
<p>You might recall that we we defined three different kinds of <em>>Field</em>s in the metamodel: </p>
<ol>
<li>Field (which is the super class for the other two field types</li>
<li>TextField</li>
<li>MultiLineTextField</li>
</ol>
<p>As their names imply, a <em>TextField</em> will be a single line text entry field, whereas <em>MultiLineTextField</em> will be a multiline text input field. We somehow need to be able to render different HTMNL code for each of these different text field types.</p>
<p>As mentioned in the introduction, Xpand is not only type safe, but also supports <strong>polymorphic dispatch</strong>. This basically means we will create three templates (one for each of the different field types) <em>with the same name</em>. When evaluating the code template, the Xpand generator will dispatch to the appropriate template by matching the most concrete type of the current model element.</p>
<p>Add the following code to the template file:</p>
<pre>
«DEFINE field FOR Field»
«ERROR "should not happen"»
«ENDDEFINE»
«DEFINE field FOR TextField»
        <label for="«this.name»">«this.label»:</label>
<input type="text" name="«this.name»" id="«this.name»" />
«ENDDEFINE»
«DEFINE field FOR MultiLineTextField»
        <label for="«this.name»">«this.label»:</label>
        <textarea name="«this.name»" id="«this.name»" rows="20" cols="20"></textarea>
«ENDDEFINE»
</pre>
<p>As you can see, all three templates have the same name. Only the type they are bound to differs. This is enough to let Xpand know which template to choose according to the type of the current model element. Let's suppose Xpand is iterating the model and the current model element is a <em>TextField</em>. Although <em>Field</em> is a direct super type of <em>TextField</em>, Xpand will not invoke the first template (<em>«DEFINE field FOR Field»</em>), but the second template (<em>«DEFINE field FOR TextField»</em>), as this is the most concrete match for the type of the model element.</p>
<h2>Running the Code Generator</h2>
<p>If you have followed the above steps, running the code generator is a piece of cake: </p>
<p>Open the context menu on <em>src/workflow/workflow.mwe</em> and select <em>Run As -> MWE Workflow</em></p>
<p>This will start the code generator. You will see some log messages in the console view. If all went well, the output in the console reads something like this:</p>
<pre>
...
1503 INFO  Generator          - Written 1 files to outlet [default](src-gen)
1503 INFO  WorkflowRunner     - workflow completed in 650ms!
</pre>
<p>The result of the code generation can be found in <em>src-gen/contact.html</em>. As this file has some dependencies to CSS/image files, please download the files from the <em>static</em> folder (<a href="http://code.google.com/p/peterfriese/source/browse/#svn/org.xpand.example.gettingstarted/trunk/org.xpand.example.gettingstarted/static">here</a>) and place them in your project before opening <em>contact.html</em> in your browser.</p>
<h2>Where to go from here</h2>
<p>If you want to learn more about Xpand, be sure to attend my talk <a href="http://www.eclipsecon.org/2010/sessions/?page=sessions&id=1129">Use models and let the computer do the grunt work with Xpand</a> at EclipseCon 2010. I'll show some more advanced topics in this talk (such as generator cartridges, using Xtend to augment your models, partitioning your code templates, using other metamodels to define your models).</p>
<p>Xpand comes with an extensive documentation (just go to <em>Help -> Help Contents -> Xpand Documentation</em> in Eclipse). You can also get help on Xpand in the <a href="http://www.eclipse.org/forums/index.php?t=tree&th=163643&">Eclipse Community Forums</a></p>
<p>Should you need help, <a href="http://www.itemis.com">itemis (the company I work with)</a> offers training and consulting for Xpand and a host of other modeling related technologies.</p>
<p>No doubt you have heard about <a href="http://www.xtext.org">Xtext</a>. Xpand and Xtext go together great: you can use Xtext to define the structure of your models and create great-looking text editors to edit your models. Then, use Xpand to create code generators that take your textual models and turn them into running software. Actually, Xtext comes with a wizard that you to create a code generator project for your DSL.</p>
<h2>Downwloads</h2>
<p>The code for this tutorial can be found in <a href="http://code.google.com/p/peterfriese/source/browse/#svn/org.xpand.example.gettingstarted/trunk/org.xpand.example.gettingstarted">my SVN repository on Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/getting-started-with-code-generation-with-xpand/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Everything You Always Wanted To Know About Modeling (But Were Afraid To Ask)</title>
		<link>http://www.peterfriese.de/everything-you-always-wanted-to-know-about-modeling-but-were-afraid-to-ask/</link>
		<comments>http://www.peterfriese.de/everything-you-always-wanted-to-know-about-modeling-but-were-afraid-to-ask/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 20:18:52 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Canada]]></category>
		<category><![CDATA[DSLs]]></category>
		<category><![CDATA[EMF]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>
		<category><![CDATA[USA]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=333</guid>
		<description><![CDATA[
Does Model Driven Software Development actually work?
Are some developers more productive than others?
What happens during code generation?
Do diagrams and text go together well?
What happens during model transformation?
What are DSLs? And can I create them with Eclipse?
Does modeling scale in the enterprise?

You guessed it, these are not the questions from a well-know Woody Allen movie, but[...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Does Model Driven Software Development actually work?</li>
<li>Are some developers more productive than others?</li>
<li>What happens during code generation?</li>
<li>Do diagrams and text go together well?</li>
<li>What happens during model transformation?</li>
<li>What are DSLs? And can I create them with Eclipse?</li>
<li>Does modeling scale in the enterprise?</li>
</ol>
<p>You guessed it, these are not the questions from a <a href="http://en.wikipedia.org/wiki/Everything_You_Always_Wanted_to_Know_About_Sex*_(*But_Were_Afraid_to_Ask)">well-know Woody Allen movie</a>, but questions that will be answered at the <a href="http://wiki.eclipse.org/Eclipse_Modeling_Day">Eclipse Modeling Days</a> which will be held in <a href="http://wiki.eclipse.org/Eclipse_Modeling_Day#New_York_City">New York</a> and <a href="http://wiki.eclipse.org/Eclipse_Modeling_Day#Toronto">Toronto</a> in November.<br />
<span id="more-333"></span><br />
So if you are wondering why everybody in Europe is so thrilled about Modeling, attend to one of these events - you'll get the answers there. </p>
<p>For your convenience, here is a list of some of the talks:</p>
<ul>
<li>Case Study: Model Transformations - Richard Woods, Credit Suisse</li>
<li>Building DSLs with Xtext - Heiko Behrens, itemis</li>
<li>Modeling on an enterprise scale - Eike Stepper, Eclipse Modeling Project</li>
<li>Query, Transaction and Validation - Bernd Kolb & Boris Gruschko, both SAP</li>
<li>Agent-Based Computer Simulation for Operational Risk Analysis - Ed MacKerrow, Los Alamos Labs</li>
<li>Papyrus: Advent of an Open Source IME - Kenn Hussey, Zeligsoft</li>
<li>B3: A Model for Unbreakable Builds</li>
<li>There's a Modeling Solution for That - Bruce Trask, MDE Systems & Angel Roman, MDE Systems</li>
</ul>
<p>If you ask me, this is a pretty decent line-up, both content-wise and people-wise. Not being one of the big conferences, the Modeling Days will actually give you the chance to talk to the experts and other end-users. Remember, networking is key.</p>
<p>So go ahead and register by adding your name to <a href="http://wiki.eclipse.org/Eclipse_Modeling_Day">this wiki page</a>. Registration is free, but you need to register in order to help the organizers to plan the catering. If you don't have an account for editing the wiki page or don't want to create one, just send mail to <a href="mailto:eclipse_modeling_nyc@eclipse.org">eclipse_modeling_nyc@eclipse.org</a> or <a href="mailto:eclipse_modeling_toronto@eclipse.org">eclipse_modeling_toronto@eclipse.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/everything-you-always-wanted-to-know-about-modeling-but-were-afraid-to-ask/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Modeling is dead. Long live Modeling!</title>
		<link>http://www.peterfriese.de/modeling-is-dead-long-live-modeling/</link>
		<comments>http://www.peterfriese.de/modeling-is-dead-long-live-modeling/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 13:44:18 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[EMF]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=218</guid>
		<description><![CDATA[Although some people seem to be convinced that Eclipse and Eclipse Modeling are dead, I have been sensing quite healthy life signals of both on EclipseCon 2009 (or rather #eclipsecon).
On Monday, Bernd, Kenn and I hosted the official Modeling BOF:



The topics discussed were focussing on consumability and long-term sustainability of EMF:
Documentation and Marketing
We all agreed[...]]]></description>
			<content:encoded><![CDATA[<p>Although <a href="http://kenn-hussey.blogspot.com/2009/03/on-death-of-eclipse-and-modeling.html">some people seem to be convinced</a> that <a href="http://www.eclipse.org/">Eclipse</a> and <a href="http://www.eclipse.org/modeling/">Eclipse Modeling</a> are dead, I have been sensing quite healthy life signals of both on EclipseCon 2009 (or rather <a href="http://search.twitter.com/search?q=%23eclipsecon">#eclipsecon</a>).</p>
<p>On Monday, <a href="http://www.flickr.com/photos/sza/3385548232/">Bernd</a>, <a href="http://kenn-hussey.blogspot.com/">Kenn</a> and I hosted the <a href="http://www.eclipsecon.org/2009/sessions?id=780">official Modeling BOF</a>:<br />
<a href="http://www.flickr.com/photos/81029262@N00/3383866773" title="View 'Modeling BOF' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3648/3383866773_ffa5c03596.jpg" alt="Modeling BOF" border="0" width="500" height="194" /></div>
<p></a><br />
The topics discussed were focussing on consumability and long-term sustainability of EMF:</p>
<p><strong>Documentation and Marketing</strong></p>
<p>We all agreed that the entire modeling project lacks a decent documentation. While of course all of the projects and subprojects do have their own documentation, there is so such thing as an overview documentation. Modelers as we are, we quickly realized we're lacking a documentation superstructure. The idea is to provide a guide for users (newbies and seasoned experts alike) to navigate the Eclipse Modeling world. The modeling project offers a great variety of technologies, so it is not always easy to find out which set of technologies / frameworks you might want to use - especially if you are new to EMF.</p>
<p>We also agreed that we need more success stories (in the form of blog entries, articles and shiny flyers for the <a href="http://www.eclipse.org/home/categories/index.php?category=modeling">modeling landing page</a>). A quick poll revealed that more than 90% of all people attending have been working on projects in which modeling was successfully applied, so there should be enough material to create success stories!</p>
<p>Kenn mentioned the Eclipse Foundation wants to start a documentation project (much like <a href="http://www.eclipse.org/babel/">Babel</a>) to improve overall documentation, we might eventually join this project. In the meantime, we decided to form a working group comprised of members of the Eclipse Modeling Project that starts to create this overview documentation. The initial members of this working group will be Kenn, Bernd, Peter, Tamer, Pierre, Marcello, Thibault and Anthony (guys, please send me your email addresses). The working group will start its work on the <a href="https://dev.eclipse.org/mailman/listinfo/emf-dev">EMF dev mailing list</a>. You are welcome to join us there.</p>
<p><strong>Consuming Modeling Technology</strong></p>
<p>I think there is no other technology that causes more emotions in an Eclipse committers life than P2. So we also had our little discussion about how to best provision Modeling technology. No big news here - we just re-iterated the pros and cons of using ZIPs vs. P2 and also had a short discussion about the Friends of Eclipse Download Wizard (which, rumor has it, will allow you to assemble a custom distro by just selecting the pieces you need). Several people mentioned that <a href="http://www.eclipse.org/modeling/amalgam/">Amalgamation</a> is intended to be a place for modeling distros.</p>
<p><strong>EMF 3.0</strong></p>
<p>We also discussed whether we should have a new major release of EMF that allows us to break API. Though not everybody agreed that we need a new major version (because the current version works smoothly for most people) we decided to set up an additional BOF to discuss this topic in more detail. I will write about the EMF 3 BOF later (yes, I am teasing)</p>
<p><strong>Miscellanea</strong></p>
<p>Someone asked if we need something like a model bus, the answer was no - we've got the <a href="http://www.eclipse.org/modeling/emft/?project=mwe">modeling workflow engine (MWE)</a>.</p>
<p>We also briefly discussed the recent change of leadership on the MDT OCL component (<a href="http://give-a-damus.blogspot.com/">Christian Damus</a> <a href="http://dev.eclipse.org/mhonarc/lists/modeling-pmc/msg01042.html">revoked</a> his committer and component lead status recently). Everybody agreed that to lead a component, a long-term committment is needed (which has been met by Christian in the most excellent way). We also agreed that we need to make avoid situations in which a whole bunch of projects / components suddenly are without a leader. This will be a task for the PMC.<br />
<a href="http://www.flickr.com/photos/81029262@N00/3383867215" title="View 'Modeling BOF' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3629/3383867215_982c6592ac.jpg" alt="Modeling BOF" border="0" width="500" height="295" /></div>
<p></a></p>
<p>After the official part of the BOF, there still was time to chat and shake hands with people you never met in person before. I had the pleasure to shake hands with Anthony Hunter, who works for IBM. From our discussions on mailing lists and bugs, you could guess that we have a totally different view on the marketing of software, but it turns out we're actually not that far apart <img src='http://www.peterfriese.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://en.wikipedia.org/wiki/Birds_of_a_Feather_(computing)">BOFs</a> are a great way to interact with like-minded people at conferences. So, next time you go to a conference, make sure you participate in a BOF to make yourself be heard and take part in the discussion.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/modeling-is-dead-long-live-modeling/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Teneo, EMF and Hibernate to update and query your data</title>
		<link>http://www.peterfriese.de/using-teneo-emf-and-hibernate-to-update-and-query-your-data/</link>
		<comments>http://www.peterfriese.de/using-teneo-emf-and-hibernate-to-update-and-query-your-data/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 20:55:49 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[EMF]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Eclipse FAQ]]></category>
		<category><![CDATA[MDSD]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=215</guid>
		<description><![CDATA[Last week I showed you how to use Teneo, EMF and Hibernate to store your data in a database.
This week, we're going to have a look at how to update the data, add more records and how to query the database for information using HQL, the Hibernate Query Language.
If you haven't done so, you might[...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.peterfriese.de/using-teneo-and-emf-to-store-your-data/">Last week I showed you</a> how to use Teneo, EMF and Hibernate to store your data in a database.</p>
<p>This week, we're going to have a look at how to update the data, add more records and how to query the database for information using HQL, the Hibernate Query Language.</p>
<p>If you haven't done so, you might consider <a href="http://www.peterfriese.de/using-teneo-and-emf-to-store-your-data/">taking last week's tutorial</a> in order to get your environment set up and understand the basic concepts. If you're lazy, you can as well download the code of the tutorial to get started more quickly. It is available <a rel="nofollow" title="Download version 0.1 of EMF_Teneo_Hibernate_Step1.zip" onclick="if (window.urchinTracker) urchinTracker ('http://www.peterfriese.de/downloads/teneo/EMF_Teneo_Hibernate_Step1.zip');" href="http://www.peterfriese.de/downloads/teneo/EMF_Teneo_Hibernate_Step1.zip">here</a>.</p>
<p>As it turns out, in order to change anything in the library database, we must first fetch the to-be-changed data, so we need to have a look at querying first.</p>
<p><strong>Retrieving and updating data</strong><br />
Let's assume we'd want to the update the number of pages in a book, because the new edition has an additional chapter.</p>
<ol>
<li>So, first of all we need to open a session and begin a transaction:
<pre>
    {
        Session session = sessionFactory.openSession();
        session.beginTransaction();</pre>
</li>
<li>Next, let's create an HQL query. We want to find any books that are written by an author by the name "A. K. Dewdney" that contain "Omnibus" in their title.
<pre>
        Query query = session.createQuery(
            "SELECT book from " +
            "    Book book, " +
            "    Writer writer " +
            "WHERE " +
            "    book.title like '%Turing Omnibus%' " +
            "AND " +
            "    writer.name = 'A. K. Dewdney'");</pre>
</li>
<li>We can now execute the query and display the results:
<pre>
        List<Book> books = query.list();
        Book book = books.get(0);
        System.out.println(book.getTitle());</pre>
</li>
<li>Updating the page count is pretty obvious:
<pre>
        book.setPages(520);</pre>
</li>
<li>Finally, don't forget to commit the transaction and close the session:
<pre>
        session.getTransaction().commit();
        session.close();
    }</pre>
</li>
</ol>
<p><strong>Adding data</strong><br />
Let's now assume we want to add more books (and authors) to the library.</p>
<ol>
<li>By now, you should be pretty familiar with the pattern of opening a new session:
<pre>
    {
        Session session = sessionFactory.openSession();
        session.beginTransaction();</pre>
</li>
<li>As we want to add new items to the library, we need to retrieve the library instance first of all:
<pre>
        Query query = session.createQuery("from Library");
        List<Library> libraries = query.list();
        Library library = libraries.get(0);</pre>
</li>
<li>Creating a new book and its author is easy, as we just have to use the API EMF so kindly generated for us:
<pre>
        Writer writer = LibraryFactory.eINSTANCE.createWriter();
        writer.setName("J.R.R. Tolkien");
        Book book = LibraryFactory.eINSTANCE.createBook();
        book.setTitle("The Hobbit");
        book.setPages(320);
        book.setAuthor(writer);
        book.setCategory(BookCategory.MYSTERY);
        library.getBooks().add(book);
        library.getWriters().add(writer);</pre>
</li>
<li>Finally, commit the transaction and close the session:
<pre>
        session.getTransaction().commit();
        session.close();
    }</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/using-teneo-emf-and-hibernate-to-update-and-query-your-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Teneo and EMF to store your data</title>
		<link>http://www.peterfriese.de/using-teneo-and-emf-to-store-your-data/</link>
		<comments>http://www.peterfriese.de/using-teneo-and-emf-to-store-your-data/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 21:22:42 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[EMF]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Eclipse FAQ]]></category>
		<category><![CDATA[MDSD]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=181</guid>
		<description><![CDATA[Most of you know that I am working as a committer for various Eclipse-related projects (such as Xtext, Xpand and the Modeling Workflow Engine). You might not know, however, that I also work as a consultant for itemis. On one of my recent consulting assignments in Ottawa, Canada, I was asked "How can we use[...]]]></description>
			<content:encoded><![CDATA[<p>Most of you know that I am working as a committer for various Eclipse-related projects (such as <a href="http://www.xtext.org">Xtext</a>, <a href="http://www.eclipse.org/modeling/m2t/?project=xpand">Xpand</a> and the <a href="http://www.eclipse.org/modeling/emft/?project=mwe#mwe">Modeling Workflow Engine</a>). You might not know, however, that I also work as a consultant for <a href="http://www.itemis.com">itemis</a>. On one of my <a href="http://www.itemis.com/itemis-ag/language=en/2621/portfolio">recent consulting assignments</a> in Ottawa, Canada, I was asked "How can we use EMF to store our data in a database?"</p>
<p>Well, it turns out EMF can help a long way to store data in a database. Here is how.<br />
<strong>Prepare your development environment</strong></p>
<ol>
<li>Get Eclipse 3.5 M5 (<a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.5M5-200902021535/index.php">click here to download</a>)</li>
<li>Unpack and start Eclipse</li>
<li>Bring up the "Install New Software" dialog (Help -&gt; Install New Software)</li>
<li>Select <em>Teneo EMF Hibernate Runtime</em> and <em>Teneo EMF Hibernate SDK</em>, version 1.0.3</li>
<li>Cick <em>Finish</em></li>
<li>You most probably will be asked to restart Eclipse.</li>
</ol>
<p><strong>Create a target definition that includes Hibernate and HSQLDB</strong><br />
In order to keep things simple, we will store the data in an <a href="http://hsqldb.org/">HSQLDB</a> database. We will use the <a href="http://www.hibernate.org/">Hibernate</a> OR Mapper to perform the mapping between your data objects and the database. As you might guess, quite a number of libraries will be involved to get the task accomplished. Instead of creating a bunch of plug-in projects containing the respective libraries, or - even worse - copying all libraries into our project, we'll set up a target definition. Target definitions help to maintain a common set of dependencies for all developers on a team, which is a Good Thing.</p>
<ol>
<li>Create a new project <em>library.target</em> (File -&gt; New -&gt; Project... -&gt; General -&gt; Project)</li>
<li>Create three folders in this project: <em>hibernate</em>, <em>dependencies</em>, <em>hsqldb</em></li>
<li>Go to the <a href="http://www.springsource.com/repository/app/">SpringSource Bundle Repository</a> and download the following OSGi bundles:<br />
<table border="0" cellspacing="5">
<tbody>
<tr>
<th align="left">file</th>
<th align="left">save in folder</th>
</tr>
<tr>
<td>com.springsource.org.hibernate-3.2.6.ga.jar</td>
<td>library.target/hibernate</td>
</tr>
<tr>
<td>com.springsource.org.apache.commons.logging-1.1.1.jar</td>
<td>library.target/dependencies</td>
</tr>
<tr>
<td>com.springsource.org.dom4j-1.6.1.jar</td>
<td>library.target/dependencies</td>
</tr>
<tr>
<td>com.springsource.org.apache.commons.collections-3.2.0.jar</td>
<td>library.target/dependencies</td>
</tr>
<tr>
<td>com.springsource.javax.transaction-1.1.0.jar</td>
<td>library.target/dependencies</td>
</tr>
<tr>
<td>com.springsource.antlr-2.7.7.jar</td>
<td>library.target/dependencies</td>
</tr>
<tr>
<td>com.springsource.org.hsqldb-1.8.0.9.jar</td>
<td>library.target/hsqldb</td>
</tr>
</tbody>
</table>
</li>
<li>Create a new target definition library.target in this project (File -&gt; New -&gt; Other... -&gt; Plug-in Development -&gt; Target Definition)</li>
<li>Open the target definition and add the three directories to it's contents. As the GUI does not allow you to work with relative paths, you might consider to use a text editor to paste the following text:
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;?pde version="3.5"?&gt;
&lt;target description="Teneo-related stuff, mostly Hibernate" name="Library Target Definition"&gt;
    &lt;locations&gt;
        &lt;location path="${eclipse_home}" type="Profile"/&gt;
        &lt;location path="${workspace_loc}/library.target/hibernate" type="Directory"/&gt;
        &lt;location path="${workspace_loc}/library.target/dependencies" type="Directory"/&gt;
        &lt;location path="${workspace_loc}/library.target/hsqldb" type="Directory"/&gt;
    &lt;/locations&gt;
&lt;/target&gt;</pre>
</li>
<li>Open the target definition in the Target Definition Editor and click on the <em>Set as Target Platform</em> hyperlink in the upper right area. This will activate the target definition. All contained bundles are now available and can be referenced as dependencies.</li>
</ol>
<p><strong>Create a model for your data</strong><br />
The data model will be based on the <a href="http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.html">well-known library tutorial</a> that ships with EMF. If you are interested in a more in-depth look, I recommend taking this tutorial. However, to shortcut things, here is the ultra-slim version of the EMF-Tutorial:</p>
<ol>
<li>Download the Rose class model and save it on your computer</li>
<li>Create a new EMF project (File -&gt; New -&gt; Other... -&gt; Eclipse Modeling Framework -&gt; EMF Project)
<ul>
<li>Project name: library</li>
<li>Model importer: Rose class model</li>
<li>Browse to the Rose class model <em>library.mdl</em> mentioned before</li>
<li>Click on Load to load the model</li>
<li>Click Next, then Finish</li>
</ul>
</li>
<li>In the library.genmodel editor, right-click on the Library node and select Generate Model Code</li>
</ol>
<p><strong>Create the library main application</strong><br />
In order to demonstrate how to use the data model and how to perform CRUD operations with your data, we will create a simple Java class. In the good spirit of encapsulation and components, we will create a new plug-in project to host this class:</p>
<ol>
<li>Create a new Plug-in project library.main (File -&gt; New -&gt; Project... -&gt; Plug-in Project)</li>
<li>Open the manifest and add the following dependencies:
<ul>
<li><em>library</em> (this is the bundle which contains our data model)</li>
<li><em>org.eclipse.emf.teneo.hibernate</em></li>
<li><em>org.eclipse.emf.ecore.xmi</em></li>
<li><em>com.springsource.org.hibernate</em></li>
<li><em>com.springsource.org.apache.commons.logging</em></li>
<li><em>com.springsource.org.dom4j</em></li>
<li><em>com.springsource.org.apache.commons.collections</em></li>
<li><em>com.springsource.javax.transaction</em></li>
<li><em>com.springsource.antlr</em></li>
<li><em>com.springsource.org.hsqldb</em></li>
</ul>
</li>
<li>Create a new Hibernate configuration file <em>hibernate.properties</em> in <em>library.main/src</em> and paste the following lines:
<pre>hibernate.connection.driver_class=org.hsqldb.jdbcDriver
# use the following line to run the embedded db:
# hibernate.connection.url=jdbc:hsqldb:file:/some/path/on/your/computer/dbname
# the following line will connect to a standalone (local) DB server:
hibernate.connection.url=jdbc:hsqldb:hsql://127.0.0.1/library
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.hbm2ddl.auto=true</pre>
</li>
</ol>
<p><strong>Implement the library main application</strong><br />
With all the boilerplate in place, we're finally ready to write some code. We will create a new class and add some code to create an author and his book and store both in a library.</p>
<ol>
<li>Create a new class LibraryDemo, making sure it has a main method</li>
<li>In order to use Teneo to persist our data, we first need to create a datastore and register our model package with it:
<pre>    // create the data store
    String dataStoreName = "LibraryDataStore";
    HbDataStore dataStore = HbHelper.INSTANCE.createRegisterDataStore(dataStoreName);

    // register the model package with the data store
    dataStore.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });

    // initialize the data store, which creates the tables
    dataStore.initialize();</pre>
</li>
<li>Next, we need to get hold of a session factory and request a new session form it:
<pre>    SessionFactory sessionFactory = dataStore.getSessionFactory();
    {
        Session session = sessionFactory.openSession();
        session.beginTransaction();</pre>
</li>
<li>Now, let's create a new library and save it to the session:
<pre>        // create a library
        Library library = LibraryFactory.eINSTANCE.createLibrary();
        library.setName("Developer's bookshelf");

        // store the library
        session.save(library);</pre>
</li>
<li>In the following part, we will create an author and his book, link them to each other and add them to the library. There is no specific Teneo aspect to this part of the code, it is just straightforward usage of the API EMF generated for your datamodel:
<pre>        // create an author
        Writer writer = LibraryFactory.eINSTANCE.createWriter();
        writer.setName("A. K. Dewdney");

        // create a book
        Book book = LibraryFactory.eINSTANCE.createBook();
        book.setTitle("The New Turing Omnibus");
        book.setPages(480);
        book.setCategory(BookCategory.MYSTERY); // oh well, let's hope it's not mystery to most readers!
        book.setAuthor(writer);

        // add book and writer to library
        library.getBooks().add(book);
        library.getWriters().add(writer);</pre>
</li>
<li>Finally, we need to commit our changes to the database and close the session:
<pre>        // commit changes to the database and close the session
        session.getTransaction().commit();
        session.close();
    }</pre>
</li>
</ol>
<p><strong>Start the DB server and run the application</strong></p>
<ol>
<li>Open a command line and navigate to the directory that contains <em>hsqldb.jar</em></li>
<li>Start the HSQLDB server using this command line:
<pre>java -cp com.springsource.org.hsqldb-1.8.0.9.jar org.hsqldb.Server -database.0 file:library -dbname.0 library</pre>
</li>
<li>Finally (!) go back to Eclipse and start <em>LibraryDemo</em>. You should get an output similar to this one:
<pre>Mar 6, 2009 1:50:26 PM org.eclipse.emf.teneo.hibernate.HbHelper createRegisterDataStore
INFO: Creating emf data store and registering it under name: LibraryDataStore
...
Mar 6, 2009 1:50:28 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete</pre>
</li>
<li>To actually see the data stored in the database, navigate to the directory containing the database and open <em>library.log</em>:
<pre>CREATE USER SA PASSWORD "" ADMIN
/*C1*/SET SCHEMA PUBLIC
CONNECT USER SA
...
INSERT INTO "library" VALUES(1,'Library',0,'Developer''s bookshelf')
INSERT INTO "writer" VALUES(1,'Writer',0,'A. K. Dewdney',NULL,NULL,'Library','1',-2)
INSERT INTO "book" VALUES(1,'Book',0,'The New Turing Omnibus',480,'Mystery',1,NULL,NULL,'Library','1',-3)
DELETE FROM "writer" WHERE E_ID=1
INSERT INTO "writer" VALUES(1,'Writer',0,'A. K. Dewdney',1,0,'Library','1',-2)
DELETE FROM "book" WHERE E_ID=1
INSERT INTO "book" VALUES(1,'Book',0,'The New Turing Omnibus',480,'Mystery',1,1,0,'Library','1',-3)
INSERT INTO "writer_books" VALUES(1,1,0)
COMMIT
DISCONNECT</pre>
</li>
</ol>
<p>In the next installment, I will show you how to retrieve objects from the database and query the database using Hibernate Query Language (HQL).</p>
<p><strong>Download the source</strong><br />
If you are interested in the source for the solution so far, you can <a rel="nofollow" title="Download version 0.1 of EMF_Teneo_Hibernate_Step1.zip" onclick="if (window.urchinTracker) urchinTracker ('http://www.peterfriese.de/downloads/teneo/EMF_Teneo_Hibernate_Step1.zip');" href="http://www.peterfriese.de/downloads/teneo/EMF_Teneo_Hibernate_Step1.zip">download</a> it here: <a rel="nofollow" title="Download version 0.1 of EMF_Teneo_Hibernate_Step1.zip" onclick="if (window.urchinTracker) urchinTracker ('http://www.peterfriese.de/downloads/teneo/EMF_Teneo_Hibernate_Step1.zip');" href="http://www.peterfriese.de/downloads/teneo/EMF_Teneo_Hibernate_Step1.zip">(click to download)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/using-teneo-and-emf-to-store-your-data/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
