<?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; MDSD</title>
	<atom:link href="http://www.peterfriese.de/category/computer/mdsd/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>Xtext Tricks #1: Enhancing Completion Proposals</title>
		<link>http://www.peterfriese.de/xtext-tricks-1-enhancing-completion-proposals/</link>
		<comments>http://www.peterfriese.de/xtext-tricks-1-enhancing-completion-proposals/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 14:55:43 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[DSLs]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=337</guid>
		<description><![CDATA[Those of you who follow me on Twitter might have noticed I am working on an Xtext based DSL for Behaviour Driven Development. Part of the DSL allows the DSL user to define actors and the verbs these actors can execute. Actors can have a hierarchy (much like a class hierarchy), meaning an actor will[...]]]></description>
			<content:encoded><![CDATA[<p>Those of you who <a href="htp://twitter.com/peterfriese">follow me on Twitter</a> might have noticed <a href="http://twitter.com/peterfriese/status/4889552469">I am working on an Xtext based DSL</a> for <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">Behaviour Driven Development</a>. Part of the DSL allows the DSL user to define actors and the verbs these actors can execute. Actors can have a hierarchy (much like a class hierarchy), meaning an actor will inherit all verbs of it's super actors. As the list of verbs can grow quite a bit, the content assist drop down menu becomes a bit overwhelming.</p>
<p><a href="http://www.flickr.com/photos/81029262@N00/4029808851" title="View 'XtextProposalProviderBefore' on Flickr.com">
<div style="text-align:center;"><img src="http://farm3.static.flickr.com/2581/4029808851_22fd514946.jpg" alt="XtextProposalProviderBefore" border="0" width="459" height="339" /></div>
<p></a></p>
<p>To alleviate  this situation, I decided to display the "owner" of a verb along with the name of the verb in the content assist drop down box. Here is my first try:<br />
<span id="more-337"></span></p>
<pre>
public class StoryDslProposalProvider extends AbstractStoryDslProposalProvider {
  @Override
  protected ICompletionProposal createCompletionProposal(EObject element, String proposal, String displayString, ContentAssistContext contentAssistContext)
  {
    if (element instanceof Verb) {
      Verb verb = (Verb) element;
      Subject owner = ((Subject)verb.eContainer());
      String myDisplayString = verb.getName() + ": " + owner.getName();
      return super.createCompletionProposal(element, proposal, myDisplayString, contentAssistContext);
    }
    return super.createCompletionProposal(element, proposal,  displayString, contentAssistContext);
  }
}
</pre>
<p>With this piece of code in place, the content assist proposals for verbs will now display the name of the "owner" to the right of the replacement text:</p>
<p><a href="http://www.flickr.com/photos/81029262@N00/4030575068" title="View 'XtextContentAssistAfter' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3526/4030575068_2358208f22.jpg" alt="XtextContentAssistAfter" border="0" width="456" height="329" /></div>
<p></a></p>
<p><a href="http://zarnekow.blogspot.com/">Sebastian</a> pointed out that there is a <code>getDisplayString()</code> in <code>AbstractContentProposalProvider</code> that you should override in order to create a custom display string. It turned out, however, that this method will not be called as expected. I <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=293380">filed a bug</a>, so expect to see a fix in one of the next milestones of the Xtext 0.8.0 stream.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/xtext-tricks-1-enhancing-completion-proposals/feed/</wfw:commentRss>
		<slash:comments>0</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>Xtext @ Google</title>
		<link>http://www.peterfriese.de/xtext-google/</link>
		<comments>http://www.peterfriese.de/xtext-google/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 12:46:02 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[DSLs]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=307</guid>
		<description><![CDATA[Last week I had the chance to speak at the EclipseDay at the GooglePlex in Mountain View, CA, an event organized by the Eclipse Foundation and hosted by Google's Open Source Programs Office.  Google is a truly amazing company and the GooglePlex is a very exciting place to be at. As I was one[...]]]></description>
			<content:encoded><![CDATA[<p>Last week I had the chance to speak at the <a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009">EclipseDay at the GooglePlex</a> in <a href="http://maps.google.com/?q=Google+Inc.%4037.423156,-122.084917&amp;hl=en&amp;ie=UTF8&amp;ll=37.42216,-122.085764&amp;spn=0.005283,0.011362&amp;t=h&amp;z=17">Mountain View, CA</a>, an event organized by the <a href="http://www.eclipse.org">Eclipse Foundation</a> and hosted by <a href="http://code.google.com/opensource/">Google's Open Source Programs Office</a>.  Google is a truly amazing company and the GooglePlex is a very exciting place to be at. As I was one day early and needed a creative place to put finishing touches on my slides, I took the chance to visit <a href="http://konigsberg.blogspot.com/">Robert Konigsberg</a> who was kind enough to host me for that day.  The organizers put together a great agenda with lots of interesting talks. <a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts">Looking at the agenda</a>, you will see that there actually are three major topics, <strong>Eclipse in the Enterprise</strong>, <strong>Modeling</strong> and <strong>Runtime</strong>:  The talks</p>
<ul>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Eclipse_in_the_Enterprise:_Lessons_from_Google">Eclipse in the Enterprise: Lessons from Google</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Distributed_OSGi_in_the_Eclipse_Runtime_Project">Distributed OSGi</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Deploying_Successful_Enterprise_Tools">Deploying Successful Enterprise Tools</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Build_and_Provision:_Two_Sides_of_the_Coin_We_Love_to_Hate">Build and Provision</a></li>
</ul>
<p>all dealt with how Eclipse can be used in the Enterprise or which challenges you will face if you start using Eclipse in large-scale scenarios.<br />
<span id="more-307"></span><br />
The talks</p>
<ul>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Developing_DSLs_with_Eclipse">Developing DSLs with Eclipse</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Eclipse_in_NASA_Mission_Control">Eclipse in NASA Mission Control</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Build_and_Provision:_Two_Sides_of_the_Coin_We_Love_to_Hate">Build and Provision</a></li>
</ul>
<p>either directly had modeling as their topic or used modeling technology to solve their problems. I especially liked the NASA talk which featured a number of computer animated videos of recent or future missions. The NASA mission control software is heavily based on Eclipse and technology form the Eclipse Modeling Project.  Finally, there were some talk on runtime technology:</p>
<ul>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#OSGi_for_Eclipse_Developers">OSGi for Eclipse Developers</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Developing_for_Android_with_Eclipse">Developing for Android with Eclipse</a></li>
<li><a href="http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009/Session_Abstacts#Google_Plugin_for_Eclipse:_Not_Just_for_Newbies_Any_More">Google Plugin for Eclipse: Not Just for Newbies Any More</a></li>
</ul>
<p>Attending great talks of course is one of the major benefits of going to a conference like this. To me, meeting other people and connecting has become even more important than attending great talks. Of course, this is nothing new to event organizers and so there were many chances to grab a drink and chat with the other attendees. With more than 170 people attending, it was hard to have a chat with everyone, but nevertheless I managed to talk to a number of people, many of which already are Xtext users or are now planing to have a detailed look at it. Even Google is using Xtext, but ssshh!  Overall, I really enjoyed my two days at Google and look forward to more events like this. Speaking of which, <a href="http://www.eclipsecon.org/summiteurope2009/">Eclipse Summit Europe is approaching fast</a>, so make sure you register on time. Also, if you're interested in Modeling and DSLs, we're organizing a Modeling / DSL Day in North America this coming fall - see <a href="http://www.peterfriese.de/eclipse-modeling-day-in-north-america/">my previous post</a> for more info.  And finally, here are the slides and the video of my talk:</p>
<div><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=buildingdslswitheclipseslideshare-key-090827153422-phpapp02&amp;stripped_title=building-dsls-with-eclipse-1916333" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="480" height="385" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=buildingdslswitheclipseslideshare-key-090827153422-phpapp02&amp;stripped_title=building-dsls-with-eclipse-1916333" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube-nocookie.com/v/bhdGNTm4PzI&amp;hl=en&amp;fs=1&amp;color1=0x234900&amp;color2=0x4e9e00" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube-nocookie.com/v/bhdGNTm4PzI&amp;hl=en&amp;fs=1&amp;color1=0x234900&amp;color2=0x4e9e00" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/xtext-google/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Eclipse Modeling Day in North America</title>
		<link>http://www.peterfriese.de/eclipse-modeling-day-in-north-america/</link>
		<comments>http://www.peterfriese.de/eclipse-modeling-day-in-north-america/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 17:22:41 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[DSLs]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=302</guid>
		<description><![CDATA[We (i.e. the Eclipse Foundation, itemis and Cloudsmith) are looking into arranging one more Eclipse Modeling Day in North America this fall and would like to gather feedback from folks interested in attending. Please use this poll to help us tailor a location and program to suit your particular interests:
 http://spreadsheets.google.com/viewform?hl=en&#38;formkey=dF ZQcGh3RDhrUUdyNTAtMXlVU2pKQ1E6MA..

Our goal is to[...]]]></description>
			<content:encoded><![CDATA[<p><span class="MsgBodyText">We (i.e. the Eclipse Foundation, <a href="http://www.itemis.com">itemis</a> and Cloudsmith) are looking into arranging one more Eclipse Modeling Day in North America this fall and would like to gather feedback from folks interested in attending. Please use this poll to help us tailor a location and program to suit your particular interests:</span></p>
<p><a href="http://spreadsheets.google.com/viewform?hl=en&amp;formkey=dFZQcGh3RDhrUUdyNTAtMXlVU2pKQ1E6MA.." target="_blank"> http://spreadsheets.google.com/viewform?hl=en&amp;formkey=dF ZQcGh3RDhrUUdyNTAtMXlVU2pKQ1E6MA..</a><br />
<span id="more-302"></span><br />
Our goal is to organize an event especially for people new to modeling or who are curious what this modeling fuss is all about and how it can help them. So, this will not be an experts meeting, but you can meet experts talking about their topics. We also are interested in case studies, so ideally you will get first-hand experience from people who use modeling in real life to meet real challenges.</p>
<p>We welcome any feedback, so please fill out our little poll.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/eclipse-modeling-day-in-north-america/feed/</wfw:commentRss>
		<slash:comments>1</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>
		<item>
		<title>O Canada</title>
		<link>http://www.peterfriese.de/o-canada/</link>
		<comments>http://www.peterfriese.de/o-canada/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 20:03:56 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Canada]]></category>
		<category><![CDATA[MDSD]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=168</guid>
		<description><![CDATA[So I arrived in Canada on Friday night aboard Air Canada 877 from Frankfurt to Toronto. I was very pleased to see that the flight wasn't fully booked, so I had the luxury of using two seats for the price of one. They have a fancy lighting system aboard these air crafts which might be[...]]]></description>
			<content:encoded><![CDATA[<p>So I arrived in Canada on Friday night aboard Air Canada 877 from Frankfurt to Toronto. I was very pleased to see that the flight wasn't fully booked, so I had the luxury of using two seats for the price of one. They have a fancy lighting system aboard these air crafts which might be supposed to simulate the diurnal rhythm, but if that's actually true, I lived through several days and nights on that flight!</p>
<p><a href="http://www.flickr.com/photos/81029262@N00/3242484712" title="View 'Disco lights aboard Air Canada 877' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3372/3242484712_a9be61503c.jpg" alt="Disco lights aboard Air Canada 877" border="0" width="500" height="335" /></div>
<p></a></p>
<p>After having a nice supper and watching "<a href="http://en.wikipedia.org/wiki/Burn_After_Reading">Burn After Reading</a>", I took the chance to have a nap and actually arrived well rested at Toronto Pearson Airport.</p>
<p><a href="http://www.flickr.com/photos/81029262@N00/3242490062" title="View 'Approaching Toronto' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3083/3242490062_f2ae80743c.jpg" alt="Approaching Toronto" border="0" width="500" height="333" /></div>
<p></a></p>
<p>Canada is full of snow at this time, which I like very much - we do not have so much snow up in Hamburg, where I live.</p>
<p><a href="http://www.flickr.com/photos/81029262@N00/3244884282" title="View 'Ballantrae' on Flickr.com">
<div style="text-align:center;"><img src="http://static.flickr.com/3390/3244884282_ffb97a69a3.jpg" alt="Ballantrae" border="0" width="" height="" /></div>
<p></a></p>
<p>I am staying at Ed Merks' place for the next few weeks in order to talk about business opportunities for itemis here in North America.</p>
<p><a href="http://www.flickr.com/photos/81029262@N00/3241511257" title="View 'Ed's house' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3368/3241511257_4d846e81b0.jpg" alt="Ed's house" border="0" width="500" height="179" /></div>
<p></a></p>
<p>So, if you're interested in doing model driven software development or need some advise on EMF, openArchitectureWare or textual DSLs (with Xtext), just drop me or Ed a note. You can reach me via peter at itemis dot com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/o-canada/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Software Engineering Radio: Eelco Visser on Parsing</title>
		<link>http://www.peterfriese.de/software-engineering-radio-eelco-visser-on-parsing/</link>
		<comments>http://www.peterfriese.de/software-engineering-radio-eelco-visser-on-parsing/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 11:57:15 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=162</guid>
		<description><![CDATA[In the current SE-Radio episode, Laurence Tratt interviews Eelco Visser on Parsing.
If you're interested in Domain Specific Languages (DSLs), you should take some time to listen to this episode. Especially the part on scanner-less parsing is very interesting, as it allows to mingle code from different languages in one single file.
]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.se-radio.net/podcast/2008-11/episode-118-eelco-visser-parsers">current SE-Radio episode</a>, <a href="http://tratt.net/laurie/">Laurence Tratt</a> interviews <a href="http://eelcovisser.org/">Eelco Visser</a> on <a href="http://en.wikipedia.org/wiki/Parsing">Parsing</a>.</p>
<p>If you're interested in <a href="http://en.wikipedia.org/wiki/Domain-specific_language">Domain Specific Languages (DSLs)</a>, you should take some time to listen to this episode. Especially the part on <a href="http://en.wikipedia.org/wiki/Scannerless_parsing">scanner-less parsing</a> is very interesting, as it allows to mingle code from different languages in one single file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/software-engineering-radio-eelco-visser-on-parsing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Xpand in your Eclipse Wizards</title>
		<link>http://www.peterfriese.de/using-xpand-in-your-eclipse-wizards/</link>
		<comments>http://www.peterfriese.de/using-xpand-in-your-eclipse-wizards/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 10:42:26 +0000</pubDate>
		<dc:creator>Peter Friese</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>

		<guid isPermaLink="false">http://www.peterfriese.de/?p=154</guid>
		<description><![CDATA[At ESE, I had a nice chat with Chris (actually, I had a lot of nice chats with a lot of nice people - it was quite a challenge to attend any of the sessions), who told me that he was looking into template engines. I leave it up to you to make any assumptions[...]]]></description>
			<content:encoded><![CDATA[<p>At <a href="http://www.eclipsecon.org/summiteurope2008/">ESE</a>, I had a nice chat with <a href="http://mea-bloga.blogspot.com/">Chris</a> (actually, I had a lot of nice chats with a lot of nice people - it was quite a challenge to attend any of the sessions), who told me that he was looking into template engines. I leave it up to you to make any assumptions on why he's interested in template engines. I happen to know at least three template engines: Velocity (which I had the joy of using in my active days at AndroMDA.org), the template, erhm, ... mechanism being used in PDE (I <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=241074">once fixed a bug</a> which had been caused by this engine) and - you might have guessed it - Xpand (which I am a committer on).</p>
<p>So, I gave a short demo of Xtext and Xpand to show Chris how easy it is to create (model-aware) code generation templates. Xpand comes with a nice editor which makes template editing a joy - it features code highlighting, hyperlink navigation, model-awareness and other editor goodness.</p>
<p>Instead of letting only Chris know how that works, here's a short guide on how to write your own Xpand template and use it in a wizard. To make the example more realistic, I chose to implement a wizard that creates an Ant build.xml file for a simple project (something which is missing in Eclipse, AFAIK). So, here we go.</p>
<h2>Prerequisites:</h2>
<ul>
<li>Eclipse 3.5M3 (3.4 might also do)</li>
<li><a href="http://www.eclipse.org/modeling/download.php?file=/modeling/emf/emf/downloads/drops/2.5.0/S200811032126/emf-sdo-xsd-SDK-2.5.0M3.zip">EMF 2.5.0M3</a></li>
<li><a href="http://www.eclipse.org/modeling/download.php?file=/modeling/emft/compare/downloads/drops/0.8.1/R200809170822/emft-compare-SDK-incubation-0.8.1.zip">EMF Compare 0.8.1</a></li>
<li><a href="http://www.eclipse.org/modeling/download.php?file=/modeling/emft/mwe/downloads/drops/0.7.0/S200811120303/emft-mwe-SDK-incubation-0.7.0M3.zip">MWE 0.7.0M3</a></li>
<li><a href="http://www.eclipse.org/modeling/download.php?file=/modeling/m2t/xpand/downloads/drops/0.7.0/S200811120513/m2t-xpand-SDK-incubation-0.7.0M3.zip">Xpand 0.7.0M3</a></li>
</ul>
<h2>How to do it</h2>
<ol>
<li>Download and install the prerequisites.</li>
<li>Create a new plug-in project named "de.peterfriese.antwizard"</li>
<li>Add a New File Wizard to the project. I used the Custom plug-in Wizard to get me started.</li>
<li>Brush up the wizard page and add some fields for project name, source folder and binary folder.</li>
<li>We want to transfer the values entered in this wizard into our template, so we need to create an Ecore model that describes our data model.<a title="View 'antwizard_metamodel' on Flickr.com" href="http://www.flickr.com/photos/81029262@N00/3065637332">
<div style="text-align:left;"><img src="http://farm4.static.flickr.com/3047/3065637332_0f345eaf86_o.jpg" border="0" alt="antwizard_metamodel" width="519" height="234" /></div>
<p></a></li>
<li>Add <em>org.eclipse.emf</em> and <em>org.eclipse.emf.edit</em> to the dependencies of you plug-in.</li>
<li>Create a genmodel and let EMF generate the model code for you.</li>
<li>Add code to your wizard that transfers the values from the input fields to your model. One might consider using databinding for doing this, I used a straight forward read'n'write approach for the time being:
<pre>public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String srcDirName = page.getSrcDirName();
    final String binDirName = page.getBinDirName();
    // ...
}
private BuildSpecification createModel(IProject project, String srcDirName,
    String binDirName) {
    BuildSpecification buildSpecification = BuildspecificationFactory.eINSTANCE.createBuildSpecification();
    Project projectSpecification = BuildspecificationFactory.eINSTANCE.createProject();
    projectSpecification.setName(project.getName());
    projectSpecification.setBinaryFolder(binDirName);
    projectSpecification.setSourceFolder(srcDirName);
    buildSpecification.setProject(projectSpecification);
    return buildSpecification;
}</pre>
</li>
<li>Create an Xpand template <em>de.peterfriese.antwizard/src/template/BuildTemplate.xpt</em>:<br />
<a title="View 'Ant file template' on Flickr.com" href="http://www.flickr.com/photos/81029262@N00/3064840225"></p>
<div style="text-align:left;"><img src="http://farm4.static.flickr.com/3008/3064840225_f3f3b2e799_o.jpg" border="0" alt="Ant file template" width="706" height="589" /></div>
<p></a><br />
In case you wonder how to get those funky characters: make sure us create this file using the Xpand editor - it has code assist (CTRL + space) for those characters.
</li>
<li>Create an Xtend file <em>de.peterfriese.antwizard/src/template/GeneratorExtensions.ext</em>:<br />
<a title="View 'Ant file extensions' on Flickr.com" href="http://www.flickr.com/photos/81029262@N00/3065691432"></p>
<div style="text-align:left;"><img src="http://farm4.static.flickr.com/3045/3065691432_b59ba29444_o.jpg" border="0" alt="Ant file extensions" width="462" height="188" /></div>
<p></a></li>
<li>Add <em>org.eclipse.xpand</em>, <em>org.eclipse.xtend</em> and <em>org.eclipse.xtend.typesystem.emf</em> to the depencies of your plug-in.</li>
<li>Finally, we need to provide some code to invoke the generator:
<pre>private void generate(BuildSpecification buildSpec, IProgressMonitor monitor) throws CoreException {

    // get project root folder as absolute file system path
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(new Path(buildSpec.getProject().getName()));
    String containerName = resource.getLocation().toPortableString();

    // configure outlets
    OutputImpl output = new OutputImpl();
    Outlet outlet = new Outlet(containerName);
    outlet.setOverwrite(true);
    output.addOutlet(outlet);

    // create execution context
    Map globalVarsMap = new HashMap();
    XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null, globalVarsMap, null, null);
    EmfRegistryMetaModel metamodel = new EmfRegistryMetaModel() {
        @Override
        protected EPackage[] allPackages() {
            return new EPackage[] { BuildspecificationPackage.eINSTANCE, EcorePackage.eINSTANCE };
        }
    };
    execCtx.registerMetaModel(metamodel);

    // generate
    XpandFacade facade = XpandFacade.create(execCtx);
    String templatePath = "template::BuildTemplate::main";
    facade.evaluate(templatePath, buildSpec);

    // refresh the project to get external updates:
    resource.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}</pre>
</li>
</ol>
<p>That's it!</p>
<h2>Taking it for a spin</h2>
<ol>
<li>Launch a runtime workbench by selecting <em>de.peterfriese.antwizard/META-INF/MANIFEST.MF</em> and invoking <em>Run As -&gt; Eclipse Application</em></li>
<li>Create a new Java project in the runtime workspace.</li>
<li>Invoke your wizard by selecting <em>File -&gt; New -&gt; Other... -&gt; Ant -&gt; Ant build file from existing project</em></li>
<li>Enter the required information (project name, source folder, binariy folder)</li>
<li>After clicking on <em>finish</em>, you should get a fresh Ant file for your project:<br />
<a title="View 'Ant file' on Flickr.com" href="http://www.flickr.com/photos/81029262@N00/3064865073"></p>
<div style="text-align:left;"><img src="http://farm4.static.flickr.com/3215/3064865073_3415a7b0c3_o.jpg" border="0" alt="Ant file" width="726" height="311" /></div>
<p></a></li>
<li>Enjoy!</li>
</ol>
<p>You can download the project <a href="http://www.peterfriese.de/wp-content/downloads/plugins/model_driven_ant_wizard.zip">here</a>. Feedback and comments are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterfriese.de/using-xpand-in-your-eclipse-wizards/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
