<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Manuel Mauky's Blog</title>
        <link>https://www.lestard.eu/</link>
        <description>Private blog about programming with Java, JavaScript, TypeScript, React, GraphQL and functional Programming</description>
        <lastBuildDate>Sat, 19 Oct 2024 19:20:08 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <copyright>All rights reserved, Manuel Mauky</copyright>
        <category>Technology</category>
        <category>Programming</category>
        <item>
            <title><![CDATA[New blog software]]></title>
            <link>https://www.lestard.eu/2020/new_blog_software/</link>
            <guid>https://www.lestard.eu/2020/new_blog_software/</guid>
            <pubDate>Fri, 19 Jun 2020 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>I've started this blog in 2009 with a Wordpress installation. Then in 2014 I re-implemented the blog based on the static
site generator <a href="https://jekyllrb.com/">Jekyll</a>. This was a great experience back then and I'm still a big fan of static
site generators and the way you are creating content with them. However, recently I wasn't that satisfied with Jekyll
anymore, and so I started to work on a re-write of the blog system again.</p>
<p>Since roughly start of 2019, this blog is now using <a href="https://www.gatsbyjs.org/">Gatsby.js</a> under the hood. Gatsby is
also a static site generator that lets me write articles with Markdown files like before. Like jekyll it then creates a
bunch of HTML, JavaScript and CSS files that I can upload to my webserver. In the past few months I was also rewriting
the website for the <a href="https://jug-gr.de">Java User Group Görlitz</a> which was also using Jekyll in the past and now uses
Gatsby.js too.</p>
<p>In this blog post I will write down some thoughts of why I switched the blogging tool, what I've learned on the way,
what is still missing compared to Jekyll and what I'm planning for the future.</p>
]]></description>
            <content:encoded><![CDATA[<p>I've started this blog in 2009 with a Wordpress installation. Then in 2014 I re-implemented the blog based on the static
site generator <a href="https://jekyllrb.com/">Jekyll</a>. This was a great experience back then and I'm still a big fan of static
site generators and the way you are creating content with them. However, recently I wasn't that satisfied with Jekyll
anymore, and so I started to work on a re-write of the blog system again.</p>
<p>Since roughly start of 2019, this blog is now using <a href="https://www.gatsbyjs.org/">Gatsby.js</a> under the hood. Gatsby is
also a static site generator that lets me write articles with Markdown files like before. Like jekyll it then creates a
bunch of HTML, JavaScript and CSS files that I can upload to my webserver. In the past few months I was also rewriting
the website for the <a href="https://jug-gr.de">Java User Group Görlitz</a> which was also using Jekyll in the past and now uses
Gatsby.js too.</p>
<p>In this blog post I will write down some thoughts of why I switched the blogging tool, what I've learned on the way,
what is still missing compared to Jekyll and what I'm planning for the future.</p>
<!--more-->
<h2>Ruby on Windows</h2>
<p>Jekyll is a cool tool and I had much fun working with it in the past few years. However, one aspect that was always a
pain is the Windows support. Jekyll is developed with Ruby as programming language and my experience with Ruby software
is that it's nearly impossible to get it running on Windows - at least not without much more effort compared to other
programming languages. I'm not a fan of windows, and I try to get around it as much as I can and so the problems with
Jekyll were not that big for me personally as I'm a happy user of linux anyway and Jekyll runs OK on linux.</p>
<p>However, at work I'm either using a windows laptop or a macbook and even on macOS I had some troubles getting Jekyll to
work. And also on Linux I had troubles from time to time when I haven't touched the code for a longer period of time and
newer versions of Jekyll weren't compatible with installed versions of some libraries. So from time to time I had to
completely reinstall Ruby on my machine to get Jekyll to work again. And in contrast to my personal blog the website of
the Java User Group Görlitz is edited by other users too and not all of them are using Linux.</p>
<p>For active Ruby developers it might be a totally different story because they know their tools - but I don't. Gatsby on
the other hand is implemented with JavaScript and NodeJS. And while this platform also don't have the best reputation
when it comes to compatibility of libraries and other aspects, for me personally it's working great. I'm developing
software with JavaScript for more than 12 years, and I'm used to the platform and it's tools. And based on the
experience from the new JUG Görlitz website which was migrated to gatsby in summer 2018, we have nearly no problems at
all with this NodeJS setup.</p>
<h2>React</h2>
<p>The second argument for using Gatsby was that it is based on React for it's rendering. This gives me the chance to
create much more sophisticated UIs and features compared to Jekyll. At the moment this isn't really needed for this blog
but during the work on the JUG Görlitz page and also the work on another page for the
<a href="https://digitale-oberlausitz.eu/">Digitale Oberlausitz e.V.</a>, another non-profit society I'm working for in a voluntary
capacity, this was a major benefit because it allows me to reuse components for repeating UIs on the website.</p>
<p>And it allows me to implement new features that were not possible before. And besides this, for me personally React is
the best UI library/framework available today and I'm happy to use it where ever it's possible and makes sense.</p>
<h2>JavaScript for custom logic</h2>
<p>Jekyll is based on Ruby and therefore also extensions are developed with Ruby. This is not a bad thing per se but for me
personal this means that I'm not able to create own extensions. Of course, I could try to learn Ruby but I have not that
much interest in this language and it would mean a lot of effort just to be able to tweak my website. An example of
extensions that I was using is the generation of RSS feeds. I was using a ruby script that I found somewhere on the
internet without really knowing what it does. I was able to understand it basic steps but I wouldn't be able to adjust
the behaviour if needed.</p>
<p>With Gatsby.js it a whole new story: With Gatsby, everything is build with JavaScript, GraphQL and React - technologies
I'm familiar with. And so I was creating my new feed generation by myself in a rather short amount of time (There is an
RSS plugin for Gatsby but it wasn't really working the way I'd like it to). This is a totally subjective opinion and
again: This argument wouldn't apply to experienced Ruby developers.</p>
<h2>Complex content management</h2>
<p>Jekyll has a clear opinion of how content has to look like. By default, it takes markdown files or plain HTML as input.
You can use plugins to add support for <a href="https://jekyllrb.com/docs/plugins/converters/">different markup languages</a> but
it still has a rather strong emphasis on blogging. Markdown files in the <code class="language-text">_posts</code> directory will be handled as blog
articles. This is cool if all you need is a simple blog and you don't like to adjust things to much. However, if you
like to build little more complex content management you will be stretched to Jekyll's limits. This was the case for the
JUG website where we have "talks" that actually where posts in Jekyll's terms. But there are other entities like
"speaker" and "location" that we haven't modelled explicitly in the old page but had copy+pasted the speaker biography
and location description in the normal text of the talk. With Gatsby I'm able to define as many content folders as I
want. In the new page we have explicit locations, speaker profiles and only link to them in the talk markdown file. This
way the system kind of knows the relation between talks, speakers and locations and you can now see other talks from the
same speaker or get a <a href="https://www.jug-gr.de/speakers/">list of all speakers with the number of their talks</a>.</p>
<p>Of course this is still not a professional content management system that stores content in a database. The relation
between content types is not enforced by the system itself. It's just a field in the frontmatter of the markdown file
and it's the job of my implementation to use this to get additional content. It's not a relational database that
enforces integrity of the data. But for our use case it looks like a both flexible and pragmatic approach.</p>
<p>For this blog I also have introduced an additional entity besides blog articles. There is now an explicit notion of
"projects" which allows me to link blog articles to their belonging projects. In the future I might add other kinds of
content like tech talks I gave or articles in print magazines.</p>
<h2>Keep URLs alive</h2>
<p>In the old setup I was using a URL schema "/year/month/day/title" which was a bad idea from the beginning. Such a schema
may be useful for blogs that post more than one article every day but for me, it's needlessly complex. In the new Gatsby
setup I'm simply using "/year/title". However, <a href="https://www.w3.org/Provider/Style/URI">Cool URIs don't change</a>, and so I
wanted to make the existing articles available under the old and new URI. This is done within Gatsby itself so that a
client-side redirect is done if an old link is used in an article. Additionally, I've generated a config file for NGinx
(my webserver) with mappings from old to new URIs so that external links using the old URI will be redirected to the new
URI with a <code class="language-text">http 301 permanent redirect</code>.</p>
<h2>What is planned?</h2>
<p>I'm very happy with Gatsby at the moment but of course there are still things to be improved. At the moment both my
personal blog and the website of the JUG Görlitz (whose source code you can see
<a href="https://github.com/juggr/juggr.github.io">on github</a> by the way) are done with pure JavaScript. In the meantime I'm
using TypeScript for all my newer projects and I'm loving it so one of the things on my list is to migrate the
JavaScript code to TypeScript in the future. I'm not sure if this is even possible with Gatsby as Gatsby.js itself is
written in JavaScript and to use TypeScript you need to adjust the build setup of Gatsby but at least there is a
<a href="https://www.gatsbyjs.org/docs/typescript">TypeScript </a> page in the docs so obviously someone has already thought about
this topic.</p>
<p>Another thing is the way my content entities are linked to each other. As described above it's not a real link but just
an interpretation of data that is done in my own page implementation. Gatsby itself has no notion of this link at all.
However, in the meantime there were some features (<a href="https://www.gatsbyjs.org/docs/gatsby-config/#mapping-node-types">1</a>,
<a href="https://www.gatsbyjs.org/docs/schema-customization/#foreign-key-fields">2</a>) added to Gatsby that I will take a closer
look into.</p>
<p>In the future I will most likely write more articles related to Gatsby.js to explore some of my insights in more detail.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Implement your own Redux in Java. Part 5: Async Middleware]]></title>
            <link>https://www.lestard.eu/2019/implement-your-own-redux-in-java5/</link>
            <guid>https://www.lestard.eu/2019/implement-your-own-redux-in-java5/</guid>
            <pubDate>Sun, 12 May 2019 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've upgraded the middleware API to match the original one from Redux.js. This was a prerequisite
to implement asynchronous middlewares. And this will be the topic for this part.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li><strong>Part 5: Async behavior with Middlewares</strong></li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
]]></description>
            <content:encoded><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've upgraded the middleware API to match the original one from Redux.js. This was a prerequisite
to implement asynchronous middlewares. And this will be the topic for this part.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li><strong>Part 5: Async behavior with Middlewares</strong></li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
<!--more-->
<h2>Predictability and async operations</h2>
<p>One of the main advantages of redux is that state changes become predictable and that you can define them with functions
and immutable data instead of in-place-editing of objects. However, to archive this predictability you have to add some
restrictions to the system. One is that actions are processed one after the other and not in parallel. If you dispatch
an action it's guaranteed that this action is processed by the redux store before the next action is processed. In other
words: <strong>The "dispatch" method of the store is a blocking operation</strong>. It blocks until the reducer was applied and the
new state is available.</p>
<p>If you think about this restriction for a moment it makes totally sense: Imagine you would process two actions in
parallel. You would spawn two threads, each one with the task to invoke the reducer with the previous state and the
action to calculate the new state. Now you would have two "new" states. Which of them would you use? What if the reducer
result of one action depends on the other action? The outcome wouldn't be predictable anymore. It's a good thing that
redux has this restriction and we don't want to change this behavior.</p>
<p>But then, where do we put side effects like network requests or operations to persist data in the database or
filesystem? The only place for this would be the UI component. You <em>could</em> spawn a new thread to request data from a
network resource and then invoke the dispatch method of the store afterwards. However, this put's logic into the UI that
doesn't belong in the UI.</p>
<p>The handling of side-effects is one of the big questions in the functional programming community and there are multiple
approaches available in functional programming. If you are interested in this topic I recommend you the paper
<a href="https://www.microsoft.com/en-us/research/wp-content/uploads/2016/07/mark.pdf">"Tackling the Awkward Squad" by Simon Peyton Jones</a>
, one of the developers of the purely functional programming language
<a href="https://en.wikipedia.org/wiki/Haskell_(programming_language)">Haskell</a>. The paper describes the problem of
side-effects in more detail and also shows the history of ideas that were developed for Haskell over time before they
found their <a href="http://learnyouahaskell.com/input-and-output">current solution</a>. However, Redux takes another approach.</p>
<h2>Middlewares to the rescue</h2>
<p>The starting point that redux provides for this problem is the middleware API. We can develop middlewares that enable us
to trigger async operations and other side-effects. In the redux.js community there were many different middlewares with
different ideas and approaches developed. There are debates on which of them is "the best" but in the end you can choose
whatever you like and what style of development you prefer. In this article I will re-implement one of the simplest
middlewares for this problem: The <a href="https://github.com/reduxjs/redux-thunk">"thunk middleware"</a>. But in future articles I
will show other examples of middlewares for async operations and other problems.</p>
<h2>Thunk middleware</h2>
<p>I'm not entirely sure where the naming "thunk" comes from but I know the term from texts about non-strict semantics and
lazy evaluation in Haskell. While languages like Java or JavaScript (and almost every other actively used programming
language) are using so called "strict semantics" and "eager evaluation", Haskell uses "lazy evaluation". This means that
the evaluation of an expression can be delayed to a later point in time when the value of the expression is actually
needed (or if the value isn't needed at all, the evaluation can be skipped entirely). In the meantime the program
"works" with these not-jet evaluated expressions, which are being called "thunks".</p>
<p>I think the naming of the "thunk middleware" comes from a similar direction. Instead of dispatching a plain object as
action you dispatch a function. The thunk middleware will detect this function and invoke it. The function itself is
called "thunk". It takes two arguments: The "dispatch" function and the "getState" function. This is similar to the API
of middlewares itself. It enables the thunk function to dispatch new actions at a later point in time, for example when
a request is finished. Notice that the thunk "function" is not a pure function in the sense of functional programming
because it doesn't return any value.</p>
<p>Let's start with an interface for our thunks:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Thunk</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">extends</span> <span class="token class-name">BiConsumer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">void</span> <span class="token function">accept</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span></code></pre></div>
<p>An action-creator that uses thunks could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Thunk</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> <span class="token function">loadTodoItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token punctuation">(</span>dispatch<span class="token punctuation">,</span> getState<span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token punctuation">{</span>

		dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">LoadItemsStartedAction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">new</span> <span class="token class-name">Thread</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token punctuation">{</span>

			<span class="token keyword">try</span> <span class="token punctuation">{</span>
				<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoItem</span><span class="token punctuation">></span></span> items <span class="token operator">=</span> todoBackendService<span class="token punctuation">.</span><span class="token function">loadItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

				dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">LoadItemsSuccessAction</span><span class="token punctuation">(</span>items<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">catch</span><span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">LoadItemsFailedAction</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>In this example I assume that there is a "todoBackendService" which provides a method <code class="language-text">loadItems</code> that loads all
existing todo-items from the Database or a webservice. This method is a blocking method, meaning that the control-flow
will stop at the method invocation until the result is available. For this reason I'm spawning a new thread to prevent
the whole app from blocking. But before this I'm dispatching a normal action <code class="language-text">LoadItemsStartedAction</code> as a signal that
the loading was triggered.</p>
<p>If the loading was successful I'm dispatching a new <code class="language-text">LoadItemsSuccessAction</code> that takes the actual items as payload.
Otherwise I'm dispatching a <code class="language-text">LoadItemsFailedAction</code> that takes the exception object as payload. This way we can now
react to these two possible outcomes in the reducer. In the success case we would add the items to our local state which
would trigger a refresh of the UI. In the failure case we could add an error message to the local state that the UI can
show to the user.</p>
<p>The reducer code could look like this and should be quite easy to understand:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoReducer</span> <span class="token keyword">implements</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">TodoState</span> <span class="token function">reduce</span><span class="token punctuation">(</span><span class="token class-name">TodoState</span> oldState<span class="token punctuation">,</span> <span class="token class-name">Action</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>

		<span class="token keyword">if</span> <span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">LoadItemsStartedAction</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> oldState<span class="token punctuation">.</span><span class="token function">withLoadingState</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

		<span class="token keyword">if</span> <span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">LoadItemsSuccessAction</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token class-name">LoadItemsSuccessAction</span> loadItemsSuccessAction <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">LoadItemsSuccessAction</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

			<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoItem</span><span class="token punctuation">></span></span> items <span class="token operator">=</span> loadItemsSuccessAction<span class="token punctuation">.</span><span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

			<span class="token keyword">return</span> oldState<span class="token punctuation">.</span><span class="token function">withLoadingState</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">withItems</span><span class="token punctuation">(</span>items<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

		<span class="token keyword">if</span> <span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">LoadItemsFailedAction</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token class-name">LoadItemsFailedAction</span> loadItemsFailedAction <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">LoadItemsFailedAction</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

			<span class="token class-name">Exception</span> reason <span class="token operator">=</span> loadItemsFailedAction<span class="token punctuation">.</span><span class="token function">getReason</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

			<span class="token keyword">return</span> oldState<span class="token punctuation">.</span><span class="token function">withLoadingState</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span>
						<span class="token punctuation">.</span><span class="token function">withItems</span><span class="token punctuation">(</span><span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">emptyList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
						<span class="token punctuation">.</span><span class="token function">withErrorReason</span><span class="token punctuation">(</span>reason<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

		<span class="token keyword">return</span> oldState<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This way of structuring the logic has some advantages and disadvantages. The good thing is that it is relatively easy to
understand and the concept is not that complicated. A disadvantage is that it's not easy to cancel already triggered
async actions and the "thunks" can become quite complex for bigger use-cases. I think the "thunk approach" is OK for
simple use-cases but there are also other interesting approaches that I will cover in one of the future posts in this
series.</p>
<p>But first let's see how the thunk-middleware itself is implemented:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ThunkMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span>
			<span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> next <span class="token operator">-></span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">Thunk</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token class-name">Thunk</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> thunk <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Thunk</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span><span class="token punctuation">)</span> action<span class="token punctuation">;</span>

				thunk<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>dispatch<span class="token punctuation">,</span> getState<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				next<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Similar to the <code class="language-text">ListMiddleware</code> from the previous article we are checking if the incoming action is a thunk. If so, we
are invoking it by passing the <code class="language-text">dispatch</code> and <code class="language-text">getState</code> functions. Otherwise we hand over the action to the next
middleware.</p>
<p>However, there is still a problem with this code. The action-creator is dispatching the action on a new thread. Starting
from there also the rest of the redux code is running on this new thread. This leads to the situation that also the
subscriber in the UI controller is invoked on this thread and this is an actual problem because in JavaFX updates to the
scene-graph may only be done on the JavaFX application thread. To fix this we would need to surround the subscriber code
in a <code class="language-text">Platform.runLater</code> call. However, this approach has several downsides:</p>
<ul>
<li>it's easy to miss by developers and the problem can be hard to notice</li>
<li>we introduce a dependency of the UI to the implementation of the action-creator. A change to the action-creator code
results in the need for a code-change in the UI</li>
</ul>
<p>Ideally, we take the responsibility of thread-handling from application developer and move this task to the redux
library itself. One solution would be to add extra code to our middleware like this:</p>
<div class="gatsby-highlight has-highlighted-lines" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ThunkMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span>
			<span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> next <span class="token operator">-></span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">Thunk</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token class-name">Thunk</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> thunk <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Thunk</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span><span class="token punctuation">)</span> action<span class="token punctuation">;</span>

<span class="gatsby-highlight-code-line">				<span class="token class-name">DispatchFunction</span> fxThreadDispatch <span class="token operator">=</span> someAction <span class="token operator">-></span> <span class="token punctuation">{</span></span><span class="gatsby-highlight-code-line">					<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">Platform</span><span class="token punctuation">.</span><span class="token function">isFxApplicationThread</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span><span class="gatsby-highlight-code-line">						dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>someAction<span class="token punctuation">)</span><span class="token punctuation">;</span></span><span class="gatsby-highlight-code-line">					<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span></span><span class="gatsby-highlight-code-line">						<span class="token class-name">Platform</span><span class="token punctuation">.</span><span class="token function">runLater</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-></span> dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>someAction<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span><span class="gatsby-highlight-code-line">					<span class="token punctuation">}</span></span><span class="gatsby-highlight-code-line">				<span class="token punctuation">}</span><span class="token punctuation">;</span></span>
<span class="gatsby-highlight-code-line">				thunk<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>fxThreadDispatch<span class="token punctuation">,</span> getState<span class="token punctuation">)</span><span class="token punctuation">;</span></span>			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				next<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Here we are creating a new dispatch function that checks whether it is invoked on the JavaFX platform thread. In this
case the actual dispatch function is directly invoked. Otherwise it's wrapped by <code class="language-text">Platform.runLater</code>. This solution
works as expected but still has a possible disadvantage: It's now the responsibility of middleware authors to check for
correct thread handling. Other async middlewares have to repeat this check in their code-base and might also miss it at
first. An alternative is to move this check to the core classes of the redux library, precisely to the Store class.
However, this is debatable too, because one could argue that it's not to much to request from middleware authors to
implement threading correctly. In the original Redux.js library there is no such problem because JavaScript doesn't
support this kind of multithreading in browsers so there is not really a good knowledge base on this topic that we can
profit from. For now I'm moving the checking code to the Store class but maybe in the future I will write in some more
detail on threading with redux.</p>
<p>The code in the Store class can be adjusted like this:</p>
<p>Before:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">this</span><span class="token punctuation">.</span>dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>After:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">Platform</span><span class="token punctuation">.</span><span class="token function">isFxApplicationThread</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
		<span class="token class-name">Platform</span><span class="token punctuation">.</span><span class="token function">runLater</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token keyword">this</span><span class="token punctuation">.</span>dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now we are checking the correct thread in the Store and can therefore leave the middleware free from thread-checking.</p>
<p>And this is all we have to do to support async operations and side-effects in redux. As I've said it's debatable if the
thunk-middleware is the best way to implement side-effects in your application. A downside is that now you have
important business logic in two places: In the reducer and in the thunk action-creators. The question of how to
structure your code and where to put which logic is an ongoing discussion in the redux community and in my opinion there
is not one definitive answer to this question. There are multiple different approaches available that compete with each
other when it comes to simplicity, expressiveness and feature-richness.</p>
<p>In the next blog post I will show some more examples of middlewares, some of them being actually useful and some are
not. But as the overall goal of this blog series is to understand the concepts of Redux and not to develop the "perfect"
solution, I think it's ok to also look on not-so-useful examples. I let the reader decide which one he or she likes
most.</p>
<hr>
<p>You can find the code for redux example in <a href="https://github.com/manuel_mauky/redux-java-example">this github repository</a>. This
<a href="https://github.com/manuel_mauky/redux-java-example/tree/77b73f4cf162972929f1aa6164c92a83c0160aec">commit</a> is pointing
directly to the state of this blog post.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Implement your own Redux in Java. Part 4: Middleware]]></title>
            <link>https://www.lestard.eu/2019/implement-your-own-redux-in-java4/</link>
            <guid>https://www.lestard.eu/2019/implement-your-own-redux-in-java4/</guid>
            <pubDate>Fri, 18 Jan 2019 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've introduced the basic concept of "middlewares", one of the extension mechanisms of Redux.
However, in the first approach I was using a simplified API for middlewares to get a better understanding of the
concept. The actual API of Middlewares is a little more complex. In this part I will show the limitations of the
previous API and what kinds of middlewares you can't build with it. Then I will transform the API and the implementation
to the "real" API. This will be a prerequisite to implement middlewares for asynchronous behavior, which will be the
topic of the next part.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><strong>Part 4: Improved Middleware API</strong></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
]]></description>
            <content:encoded><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've introduced the basic concept of "middlewares", one of the extension mechanisms of Redux.
However, in the first approach I was using a simplified API for middlewares to get a better understanding of the
concept. The actual API of Middlewares is a little more complex. In this part I will show the limitations of the
previous API and what kinds of middlewares you can't build with it. Then I will transform the API and the implementation
to the "real" API. This will be a prerequisite to implement middlewares for asynchronous behavior, which will be the
topic of the next part.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><strong>Part 4: Improved Middleware API</strong></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
<!--more-->
<p>In the <a href="/2019/implement-your-own-redux-in-java3/">previous part</a> I've created a <code class="language-text">ListMiddleware</code> that supports the
dispatch of <code class="language-text">List</code>s of actions. It checks if an incoming action is of type list and when this is the case it will
dispatch all elements of the list. This was the code:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ListMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">List</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token class-name">List</span> actionList <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">List</span><span class="token punctuation">)</span> action<span class="token punctuation">;</span>

				actionList<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>dispatch<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>While this middleware is not <em>that</em> useful in reality, it' a good example for the restrictions that we have with the
current Middleware API. It's using a special type of object as action which is a common pattern when it comes to
asynchronous middlewares.</p>
<h2>Action-Creators</h2>
<p>In the Redux community their is the pattern of so called "action-creators". Instead of creating actions directly in your
UI components, you move the creation-logic into a separate function. This way you can hide the creation of actions from
the UI components and it's easier to reuse and to refactor logic to create actions.</p>
<p>In our application we have the <code class="language-text">AddItemAction</code> and so we could create an action-creator like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoActionCreators</span> <span class="token punctuation">{</span>

	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Object</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token class-name">String</span> text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span></code></pre></div>
<p>The calling code in the UI component now looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">final</span> <span class="token class-name">String</span> text <span class="token operator">=</span> input<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">TodoActionCreators</span><span class="token punctuation">.</span><span class="token function">addItem</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	input<span class="token punctuation">.</span><span class="token function">setText</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If at some later point in time we decide that we need to dispatch an additional action in the "add item" use-case, we
can simply adjust the action-creator while leaving the UI component as it is. Our new action-creator could now look like
this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Object</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token class-name">String</span> text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">asList</span><span class="token punctuation">(</span>
		<span class="token keyword">new</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">,</span>
		<span class="token keyword">new</span> <span class="token class-name">SomeOtherAction</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>To support this we have to install the ListMiddleware. Otherwise the List would reach the reducer which is not what we
want (in our current implementation it wouldn't reach the reducer but instead throw a <code class="language-text">ClassCastException</code>). With Lists
as actions it might even be possible to handle this in the reducer but when we start to send asynchronous actions we get
a real problem: The reducer has to be a pure function. It may not trigger any side-effects.</p>
<p>The other problem is that we would introduce a dependency to our middlewares in the reducer. This makes it harder to
replace middlewares later on. So the general rule is: <strong>If your middleware allows you to dispatch special action objects
it should also take care that these special objects don't reach the reducer</strong>. Your middleware has to filter out all
"non-normal" actions.</p>
<p>Is this the case with the current implementation of the <code class="language-text">ListMiddleware</code>? At first sight this seems to be the case. We
check for every incoming action if it is of type List. But what happens when the list itself contains another list? You
might ask, why would anybody pack a list of actions in a list of actions? Well we said that we like to decouple actions
by using action-creators and this means that it's possible that one action-creator uses another action-creator. So our
code could also look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Object</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token class-name">String</span> text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">asList</span><span class="token punctuation">(</span>
		<span class="token keyword">new</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">,</span>
		<span class="token function">someOtherActionCreator</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Here we invoke another action-creator in our own action-creator. And now it's possible that the other action-creator
itself produces a List of actions. If we would restrict this nesting of special actions we would again introduce
coupling between action-creators. We wouldn't be able to refactor one action-creator if it is used by another one. So in
general we like to support such nested lists of actions. When we come to async middlewares later on we will see that we
have a similar situation there.</p>
<p>So how would our ListMiddleware react in this situation? It passes the list down to the next dispatch function and
ultimately to the dispatch function of the store. The store will try to cast the action to our marker interface <code class="language-text">Action</code>
and will throw a <code class="language-text">ClassCastException</code> instead.</p>
<p>To understand this behavior we should go one step back and look closer at the chain of middlewares. The store has the
"original" dispatch-function and passes it to the first middleware in the chain. The first middleware enhances/wraps the
dispatch function and returns a new one. This new dispatch function will be passed to the second middleware in the chain
and so on. The last middleware returns it's enhanced dispatch function, which will then be used by the store.</p>
<h2>"Real" Middleware API</h2>
<p>What we want is a way to pass an action to the start of the middleware chain. We like to have access to the actual
dispatch function that the store uses. For this we need to change our middleware API. There are many ways to extend our
API to support this but I will try to keep the code close to the original Redux library and there a nested function is
used. In the original API a middleware is a function that takes the original dispatch function of the store and the
getState function as argument and returns a function. This function is the "real" middleware: It takes a
dispatch-function as argument and returns an enhanced dispatch-function.</p>
<p>Before I describe this in more details, let's adjust our <code class="language-text">Middleware</code> interface:</p>
<p><strong>Before</strong></p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">extends</span> <span class="token class-name">BiFunction</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span></code></pre></div>
<p><strong>After</strong></p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">extends</span> <span class="token class-name">BiFunction</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span><span class="token punctuation">,</span> <span class="token class-name">Function</span><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Ok, this can be confusing. Let's take a closer look at the arguments of the "outer" function: It takes a
dispatch-function and a getState function as argument. These two are taken directly from the Store. The
dispatch-function is the one that the middleware can use to pass an action to the start of the middleware chain. Maybe
you can think of this outer function as some sort of "middleware factory method". It will be invoked by the Store to
create the middleware's actual enhancer-function. This enhancer-function takes a dispatch-function as argument and
enhances it and returns a new dispatch function. The difference here is that it don't get the original dispatch-function
as argument but instead the dispatch function of the next middleware in the chain.</p>
<p>Maybe this becomes clearer when we look at how our two existing middlewares look like when we adjust the code to our new
API. The LoggingMiddleware looks like this:</p>
<div class="gatsby-highlight has-highlighted-lines" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoggingMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="gatsby-highlight-code-line">		<span class="token keyword">return</span> next <span class="token operator">-></span> action <span class="token operator">-></span> <span class="token punctuation">{</span></span>
			<span class="token class-name">S</span> stateBefore <span class="token operator">=</span> getState<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="gatsby-highlight-code-line">			next<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
			<span class="token class-name">S</span> stateAfter <span class="token operator">=</span> getState<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"dispatched action: "</span> <span class="token operator">+</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"state before:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>stateBefore<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"state after:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>stateAfter<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The first thing you might notice is the <code class="language-text">next -> action -> ...</code> line with the double arrows. This is the "nested"
function I've mentioned before. In functional programming this is also known as
<a href="https://en.wikipedia.org/wiki/Currying">Currying</a>. It's the idea that every function that takes multiple arguments can
also be expressed as sequence of functions, each of them taking only a single argument. So in principle it would also be
possible to define the middleware API with this signature:
<code class="language-text">DispatchFunction apply (DispatchFunction storeDispatch, Supplier&lt;S> getState, DispatchFunction next)</code>. For developers
that aren't that familiar with functional programming this version might be easier to handle because in my experience,
many developers have some kind of "fear" when it comes to functions that return functions that return functions. On the
other hand, if your <em>are</em> familiar with functional programming, this style of development becomes quite natural. And in
many situations makes the code more composable which is also the case with redux middlewares. We will see this in just a
few moments when we implement the handling of middlewares in our store but I'm also planning to write a dedicated blog
post in this series on the topic of function composition.</p>
<p>What you should also notice in this code example is that the <code class="language-text">LoggingMiddleware</code> ignores the original dispatch function
from the store but instead just uses the "next" dispatch function from the middleware chain. This is important: If we
would change this line to <code class="language-text">dispatch.accept(action)</code> we would get an infinite loop (and a <code class="language-text">StackOverflowError</code>) as a
result.</p>
<p>Let's look at the <code class="language-text">ListMiddleware</code> for another example:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ListMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> next <span class="token operator">-></span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">List</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token class-name">List</span> actionList <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">List</span><span class="token punctuation">)</span> action<span class="token punctuation">;</span>

				actionList<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>dispatch<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				next<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If our action is an instance of <code class="language-text">List</code>, we cast it to the list of actions and pass them to the original dispatch
function from the store. This way we can make sure that they run through the whole middleware chain from the beginning.
If our action is not a list, we ignore it and pass it to the next middleware in line. This finally solves our problem
with the list of list of actions. With this API we now have everything at hand to implement more interesting middlewares
like those for handling asynchronous behavior. This will be the topic of the next blog post in this series.</p>
<p>But before that we still have to adjust our Store implementation to our new API. The old version looked like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token comment">// ...</span>
	<span class="token keyword">private</span> <span class="token class-name">DispatchFunction</span> dispatch <span class="token operator">=</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
		<span class="token class-name">S</span> oldState <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">;</span>

		<span class="token class-name">S</span> newState <span class="token operator">=</span> reducer<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span>oldState<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token class-name">Action</span><span class="token punctuation">)</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">if</span><span class="token punctuation">(</span>oldState <span class="token operator">!=</span> newState <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>oldState<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>newState<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> newState<span class="token punctuation">;</span>

			<span class="token function">notifySubscribers</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token class-name">Store</span><span class="token punctuation">(</span><span class="token class-name">S</span> initialState<span class="token punctuation">,</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> rootReducer<span class="token punctuation">,</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>middlewares<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> initialState<span class="token punctuation">;</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>reducer <span class="token operator">=</span> rootReducer<span class="token punctuation">;</span>

		<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> middleware <span class="token operator">:</span> middlewares<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>dispatch <span class="token operator">=</span> middleware<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>dispatch<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">getState</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The only needed changes are within the constructor:</p>
<div class="gatsby-highlight has-highlighted-lines" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token class-name">Store</span><span class="token punctuation">(</span><span class="token class-name">S</span> initialState<span class="token punctuation">,</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> rootReducer<span class="token punctuation">,</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>middlewares<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> initialState<span class="token punctuation">;</span>
	<span class="token keyword">this</span><span class="token punctuation">.</span>reducer <span class="token operator">=</span> rootReducer<span class="token punctuation">;</span>

	<span class="token keyword">for</span><span class="token punctuation">(</span><span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> middleware <span class="token operator">:</span> middlewares<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="gatsby-highlight-code-line">		<span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> middlewareFunction <span class="token operator">=</span> middleware<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token operator">::</span><span class="token function">dispatch</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">getState</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span><span class="gatsby-highlight-code-line"></span><span class="gatsby-highlight-code-line">		<span class="token keyword">this</span><span class="token punctuation">.</span>dispatch <span class="token operator">=</span> middlewareFunction<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>dispatch<span class="token punctuation">)</span><span class="token punctuation">;</span></span>	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>As we have nested functions we have to apply them separately. First we have to invoke our "middleware factory function"
(don't know a better name for it) to get our "middlewareFunction". Important here is that I'm passing <code class="language-text">this::dispatch</code>
instead of <code class="language-text">this.dispatch</code>. It's a method reference to the store's <code class="language-text">dispatch</code> method. Then I'm applying the actual
middleware function and passing the "dispatch" object to it. For the first middleware in the chain this is the original
dispatch function and for all following middlewares it's the enhanced dispatch function from the previous middleware.</p>
<p>And that's all. Our Store now supports Middlewares, the first of two extension mechanisms that the original Redux
library provides. The second extension mechanism is called "Store enhancer". Store enhancers are much more powerful in
the sense that they can adjust the behavior of the store in a much deeper way. Why am I telling you about store
enhancers in an article about middlewares? While <a href="https://redux.js.org/advanced/middleware">middlewares</a> <strong>are</strong> an
official extension mechanism of the original redux library, the store implementation itself has no idea of middlewares
at all. Instead, the whole concept of middlewares is implemented by a store enhancer called
<a href="https://redux.js.org/api/applymiddleware#applymiddlewaremiddleware">"applyMiddlewares"</a>. In one of the future blog
posts in this series I will describe what store enhancers are and how we can extract the middleware support into a store
enhancer. But in the mean time we will keep this implementation and in the next few posts I will write more on
middleware details and different types of middlewares.</p>
<hr>
<p>You can find the code for redux example in <a href="https://github.com/manuel_mauky/redux-java-example">this github repository</a>. This
<a href="https://github.com/manuel_mauky/redux-java-example/tree/07691885e6ba90180efa03cd1710c87e41e097b6">commit</a> is pointing
directly to the state of this blog post.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Implement your own Redux in Java. Part 3: First approach on Middlewares]]></title>
            <link>https://www.lestard.eu/2019/implement-your-own-redux-in-java3/</link>
            <guid>https://www.lestard.eu/2019/implement-your-own-redux-in-java3/</guid>
            <pubDate>Wed, 09 Jan 2019 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've showed how to connect the basic redux store to a JavaFX view. In this part I will take a first
look into the first extension mechanism that Redux provides: Middlewares.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><strong>Part 3: First approach on Middlewares</strong></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
]]></description>
            <content:encoded><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've showed how to connect the basic redux store to a JavaFX view. In this part I will take a first
look into the first extension mechanism that Redux provides: Middlewares.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><strong>Part 3: First approach on Middlewares</strong></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
<!--more-->
<p><a href="https://redux.js.org/advanced/middleware">Middlewares</a> in Redux are an extension mechanism that let's you intercept and
manipulate actions before they reach the reducer. While the idea of middlewares in Redux is not that complicated the API
can be a little confusing at first. For this reason first I will start with a simplified API and then later on will
advance it to match the original API.</p>
<p>Simply put, a middleware is a wrapper around the dispatch function. It can be expressed as a function that takes the
original dispatch function as argument and returns a new enhanced dispatch function as result. To put this into code
let's first take a closer look at the dispatch function itself. At the moment our Store has the method
<code class="language-text">void dispatch(Object action)</code>. It takes the action as argument and returns nothing (by the way: The JavaScript Redux
library returns the action object itself but I'm using 'void' here. We will see why in one of the next posts). We can
also define a functional interface for this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token annotation punctuation">@FunctionalInterface</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">DispatchFunction</span> <span class="token keyword">extends</span> <span class="token class-name">Consumer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">void</span> <span class="token function">accept</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>With this definition we can define our first approach for a middleware interface:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Middleware</span> <span class="token keyword">extends</span> <span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
	<span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now let's implement some middlewares. Of course the simplest possible middleware is one that just returns the argument
without touching it (in functional programming we call such a function
<a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html#identity--">"identity"</a>). The implementation
could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">NoopMiddleware</span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> dispatch<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>or</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">NoopMiddleware</span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
            dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Another quite useless middleware would be one that "eats up" actions without further dispatching them:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BlackHoleMiddleware</span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
			<span class="token comment">// nothing</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Ok, these examples don't make much sense. Let's implement a more useful middleware: The <code class="language-text">LoggingMiddleware</code> print's a
log-message everytime an action is dispatched. This way developers can get a better understanding of what's happening in
their apps.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoggingMiddleware</span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"dispatched action:"</span> <span class="token operator">+</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>

            dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Even cooler would be to be see what the state was before and after processing the action. This way developers could see
what effects an action had.</p>
<p>Because it's useful for many middleware to have access to the current state of the Store, the middleware API of redux
also provides a "getState" function to the middleware. Let's adjust our <code class="language-text">Middleware</code> interface:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">extends</span> <span class="token class-name">BiFunction</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DispatchFunction</span><span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span><span class="token punctuation">,</span> <span class="token class-name">DispatchFunction</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span></code></pre></div>
<p>We see that now a middleware takes two arguments: The dispatch function and a <code class="language-text">Supplier&lt;S></code>.
<code class="language-text">java.util.function.Supplier</code> is a standard functional interface with the method <code class="language-text">S get()</code>. It's our "getState" method
that returns the current State of our Store. For typing reasons we need to add a generic type-param <code class="language-text">S</code> to our
middleware interface.</p>
<p>Now we can improve our LoggingMiddleware like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoggingMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token class-name">S</span> stateBefore <span class="token operator">=</span> getState<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token class-name">S</span> stateAfter <span class="token operator">=</span> getState<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"dispatched action:"</span> <span class="token operator">+</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"state before:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>stateBefore<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"state after:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>stateAfter<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>We request the state before we pass the action to the dispatch function. After the dispatch function is finished we
again request the state and print everything on the screen.</p>
<h2>Using other types of actions</h2>
<p>Another common use-case for middlewares is to enable users to dispatch other types of actions and react to them in the
middleware. This can be used to enable async behavior. In the next post in this series I will show this in more detail.
But for now I will show a middleware that let's you dispatch a <code class="language-text">List</code> of actions instead of just a single one. This
might be useful if you like to compose action-creators so that multiple actions are dispatched by a single action
creator.</p>
<p>This type of middlewares is possible because the type of actions that the dispatch-function takes is <code class="language-text">Object</code>. Therefore
almost everything can be passed as action. However, our Reducer still takes an <code class="language-text">Action</code> as argument and our current
implementation of <code class="language-text">dispatch</code> in the Store casts the action object to <code class="language-text">Action</code>. This would lead to a
<code class="language-text">ClassCastException</code>. We could change the signature of our <code class="language-text">Reducer</code> interface and remove the cast but then the reducer
would need to know which types of actions might be passed which would introduce a tighter coupling between the reducer
and the installed middlewares. Instead we let our middleware make sure that only "real" actions may arrive at the
reducer. So for middlewares it's a common pattern to check for the type of an action and to implement a special handling
for a given type while ignoring actions of other types.</p>
<p>For our List-Middleware the code looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ListMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">DispatchFunction</span> <span class="token function">apply</span><span class="token punctuation">(</span><span class="token class-name">DispatchFunction</span> dispatch<span class="token punctuation">,</span> <span class="token class-name">Supplier</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> getState<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">List</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token class-name">List</span> actionList <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">List</span><span class="token punctuation">)</span> action<span class="token punctuation">;</span>

				actionList<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>dispatch<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>As you can see I'm checking if the action is of type <code class="language-text">List</code>. In this case I'm doing a cast and invoke the dispatch
function for each action in the list. If the action is not a list I'm just passing it down to the normal dispatch
function.</p>
<p>Before we take a look at how we add support for middlewares to our Store, lets see how the usage of our new
<code class="language-text">ListMiddleware</code> could look like. In our todo example app we have the <code class="language-text">TodoViewController</code> which has a reference to the
Store. When the user clicks the "add" button an <code class="language-text">AddItemAction</code> is created and passed to the <code class="language-text">dispatch</code> function of the
Store. If (for whatever reason) we like to dispatch another action in the same button-handler we could simply invoke the
<code class="language-text">dispatch</code> method a second time. However, in redux it's a common practice to encapsulate the creation of actions to
so-called "action-creators". The UI passes just the needed data as parameter to the action-creator and the actual
creation of actions is hidden from the UI. This minimizes the coupling of the UI to the actual creation of actions. If
later on we decide to change the implementation of the action-creation the UI can stay untouched.</p>
<p>An example action-creater could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Object</span> <span class="token function">addItemAction</span><span class="token punctuation">(</span><span class="token class-name">String</span> text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// usage:</span>
store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token function">addItemAction</span><span class="token punctuation">(</span>input<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>If we now come to the conclusion that we need a second action to be dispatched for the same user-interaction we can
refactor our action-creator to this code:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Object</span> <span class="token function">addItemAction</span><span class="token punctuation">(</span><span class="token class-name">String</span> text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token class-name">List</span> actions <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">asList</span><span class="token punctuation">(</span>
			<span class="token keyword">new</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token keyword">new</span> <span class="token class-name">SomeOtherAction</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token keyword">return</span> actions<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>We doesn't need to change the UI code for this refactoring. Our <code class="language-text">ListMiddleware</code> will now detect that an instance of
<code class="language-text">List</code> was dispatched and react accordingly. In the next blog post I will come back to this code to show the limitations
of our simplified Middleware API. Maybe you can already see what can go wrong with this approach?</p>
<h2>Chaining middlewares</h2>
<p>In this blog post we have already seen some implementations of middlewares and you can implement many more if you like.
But can we use multiple middlewares in combination? The answer is: Yes.</p>
<p>A middleware is like an enhancer of the dispatch-function that takes a dispatch-function as parameter and returns an
enhanced dispatch-function. This enables us to chain multiple middlewares. The first middleware in the chain get's the
original dispatch-function from the store and returns an enhanced dispatch-function. This function is then passed to the
next middleware in the chain and so on and so forth until the last middleware produces it's dispatch-function.</p>
<p>This final dispatch-function is then the one the Store has to use when a user dispatches a new action. The action can
then "flow" through the middlewares until it reaches the original dispatch-function and is processed by the reducer.</p>
<p>In functional programming this is called "function composition". Maybe in a future blog post I will go into more detail
on the theory on function composition and how it applies to middlewares. But for now you should just keep two things in
mind:</p>
<ol>
<li>
<p>The order of middlewares in the chain is important. A different order may change the semantics of the action
processing. For example if the LoggerMiddleware "sees" an action before the ListMiddleware, the logger will print a
List. On the other hand if the ListMiddleware comes before the LoggerMiddleware, the logger won't ever notice that a
List was dispatched.</p>
</li>
<li>
<p>The invocation order is back-to-front. The "first" middleware that enhances the original dispatch-function will see
an incoming action as the last. This is generally the case for function composition and can be a little confusing at
first.</p>
</li>
</ol>
<h2>Implementing the simplified middleware API</h2>
<p>Now let's start implementing the actual support for this simplified middleware API in our Store. Middlewares are getting
the original dispatch-function as argument and are creating a new one that has to be used by the Store afterwards. To
enable this we have to make the dispatch-function of the Store exchangeable. At the moment it's a normal Java method but
now we will create a field for it:</p>
<p>Before:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token comment">// ...</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">S</span> oldState <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">;</span>

		<span class="token class-name">S</span> newState <span class="token operator">=</span> reducer<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span>oldState<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token class-name">Action</span><span class="token punctuation">)</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">if</span><span class="token punctuation">(</span>oldState <span class="token operator">!=</span> newState <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>oldState<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>newState<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> newState<span class="token punctuation">;</span>

			<span class="token function">notifySubscribers</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>After:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token comment">// ...</span>

	<span class="token keyword">private</span> <span class="token class-name">DispatchFunction</span> dispatch <span class="token operator">=</span> action <span class="token operator">-></span> <span class="token punctuation">{</span>
		<span class="token class-name">S</span> oldState <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">;</span>

		<span class="token class-name">S</span> newState <span class="token operator">=</span> reducer<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span>oldState<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token class-name">Action</span><span class="token punctuation">)</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">if</span><span class="token punctuation">(</span>oldState <span class="token operator">!=</span> newState <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>oldState<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>newState<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> newState<span class="token punctuation">;</span>

			<span class="token function">notifySubscribers</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>dispatch<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This enables us to switch the dispatch-function by re-assigning the "dispatch"-field.</p>
<p>The second step is to take the middlewares and invoke them one after the other to get the final dispatch-function. For
this we extend the constructor of the Store to take a variable number of middlewares:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
	<span class="token comment">// ...</span>

	<span class="token keyword">public</span> <span class="token class-name">Store</span><span class="token punctuation">(</span><span class="token class-name">S</span> initialState<span class="token punctuation">,</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> rootReducer<span class="token punctuation">,</span> <span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>middlewares<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> initialState<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>reducer <span class="token operator">=</span> rootReducer<span class="token punctuation">;</span>

        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">Middleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> middleware <span class="token operator">:</span> middlewares<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>dispatch <span class="token operator">=</span> middleware<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>dispatch<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">getState</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// ...</span>
<span class="token punctuation">}</span></code></pre></div>
<p>And that's basically all we have to do. We can now adjust our example app to use the LoggingMiddleware and
ListMiddleware:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> store <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>
		initialState<span class="token punctuation">,</span>
		<span class="token keyword">new</span> <span class="token class-name">TodoReducer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
		<span class="token comment">// middlewares</span>
		<span class="token keyword">new</span> <span class="token class-name">LoggingMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
		<span class="token keyword">new</span> <span class="token class-name">ListMiddleware</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>For simple middlewares like the LoggingMiddleware this simplified middleware API is sufficient. However, the original
Middleware API of Redux.js is a little more complex and this is for a reason. In the
<a href="/2019/implement-your-own-redux-in-java4/">next blog post</a> of this series I will show the limitations of the current API
and I will refactor it to match the original API. After that in another post I will show how you can enable async
behavior with middlewares.</p>
<hr>
<p>You can find the code for redux example in <a href="https://github.com/manuel_mauky/redux-java-example">this github repository</a>. This
<a href="https://github.com/manuel_mauky/redux-java-example/tree/e5c66df81af7a5de1ab1a1ed8c3f803f0ec3fbe6">commit</a> is pointing
directly to the state of this blog post.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Highlight Days in JavaFX DatePicker]]></title>
            <link>https://www.lestard.eu/2018/date-picker-highlighting/</link>
            <guid>https://www.lestard.eu/2018/date-picker-highlighting/</guid>
            <pubDate>Mon, 15 Oct 2018 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Today I had the requirement to implement a highlighting of some days in the JavaFX <code class="language-text">DatePicker</code>. As I haven't found an
existing blog post or tutorial that describes this topic I will provide a short example here.</p>
<p>Similar to other JavaFX controls like <code class="language-text">ListView</code> or <code class="language-text">TreeTable</code> the <code class="language-text">DatePicker</code> can be configured with a CellFactory.
In this cellFactory you can configure the styling of individual cells.</p>
<p>The basic code looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">DatePicker</span> datePicker <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatePicker</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

datePicker<span class="token punctuation">.</span><span class="token function">setDayCellFactory</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DatePicker</span><span class="token punctuation">,</span> <span class="token class-name">DateCell</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token annotation punctuation">@Override</span>
  <span class="token keyword">public</span> <span class="token class-name">DateCell</span> <span class="token function">call</span><span class="token punctuation">(</span><span class="token class-name">DatePicker</span> param<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">DateCell</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token annotation punctuation">@Override</span>
      <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">updateItem</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span> item<span class="token punctuation">,</span> <span class="token keyword">boolean</span> empty<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">updateItem</span><span class="token punctuation">(</span>item<span class="token punctuation">,</span> empty<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span></code></pre></div>
<p>JavaFX will reuse existing <code class="language-text">DateCell</code> instances when the visible viewport is changed when the user switches between
pages in the DatePicker. This way JavaFX saves resources and minimizes new instances as much as possible.</p>
<p>To reuse existing cells we need to override the <code class="language-text">updateItem</code> method which will get the new <code class="language-text">LocalDate</code> object as
parameter. Inside this method we can now check if this day should get a special styling.</p>
<p>In my example I will highlight the holidays (in Saxony, Germany) with a special color.</p>
]]></description>
            <content:encoded><![CDATA[<p>Today I had the requirement to implement a highlighting of some days in the JavaFX <code class="language-text">DatePicker</code>. As I haven't found an
existing blog post or tutorial that describes this topic I will provide a short example here.</p>
<p>Similar to other JavaFX controls like <code class="language-text">ListView</code> or <code class="language-text">TreeTable</code> the <code class="language-text">DatePicker</code> can be configured with a CellFactory.
In this cellFactory you can configure the styling of individual cells.</p>
<p>The basic code looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">DatePicker</span> datePicker <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatePicker</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

datePicker<span class="token punctuation">.</span><span class="token function">setDayCellFactory</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DatePicker</span><span class="token punctuation">,</span> <span class="token class-name">DateCell</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token annotation punctuation">@Override</span>
  <span class="token keyword">public</span> <span class="token class-name">DateCell</span> <span class="token function">call</span><span class="token punctuation">(</span><span class="token class-name">DatePicker</span> param<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">DateCell</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token annotation punctuation">@Override</span>
      <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">updateItem</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span> item<span class="token punctuation">,</span> <span class="token keyword">boolean</span> empty<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">updateItem</span><span class="token punctuation">(</span>item<span class="token punctuation">,</span> empty<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span></code></pre></div>
<p>JavaFX will reuse existing <code class="language-text">DateCell</code> instances when the visible viewport is changed when the user switches between
pages in the DatePicker. This way JavaFX saves resources and minimizes new instances as much as possible.</p>
<p>To reuse existing cells we need to override the <code class="language-text">updateItem</code> method which will get the new <code class="language-text">LocalDate</code> object as
parameter. Inside this method we can now check if this day should get a special styling.</p>
<p>In my example I will highlight the holidays (in Saxony, Germany) with a special color.</p>
<!--more-->
<p>The first step is to define the list of <code class="language-text">LocalDate</code>s that we are interested in. Then we can check the given <code class="language-text">LocalDate</code>
value in the <code class="language-text">updateItem</code> method.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">LocalDate</span><span class="token punctuation">></span></span> holidays <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">JANUARY</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">MARCH</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">APRIL</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">MAY</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">MAY</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">MAY</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">OCTOBER</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">OCTOBER</span><span class="token punctuation">,</span><span class="token number">31</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">NOVEMBER</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">DECEMBER</span><span class="token punctuation">,</span><span class="token number">25</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
holidays<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2018</span><span class="token punctuation">,</span> <span class="token class-name">Month</span><span class="token punctuation">.</span><span class="token constant">DECEMBER</span><span class="token punctuation">,</span><span class="token number">26</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>


<span class="token class-name">DatePicker</span> datePicker <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatePicker</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

datePicker<span class="token punctuation">.</span><span class="token function">setDayCellFactory</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DatePicker</span><span class="token punctuation">,</span> <span class="token class-name">DateCell</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">DateCell</span> <span class="token function">call</span><span class="token punctuation">(</span><span class="token class-name">DatePicker</span> param<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">DateCell</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
			<span class="token annotation punctuation">@Override</span>
			<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">updateItem</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span> item<span class="token punctuation">,</span> <span class="token keyword">boolean</span> empty<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">updateItem</span><span class="token punctuation">(</span>item<span class="token punctuation">,</span> empty<span class="token punctuation">)</span><span class="token punctuation">;</span>

				<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>empty <span class="token operator">&amp;&amp;</span> item <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token keyword">if</span><span class="token punctuation">(</span>holidays<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
						<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setStyle</span><span class="token punctuation">(</span><span class="token string">"-fx-background-color: pink"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token punctuation">}</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>The result looks like this:</p>
<p><img src="/files/pics/2018/datepicker_screenshot.png" alt="Screenshot"></p>
<p>An even better approach is to use a CSS file to define the styling. In the cell-factory we then only set a CSS class
that is referred to in the CSS file. The code of the cell-factory could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java">datePicker<span class="token punctuation">.</span><span class="token function">setDayCellFactory</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">DatePicker</span><span class="token punctuation">,</span> <span class="token class-name">DateCell</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">DateCell</span> <span class="token function">call</span><span class="token punctuation">(</span><span class="token class-name">DatePicker</span> param<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">DateCell</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
			<span class="token annotation punctuation">@Override</span>
			<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">updateItem</span><span class="token punctuation">(</span><span class="token class-name">LocalDate</span> item<span class="token punctuation">,</span> <span class="token keyword">boolean</span> empty<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">updateItem</span><span class="token punctuation">(</span>item<span class="token punctuation">,</span> empty<span class="token punctuation">)</span><span class="token punctuation">;</span>

				<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>empty <span class="token operator">&amp;&amp;</span> item <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token keyword">if</span><span class="token punctuation">(</span>holidays<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
						<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getStyleClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">"holiday"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					<span class="token punctuation">}</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>To write the CSS code we can use the
<a href="http://hg.openjdk.java.net/openjfx/8/master/rt/file/94331ac42150/modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css#l2934">modena.css</a>
as a reference point. The code looks like this:</p>
<div class="gatsby-highlight" data-language="css"><pre class="language-css"><code class="language-css"><span class="token selector">.date-picker-popup > * > .date-cell.holiday</span> <span class="token punctuation">{</span>
  <span class="token property">-fx-background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Implement your own Redux in Java. Part 2: Simple FXML Views]]></title>
            <link>https://www.lestard.eu/2018/implement-your-own-redux-in-java2/</link>
            <guid>https://www.lestard.eu/2018/implement-your-own-redux-in-java2/</guid>
            <pubDate>Sun, 17 Jun 2018 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've showed how the basic Redux functionality can be implemented. In this part I will show how to
use it with JavaFX and how to combine a simple FXML based JavaFX View with our Redux store.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><strong>Part 2: Simple FXML Views</strong></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
]]></description>
            <content:encoded><![CDATA[<p>In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.</p>
<p>However, the purpose is <em>not</em> to create a production-ready library (because there is already
<a href="https://github.com/netopyr/reduxfx">ReduxFX</a> available) but instead to learn by re-implementing it.</p>
<p>In the previous part I've showed how the basic Redux functionality can be implemented. In this part I will show how to
use it with JavaFX and how to combine a simple FXML based JavaFX View with our Redux store.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><a href="/2018/implement-your-own-redux-in-java/">Part 1: Basic Redux functionality</a></li>
<li><strong>Part 2: Simple FXML Views</strong></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
<!--more-->
<h2>The UI</h2>
<p>A typical JavaFX UI consists of a
<a href="https://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm">FXML file</a> and a controller class. This
can look like this:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>

<span class="token prolog">&lt;?import javafx.geometry.Insets?></span>
<span class="token prolog">&lt;?import javafx.scene.control.Button?></span>
<span class="token prolog">&lt;?import javafx.scene.control.ListView?></span>
<span class="token prolog">&lt;?import javafx.scene.control.TextField?></span>
<span class="token prolog">&lt;?import javafx.scene.layout.HBox?></span>
<span class="token prolog">&lt;?import javafx.scene.layout.VBox?></span>


<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>VBox</span> <span class="token attr-name"><span class="token namespace">fx:</span>controller</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>example.TodoViewController<span class="token punctuation">"</span></span> <span class="token attr-name">maxHeight</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>-Infinity<span class="token punctuation">"</span></span> <span class="token attr-name">maxWidth</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>-Infinity<span class="token punctuation">"</span></span> <span class="token attr-name">minHeight</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>-Infinity<span class="token punctuation">"</span></span>
      <span class="token attr-name">minWidth</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>-Infinity<span class="token punctuation">"</span></span> <span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://javafx.com/javafx/8.0.141<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">xmlns:</span>fx</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://javafx.com/fxml/1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>HBox</span> <span class="token attr-name">spacing</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>5.0<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>padding</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Insets</span> <span class="token attr-name">bottom</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>5.0<span class="token punctuation">"</span></span> <span class="token attr-name">left</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>5.0<span class="token punctuation">"</span></span> <span class="token attr-name">right</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>5.0<span class="token punctuation">"</span></span> <span class="token attr-name">top</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>5.0<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>padding</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TextField</span> <span class="token attr-name"><span class="token namespace">fx:</span>id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>input<span class="token punctuation">"</span></span> <span class="token attr-name">HBox.hgrow</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ALWAYS<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Button</span> <span class="token attr-name">mnemonicParsing</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>false<span class="token punctuation">"</span></span> <span class="token attr-name">text</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Add<span class="token punctuation">"</span></span> <span class="token attr-name">onAction</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#addItem<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>HBox</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ListView</span> <span class="token attr-name"><span class="token namespace">fx:</span>id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>items<span class="token punctuation">"</span></span> <span class="token attr-name">VBox.vgrow</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ALWAYS<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>VBox</span><span class="token punctuation">></span></span></code></pre></div>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">package</span> <span class="token namespace">example</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> <span class="token import"><span class="token namespace">javafx<span class="token punctuation">.</span>fxml<span class="token punctuation">.</span></span><span class="token class-name">FXML</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">javafx<span class="token punctuation">.</span>scene<span class="token punctuation">.</span>control<span class="token punctuation">.</span></span><span class="token class-name">ListView</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">javafx<span class="token punctuation">.</span>scene<span class="token punctuation">.</span>control<span class="token punctuation">.</span></span><span class="token class-name">TextField</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoViewController</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@FXML</span>
	<span class="token keyword">private</span> <span class="token class-name">ListView</span> items<span class="token punctuation">;</span>
	<span class="token annotation punctuation">@FXML</span>
	<span class="token keyword">private</span> <span class="token class-name">TextField</span> input<span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// todo implement</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now we need to solve two problems: 1) we need to create and dispatch a new action when the add-button is clicked and 2)
we need to get the data from the store and update our UI when the data has changed. The easiest way to solve this is to
give the controller access to our Redux store. This is a typical use-case for
<a href="/2014/dependency-injection-in-less-then-50-loc/">dependency-injection</a> and for this example I'm using my own
dependency-injection library <a href="/2014/easy-di/">Easy-DI</a>. This way we can inject an instance of the Redux store into the
controller. The setup code in the main app class looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">start</span><span class="token punctuation">(</span><span class="token class-name">Stage</span> primaryStage<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
	<span class="token comment">// create dependency injection context</span>
	<span class="token class-name">EasyDI</span> context <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">EasyDI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// create the initial state with an empty item list</span>
	<span class="token class-name">TodoState</span> initialState <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TodoState</span><span class="token punctuation">(</span><span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">emptyList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// create the store by passing the initial state and the reducer to the constructor</span>
	<span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> store <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>initialState<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">TodoReducer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// configure the DI context so that the store instance can be injected</span>
	context<span class="token punctuation">.</span><span class="token function">bindInstance</span><span class="token punctuation">(</span><span class="token class-name">Store</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> store<span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// the location of the fxml file to load</span>
	<span class="token keyword">final</span> <span class="token class-name">URL</span> location <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getResource</span><span class="token punctuation">(</span><span class="token string">"TodoView.fxml"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toURI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toURL</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token class-name">FXMLLoader</span> fxmlLoader <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FXMLLoader</span><span class="token punctuation">(</span>location<span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// tell JavaFX how to get new instances from the DI context</span>
	fxmlLoader<span class="token punctuation">.</span><span class="token function">setControllerFactory</span><span class="token punctuation">(</span>context<span class="token operator">::</span><span class="token function">getInstance</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token keyword">final</span> <span class="token class-name">VBox</span> parent <span class="token operator">=</span> fxmlLoader<span class="token punctuation">.</span><span class="token function">load</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	primaryStage<span class="token punctuation">.</span><span class="token function">setScene</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Scene</span><span class="token punctuation">(</span>parent<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	primaryStage<span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>EasyDI only supports constructor-injection but if you are using other DI frameworks maybe you can also use field
injection. Our controller now looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoViewController</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@FXML</span>
	<span class="token keyword">private</span> <span class="token class-name">ListView</span> items<span class="token punctuation">;</span>
	<span class="token annotation punctuation">@FXML</span>
	<span class="token keyword">private</span> <span class="token class-name">TextField</span> input<span class="token punctuation">;</span>

	<span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> store<span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token class-name">TodoViewController</span><span class="token punctuation">(</span><span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> store<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>store <span class="token operator">=</span> store<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// todo implement</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<h3>Dispatching actions</h3>
<p>Now that we have access to the store it's easy to dispatch new actions with the <code class="language-text">dispatch</code> method:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">addItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">final</span> <span class="token class-name">String</span> text <span class="token operator">=</span> input<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token class-name">Action</span> action <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span>
	store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span><span class="token punctuation">;</span>

	input<span class="token punctuation">.</span><span class="token function">setText</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<h3>Update the UI on state changes</h3>
<p>With the <code class="language-text">subscribe</code> method we have a way to get notified about state changes.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token class-name">TodoViewController</span><span class="token punctuation">(</span><span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> store<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">this</span><span class="token punctuation">.</span>store <span class="token operator">=</span> store<span class="token punctuation">;</span>

	store<span class="token punctuation">.</span><span class="token function">subscribe</span><span class="token punctuation">(</span>newState <span class="token operator">-></span> <span class="token punctuation">{</span>
		items<span class="token punctuation">.</span><span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setAll</span><span class="token punctuation">(</span>newState<span class="token punctuation">.</span><span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>For this small example updating the UI is easy. We throw away the existing items in the JavaFX <code class="language-text">ListView</code> and overwrite
them with the new ones. However, for more complex use-cases and UIs it can become really tricky. This style of
development can be a problem because JavaFX itself is not optimized for this kind of usage. The reason for this is that
JavaFX has an imperative API - at least when you compare it to the fully declarative API of React.js for which the
original Redux was invented. In a future post I will go into more detail what I mean with "fully declarative API" and
why in my opinion JavaFX is not fully declarative. And I will also show an alternative declarative and functional API
for JavaFX that is more similar to react.js and is a good fit for a Redux based app.</p>
<p>However, even with the "normal" FXML based approach you can create good UI's with Redux. Last year I have written some
useful helpers to support the combination of FXML and Redux as a contribution to the
<a href="https://github.com/netopyr/reduxfx">ReduxFX project</a>. In one of the next blog posts I will give a more detailed
explanation of these tools and show some patterns for Redux+FXML.</p>
<hr>
<p>You can find the code for redux example in <a href="https://github.com/manuel_mauky/redux-java-example">this github repository</a>. This
<a href="https://github.com/manuel_mauky/redux-java-example/tree/0820137ce9d11a52c19bb471df8a82600f084398">commit</a> is pointing
directly to the state of this blog post.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Implement your own Redux in Java. Part 1: Basic Redux functionality]]></title>
            <link>https://www.lestard.eu/2018/implement-your-own-redux-in-java/</link>
            <guid>https://www.lestard.eu/2018/implement-your-own-redux-in-java/</guid>
            <pubDate>Fri, 18 May 2018 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>To learn and understand new tech things I'm often
<a href="/2014/dependency-injection-in-less-then-50-loc">implementing them on my own</a>. I mean,
<a href="https://youtu.be/MShbP3OpASA?t=372">How hard can it be?</a> This time I'd like to show how to implement
<a href="https://redux.js.org/introduction">Redux</a> with Java targeted towards JavaFX. The purpose here is not to actually use
this implementation because there is already a <a href="https://github.com/netopyr/reduxfx">really good one available</a>. The
purpose is only to see that Redux actually isn't that complex when it comes to a basic implementation of the library. As
this topic includes a lot of sub-topics I will start a little series of blog posts that will cover the implementation of
a Redux library in Java, the extension mechanisms of Redux and how to use them with JavaFX.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><strong>Part 1: Basic Redux functionality</strong></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
]]></description>
            <content:encoded><![CDATA[<p>To learn and understand new tech things I'm often
<a href="/2014/dependency-injection-in-less-then-50-loc">implementing them on my own</a>. I mean,
<a href="https://youtu.be/MShbP3OpASA?t=372">How hard can it be?</a> This time I'd like to show how to implement
<a href="https://redux.js.org/introduction">Redux</a> with Java targeted towards JavaFX. The purpose here is not to actually use
this implementation because there is already a <a href="https://github.com/netopyr/reduxfx">really good one available</a>. The
purpose is only to see that Redux actually isn't that complex when it comes to a basic implementation of the library. As
this topic includes a lot of sub-topics I will start a little series of blog posts that will cover the implementation of
a Redux library in Java, the extension mechanisms of Redux and how to use them with JavaFX.</p>
<p><strong>Topics in this blog series</strong> (maybe I will adjust this in the process of writing):</p>
<ul>
<li><strong>Part 1: Basic Redux functionality</strong></li>
<li><a href="/2018/implement-your-own-redux-in-java2/">Part 2: Simple FXML Views</a></li>
<li><a href="/2019/implement-your-own-redux-in-java3/">Part 3: First approach on Middlewares</a></li>
<li><a href="/2019/implement-your-own-redux-in-java4/">Part 4: Improved Middleware API</a></li>
<li>Part 5: Async behavior with Middlewares</li>
<li>Part 6: Other examples for Middlewares</li>
<li>Store-enhancers</li>
<li>Dev-Tools with time-travel-debugging</li>
<li>advanced FXML views</li>
<li>declarative JavaFX Views</li>
<li>ReduxFX - an actual library</li>
</ul>
<!--more-->
<p>The first thing when implementing a library is to think about how a user would like to use it. How do you like your app
code to look like?</p>
<p>First let's create some actions. I'm using the classic <a href="/2016/todomvc_javafx/">Todo app</a> as an example here so we need
an "AddItemAction":</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AddItemAction</span> <span class="token keyword">implements</span> <span class="token class-name">Action</span> <span class="token punctuation">{</span>
  <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">String</span> value<span class="token punctuation">;</span>

  <span class="token keyword">public</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">(</span><span class="token class-name">String</span> value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>value <span class="token operator">=</span> value<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> value<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// equals &amp; hashcode</span>
<span class="token punctuation">}</span></code></pre></div>
<p>To give the class a little more context and to make the implementation of reducers easier I've also created a marker
interface <code class="language-text">Action</code> here that doesn't contain any methods.</p>
<p>The next step is to create a class for the State. This could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoState</span> <span class="token punctuation">{</span>

  <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> items<span class="token punctuation">;</span>

  <span class="token keyword">public</span> <span class="token class-name">TodoState</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> items<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>items <span class="token operator">=</span> items<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> items<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token class-name">TodoState</span> <span class="token function">withItems</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> items<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>items<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>items<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">TodoState</span><span class="token punctuation">(</span>items<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Here I'm implementing the state as an immutable class. This is important for Redux: You can't change the fields of the
state object. Instead you have to create a copy that has your desired changes applied. In this example I'm implementing
the immutability by hand. Of cource this won't scale for bigger applications. So for real-world applications I would
suggest you to use a library like <a href="https://immutables.github.io/">Immutables.org</a> that creates immutable classes for
you.</p>
<p>The next step for a Redux application is the <strong>Reducer</strong>. This can also be implemented with pure Java code like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoReducer</span> <span class="token punctuation">{</span>

  <span class="token keyword">public</span> <span class="token class-name">TodoState</span> <span class="token function">reduce</span><span class="token punctuation">(</span><span class="token class-name">TodoState</span> oldState<span class="token punctuation">,</span> <span class="token class-name">Action</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>action <span class="token keyword">instanceof</span> <span class="token class-name">AddItemAction</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">AddItemAction</span> addItemAction <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">AddItemAction</span><span class="token punctuation">)</span> action<span class="token punctuation">;</span>

      <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> oldItems <span class="token operator">=</span> oldState<span class="token punctuation">.</span><span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

      <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> newItems <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>oldItems<span class="token punctuation">)</span><span class="token punctuation">;</span>
      newItems<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>addItemAction<span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

      <span class="token keyword">return</span> oldState<span class="token punctuation">.</span><span class="token function">withItems</span><span class="token punctuation">(</span>newItems<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">return</span> oldState<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The implementation is pretty straight forward. If the incoming action is of type <code class="language-text">AddItemAction</code> we handle it by
creating a new item list containing the old items together with the new one. Then we create an immutable copy with the
new items by invoking <code class="language-text">withItems</code> on the old state instance. If the action doesn't match the desired type we ignore it
and simply return the existing state.</p>
<p>This is the basic redux code for our application. What is missing is the UI component to visualize the app but we will
come to this later. Now we can start implementing our Redux library. The first step is to introduce an interface for
Reducers. This should look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
  <span class="token class-name">S</span> <span class="token function">reduce</span><span class="token punctuation">(</span><span class="token class-name">S</span> oldState<span class="token punctuation">,</span> <span class="token class-name">Action</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The generic type variable <code class="language-text">S</code> is used for the actual type of the State. Now our example reducer can implement the new
interface:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TodoReducer</span> <span class="token keyword">implements</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TodoState</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

  <span class="token annotation punctuation">@Override</span>
  <span class="token keyword">public</span> <span class="token class-name">TodoState</span> <span class="token function">reduce</span><span class="token punctuation">(</span><span class="token class-name">TodoState</span> oldState<span class="token punctuation">,</span> <span class="token class-name">Action</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<h2>The Redux store</h2>
<p>Now we can implement the actual Redux store. The task of the Store is to hold an instance of the current State and to
exchange the state every time an action is dispatched. So the basic interface for the Store could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Store</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
  <span class="token keyword">private</span> <span class="token class-name">S</span> currentState<span class="token punctuation">;</span>
  <span class="token keyword">private</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> reducer<span class="token punctuation">;</span>

  <span class="token keyword">public</span> <span class="token class-name">Store</span><span class="token punctuation">(</span><span class="token class-name">S</span> initialState<span class="token punctuation">,</span> <span class="token class-name">Reducer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> rootReducer<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> initialState<span class="token punctuation">;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>reducer <span class="token operator">=</span> rootReducer<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token class-name">S</span> <span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// todo</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>To create a Store instance we need to provide an initial State and the Reducer. Then you can request the current State
with <code class="language-text">getState</code> and dispatch an Action with <code class="language-text">dispatch</code>.</p>
<p>Now let's implement the <code class="language-text">dispatch</code> method. Notice that I've used the type <code class="language-text">Object</code> for the action param instead of our
<code class="language-text">Action</code> interface. At first this might look strange but it enables us to create powerful extension mechanisms later on.
These extensions will make it possible to not only dispatch simple action objects but also other things like function
definitions or <code class="language-text">CompleteableFuture</code>s. This way it is possible to introduce different strategies to handle asynchronous
behavior that otherwise wouldn't be possible. Of course at this stage dispatching something other than a simple action
object would crash the app with a <code class="language-text">ClassCastException</code>. In one of the next blog posts I will introduce the concept of
"middlewares" and then we will fix this issue.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> reducer<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token class-name">Action</span><span class="token punctuation">)</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<h2>Subscribe to changes</h2>
<p>We are now able to dispatch actions and have the reducer creating new states for us. However, this implementation isn't
really useful yet. What is missing is a way to get notified about state-changes so that you can re-render the UI. For
this I'm introducing two interfaces:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Subscription</span> <span class="token punctuation">{</span>
  <span class="token keyword">void</span> <span class="token function">unsubscribe</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Subscriber</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
  <span class="token keyword">void</span> <span class="token function">onChange</span><span class="token punctuation">(</span><span class="token class-name">S</span> state<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p><code class="language-text">Subscriber</code> is just a regular observer. It's <code class="language-text">onChange</code> method will be invoked when the State in the store has been
changed. When subscribing to the Store you pass a <code class="language-text">Subscriber</code> as argument and you will get a <code class="language-text">Subscription</code> as a
result. You can ignore this <code class="language-text">Subscription</code> or use it later to unsubscribe from the Store. This is a nice convenience
feature but if you like you can also just implement a classic observer pattern. Subscribing to the Store looks like
this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Subscription</span> sub <span class="token operator">=</span> store<span class="token punctuation">.</span><span class="token function">subscribe</span><span class="token punctuation">(</span>state <span class="token operator">-></span> <span class="token punctuation">{</span>
  <span class="token comment">// do some updates based on the new state</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>


<span class="token comment">// later</span>
sub<span class="token punctuation">.</span><span class="token function">unsubscribe</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>Now the implementation of the Store get's a little more interesting. First we add a
<code class="language-text">private List&lt;Subscriber&lt;S>> subscribers = new ArrayList&lt;>();</code> list to the store. Then we add the <code class="language-text">subscribe</code> method:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token class-name">Subscription</span> <span class="token function">subscribe</span><span class="token punctuation">(</span><span class="token class-name">Subscriber</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">S</span><span class="token punctuation">></span></span> subscriber<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  subscribers<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>subscriber<span class="token punctuation">)</span><span class="token punctuation">;</span>

  subscriber<span class="token punctuation">.</span><span class="token function">onChange</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token punctuation">{</span>
    subscribers<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>subscriber<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The subscriber is added to the subscriber list and it's <code class="language-text">onChange</code> method is invoked with the current state. This way
the subscribing code can properly initialize itself. Then we create a lambda for the <code class="language-text">Subscription</code> which, when invoked,
will remove the subscriber from the list.</p>
<p>The next step is to update the <code class="language-text">dispatch</code> method. We need to notify all subscribers when an action is dispatched.
Additionally I'm adding a check to see if the new state was really changed. A friendly reducer returns the existing
state untouched if it doesn't know the incoming Action or it don't want to react to the action. Therefore it's likely
that the resulting state instance is the same as the existing one. In this situation we don't want to notify the
subscribers to minimize unnecessary re-renderings of the UI. The implementation now looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">notifySubscribers</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  subscribers<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>subscriber <span class="token operator">-></span> subscriber<span class="token punctuation">.</span><span class="token function">onChange</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token class-name">Object</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token class-name">S</span> oldState <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">;</span>

  <span class="token class-name">S</span> newState <span class="token operator">=</span> reducer<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>currentState<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token class-name">Action</span><span class="token punctuation">)</span> action<span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">if</span> <span class="token punctuation">(</span>oldState <span class="token operator">!=</span> newState <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>oldState<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>newState<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>currentState <span class="token operator">=</span> newState<span class="token punctuation">;</span>

    <span class="token function">notifySubscribers</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>And that's it. This is a basic but fully functional Redux implementation. In comparison with the original redux.js
library it misses some extension APIs like <a href="https://redux.js.org/advanced/middleware">Middlewares</a> and
<a href="https://redux.js.org/glossary#store-enhancer">Store-Enhancers</a> but we will work on this in a separate blog post. What
is missing now to be useful is the UI component and the connection between the UI and the Redux Store. This will be the
topic for the <a href="/2018/implement-your-own-redux-in-java2/">next part</a> of this series.</p>
<hr>
<p>You can find the code for redux example in <a href="https://github.com/manuel_mauky/redux-java-example">this github repository</a>. This
<a href="https://github.com/manuel_mauky/redux-java-example/tree/3d7751097896e60cde24c4bdbfa99e0a209a41bf">commit</a> is pointing
directly to the state of this blog post.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[GraphQL Example App 'Bloggie']]></title>
            <link>https://www.lestard.eu/2018/bloggie/</link>
            <guid>https://www.lestard.eu/2018/bloggie/</guid>
            <pubDate>Mon, 23 Apr 2018 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In the past I've given several talks on GraphQL (JavaLand 2017,
<a href="https://jugsaxony.org/2017/04/10/89-treffen-graphql-als-alternative-zu-rest/">JUG Saxony</a>,
<a href="http://www.jug-berlin-brandenburg.de/blog/2017/graphql.html">JUG Berlin</a>,
<a href="http://bed-con.org/2017/talks/GraphQL-als-Alternative-zu-REST">BEDCon 2017</a>,
<a href="https://www.oop-konferenz.de/oop2018/programm/freies-programm/sessiondetails.html?tx_dmconferences_sessionpaid%5Bsession%5D=114&#x26;tx_dmconferences_sessionpaid%5Btalk%5D=&#x26;tx_dmconferences_sessionpaid%5Baction%5D=detail&#x26;tx_dmconferences_sessionpaid%5Bcontroller%5D=SessionPaid&#x26;cHash=ca60bf012e2d895ebc1227f50daca125">OOP 2018</a>),
a query language for web API's. In those talks I've used the example of a blog application with the name "Bloggie".
Today I have made the github repository of this example public so that everyone interested in this example app can see
the source code.</p>
<p>You can find it here: <a href="https://github.com/manuel_mauky/bloggie">https://github.com/manuel_mauky/bloggie</a></p>
<p><img src="/files/pics/2018/bloggie_screenshot.png" alt="bloggie screenshot"></p>
<p>The app shows articles and authors both in a overview page and a details page and a comment section will be added in the
future. The idea of this repository is to not only contain a single example but instead to implement the same use-case
with different technologies and implementation styles.</p>
<p>At the moment I have a backend implemented with node.js and a frontend written with React.js and
<a href="https://www.apollographql.com">Apollo Client</a> but in the future I'm planning to add other variants too. For example, a
student I'm mentoring has compared several ways to implement GraphQL servers. This includes node.js,
<a href="https://github.com/graphql-java/graphql-java">pure Java</a> and
<a href="https://github.com/jcrygier/graphql-jpa">Java with Java-Persistence API</a>. So it's likely that I will add a Java
implementation too.</p>
<p>In the frontend I'm planning to add another implementation with Angular and maybe another react-variant using a
different graphql client library.</p>
<p>What is important to notice here is: <strong>This app is not intended for real-world usage!</strong> It's neither optimized for a
good usability as a blogging platform nor can I guarantee the absence of bugs or security issues. The only purpose of
the repository is to show and learn technologies and patterns around GraphQL.</p>
<p>One of the reasons to "open-source" the example app is that I'm planing to write more blog posts on GraphQL, React,
Redux and other web technologies in the future. Because even though I'm programming with JavaScript for 10 years now and
I've also used react.js, redux and GraphQL for several applications I haven't been blogging about these topics in the
past.</p>]]></description>
            <content:encoded><![CDATA[<p>In the past I've given several talks on GraphQL (JavaLand 2017,
<a href="https://jugsaxony.org/2017/04/10/89-treffen-graphql-als-alternative-zu-rest/">JUG Saxony</a>,
<a href="http://www.jug-berlin-brandenburg.de/blog/2017/graphql.html">JUG Berlin</a>,
<a href="http://bed-con.org/2017/talks/GraphQL-als-Alternative-zu-REST">BEDCon 2017</a>,
<a href="https://www.oop-konferenz.de/oop2018/programm/freies-programm/sessiondetails.html?tx_dmconferences_sessionpaid%5Bsession%5D=114&#x26;tx_dmconferences_sessionpaid%5Btalk%5D=&#x26;tx_dmconferences_sessionpaid%5Baction%5D=detail&#x26;tx_dmconferences_sessionpaid%5Bcontroller%5D=SessionPaid&#x26;cHash=ca60bf012e2d895ebc1227f50daca125">OOP 2018</a>),
a query language for web API's. In those talks I've used the example of a blog application with the name "Bloggie".
Today I have made the github repository of this example public so that everyone interested in this example app can see
the source code.</p>
<p>You can find it here: <a href="https://github.com/manuel_mauky/bloggie">https://github.com/manuel_mauky/bloggie</a></p>
<p><img src="/files/pics/2018/bloggie_screenshot.png" alt="bloggie screenshot"></p>
<p>The app shows articles and authors both in a overview page and a details page and a comment section will be added in the
future. The idea of this repository is to not only contain a single example but instead to implement the same use-case
with different technologies and implementation styles.</p>
<p>At the moment I have a backend implemented with node.js and a frontend written with React.js and
<a href="https://www.apollographql.com">Apollo Client</a> but in the future I'm planning to add other variants too. For example, a
student I'm mentoring has compared several ways to implement GraphQL servers. This includes node.js,
<a href="https://github.com/graphql-java/graphql-java">pure Java</a> and
<a href="https://github.com/jcrygier/graphql-jpa">Java with Java-Persistence API</a>. So it's likely that I will add a Java
implementation too.</p>
<p>In the frontend I'm planning to add another implementation with Angular and maybe another react-variant using a
different graphql client library.</p>
<p>What is important to notice here is: <strong>This app is not intended for real-world usage!</strong> It's neither optimized for a
good usability as a blogging platform nor can I guarantee the absence of bugs or security issues. The only purpose of
the repository is to show and learn technologies and patterns around GraphQL.</p>
<p>One of the reasons to "open-source" the example app is that I'm planing to write more blog posts on GraphQL, React,
Redux and other web technologies in the future. Because even though I'm programming with JavaScript for 10 years now and
I've also used react.js, redux and GraphQL for several applications I haven't been blogging about these topics in the
past.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Javaland 2018: Talk about Immutables]]></title>
            <link>https://www.lestard.eu/2018/javaland_immutables/</link>
            <guid>https://www.lestard.eu/2018/javaland_immutables/</guid>
            <pubDate>Sat, 17 Feb 2018 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>I will be speaking at the <a href="https://www.javaland.eu/">Javaland conference 2018</a>. This conference is organized by the
<a href="http://www.ijug.eu">iJUG e.V.</a> which is the association of german speaking Java User Groups of which we as
<a href="http://www.jug-gr.de">JUG Görlitz</a> are a part of. The conference is also special because of the location: It will take
place in the <a href="http://www.phantasialand.de/en/home/">Phantasialand Brühl</a>, a theme park in the area of cologne. It will
last from 13th to 15th of march.</p>
<p><img src="/files/pics/2018/javaland_banner.jpg" alt="javaland banner"></p>
<p><a href="https://programm.javaland.eu/2018/#/scheduledEvent/548965">My talk</a> will be about immutable data with Java. As I'm a
fan of functional programming, I'm using immutable data structures a lot. For example when developing applications with
Redux both in JavaScript and in Java, immutability is an important thing to keep in mind. For me personally, thinking in
immutable objects is not a big deal anymore. It's natural and by this time I'm used to it. But when I talk to other
developers or doing code reviews I sometimes see people having problems with this kind of development style. Therefore I
hope to give a good introduction to the topic with the talk and also show how people can implement their own immutable
data structures in Java - either by hand or by using third-party libraries. And I will also take a short look at other
JVM languages like Kotlin or Frege.</p>]]></description>
            <content:encoded><![CDATA[<p>I will be speaking at the <a href="https://www.javaland.eu/">Javaland conference 2018</a>. This conference is organized by the
<a href="http://www.ijug.eu">iJUG e.V.</a> which is the association of german speaking Java User Groups of which we as
<a href="http://www.jug-gr.de">JUG Görlitz</a> are a part of. The conference is also special because of the location: It will take
place in the <a href="http://www.phantasialand.de/en/home/">Phantasialand Brühl</a>, a theme park in the area of cologne. It will
last from 13th to 15th of march.</p>
<p><img src="/files/pics/2018/javaland_banner.jpg" alt="javaland banner"></p>
<p><a href="https://programm.javaland.eu/2018/#/scheduledEvent/548965">My talk</a> will be about immutable data with Java. As I'm a
fan of functional programming, I'm using immutable data structures a lot. For example when developing applications with
Redux both in JavaScript and in Java, immutability is an important thing to keep in mind. For me personally, thinking in
immutable objects is not a big deal anymore. It's natural and by this time I'm used to it. But when I talk to other
developers or doing code reviews I sometimes see people having problems with this kind of development style. Therefore I
hope to give a good introduction to the topic with the talk and also show how people can implement their own immutable
data structures in Java - either by hand or by using third-party libraries. And I will also take a short look at other
JVM languages like Kotlin or Frege.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[JavaFX Dialogs: How to set min-size and prevent closing?]]></title>
            <link>https://www.lestard.eu/2018/dialogs_minsize_closing/</link>
            <guid>https://www.lestard.eu/2018/dialogs_minsize_closing/</guid>
            <pubDate>Sun, 11 Feb 2018 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>In this post I will write about two problems with JavaFX dialogs and how to solve them: How can you set a minimal size
for a dialog and how can you prevent the dialog from closing?</p>
<h2>How to set a min-size for JavaFX Dialogs?</h2>
<p>If you create a JavaFX Application Window without further configuration, you can resize the window without limitations.
This means you can change the size so that no content is visible anymore.</p>
<p><img src="/files/pics/2018/jfx_dialog_minsize.png" alt="todo app with JavaFX"></p>
<p>To prevent this you have to set a <code class="language-text">minHeight</code> and <code class="language-text">minWidth</code> on the <code class="language-text">Stage</code> of the window:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestApp</span> <span class="token keyword">extends</span> <span class="token class-name">Application</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">start</span><span class="token punctuation">(</span><span class="token class-name">Stage</span> primaryStage<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">VBox</span> root <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Vbox</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		primaryStage<span class="token punctuation">.</span><span class="token function">setMinHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		primaryStage<span class="token punctuation">.</span><span class="token function">setMinWidth</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		primaryStage<span class="token punctuation">.</span><span class="token function">setScene</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Scene</span><span class="token punctuation">(</span>root<span class="token punctuation">,</span> <span class="token number">400</span><span class="token punctuation">,</span> <span class="token number">400</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		primaryStage<span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>With Dialog you have a similar situation. By default JavaFX Dialogs are not resizeable but it is possible to change this
default behavior. However, if the Dialog is set to be resizeable you are then able to minimize the size to 0 pixel like
with the application window. In contrast to the main application window you can't set the min-size on the Dialog though.
At least not directly.</p>
<p>To fix this you have to set the min-size on the stage of the dialog. This can be done like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Dialog</span> dialog <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Dialog</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
dialog<span class="token punctuation">.</span><span class="token function">setResizable</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">final</span> <span class="token class-name">Window</span> window <span class="token operator">=</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getScene</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getWindow</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Stage</span> stage <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Stage</span><span class="token punctuation">)</span> window<span class="token punctuation">;</span>

stage<span class="token punctuation">.</span><span class="token function">setMinHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
stage<span class="token punctuation">.</span><span class="token function">setMinWidth</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<h2>How to prevent the closing of a Dialog.</h2>
<p>Another situation that we were facing in a real-world app lately was to prevent closing of a JavaFX Dialog when some
validation logic has failed.</p>
<p>In the <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html">JavaDoc</a> for the <code class="language-text">Dialog</code> class
you can find two paragraphs that look promising at a first glance: "Dialog Validation / Intercepting Button Actions" and
"Dialog Closing Rules".</p>
<p>The first one tells you how you can add validation rules for dialog buttons and how to prevent the dialog from closing
if the condition is not met when attempting to close the dialog.</p>
<p>With the <code class="language-text">lookup</code> method of the <code class="language-text">DialogPane</code> you can get the buttons of the Dialog and add EventFilters on them. If your
validation fails you can consume the event to prevent the Dialog from closing:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Dialog</span> dialog <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Dialog</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>getButtonTypes<span class="token punctuation">.</span><span class="token function">addAll</span><span class="token punctuation">(</span><span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">,</span> <span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">CANCEL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">TextField</span> textField <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TextField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setContent</span><span class="token punctuation">(</span>textField<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// Create an event filter that consumes the action if the text is empty</span>
<span class="token class-name">EventHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ActionEvent</span><span class="token punctuation">></span></span> filter <span class="token operator">=</span> event <span class="token operator">-></span> <span class="token punctuation">{</span>
	<span class="token keyword">if</span><span class="token punctuation">(</span>textField<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		event<span class="token punctuation">.</span><span class="token function">consume</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token comment">// lookup the buttons</span>
<span class="token class-name">Button</span> okButton <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Button</span><span class="token punctuation">)</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lookup</span><span class="token punctuation">(</span><span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Button</span> cancelButton <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Button</span><span class="token punctuation">)</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lookup</span><span class="token punctuation">(</span><span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">CANCEL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// add the event-filter</span>
okButton<span class="token punctuation">.</span><span class="token function">addEventFilter</span><span class="token punctuation">(</span><span class="token class-name">ActionEvent</span><span class="token punctuation">.</span><span class="token constant">ACTION</span><span class="token punctuation">,</span> filter<span class="token punctuation">)</span><span class="token punctuation">;</span>
cancelButton<span class="token punctuation">.</span><span class="token function">addEventFilter</span><span class="token punctuation">(</span><span class="token class-name">ActionEvent</span><span class="token punctuation">.</span><span class="token constant">ACTION</span><span class="token punctuation">,</span> filter<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>The code above creates a Dialog with a TextField and two Buttons (OK and CANCEL). You can't close the dialog with these
buttons as long as the TextField is empty. In many situations this may not be your desired behavior: Typically you like
to prevent closing with the OK Button but allow the user to cancel the action and close the dialog with the CANCEL
button. However, in other situations you may want to achive exactly this: Prevent the closing even when the cancel
button is pressed. So everything is ok with this code? Not quite. You can still click the "x" in the window of the
dialog and the Dialog will close no matter what your validation says.</p>
<p>This is when the second part of the
<a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html">JavaDoc</a> page comes into play. It
describes the rules when it's possible to close a Dialog "abnormally" (which includes clicking the "x" but also pressing
some OS specific shortcut like Alt+F4 on Windows). These rules are not bad. You can only close a dialog this way if the
dialog has a CANCEL Button. From a usability perspective this makes sense: If the user can't finish the process in the
dialog she may want cancel it either by pressing the cancel button of the dialog or the "x" in the window title.</p>
<p>But what if (for some reasons) you have other requirements? What if you have to prevent the closing even though it might
not result in good usability? For this usage there is no easy API available.</p>
<p>But it is still possible with some workarounds: In JavaFX you can prevent the closing of a <code class="language-text">Stage</code> by adding an
event-filter with the <code class="language-text">setOnCloseRequest</code> method. With this knowledge you can use the same approach from the beginning
of this article to access the Stage of the dialog to add this event-filter:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Stage</span> stage <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Stage</span><span class="token punctuation">)</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getScene</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getWindow</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

stage<span class="token punctuation">.</span><span class="token function">setOnCloseRequest</span><span class="token punctuation">(</span>event <span class="token operator">-></span> <span class="token punctuation">{</span>
	<span class="token keyword">if</span><span class="token punctuation">(</span>tf<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		event<span class="token punctuation">.</span><span class="token function">consume</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>]]></description>
            <content:encoded><![CDATA[<p>In this post I will write about two problems with JavaFX dialogs and how to solve them: How can you set a minimal size
for a dialog and how can you prevent the dialog from closing?</p>
<h2>How to set a min-size for JavaFX Dialogs?</h2>
<p>If you create a JavaFX Application Window without further configuration, you can resize the window without limitations.
This means you can change the size so that no content is visible anymore.</p>
<p><img src="/files/pics/2018/jfx_dialog_minsize.png" alt="todo app with JavaFX"></p>
<p>To prevent this you have to set a <code class="language-text">minHeight</code> and <code class="language-text">minWidth</code> on the <code class="language-text">Stage</code> of the window:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestApp</span> <span class="token keyword">extends</span> <span class="token class-name">Application</span> <span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">start</span><span class="token punctuation">(</span><span class="token class-name">Stage</span> primaryStage<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">VBox</span> root <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Vbox</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		primaryStage<span class="token punctuation">.</span><span class="token function">setMinHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		primaryStage<span class="token punctuation">.</span><span class="token function">setMinWidth</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		primaryStage<span class="token punctuation">.</span><span class="token function">setScene</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Scene</span><span class="token punctuation">(</span>root<span class="token punctuation">,</span> <span class="token number">400</span><span class="token punctuation">,</span> <span class="token number">400</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		primaryStage<span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>With Dialog you have a similar situation. By default JavaFX Dialogs are not resizeable but it is possible to change this
default behavior. However, if the Dialog is set to be resizeable you are then able to minimize the size to 0 pixel like
with the application window. In contrast to the main application window you can't set the min-size on the Dialog though.
At least not directly.</p>
<p>To fix this you have to set the min-size on the stage of the dialog. This can be done like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Dialog</span> dialog <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Dialog</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
dialog<span class="token punctuation">.</span><span class="token function">setResizable</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">final</span> <span class="token class-name">Window</span> window <span class="token operator">=</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getScene</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getWindow</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Stage</span> stage <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Stage</span><span class="token punctuation">)</span> window<span class="token punctuation">;</span>

stage<span class="token punctuation">.</span><span class="token function">setMinHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
stage<span class="token punctuation">.</span><span class="token function">setMinWidth</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<h2>How to prevent the closing of a Dialog.</h2>
<p>Another situation that we were facing in a real-world app lately was to prevent closing of a JavaFX Dialog when some
validation logic has failed.</p>
<p>In the <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html">JavaDoc</a> for the <code class="language-text">Dialog</code> class
you can find two paragraphs that look promising at a first glance: "Dialog Validation / Intercepting Button Actions" and
"Dialog Closing Rules".</p>
<p>The first one tells you how you can add validation rules for dialog buttons and how to prevent the dialog from closing
if the condition is not met when attempting to close the dialog.</p>
<p>With the <code class="language-text">lookup</code> method of the <code class="language-text">DialogPane</code> you can get the buttons of the Dialog and add EventFilters on them. If your
validation fails you can consume the event to prevent the Dialog from closing:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Dialog</span> dialog <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Dialog</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>getButtonTypes<span class="token punctuation">.</span><span class="token function">addAll</span><span class="token punctuation">(</span><span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">,</span> <span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">CANCEL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">TextField</span> textField <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TextField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setContent</span><span class="token punctuation">(</span>textField<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// Create an event filter that consumes the action if the text is empty</span>
<span class="token class-name">EventHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ActionEvent</span><span class="token punctuation">></span></span> filter <span class="token operator">=</span> event <span class="token operator">-></span> <span class="token punctuation">{</span>
	<span class="token keyword">if</span><span class="token punctuation">(</span>textField<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		event<span class="token punctuation">.</span><span class="token function">consume</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token comment">// lookup the buttons</span>
<span class="token class-name">Button</span> okButton <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Button</span><span class="token punctuation">)</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lookup</span><span class="token punctuation">(</span><span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Button</span> cancelButton <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Button</span><span class="token punctuation">)</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lookup</span><span class="token punctuation">(</span><span class="token class-name">ButtonType</span><span class="token punctuation">.</span><span class="token constant">CANCEL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// add the event-filter</span>
okButton<span class="token punctuation">.</span><span class="token function">addEventFilter</span><span class="token punctuation">(</span><span class="token class-name">ActionEvent</span><span class="token punctuation">.</span><span class="token constant">ACTION</span><span class="token punctuation">,</span> filter<span class="token punctuation">)</span><span class="token punctuation">;</span>
cancelButton<span class="token punctuation">.</span><span class="token function">addEventFilter</span><span class="token punctuation">(</span><span class="token class-name">ActionEvent</span><span class="token punctuation">.</span><span class="token constant">ACTION</span><span class="token punctuation">,</span> filter<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>The code above creates a Dialog with a TextField and two Buttons (OK and CANCEL). You can't close the dialog with these
buttons as long as the TextField is empty. In many situations this may not be your desired behavior: Typically you like
to prevent closing with the OK Button but allow the user to cancel the action and close the dialog with the CANCEL
button. However, in other situations you may want to achive exactly this: Prevent the closing even when the cancel
button is pressed. So everything is ok with this code? Not quite. You can still click the "x" in the window of the
dialog and the Dialog will close no matter what your validation says.</p>
<p>This is when the second part of the
<a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html">JavaDoc</a> page comes into play. It
describes the rules when it's possible to close a Dialog "abnormally" (which includes clicking the "x" but also pressing
some OS specific shortcut like Alt+F4 on Windows). These rules are not bad. You can only close a dialog this way if the
dialog has a CANCEL Button. From a usability perspective this makes sense: If the user can't finish the process in the
dialog she may want cancel it either by pressing the cancel button of the dialog or the "x" in the window title.</p>
<p>But what if (for some reasons) you have other requirements? What if you have to prevent the closing even though it might
not result in good usability? For this usage there is no easy API available.</p>
<p>But it is still possible with some workarounds: In JavaFX you can prevent the closing of a <code class="language-text">Stage</code> by adding an
event-filter with the <code class="language-text">setOnCloseRequest</code> method. With this knowledge you can use the same approach from the beginning
of this article to access the Stage of the dialog to add this event-filter:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Stage</span> stage <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Stage</span><span class="token punctuation">)</span> dialog<span class="token punctuation">.</span><span class="token function">getDialogPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getScene</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getWindow</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

stage<span class="token punctuation">.</span><span class="token function">setOnCloseRequest</span><span class="token punctuation">(</span>event <span class="token operator">-></span> <span class="token punctuation">{</span>
	<span class="token keyword">if</span><span class="token punctuation">(</span>tf<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		event<span class="token punctuation">.</span><span class="token function">consume</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[New mvvmFX version 1.6.0 released]]></title>
            <link>https://www.lestard.eu/2017/new_mvvmfx_version/</link>
            <guid>https://www.lestard.eu/2017/new_mvvmfx_version/</guid>
            <pubDate>Sat, 04 Mar 2017 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>This week I've released a <a href="https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.6.0">new version</a> of
<a href="https://github.com/sialcasa/mvvmFX">mvvmFX</a>. In this blog post I will highlight some of the new features and changes.</p>
<h2>EasyDI integration</h2>
<p>Support for dependency injection was always one of the main goals of mvvmFX and one of the first features we had
implemented. Previously, mvvmFX was supporting <a href="https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-cdi">CDI/Weld</a>
and <a href="https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-guice">Guice</a> as dependency injection frameworks. With the
new release we added support for the small DI library
<a href="https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-easydi">EasyDI</a>.<br>
I've written <a href="https://github.com/manuel_mauky/EasyDI">EasyDI</a> as a dependency injection alternative for small to medium
projects with the goal of an easy setup without extra configuration but with the tradeof of haven limited features
compared to full-fladged DI frameworks like CDI or Guice. If you are interested in EasyDI you can read more about it
<a href="/2014/dependency-injection-in-less-then-50-loc">here</a> and <a href="/2014/easy-di">here</a>.</p>
<h2>Validation in separate module</h2>
<p>We have extracted the <a href="https://github.com/sialcasa/mvvmFX/wiki/Validation">Validation</a> feature into it's own maven
module. This way you can use the validation mechanism without having to import the whole mvvmFX module. If you are using
the validation classes and you upgrade to the new version you will have to add the
<a href="https://search.maven.org/#artifactdetails%7Cde.saxsys%7Cmvvmfx-validation%7C1.6.0%7Cjar">mvvmfx-validation</a> module to
your maven/gradle build file. Everything else (i.e. package names) stays the same.</p>
<p>Additionally we have improved the
<a href="https://github.com/sialcasa/mvvmFX/wiki/Validation#observablerulebasedvalidator">ObservableRuleBasedValidation</a> to be
more flexible. Instead of an <code class="language-text">ObservableValue&lt;Boolean></code> you can now also use an <code class="language-text">ObservableValue&lt;ValidationMessage></code> as
rule to control when a validation is failed and which message should be used in this case.</p>
<h2>Lifecycle methods for ViewModels</h2>
<p>It's now possible to add lifecycle hooks to the ViewModel. This way you can react to the event of the View being added
to or removed from the SceneGraph. This can be useful to implement housekeeping of listeners or cleanup of used
resources.<br>
However, at the moment we see this as <strong>beta</strong>: It works for many of our use cases but we aren't 100% sure if there are
hidden side effects that we haven't thought of yet. As always we highly appreciate your feedback.<br>
At the moment this lifecylce hook is only available for FXML bases Views and only in the ViewModel. For the next version
we are planing to add it for <a href="https://github.com/sialcasa/mvvmFX/issues/470">Java code based Views</a> and the
<a href="https://github.com/sialcasa/mvvmFX/issues/471">CodeBehind classes</a> itself.</p>
<p>This is just a first step to help preventing memory leaks. For the next version we are also
<a href="https://github.com/sialcasa/mvvmFX/issues/430">planing</a> to provide a way to prevent unintentional garbage collection of
Controller/CodeBehind classes as a second step.</p>
<h2>New example app showing asynchrounous behavior usind CompletableFuture</h2>
<p>There are many ways of handling asynchrounous behavior in JavaFX apps. One that I personally like a lot is using java's
CompletableFuture. Therefore I've added a new example app that shows how you can use CompletableFuture with mvvmFX to
wrap a blocking/synchrounous backend service in the ViewModel and still have a non-blocking UI. You can find the
<a href="https://github.com/sialcasa/mvvmFX/tree/develop/examples/mini-examples/async-todoapp-futures">example code here</a>.</p>
<p>I hope you like the new release. Tell us how you like it and provide feedback in the comments or in the
<a href="https://github.com/sialcasa/mvvmFX/issues">issue tracker</a> of the project.</p>]]></description>
            <content:encoded><![CDATA[<p>This week I've released a <a href="https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.6.0">new version</a> of
<a href="https://github.com/sialcasa/mvvmFX">mvvmFX</a>. In this blog post I will highlight some of the new features and changes.</p>
<h2>EasyDI integration</h2>
<p>Support for dependency injection was always one of the main goals of mvvmFX and one of the first features we had
implemented. Previously, mvvmFX was supporting <a href="https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-cdi">CDI/Weld</a>
and <a href="https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-guice">Guice</a> as dependency injection frameworks. With the
new release we added support for the small DI library
<a href="https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-easydi">EasyDI</a>.<br>
I've written <a href="https://github.com/manuel_mauky/EasyDI">EasyDI</a> as a dependency injection alternative for small to medium
projects with the goal of an easy setup without extra configuration but with the tradeof of haven limited features
compared to full-fladged DI frameworks like CDI or Guice. If you are interested in EasyDI you can read more about it
<a href="/2014/dependency-injection-in-less-then-50-loc">here</a> and <a href="/2014/easy-di">here</a>.</p>
<h2>Validation in separate module</h2>
<p>We have extracted the <a href="https://github.com/sialcasa/mvvmFX/wiki/Validation">Validation</a> feature into it's own maven
module. This way you can use the validation mechanism without having to import the whole mvvmFX module. If you are using
the validation classes and you upgrade to the new version you will have to add the
<a href="https://search.maven.org/#artifactdetails%7Cde.saxsys%7Cmvvmfx-validation%7C1.6.0%7Cjar">mvvmfx-validation</a> module to
your maven/gradle build file. Everything else (i.e. package names) stays the same.</p>
<p>Additionally we have improved the
<a href="https://github.com/sialcasa/mvvmFX/wiki/Validation#observablerulebasedvalidator">ObservableRuleBasedValidation</a> to be
more flexible. Instead of an <code class="language-text">ObservableValue&lt;Boolean></code> you can now also use an <code class="language-text">ObservableValue&lt;ValidationMessage></code> as
rule to control when a validation is failed and which message should be used in this case.</p>
<h2>Lifecycle methods for ViewModels</h2>
<p>It's now possible to add lifecycle hooks to the ViewModel. This way you can react to the event of the View being added
to or removed from the SceneGraph. This can be useful to implement housekeeping of listeners or cleanup of used
resources.<br>
However, at the moment we see this as <strong>beta</strong>: It works for many of our use cases but we aren't 100% sure if there are
hidden side effects that we haven't thought of yet. As always we highly appreciate your feedback.<br>
At the moment this lifecylce hook is only available for FXML bases Views and only in the ViewModel. For the next version
we are planing to add it for <a href="https://github.com/sialcasa/mvvmFX/issues/470">Java code based Views</a> and the
<a href="https://github.com/sialcasa/mvvmFX/issues/471">CodeBehind classes</a> itself.</p>
<p>This is just a first step to help preventing memory leaks. For the next version we are also
<a href="https://github.com/sialcasa/mvvmFX/issues/430">planing</a> to provide a way to prevent unintentional garbage collection of
Controller/CodeBehind classes as a second step.</p>
<h2>New example app showing asynchrounous behavior usind CompletableFuture</h2>
<p>There are many ways of handling asynchrounous behavior in JavaFX apps. One that I personally like a lot is using java's
CompletableFuture. Therefore I've added a new example app that shows how you can use CompletableFuture with mvvmFX to
wrap a blocking/synchrounous backend service in the ViewModel and still have a non-blocking UI. You can find the
<a href="https://github.com/sialcasa/mvvmFX/tree/develop/examples/mini-examples/async-todoapp-futures">example code here</a>.</p>
<p>I hope you like the new release. Tell us how you like it and provide feedback in the comments or in the
<a href="https://github.com/sialcasa/mvvmFX/issues">issue tracker</a> of the project.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[TodoMVC for JavaFX]]></title>
            <link>https://www.lestard.eu/2016/todomvc_javafx/</link>
            <guid>https://www.lestard.eu/2016/todomvc_javafx/</guid>
            <pubDate>Tue, 04 Oct 2016 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In the JavaScript world there are thousands of libraries and frameworks available for you to use for your next
application. And with plenty of choice there comes the agony of choice. Before you can even think about choosing the
"best" framework you need a set of frameworks that you will take a closer look at in the second step. To get a first
impression of a framework and to help you decide which framework is worth a closer look, one starting point is the
<a href="http://todomvc.com/">TodoMVC</a> project. It contains the same simple task management app created with different
Web/JavaScript frameworks.</p>
<p><img src="https://raw.githubusercontent.com/tastejs/todomvc/master/media/logo.png" alt="TodoMVC logo"></p>
<p>It's not a real-world application and ignores lot's of topics that are important for a typical web application. But it
gives you a basic idea of the core principles and approaches of each framework and the differences between the
frameworks. Another nice aspect of TodoMVC is that you can see a basic project setup for the framework of your choice.
The TodoMVC app is neither too trivial (like the typical "hello world") nor is it too complex to understand the code
anytime soon.</p>
<p>The idea to have a small <a href="https://github.com/tastejs/todomvc/blob/master/app-spec.md">set of requirements</a> that are
implemented with different approaches, libraries and frameworks isn't only limited to JavaScript frameworks but would be
useful in other domains like <strong>JavaFX</strong> too.</p>
<p>For this reason I've started a "<strong>TodoMVC JavaFX</strong>" Project. Let's create the same app with different JavaFX frameworks!
You can find the repository of the project on Github:</p>
<p><a class="special_center" href="https://github.com/manuel_mauky/todomvcFX"><a href="https://github.com/manuel_mauky/todomvcFX">https://github.com/manuel_mauky/todomvcFX</a></a></p>
<p>The first idea to start this kind of project came to me after a talk I gave at the Java User Group Görlitz on
<a href="http://www.jug-gr.de/2014/12/03/model-view-star.html">"UI Design Patterns"</a>. In this talk I was comparing several MVC
variants by implementing the same app with each pattern
(<a href="https://github.com/manuel_mauky/juggr_model-view-star">here you can find the code</a>).</p>
<p>Some time later I was creating a Todo example app for
<a href="https://github.com/sialcasa/mvvmFX/tree/develop/examples/todomvc-example">mvvmFX</a> which I later used as starting point
for the <em>TodoMVC JavaFX</em> project.</p>
<p><img src="/files/pics/2016/todomvc_screenshot.png" alt="todo app with JavaFX"></p>
<p>At the moment there are 3 implementations: First there is a
"<a href="https://github.com/manuel_mauky/todomvcFX/tree/master/reference_impl">reference implementation</a>" that only uses pure JavaFX
without any framework. It's meant be a reference of how the application should behave and look like. Developers can take
FXML, CSS or Java files from it to start with their own implementation.</p>
<p>The second example is the <a href="https://github.com/manuel_mauky/todomvcFX/tree/master/examples/mvvmfx">mvvmFX implementation</a> I've
mentioned above. The third example uses <a href="https://github.com/manuel_mauky/FluxFX">FluxFX</a>, an experimental library that I've
created for <a href="https://jaxenter.de/flux-javafx-44532">a talk</a> on how to implement the
<a href="https://static.rainfocus.com/oracle/oow16/sess/1462804682452001cMeJ/ppt/Flux%20with%20JavaFX%20(JavaOne%202016).pdf">Flux architecture with JavaFX</a>.</p>
<p>In the future I will add other examples and I hope that the community will contribute other examples too. At the moment
I'm working on an example using the Haskell-like pure functional language <a href="https://github.com/Frege/frege">Frege</a> and
<a href="https://github.com/Frege/FregeFX">FregeFX</a>.</p>
<p>If you like to add another example with your framework of choice (No matter if you are the author of this framework or
just a user) you are very welcome. Just add an issue in the
<a href="https://github.com/manuel_mauky/todomvcFX/issues">github project</a> so that me and others know you are working on it and so we
can discuss your idea. Or simply send a PullRequest :-)</p>
<p>I hope that the gradle build configuration I'm using at the moment works for your framework/language too. If this is not
the case please tell me - I'm open to suggestions of how to improve the build process and project setup. You can find
more information on how to contribute in the <a href="https://github.com/manuel_mauky/todomvcFX/blob/master/README.md">readme</a> file.
And of cause I'm also happy to hear if you think there is some information missing or the description could be improved.</p>
<p>To make sure that all examples are fulfilling the requirements I've added a set of
<a href="https://github.com/TestFX/TestFX">TestFX</a> tests. These
<a href="https://github.com/manuel_mauky/todomvcFX/blob/master/tests/src/main/java/todomvcfx/AbstractTest.java">UI tests</a> are
simulating a user interacting with the app. If you've never seen a little more complex TestFX test this might be
interesting for you too.</p>
<p>I hope this project will be useful for JavaFX developers out there. Please tell me what you think :-)</p>]]></description>
            <content:encoded><![CDATA[<p>In the JavaScript world there are thousands of libraries and frameworks available for you to use for your next
application. And with plenty of choice there comes the agony of choice. Before you can even think about choosing the
"best" framework you need a set of frameworks that you will take a closer look at in the second step. To get a first
impression of a framework and to help you decide which framework is worth a closer look, one starting point is the
<a href="http://todomvc.com/">TodoMVC</a> project. It contains the same simple task management app created with different
Web/JavaScript frameworks.</p>
<p><img src="https://raw.githubusercontent.com/tastejs/todomvc/master/media/logo.png" alt="TodoMVC logo"></p>
<p>It's not a real-world application and ignores lot's of topics that are important for a typical web application. But it
gives you a basic idea of the core principles and approaches of each framework and the differences between the
frameworks. Another nice aspect of TodoMVC is that you can see a basic project setup for the framework of your choice.
The TodoMVC app is neither too trivial (like the typical "hello world") nor is it too complex to understand the code
anytime soon.</p>
<p>The idea to have a small <a href="https://github.com/tastejs/todomvc/blob/master/app-spec.md">set of requirements</a> that are
implemented with different approaches, libraries and frameworks isn't only limited to JavaScript frameworks but would be
useful in other domains like <strong>JavaFX</strong> too.</p>
<p>For this reason I've started a "<strong>TodoMVC JavaFX</strong>" Project. Let's create the same app with different JavaFX frameworks!
You can find the repository of the project on Github:</p>
<p><a class="special_center" href="https://github.com/manuel_mauky/todomvcFX"><a href="https://github.com/manuel_mauky/todomvcFX">https://github.com/manuel_mauky/todomvcFX</a></a></p>
<p>The first idea to start this kind of project came to me after a talk I gave at the Java User Group Görlitz on
<a href="http://www.jug-gr.de/2014/12/03/model-view-star.html">"UI Design Patterns"</a>. In this talk I was comparing several MVC
variants by implementing the same app with each pattern
(<a href="https://github.com/manuel_mauky/juggr_model-view-star">here you can find the code</a>).</p>
<p>Some time later I was creating a Todo example app for
<a href="https://github.com/sialcasa/mvvmFX/tree/develop/examples/todomvc-example">mvvmFX</a> which I later used as starting point
for the <em>TodoMVC JavaFX</em> project.</p>
<p><img src="/files/pics/2016/todomvc_screenshot.png" alt="todo app with JavaFX"></p>
<p>At the moment there are 3 implementations: First there is a
"<a href="https://github.com/manuel_mauky/todomvcFX/tree/master/reference_impl">reference implementation</a>" that only uses pure JavaFX
without any framework. It's meant be a reference of how the application should behave and look like. Developers can take
FXML, CSS or Java files from it to start with their own implementation.</p>
<p>The second example is the <a href="https://github.com/manuel_mauky/todomvcFX/tree/master/examples/mvvmfx">mvvmFX implementation</a> I've
mentioned above. The third example uses <a href="https://github.com/manuel_mauky/FluxFX">FluxFX</a>, an experimental library that I've
created for <a href="https://jaxenter.de/flux-javafx-44532">a talk</a> on how to implement the
<a href="https://static.rainfocus.com/oracle/oow16/sess/1462804682452001cMeJ/ppt/Flux%20with%20JavaFX%20(JavaOne%202016).pdf">Flux architecture with JavaFX</a>.</p>
<p>In the future I will add other examples and I hope that the community will contribute other examples too. At the moment
I'm working on an example using the Haskell-like pure functional language <a href="https://github.com/Frege/frege">Frege</a> and
<a href="https://github.com/Frege/FregeFX">FregeFX</a>.</p>
<p>If you like to add another example with your framework of choice (No matter if you are the author of this framework or
just a user) you are very welcome. Just add an issue in the
<a href="https://github.com/manuel_mauky/todomvcFX/issues">github project</a> so that me and others know you are working on it and so we
can discuss your idea. Or simply send a PullRequest :-)</p>
<p>I hope that the gradle build configuration I'm using at the moment works for your framework/language too. If this is not
the case please tell me - I'm open to suggestions of how to improve the build process and project setup. You can find
more information on how to contribute in the <a href="https://github.com/manuel_mauky/todomvcFX/blob/master/README.md">readme</a> file.
And of cause I'm also happy to hear if you think there is some information missing or the description could be improved.</p>
<p>To make sure that all examples are fulfilling the requirements I've added a set of
<a href="https://github.com/TestFX/TestFX">TestFX</a> tests. These
<a href="https://github.com/manuel_mauky/todomvcFX/blob/master/tests/src/main/java/todomvcfx/AbstractTest.java">UI tests</a> are
simulating a user interacting with the app. If you've never seen a little more complex TestFX test this might be
interesting for you too.</p>
<p>I hope this project will be useful for JavaFX developers out there. Please tell me what you think :-)</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Reactive Programming and JavaFX - Article in german JavaMagazin]]></title>
            <link>https://www.lestard.eu/2015/reactive_programming_javafx_javamagazin.md/</link>
            <guid>https://www.lestard.eu/2015/reactive_programming_javafx_javamagazin.md/</guid>
            <pubDate>Wed, 03 Jun 2015 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>I've written an article for the <a href="https://jaxenter.de/ausgaben/java-magazin-7-15">german JavaMagazin 7.15</a> with the topic
"Reactive Programming mit JavaFX" (you can find it here online:
<a href="https://jaxenter.de/einfach-und-effizient-reactive-programming-mit-javafx-28498">jaxenter.de</a>).</p>
<p>In the article I'm introducing the reactive programming paradigm from the perspective of a UI developer. Reactive
Programming is technique to escape from the so called "callback hell". Instead of reacting to user events with callbacks
(i.e. side effects on a global state) you define dependencies between time-varing values that will be updated
automatically by the programming environment when changes or events are happening.</p>
<p>With its properties and data-binding API, JavaFX already has a good base for reactive programming.</p>
<p>One point I wanted to highlight in the article is the fact that you don't necessarily need a functional programming
language to do "Reactive Programming". Of course the original work and research in the field of reactive programming was
done with functional languages but it's possible with non-functional languages like Java too (of course the syntax is
far more inconvenient but thats a fact that apparently every java developer has resigned to ;-)). A relatively simple
abstraction over the Observer design pattern is all you need, like it is done in the internal implementation of the
JavaFX properties and databindings.</p>
<p>To make the programming easier there are also libraries available that can help to write JavaFX application in a
reactive programming way. The first library I'm introducing in the article is my own
<a href="https://github.com/manuel_mauky/advanced-bindings">Advanced-Bindings</a> project that can be used for more complex bindings.</p>
<p>After that I'm using the really cool <a href="https://github.com/TomasMikula/ReactFX">ReactFX</a> library for composition of event
streams. At the end I'm presenting the library <a href="https://github.com/ReactiveX/RxJava">RxJava</a> which is obviously the most
famous of the stated libs. In the article I'm showing how you can integrate a RxJava based service in a JavaFX
application.</p>]]></description>
            <content:encoded><![CDATA[<p>I've written an article for the <a href="https://jaxenter.de/ausgaben/java-magazin-7-15">german JavaMagazin 7.15</a> with the topic
"Reactive Programming mit JavaFX" (you can find it here online:
<a href="https://jaxenter.de/einfach-und-effizient-reactive-programming-mit-javafx-28498">jaxenter.de</a>).</p>
<p>In the article I'm introducing the reactive programming paradigm from the perspective of a UI developer. Reactive
Programming is technique to escape from the so called "callback hell". Instead of reacting to user events with callbacks
(i.e. side effects on a global state) you define dependencies between time-varing values that will be updated
automatically by the programming environment when changes or events are happening.</p>
<p>With its properties and data-binding API, JavaFX already has a good base for reactive programming.</p>
<p>One point I wanted to highlight in the article is the fact that you don't necessarily need a functional programming
language to do "Reactive Programming". Of course the original work and research in the field of reactive programming was
done with functional languages but it's possible with non-functional languages like Java too (of course the syntax is
far more inconvenient but thats a fact that apparently every java developer has resigned to ;-)). A relatively simple
abstraction over the Observer design pattern is all you need, like it is done in the internal implementation of the
JavaFX properties and databindings.</p>
<p>To make the programming easier there are also libraries available that can help to write JavaFX application in a
reactive programming way. The first library I'm introducing in the article is my own
<a href="https://github.com/manuel_mauky/advanced-bindings">Advanced-Bindings</a> project that can be used for more complex bindings.</p>
<p>After that I'm using the really cool <a href="https://github.com/TomasMikula/ReactFX">ReactFX</a> library for composition of event
streams. At the end I'm presenting the library <a href="https://github.com/ReactiveX/RxJava">RxJava</a> which is obviously the most
famous of the stated libs. In the article I'm showing how you can integrate a RxJava based service in a JavaFX
application.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Generic repository for Java (Part 2)]]></title>
            <link>https://www.lestard.eu/2015/generic_repository_part2/</link>
            <guid>https://www.lestard.eu/2015/generic_repository_part2/</guid>
            <pubDate>Mon, 25 May 2015 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In the <a href="/2015/generic_repository_part1">first part of this series</a> I was showing an interface for a generic repository
and an in-memory implementation. In this part I will show another implementation with the Java Persistence API (JPA).</p>
<p>An in-memory repository is a good starting point and is handy during the development but at some point you need "real"
persistence. One option in the Java world is the "Java Persistence API" (JPA). This blog post is not a JPA tutorial so I
expect you to have some knowledge about JPA already. Furthermore I have to admit that I'm not a pro when it comes to
JPA. Again: The things described here are working for me but I'm sure there are many improvements possible.</p>
]]></description>
            <content:encoded><![CDATA[<p>In the <a href="/2015/generic_repository_part1">first part of this series</a> I was showing an interface for a generic repository
and an in-memory implementation. In this part I will show another implementation with the Java Persistence API (JPA).</p>
<p>An in-memory repository is a good starting point and is handy during the development but at some point you need "real"
persistence. One option in the Java world is the "Java Persistence API" (JPA). This blog post is not a JPA tutorial so I
expect you to have some knowledge about JPA already. Furthermore I have to admit that I'm not a pro when it comes to
JPA. Again: The things described here are working for me but I'm sure there are many improvements possible.</p>
<!--more-->
<p>The first step is to include the needed libraries for JPA and setup a <code class="language-text">persistence.xml</code> (which I won't describe here).
After that we can start with the interesting stuff. Let's start with the <code class="language-text">Identity</code> class. We have a field <code class="language-text">id</code> that we
have to tell JPA about. This is done with the <code class="language-text">@Id</code> annotation. As we are generating the value of the ID on our own in
the constructor we don't need the <code class="language-text">@GeneratedValue</code> annotation. Additionally we need the <code class="language-text">@MappedSuperclass</code> annotation
on the <code class="language-text">Identity</code> class. Otherwise JPA wouldn't find the id field in the derived entity classes.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javax<span class="token punctuation">.</span>persistence<span class="token punctuation">.</span></span><span class="token class-name">Id</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">javax<span class="token punctuation">.</span>persistence<span class="token punctuation">.</span></span><span class="token class-name">MappedSuperclass</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Objects</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">UUID</span></span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@MappedSuperclass</span>
<span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Identity</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Id</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">String</span> id<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">Identity</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>id <span class="token operator">=</span> <span class="token constant">UUID</span><span class="token punctuation">.</span><span class="token function">randomUUID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Our Person class looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javax<span class="token punctuation">.</span>persistence<span class="token punctuation">.</span></span><span class="token class-name">Entity</span></span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Entity</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Person</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">String</span> name<span class="token punctuation">;</span>

    <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>There are two changes in the Person class: We have added the <code class="language-text">@Entity</code> annotation to tell JPA that this class can be
persisted. The second change is that we need a no-arg constructor. Otherwise JPA would throw an exception. However, it
is possible to make the constructor package scoped.</p>
<p>Now lets look at the generic repository. Again we like to have a generic implementation that works for all entity
classes. Similar to the in-memory implementation we create a generic class <code class="language-text">JpaRepository</code> that overwrites the three
methods <code class="language-text">Set&lt;T> get()</code>, <code class="language-text">void persist(T entity)</code> and <code class="language-text">void remove(T entity)</code>. Here is a possible implementation:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JpaRepository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">EntityManagerFactory</span> emf<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> type<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">JpaRepository</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> type<span class="token punctuation">,</span> <span class="token class-name">String</span> persistenceUnitName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>type <span class="token operator">=</span> type<span class="token punctuation">;</span>
        emf <span class="token operator">=</span> <span class="token class-name">Persistence</span><span class="token punctuation">.</span><span class="token function">createEntityManagerFactory</span><span class="token punctuation">(</span>persistenceUnitName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>


    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">EntityManager</span> entityManager <span class="token operator">=</span> emf<span class="token punctuation">.</span><span class="token function">createEntityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">CriteriaBuilder</span> criteriaBuilder <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">getCriteriaBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">CriteriaQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> criteria <span class="token operator">=</span> criteriaBuilder<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">Root</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> root <span class="token operator">=</span> criteria<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>
        criteria<span class="token punctuation">.</span><span class="token function">select</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">TypedQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> query <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>criteria<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> resultList <span class="token operator">=</span> query<span class="token punctuation">.</span><span class="token function">getResultList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        entityManager<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>resultList<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">EntityManager</span> entityManager <span class="token operator">=</span> emf<span class="token punctuation">.</span><span class="token function">createEntityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        entityManager<span class="token punctuation">.</span><span class="token function">merge</span><span class="token punctuation">(</span>entity<span class="token punctuation">)</span><span class="token punctuation">;</span>

        entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        entityManager<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">EntityManager</span> entityManager <span class="token operator">=</span> emf<span class="token punctuation">.</span><span class="token function">createEntityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">T</span> managedEntity <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span>type<span class="token punctuation">,</span> entity<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>managedEntity <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>managedEntity<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        entityManager<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>A you can see it is no problem to provide generic implementations for the three methods. Other than the in-memory
version this repository needs some constructor arguments. The first one is the generic class type of the entity. This is
needed for queries. The second argument is the persistence unit name that is defined in the persistence.xml.</p>
<p>Please note: I'm using explicit transaction handling here (<code class="language-text">entityManager.getTransaction().begin()</code>). The reason is that
I'm not using an EJB container anymore. If you are using EJB you can remove the transaction handling statements.</p>
<p>The concrete implementation for the Person entity looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PersonJpaRepository</span> <span class="token keyword">extends</span> <span class="token class-name">JpaRepository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Person</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token class-name">PersonJpaRepository</span><span class="token punctuation">(</span><span class="token class-name">String</span> persistenceUnitName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span><span class="token class-name">Person</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> persistenceUnitName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This time we need to provide a constructor.</p>
<h2>Improving the JPA version</h2>
<p>At this point you might already noticed that the JPA implementation isn't realy smart. The reason is how the default
methods of the <code class="language-text">Repository</code> interface are implemented.</p>
<p>For example the <code class="language-text">void persist(Collection&lt;T> entities)</code> method. Instead of writing all entities to the database in one
transaction it will create and commit a new transaction for each entity. Another example is the
<code class="language-text">Set&lt;T> get(Predicate&lt;T> predicate)</code> method. It will load <em>all</em> entities from the database and then filter them in the
memory. This kind of works for small databases but will blow up with slightly bigger ones.</p>
<h3>Refactoring</h3>
<p>But before we implement specific versions for some of the interface methods we will do some refactoring. If you look at
the code you can see some code duplication that can be removed.</p>
<p>Lets start with this method:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">R</span><span class="token punctuation">></span></span> <span class="token class-name">R</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">,</span> <span class="token class-name">R</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token keyword">final</span> <span class="token class-name">EntityManager</span> entityManager <span class="token operator">=</span> emf<span class="token punctuation">.</span><span class="token function">createEntityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token keyword">try</span> <span class="token punctuation">{</span>
       <span class="token keyword">return</span> function<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
       entityManager<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>It takes a function as argument that takes the entityManager as argument and returns some generic result. A caller now
doesn't need to bother the creation and closing of the entityManager. With this method we can implement the <code class="language-text">get</code> method
like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token annotation punctuation">@Override</span>
<span class="token keyword">public</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> resultList <span class="token operator">=</span> <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">CriteriaBuilder</span> criteriaBuilder <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">getCriteriaBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">CriteriaQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> criteria <span class="token operator">=</span> criteriaBuilder<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">Root</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> root <span class="token operator">=</span> criteria<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>
        criteria<span class="token punctuation">.</span><span class="token function">select</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">TypedQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> query <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>criteria<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> query<span class="token punctuation">.</span><span class="token function">getResultList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>resultList<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>For the <code class="language-text">persist</code> and <code class="language-text">remove</code> methods this isn't sufficient because we need the transaction handling. Therefore we
create this method:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">R</span><span class="token punctuation">></span></span> <span class="token class-name">R</span> <span class="token function">runInTransaction</span><span class="token punctuation">(</span><span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">,</span> <span class="token class-name">R</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
        entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">final</span> <span class="token class-name">R</span> result <span class="token operator">=</span> function<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>

        entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">return</span> result<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>It uses the existing <code class="language-text">run</code> method and adds the transaction handling. For use cases where no result is needed we can
provide two variants of the <code class="language-text">run</code>/<code class="language-text">runInTransaction</code> methods that take <code class="language-text">Consumer&lt;EntityManager></code> as argument. Now the
whole repository looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JpaRepository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">EntityManagerFactory</span> emf<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> type<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">JpaRepository</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> type<span class="token punctuation">,</span> <span class="token class-name">String</span> persistenceUnitName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>type <span class="token operator">=</span> type<span class="token punctuation">;</span>
        emf <span class="token operator">=</span> <span class="token class-name">Persistence</span><span class="token punctuation">.</span><span class="token function">createEntityManagerFactory</span><span class="token punctuation">(</span>persistenceUnitName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>


    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> resultList <span class="token operator">=</span> <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">final</span> <span class="token class-name">CriteriaBuilder</span> criteriaBuilder <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">getCriteriaBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">final</span> <span class="token class-name">CriteriaQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> criteria <span class="token operator">=</span> criteriaBuilder<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">final</span> <span class="token class-name">Root</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> root <span class="token operator">=</span> criteria<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>
            criteria<span class="token punctuation">.</span><span class="token function">select</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">final</span> <span class="token class-name">TypedQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> query <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>criteria<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> query<span class="token punctuation">.</span><span class="token function">getResultList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>resultList<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">merge</span><span class="token punctuation">(</span>entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">final</span> <span class="token class-name">T</span> managedEntity <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span>type<span class="token punctuation">,</span> entity<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>managedEntity <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                entityManager<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>managedEntity<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">R</span><span class="token punctuation">></span></span> <span class="token class-name">R</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">,</span> <span class="token class-name">R</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">EntityManager</span> entityManager <span class="token operator">=</span> emf<span class="token punctuation">.</span><span class="token function">createEntityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> function<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">Consumer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            function<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">R</span><span class="token punctuation">></span></span> <span class="token class-name">R</span> <span class="token function">runInTransaction</span><span class="token punctuation">(</span><span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">,</span> <span class="token class-name">R</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">final</span> <span class="token class-name">R</span> result <span class="token operator">=</span> function<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>

            entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">return</span> result<span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">runInTransaction</span><span class="token punctuation">(</span><span class="token class-name">Consumer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            function<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now lets start to implement the other methods of the <code class="language-text">Repository</code> interface. I won't describe all methods in detail
because everyone who can read Java-8-Stream-API based code will have no problem understanding the code (I hope so).</p>
<p>For example this method:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token annotation punctuation">@Override</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
        entities<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>entityManager<span class="token operator">::</span><span class="token function">merge</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The difference to the default version is that now all <code class="language-text">merge</code> operations are done in one single transaction instead of
using a new transaction for each entity.</p>
<p>Another interesting one is the <code class="language-text">void remove(Collection&lt;T> entities)</code> method:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token annotation punctuation">@Override</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
        entities
                <span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token class-name">Identity</span><span class="token operator">::</span><span class="token function">getId</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>id <span class="token operator">-></span> entityManager<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span>type<span class="token punctuation">,</span> id<span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token class-name">Objects</span><span class="token operator">::</span><span class="token function">nonNull</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>entityManager<span class="token operator">::</span><span class="token function">remove</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The <code class="language-text">remove</code> method of the <code class="language-text">EntityManager</code> can only handle so called <em>managed</em> entities. Simply speaking, an entity
instance is <em>managed</em> when it is freshly loaded from the EntityManager. Therefore we have to reload all entities from
the given collection before we can remove them. This is done in a stream. At first we map the Stream of entities to a
stream of IDs of each entity. Then we map the stream of IDs to a stream of managed entities by using the <code class="language-text">find</code> method.
If, for some reason, an entity of the argument collection was already removed, the find method would return <code class="language-text">null</code>. This
means the Stream of managed entities may contain <code class="language-text">null</code> entries that should be filtered out. The last step is to call
<code class="language-text">EntityManager.remove</code> for all managed entities in the stream.</p>
<p>The whole code for the <code class="language-text">JpaRepository</code> now looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JpaRepository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">EntityManagerFactory</span> emf<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> type<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">JpaRepository</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> type<span class="token punctuation">,</span> <span class="token class-name">String</span> persistenceUnitName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>type <span class="token operator">=</span> type<span class="token punctuation">;</span>
        emf <span class="token operator">=</span> <span class="token class-name">Persistence</span><span class="token punctuation">.</span><span class="token function">createEntityManagerFactory</span><span class="token punctuation">(</span>persistenceUnitName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>


    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> resultList <span class="token operator">=</span> <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">final</span> <span class="token class-name">CriteriaBuilder</span> criteriaBuilder <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">getCriteriaBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">final</span> <span class="token class-name">CriteriaQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> criteria <span class="token operator">=</span> criteriaBuilder<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">final</span> <span class="token class-name">Root</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> root <span class="token operator">=</span> criteria<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>
            criteria<span class="token punctuation">.</span><span class="token function">select</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">final</span> <span class="token class-name">TypedQuery</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> query <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">createQuery</span><span class="token punctuation">(</span>criteria<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> query<span class="token punctuation">.</span><span class="token function">getResultList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>resultList<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>


    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Optional</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">Optional</span><span class="token punctuation">.</span><span class="token function">ofNullable</span><span class="token punctuation">(</span><span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> entityManager<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span>type<span class="token punctuation">,</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>


    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">merge</span><span class="token punctuation">(</span>entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            entities<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>entityManager<span class="token operator">::</span><span class="token function">merge</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">remove</span><span class="token punctuation">(</span>entity<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">final</span> <span class="token class-name">T</span> managedEntity <span class="token operator">=</span> entityManager<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span>type<span class="token punctuation">,</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>managedEntity <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                entityManager<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>managedEntity<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            entities
                    <span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token class-name">Identity</span><span class="token operator">::</span><span class="token function">getId</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>id <span class="token operator">-></span> entityManager<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span>type<span class="token punctuation">,</span> id<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token class-name">Objects</span><span class="token operator">::</span><span class="token function">nonNull</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>entityManager<span class="token operator">::</span><span class="token function">remove</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Predicate</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> predicate<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">remove</span><span class="token punctuation">(</span><span class="token function">get</span><span class="token punctuation">(</span>predicate<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">R</span><span class="token punctuation">></span></span> <span class="token class-name">R</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">,</span> <span class="token class-name">R</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">EntityManager</span> entityManager <span class="token operator">=</span> emf<span class="token punctuation">.</span><span class="token function">createEntityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> function<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">Consumer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            function<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">R</span><span class="token punctuation">></span></span> <span class="token class-name">R</span> <span class="token function">runInTransaction</span><span class="token punctuation">(</span><span class="token class-name">Function</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">,</span> <span class="token class-name">R</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">run</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">final</span> <span class="token class-name">R</span> result <span class="token operator">=</span> function<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>

            entityManager<span class="token punctuation">.</span><span class="token function">getTransaction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">return</span> result<span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">runInTransaction</span><span class="token punctuation">(</span><span class="token class-name">Consumer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">EntityManager</span><span class="token punctuation">></span></span> function<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">runInTransaction</span><span class="token punctuation">(</span>entityManager <span class="token operator">-></span> <span class="token punctuation">{</span>
            function<span class="token punctuation">.</span><span class="token function">accept</span><span class="token punctuation">(</span>entityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Maybe you have already noticed that I have no implementation for the method <code class="language-text">Set&lt;T> get(Predicate&lt;T> predicate)</code>. I
haven't found a clean way of doing this with JPA in a generic way. As far as I know there is no <em>functional-style</em> of
filtering and processing of data with JPA. Instead JPA is heavily based on the relational database model and SQL-like
queries. Maybe someone has a good idea for an implementation of the predicate based method. In general this JPA
implementation may still be not optimal for some situations where big data bases are used. In such cases you will
typically define special queries for each entity type. But the given generic repository may still be a good starting
point for some basic CRUD functionality.</p>
<p>All code can be found (and freely used) at github:
<a href="https://github.com/manuel_mauky/blogpost_generic_repository">https://github.com/manuel_mauky/blogpost_generic_repository</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Generic repository for Java (Part 1)]]></title>
            <link>https://www.lestard.eu/2015/generic_repository_part1/</link>
            <guid>https://www.lestard.eu/2015/generic_repository_part1/</guid>
            <pubDate>Sun, 24 May 2015 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Persisting data is part of most apps and there are several ways of doing persistence. In this blog post I'm sharing some
of my techniques and personal oppinions. Maybe it doesn't fit for everybody but it works for me and maybe this is
helpful for some people.</p>
<p>When it comes to persistence my favorite is <a href="http://martinfowler.com/eaaDev/EventSourcing.html">EventSourcing</a>: Instead
of persisting the current state of your data, only events of changes to your data are persisted. The current state can
then be (re-)calculated from the events. In my oppinion this is the most natural and elegant way of handling persistence
but, to be honest, it's not the easiest to implement, especially in Java.</p>
<p>But this is another story. Today I want to further investigate persistence for use cases where EventSourcing is not an
option and/or classical state-based persistence is needed. In such cases I'm typically using the <strong>repository pattern</strong>.
The key of this design pattern is to define a common interface for persistence functionality that is independent from
the underlaying persistence technique. For each specific persistence technique (for example a database, the filesystem
or a cloud storage) an implementation of the interface can be provided. This way you can exchange the persistence
technique without touching the rest of your application. Additionally this improves the testability because you can
provide a mock implementation of the repository interface for unit tests.</p>
]]></description>
            <content:encoded><![CDATA[<p>Persisting data is part of most apps and there are several ways of doing persistence. In this blog post I'm sharing some
of my techniques and personal oppinions. Maybe it doesn't fit for everybody but it works for me and maybe this is
helpful for some people.</p>
<p>When it comes to persistence my favorite is <a href="http://martinfowler.com/eaaDev/EventSourcing.html">EventSourcing</a>: Instead
of persisting the current state of your data, only events of changes to your data are persisted. The current state can
then be (re-)calculated from the events. In my oppinion this is the most natural and elegant way of handling persistence
but, to be honest, it's not the easiest to implement, especially in Java.</p>
<p>But this is another story. Today I want to further investigate persistence for use cases where EventSourcing is not an
option and/or classical state-based persistence is needed. In such cases I'm typically using the <strong>repository pattern</strong>.
The key of this design pattern is to define a common interface for persistence functionality that is independent from
the underlaying persistence technique. For each specific persistence technique (for example a database, the filesystem
or a cloud storage) an implementation of the interface can be provided. This way you can exchange the persistence
technique without touching the rest of your application. Additionally this improves the testability because you can
provide a mock implementation of the repository interface for unit tests.</p>
<!--more-->
<h2>Entities</h2>
<p>The first part is to define "Entities". An "Entity" is an object-oriented abstraction of a part of the reality. For
example when we create a contact management app a possible Entity would be "Person".</p>
<p>An entity has an identity: The state of an entity can change over time but it is still the "same" entity. For example
the name of a person may change but it is still the same person. Another important point: Two persons may have the same
name (and other properties) but they are still different persons. This means the distinction of instances of entities
isn't done based on their properties. Instead we need an identifier. I'm typically using a
<a href="https://en.wikipedia.org/wiki/Universally_unique_identifier">UUID</a>.</p>
<p>A base class for entities can look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Objects</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">UUID</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Identity</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">String</span> id<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">Identity</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>id <span class="token operator">=</span> <span class="token constant">UUID</span><span class="token punctuation">.</span><span class="token function">randomUUID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> id<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">equals</span><span class="token punctuation">(</span><span class="token class-name">Object</span> o<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span> <span class="token operator">==</span> o<span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>o <span class="token operator">==</span> <span class="token keyword">null</span> <span class="token operator">||</span> <span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> o<span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
        <span class="token class-name">Identity</span> identity <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Identity</span><span class="token punctuation">)</span> o<span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token class-name">Objects</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>id<span class="token punctuation">,</span> identity<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">hashCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">Objects</span><span class="token punctuation">.</span><span class="token function">hash</span><span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getSimpleName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">"[id="</span> <span class="token operator">+</span> id<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">"...]"</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>As you can see the <code class="language-text">equals</code> and <code class="language-text">hashcode</code> methods are only working with the <code class="language-text">id</code> property. The <code class="language-text">id</code> is marked as
<code class="language-text">final</code> and therefore can't be changed after it is assigned in the constructor.</p>
<p>A concrete entity could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Person</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> name<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setName</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<h2>Interface for a Repository</h2>
<p>Now we can define an interface for our Repository. For the person it could look like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">PersonRepository</span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * @return the person with the given id.
     */</span>
    <span class="token class-name">Optional</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Person</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * @return a collection of all persons.
     */</span>
    <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Person</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * Persist the given person instance.
     */</span>
    <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">Person</span> person<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * Remove the given person instance.
     */</span>
    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Person</span> person<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The cool thing is: As we have the <code class="language-text">Identity</code> base class we can define a generic interface for the repository
functionality:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token class-name">Optional</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This way we can have repositories for many entity types that share a common interface for persistence. The given example
only defines some base functionality but we could extend the interface a little bit. For example we may want to
persist/remove many entities at once. Or we like to make more specific queries to get entity instances that match a
given condition.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token class-name">Optional</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * return all entities that match the given predicate.
     */</span>
    <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">Predicate</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> predicate<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> entities<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> entities<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * remove the entity with the given id.
     */</span>
    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * remove all entities that match the given predicate.
     */</span>
    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Predicate</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> predicate<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>These additional methods can be intersting for many use cases. The downside is that the implementor of a specific
Repository has a lot of methods to implement. But this can be fixed with a
<a href="https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html">default methods</a> feature of Java 8 like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">default</span> <span class="token class-name">Optional</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>entity <span class="token operator">-></span> entity<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">findAny</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">default</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">Predicate</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> predicate<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>predicate<span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">collect</span><span class="token punctuation">(</span><span class="token class-name">Collectors</span><span class="token punctuation">.</span><span class="token function">toSet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">default</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">asList</span><span class="token punctuation">(</span>entities<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">default</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        entities<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token operator">::</span><span class="token function">persist</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">default</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">asList</span><span class="token punctuation">(</span>entities<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">default</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        entities<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token operator">::</span><span class="token function">remove</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">default</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">String</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">remove</span><span class="token punctuation">(</span>entity <span class="token operator">-></span> entity<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// predicate to match the id</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">default</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">Predicate</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> predicate<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">get</span><span class="token punctuation">(</span>predicate<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token operator">::</span><span class="token function">remove</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now there are only three methods that needs to be implemented: <code class="language-text">Set&lt;T> get()</code>, <code class="language-text">void persist(T entity)</code> and
<code class="language-text">void remove(T entity)</code>. For all other methods there are default implementations that are using these three methods
directly or indirectly. An interesting detail is that we can use the <code class="language-text">String getId()</code> method of the <code class="language-text">Identity</code> class
because we have the type constraint for <code class="language-text">T</code> to be a subclass of <code class="language-text">Identity</code>.</p>
<p>Of cause the default implementations may not be optimal when it comes to performance. But every implementor can choose
to overwrite the default implementations with a more advanced implementation that makes better use of the underlaying
persistence technique.</p>
<h2>In-Memory Repository</h2>
<p>Most of the time when I'm developing apps I'm starting with the frontend. In the frontend I only have a static
dependency (i.e. an import) to the repository interfaces. The specific implementation for the interfaces are provided by
a dependency-injection library. During the development I'm typically using an in-memory implementation for the
repositories because it's easy and fast (but loses the persisted data on every application start of cause).</p>
<p>Given the interface from above we can even provide a generic in-memory implementation for the repository:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">InMemoryRepository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span> <span class="token keyword">extends</span> <span class="token class-name">Identity</span><span class="token punctuation">></span></span> <span class="token keyword">implements</span> <span class="token class-name">Repository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> entities <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">unmodifiableSet</span><span class="token punctuation">(</span>entities<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">persist</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        entities<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token class-name">T</span> entity<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        entities<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>A concrete implementation for the <code class="language-text">Person</code> entity looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PersonInMemoryRepository</span> <span class="token keyword">extends</span> <span class="token class-name">InMemoryRepository</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Person</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Thats all. No code is needed at all. Of cause an in-memory repository isn't sufficient for a real application. In the
<a href="/2015/generic_repository_part2">second part</a> of this series I will show an implementation based on the Java Persistence
API that can be used to store the data in a relational database.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Released mvvmFX 1.1.0]]></title>
            <link>https://www.lestard.eu/2015/mvvmfx_1_1/</link>
            <guid>https://www.lestard.eu/2015/mvvmfx_1_1/</guid>
            <pubDate>Sun, 19 Apr 2015 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Yesterday we released the <a href="https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0">new version 1.1.0</a> of
<a href="https://github.com/sialcasa/mvvmFX">mvvmFX</a>. This time we have lots of new features that can make the development of
JavaFX applications easier.</p>
<p>Some of the new features:</p>
<h3>Commands</h3>
<p>The most interesting new feature are the <strong>Commands</strong>. With them you can now encapsulate actions in the ViewModel and
provide them to the View. Each Command has boolean properties showing if it is <code class="language-text">running</code> at the moment and if it
<code class="language-text">isExecutable</code>. The latter can for example be used in the View to bind the visibility of a button. With
<code class="language-text">CompositeCommand</code>s you can compose many commands so that all sub-commands are executed when the composite command is
triggered. See the <a href="https://github.com/sialcasa/mvvmFX/wiki/Commands">wiki page</a> for a detailed explanation.</p>
<h3>ModelWrapper</h3>
<p>The second big feature is the <strong>ModelWrapper</strong>. This class can simplify the mapping between the Model and the ViewModel
for CRUD like applications. Instead of duplicating the fields of a model class in the ViewModel you can now use the
<code class="language-text">ModelWrapper</code> that support <em>reloading</em> (copy values from Model to ViewModel), <em>resetting</em> (set ViewModel to default
values) and <em>committing</em> (copy values from ViewModel to Model). In the
<a href="https://github.com/sialcasa/mvvmFX/wiki/ModelWrapper">wiki</a> you can see a detailed example.</p>
<h3>Using mvvmFX views as items of ListView</h3>
<p>You can now use the
<a href="https://sialcasa.github.io/mvvmFX/javadoc/1.1.0/mvvmfx/de/saxsys/mvvmfx/utils/viewlist/CachedViewModelCellFactory.html">CachedViewModelCellFactory</a>
as CellFactory for the javaFX <code class="language-text">ListView</code> component. This way you can use mvvmFX Views as items of the ListView. See a
more detailed description in the wiki:
<a href="https://github.com/sialcasa/mvvmFX/wiki/ListView-containing-mvvmFX-views">https://github.com/sialcasa/mvvmFX/wiki/ListView-containing-mvvmFX-views</a>.</p>
<h3>Inject ResourceBundle in the ViewModel</h3>
<p>Until now it was only possible to inject the ResourceBundle in the View. But for some use cases it would be useful to
have the ResourceBundle available in the ViewModel too. With the new version this is possible via the annotation
<code class="language-text">@InjectResourceBundle</code>. In addition we have added a live cycle method for the ViewModel like it was possible in the
View before. We use the same naming conventions for this: If the ViewModel has a method with the signature
<code class="language-text">public void initialize()</code> it will be called by the framework after the injection of the ResourceBundle is done.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token class-name">MyViewModel</span> <span class="token keyword">implements</span> <span class="token class-name">ViewModel</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@InjectResourceBundle</span>
    <span class="token class-name">ResourceBundle</span> resourceBundle<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">StringProperty</span> title <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleStringProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">initialize</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        title<span class="token punctuation">.</span><span class="token function">setValue</span><span class="token punctuation">(</span>resourceBundle<span class="token punctuation">.</span><span class="token function">getString</span><span class="token punctuation">(</span><span class="token string">"app.title"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<h3>Utility modules</h3>
<p>Additionally we have introduced two more Maven modules:</p>
<p><strong>mvvmfx-utils</strong> contains utilities that are not directly related to MVVM but that are more generally useful for JavaFX
development. We moved the <code class="language-text">SizeBindingsBuilder</code> and the <code class="language-text">ListenerManager</code> from the core module to this new module to
improve the cohesion of the core module.</p>
<p><strong>mvvmfx-testing-utils</strong> contains utils that we used for testing purposes internally for some time. Now these utils are
available for the public. The most interesting is the <code class="language-text">GCVerifier</code> that we are using for testing situations where
Garbage Collection is important.</p>
<p>See the whole list of changes at github:
<a href="https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0">https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0</a></p>]]></description>
            <content:encoded><![CDATA[<p>Yesterday we released the <a href="https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0">new version 1.1.0</a> of
<a href="https://github.com/sialcasa/mvvmFX">mvvmFX</a>. This time we have lots of new features that can make the development of
JavaFX applications easier.</p>
<p>Some of the new features:</p>
<h3>Commands</h3>
<p>The most interesting new feature are the <strong>Commands</strong>. With them you can now encapsulate actions in the ViewModel and
provide them to the View. Each Command has boolean properties showing if it is <code class="language-text">running</code> at the moment and if it
<code class="language-text">isExecutable</code>. The latter can for example be used in the View to bind the visibility of a button. With
<code class="language-text">CompositeCommand</code>s you can compose many commands so that all sub-commands are executed when the composite command is
triggered. See the <a href="https://github.com/sialcasa/mvvmFX/wiki/Commands">wiki page</a> for a detailed explanation.</p>
<h3>ModelWrapper</h3>
<p>The second big feature is the <strong>ModelWrapper</strong>. This class can simplify the mapping between the Model and the ViewModel
for CRUD like applications. Instead of duplicating the fields of a model class in the ViewModel you can now use the
<code class="language-text">ModelWrapper</code> that support <em>reloading</em> (copy values from Model to ViewModel), <em>resetting</em> (set ViewModel to default
values) and <em>committing</em> (copy values from ViewModel to Model). In the
<a href="https://github.com/sialcasa/mvvmFX/wiki/ModelWrapper">wiki</a> you can see a detailed example.</p>
<h3>Using mvvmFX views as items of ListView</h3>
<p>You can now use the
<a href="https://sialcasa.github.io/mvvmFX/javadoc/1.1.0/mvvmfx/de/saxsys/mvvmfx/utils/viewlist/CachedViewModelCellFactory.html">CachedViewModelCellFactory</a>
as CellFactory for the javaFX <code class="language-text">ListView</code> component. This way you can use mvvmFX Views as items of the ListView. See a
more detailed description in the wiki:
<a href="https://github.com/sialcasa/mvvmFX/wiki/ListView-containing-mvvmFX-views">https://github.com/sialcasa/mvvmFX/wiki/ListView-containing-mvvmFX-views</a>.</p>
<h3>Inject ResourceBundle in the ViewModel</h3>
<p>Until now it was only possible to inject the ResourceBundle in the View. But for some use cases it would be useful to
have the ResourceBundle available in the ViewModel too. With the new version this is possible via the annotation
<code class="language-text">@InjectResourceBundle</code>. In addition we have added a live cycle method for the ViewModel like it was possible in the
View before. We use the same naming conventions for this: If the ViewModel has a method with the signature
<code class="language-text">public void initialize()</code> it will be called by the framework after the injection of the ResourceBundle is done.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token class-name">MyViewModel</span> <span class="token keyword">implements</span> <span class="token class-name">ViewModel</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@InjectResourceBundle</span>
    <span class="token class-name">ResourceBundle</span> resourceBundle<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">StringProperty</span> title <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleStringProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">initialize</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        title<span class="token punctuation">.</span><span class="token function">setValue</span><span class="token punctuation">(</span>resourceBundle<span class="token punctuation">.</span><span class="token function">getString</span><span class="token punctuation">(</span><span class="token string">"app.title"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<h3>Utility modules</h3>
<p>Additionally we have introduced two more Maven modules:</p>
<p><strong>mvvmfx-utils</strong> contains utilities that are not directly related to MVVM but that are more generally useful for JavaFX
development. We moved the <code class="language-text">SizeBindingsBuilder</code> and the <code class="language-text">ListenerManager</code> from the core module to this new module to
improve the cohesion of the core module.</p>
<p><strong>mvvmfx-testing-utils</strong> contains utils that we used for testing purposes internally for some time. Now these utils are
available for the public. The most interesting is the <code class="language-text">GCVerifier</code> that we are using for testing situations where
Garbage Collection is important.</p>
<p>See the whole list of changes at github:
<a href="https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0">https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Exception in ChangeListener]]></title>
            <link>https://www.lestard.eu/2015/exception_in_listener/</link>
            <guid>https://www.lestard.eu/2015/exception_in_listener/</guid>
            <pubDate>Mon, 13 Apr 2015 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Today I had an interesting issue with JavaFX ChangeListeners and Exceptions. I was writing a unit test to reproduce a
simple <a href="https://github.com/sialcasa/mvvmFX/issues/204">bug in mvvmFX</a>. The issue was a NullPointerException that was
thrown under some specific conditions. No big deal. I had written the test case that reproduces the exception in no time
but something was still wrong. The exception was visible in the console window of the IDE but the test was still green.</p>
<p><img src="/files/pics/2015/exception_listener.png" alt="green test and still an exception"></p>
]]></description>
            <content:encoded><![CDATA[<p>Today I had an interesting issue with JavaFX ChangeListeners and Exceptions. I was writing a unit test to reproduce a
simple <a href="https://github.com/sialcasa/mvvmFX/issues/204">bug in mvvmFX</a>. The issue was a NullPointerException that was
thrown under some specific conditions. No big deal. I had written the test case that reproduces the exception in no time
but something was still wrong. The exception was visible in the console window of the IDE but the test was still green.</p>
<p><img src="/files/pics/2015/exception_listener.png" alt="green test and still an exception"></p>
<!--more-->
<p>The problem was that the exception was thrown inside of a JavaFX
<a href="https://docs.oracle.com/javase/8/javafx/api/javafx/beans/value/ChangeListener.html">ChangeListener</a>. The question ist:
Why is the exception visible in the console window but doesn't crash the current running Thread?</p>
<p>To find an answer I was digging in the depth of the <a href="http://hg.openjdk.java.net/openjfx/8u40/rt/">JavaFX source code</a> (I
love open source).</p>
<p>And there it is: In
<a href="http://hg.openjdk.java.net/openjfx/8u40/rt/file/eb264cdc5828/modules/base/src/main/java/javafx/beans/property/StringPropertyBase.java">StringPropertyBase.java</a>
an <code class="language-text">ExpressionHelper</code> is handling
<a href="http://hg.openjdk.java.net/openjfx/8u40/rt/file/eb264cdc5828/modules/base/src/main/java/javafx/beans/property/StringPropertyBase.java#l84">added Listeners</a>.
Every
<a href="http://hg.openjdk.java.net/openjfx/8u40/rt/file/eb264cdc5828/modules/base/src/main/java/com/sun/javafx/binding/ExpressionHelper.java">ExpressionHelper</a>
has a <code class="language-text">fireValueChangedEvent</code> method that is responsible for calling the registered listener. And there you find this
<a href="http://hg.openjdk.java.net/openjfx/8u40/rt/file/eb264cdc5828/modules/base/src/main/java/com/sun/javafx/binding/ExpressionHelper.java#l181">interesting code</a>:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">try</span> <span class="token punctuation">{</span>
    listener<span class="token punctuation">.</span><span class="token function">changed</span><span class="token punctuation">(</span>observable<span class="token punctuation">,</span> oldValue<span class="token punctuation">,</span> currentValue<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token function">currentThread</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getUncaughtExceptionHandler</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">uncaughtException</span><span class="token punctuation">(</span><span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token function">currentThread</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The line in the catch clause is interesting. In Java you can define an
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.UncaughtExceptionHandler.html">"UncaughtExceptionHandler"</a>
that is responsible for handling exceptions that aren't caught by the application itself. This can be useful when you
don't want to crash the whole JVM when an exception wasn't properly handled. For example think of a servlet container
that shouldn't be terminated when one of the servlets throws an exception.</p>
<p>But in our use case we don't want to hold back the exception. We want to see our test case fail if there is an exception
thrown. So what is the solution? Look at this code:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token keyword">static</span> <span class="token import static"><span class="token namespace">org<span class="token punctuation">.</span>assertj<span class="token punctuation">.</span>core<span class="token punctuation">.</span>api<span class="token punctuation">.</span></span><span class="token class-name">Assertions</span><span class="token punctuation">.</span><span class="token static">fail</span></span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Test</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
    <span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token function">currentThread</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setUncaughtExceptionHandler</span><span class="token punctuation">(</span><span class="token punctuation">(</span>thread<span class="token punctuation">,</span> exception<span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"Exception was thrown"</span><span class="token punctuation">,</span> exception<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">Example</span> example <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Example</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    example<span class="token punctuation">.</span>value<span class="token punctuation">.</span><span class="token function">setValue</span><span class="token punctuation">(</span><span class="token string">"test"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now the test fails as expected. We define our own "UncaughtExceptionHandler" with a lambda expression. Inside of the
lambda the
<a href="https://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/Assertions.html#fail-java.lang.String-java.lang.Throwable-">"fail" method</a>
of <a href="https://joel-costigliola.github.io/assertj/index.html">AssertJ</a> is called which leads to a test failure.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[JavaFX: Data Model for TreeTable]]></title>
            <link>https://www.lestard.eu/2015/treetable_datamodel/</link>
            <guid>https://www.lestard.eu/2015/treetable_datamodel/</guid>
            <pubDate>Fri, 27 Feb 2015 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>When you use a <a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ListView.html">ListView</a> or a
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html">TableView</a> in JavaFX you can easily
separate the definition of the List/Table and the data that is displayed by the component.</p>
<p>For example when you use a TableView you could create an <code class="language-text">ObservableList</code> containing your data objects and set
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableColumn.html#cellFactoryProperty--">CellValueFactories</a>
to define what value will be displayed by a specific column. Look at the
<a href="http://docs.oracle.com/javafx/2/ui_controls/table-view.htm">code from the Oracle docs</a> for a simple example.</p>
<p>The key point is: When you add/remove an instance of your data in the observable list (your data model) the table will
update itself accordingly. You don't need to manually add a new row to the table or anything like that. This is a realy
cool way to separate the visualization of the table from the data to be displayed.</p>
]]></description>
            <content:encoded><![CDATA[<p>When you use a <a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ListView.html">ListView</a> or a
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html">TableView</a> in JavaFX you can easily
separate the definition of the List/Table and the data that is displayed by the component.</p>
<p>For example when you use a TableView you could create an <code class="language-text">ObservableList</code> containing your data objects and set
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableColumn.html#cellFactoryProperty--">CellValueFactories</a>
to define what value will be displayed by a specific column. Look at the
<a href="http://docs.oracle.com/javafx/2/ui_controls/table-view.htm">code from the Oracle docs</a> for a simple example.</p>
<p>The key point is: When you add/remove an instance of your data in the observable list (your data model) the table will
update itself accordingly. You don't need to manually add a new row to the table or anything like that. This is a realy
cool way to separate the visualization of the table from the data to be displayed.</p>
<!--more-->
<h3>TreeView and TreeTableView</h3>
<p>When you create an application with the
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeView.html">TreeView</a> component or the new
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeTableView.html">TreeTableView</a> that was added in
JavaFX 8 you will probably be disappointed because there is no easy way of separation available for these components out
of the box.</p>
<p>Think of the following example requirements:</p>
<p>You like to create a simple todo app to structure your tasks. Every task can have several sub-tasks.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Task</span> <span class="token punctuation">{</span>
  <span class="token class-name">StringProperty</span> description <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleStringProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token class-name">ObservableList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span> subtasks <span class="token operator">=</span> <span class="token class-name">FXCollections</span><span class="token punctuation">.</span><span class="token function">observableArrayList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token comment">// getter / setter</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This is a recursive data-structure and a TreeTableView would be the perfect visualization for this use case.</p>
<p>Ideally you would again try to separate the concerns of visualisation and data management from each other: When you add
a sub task to one of your existing task elements the TreeTable should update itself automatically.</p>
<p>Sadly there is no such functionality provided by the TreeView/TreeTableView class out of the box (as far as I know. Let
me know if I'm wrong).</p>
<p>Instead you have to create a new
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeItem.html">TreeItem</a> for every task that is added
to your data model by hand.</p>
<p>Look at the following example code:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">start</span><span class="token punctuation">(</span><span class="token class-name">Stage</span> stage<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>

  <span class="token comment">// 1.</span>
  <span class="token class-name">TreeTableView</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span> tree <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TreeTableView</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  tree<span class="token punctuation">.</span><span class="token function">setColumnResizePolicy</span><span class="token punctuation">(</span><span class="token class-name">TreeTableView</span><span class="token punctuation">.</span><span class="token constant">CONSTRAINED_RESIZE_POLICY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token class-name">TreeTableColumn</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">></span></span> descriptionColumn <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TreeTableColumn</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token string">"Description"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  tree<span class="token punctuation">.</span><span class="token function">getColumns</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>descriptionColumn<span class="token punctuation">)</span><span class="token punctuation">;</span>
  descriptionColumn<span class="token punctuation">.</span><span class="token function">setCellValueFactory</span><span class="token punctuation">(</span>param <span class="token operator">-></span> param<span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">descriptionProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token comment">// 2.</span>
  <span class="token class-name">Task</span> root <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Task</span><span class="token punctuation">(</span><span class="token string">"ToDo"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">final</span> <span class="token class-name">Task</span> shoppingTask <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Task</span><span class="token punctuation">(</span><span class="token string">"Shopping"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  shoppingTask<span class="token punctuation">.</span><span class="token function">getSubtasks</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Task</span><span class="token punctuation">(</span><span class="token string">"Buy milk"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  shoppingTask<span class="token punctuation">.</span><span class="token function">getSubtasks</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Task</span><span class="token punctuation">(</span><span class="token string">"Buy bread"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  shoppingTask<span class="token punctuation">.</span><span class="token function">getSubtasks</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Task</span><span class="token punctuation">(</span><span class="token string">"Buy lemonade"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  root<span class="token punctuation">.</span><span class="token function">getSubtasks</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>shoppingTask<span class="token punctuation">)</span><span class="token punctuation">;</span>


  <span class="token comment">// 3.</span>
  <span class="token keyword">final</span> <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span> rootItem <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>root<span class="token punctuation">)</span><span class="token punctuation">;</span>
  tree<span class="token punctuation">.</span><span class="token function">setRoot</span><span class="token punctuation">(</span>rootItem<span class="token punctuation">)</span><span class="token punctuation">;</span>


  <span class="token comment">// 4.</span>
  <span class="token function">addTreeItemsRecursive</span><span class="token punctuation">(</span>root<span class="token punctuation">,</span> rootItem<span class="token punctuation">)</span><span class="token punctuation">;</span>



  <span class="token class-name">VBox</span> parent <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">VBox</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  parent<span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>tree<span class="token punctuation">)</span><span class="token punctuation">;</span>

  stage<span class="token punctuation">.</span><span class="token function">setScene</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Scene</span><span class="token punctuation">(</span>parent<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  stage<span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// 5.</span>
<span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">addTreeItemsRecursive</span><span class="token punctuation">(</span><span class="token class-name">Task</span> task<span class="token punctuation">,</span> <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span> item<span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">Task</span> subtask <span class="token operator">:</span> task<span class="token punctuation">.</span><span class="token function">getSubtasks</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span> subTaskItem <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>subtask<span class="token punctuation">)</span><span class="token punctuation">;</span>
    item<span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>subTaskItem<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">addTreeItemsRecursive</span><span class="token punctuation">(</span>subtask<span class="token punctuation">,</span> subTaskItem<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>At first we define the TreeTable (1.) with a single column that will show the <code class="language-text">description</code> value of the task.</p>
<p>After that we create a task instance that will become the root element of our tree. Additionally we are adding an
example subtask ("shopping") which itself contains some subtasks.</p>
<p>Now we need to connect our TreeTable with our data. To do this we need to create a <code class="language-text">TreeItem</code> instance for our root task
and use the <code class="language-text">setRoot()</code> method (3.). Note that at this point the TreeTable will only show the root task but no sub tasks
at all. Instead we have to create <code class="language-text">TreeItem</code> instances for all our Subtasks by hand. To simplyfy this a little I have
created a method <code class="language-text">addTreeItemsRecursive</code> that is doing exactly what it's name suggests: Go through all subtasks of the
given task and add a TreeItem for this subtask. Then apply this method to each subtask recursivly (5.).</p>
<p>When you look at this code you will see that it isn't very smart at all and has some disadvantages: What if I add
annother subtask later? What if I remove a subtask? In both cases the TreeTable won't update itself automatically.</p>
<h2>Recursive TreeItem</h2>
<p>To solve this I've created a little helper class <code class="language-text">RecursiveTreeItem</code> (maybe someone has a better name for it ;-)) which
extends <code class="language-text">TreeItem</code>. With this class you can write the code as follows:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">start</span><span class="token punctuation">(</span><span class="token class-name">Stage</span> stage<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
    <span class="token comment">// 1. and 2. stays the same</span>
    <span class="token comment">// ...</span>

    <span class="token comment">// 3.</span>
    <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span> rootItem <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Task</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>root<span class="token punctuation">,</span> <span class="token class-name">Task</span><span class="token operator">::</span><span class="token function">getSubtasks</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    tree<span class="token punctuation">.</span><span class="token function">setRoot</span><span class="token punctuation">(</span>rootItem<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// ..,</span>
<span class="token punctuation">}</span></code></pre></div>
<p>To use this class you specify the root Task element and a function ('Task:getSubtasks') that can be used to get the
sub-items from an item. The function has to have the signature <code class="language-text">Callback&lt;T, ObservableList&lt;T>></code>: It takes an instance of
<code class="language-text">T</code> (in our example <code class="language-text">Task</code>) and returns an observable List of <code class="language-text">T</code> representing the sub items. The <code class="language-text">RecursiveTreeItem</code>
will take care for updates of the TreeTable when the data structure is updated.</p>
<p>The code looks like this (notice: This code isn't handling icons correctly. At the end of this blog post I've posted an
updated version):</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token keyword">extends</span> <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> childrenFactory<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">(</span><span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> func<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> func<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">T</span> value<span class="token punctuation">,</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> func<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token class-name">Node</span><span class="token punctuation">)</span> <span class="token keyword">null</span><span class="token punctuation">,</span> func<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">T</span> value<span class="token punctuation">,</span> <span class="token class-name">Node</span> graphic<span class="token punctuation">,</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> func<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> graphic<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span>childrenFactory <span class="token operator">=</span> func<span class="token punctuation">;</span>

        <span class="token keyword">if</span><span class="token punctuation">(</span>value <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token function">addChildrenListener</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token function">valueProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span>obs<span class="token punctuation">,</span> oldValue<span class="token punctuation">,</span> newValue<span class="token punctuation">)</span><span class="token operator">-></span><span class="token punctuation">{</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>newValue <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">addChildrenListener</span><span class="token punctuation">(</span>newValue<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">addChildrenListener</span><span class="token punctuation">(</span><span class="token class-name">T</span> value<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">ObservableList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> children <span class="token operator">=</span> childrenFactory<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">;</span>

        children<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>child <span class="token operator">-></span>
            <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>
              <span class="token keyword">new</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>child<span class="token punctuation">,</span> <span class="token function">getGraphic</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        children<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token class-name">ListChangeListener</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span><span class="token punctuation">)</span> change <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">while</span><span class="token punctuation">(</span>change<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

                <span class="token keyword">if</span><span class="token punctuation">(</span>change<span class="token punctuation">.</span><span class="token function">wasAdded</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    change<span class="token punctuation">.</span><span class="token function">getAddedSubList</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                      <span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>t<span class="token operator">-></span>
                          <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>
                              <span class="token keyword">new</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token function">getGraphic</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

                <span class="token keyword">if</span><span class="token punctuation">(</span>change<span class="token punctuation">.</span><span class="token function">wasRemoved</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    change<span class="token punctuation">.</span><span class="token function">getRemoved</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>t<span class="token operator">-></span><span class="token punctuation">{</span>
                        <span class="token keyword">final</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TreeItem</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> itemsToRemove <span class="token operator">=</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                          <span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                          <span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>treeItem <span class="token operator">-></span>
                            treeItem<span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">collect</span><span class="token punctuation">(</span><span class="token class-name">Collectors</span><span class="token punctuation">.</span><span class="token function">toList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                        <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">removeAll</span><span class="token punctuation">(</span>itemsToRemove<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>I don't want to describe every line as I think it's pretty straight forward. When the <code class="language-text">RecursiveTreeItem</code> is created the
first thing I'm doing is to recursivly go through all sub items and create <code class="language-text">RecursiveTreeItems</code> for each of them. After
that I'm adding a listener to the observable list of sub items to react on list changes.</p>
<p>This code isn't battle tested and there are probably some cases that I haven't taken care of (for example I'm only
reacting to <code class="language-text">wasRemoved</code> and <code class="language-text">wasAdded</code> events). If you have ideas for improvements or are a developer of an (open
source) component library and this could be helpful for you, feel free to use the code as you like (and let me know
:-)).</p>
<p>To see the class in action you can take a look at my toy project
<a href="https://github.com/manuel_mauky/structured-list">structure-list</a> which is a Todo app prototype. The actual
<code class="language-text">RecursiveTreeItem</code> class can be found
<a href="https://github.com/manuel_mauky/structured-list/blob/master/client-javafx/src/main/java/eu/lestard/structuredlist/util/RecursiveTreeItem.java">here</a>.</p>
<p><img src="/files/pics/2015/structurelist.png" alt="structure-list"></p>
<p>A limitation of this approach is that it only works for data models with a single type. In the example I have a <em>Task</em>
that has many Sub-<em>Task</em>s. For more complex models this won't work. Think of a Scrum-like model where a <em>Project</em>
consists of many <em>Sprint</em>s consisting of many <em>Stories</em> consisting of many <em>Tasks</em> ... you get the point. Maybe there is
a clever solution for such situations too?</p>
<h2>-- EDIT --</h2>
<p>In the previous code of <code class="language-text">RecursiveTreeItem</code> the handling of graphics isn't working correctly. The problem is in the
third constructor that takes a <code class="language-text">Node grpahic</code> as second argument. This is based on the original constructor of
<code class="language-text">TreeItem</code> and therefore the graphics node is immediately passed to the super constructor. After that in the listener
that checks for added items, new <code class="language-text">RecursiveTreeItem</code> instances are created recursivly and the same graphics instance
(via <code class="language-text">getGraphic()</code>) is used for each new tree item. This doesn't work. In JavaFX a node can only appear once in the
scenegraph. If you add a node a second time to the scenegraph, it will disappear at the previous position. This is
happening here too. With the previous code only the last added tree item will have an icon. I haven't found this bug
earlier because in my example application I wasn't using icons for the tree nodes.</p>
<p>The solution is quite simple. The <code class="language-text">RecursiveTreeItem</code> needs an API that allows the user to create a new graphics
instance every time a new tree item is created. So instead of passing a graphics instance to the constructor of
<code class="language-text">RecursiveTreeItem</code>, it now takes a (factory-)function as constructor argument. This function has to return a new
graphics instance when applied. It will get the current item value as argument so that different icons can be used for
different types of values. The new code is this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token keyword">extends</span> <span class="token class-name">TreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> childrenFactory<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">Node</span><span class="token punctuation">></span></span> graphicsFactory<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">(</span><span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">T</span> value<span class="token punctuation">,</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> <span class="token punctuation">(</span>item<span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token keyword">null</span><span class="token punctuation">,</span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">T</span> value<span class="token punctuation">,</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">Node</span><span class="token punctuation">></span></span> graphicsFactory<span class="token punctuation">,</span> <span class="token class-name">Callback</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token class-name">ObservableList</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> graphicsFactory<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span>graphicsFactory <span class="token operator">=</span> graphicsFactory<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>childrenFactory <span class="token operator">=</span> childrenFactory<span class="token punctuation">;</span>

        <span class="token keyword">if</span><span class="token punctuation">(</span>value <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token function">addChildrenListener</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token function">valueProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span>obs<span class="token punctuation">,</span> oldValue<span class="token punctuation">,</span> newValue<span class="token punctuation">)</span><span class="token operator">-></span><span class="token punctuation">{</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>newValue <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">addChildrenListener</span><span class="token punctuation">(</span>newValue<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setExpanded</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">addChildrenListener</span><span class="token punctuation">(</span><span class="token class-name">T</span> value<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">ObservableList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> children <span class="token operator">=</span> childrenFactory<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">;</span>

        children<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>child <span class="token operator">-></span>  <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>
            <span class="token keyword">new</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>child<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>graphicsFactory<span class="token punctuation">,</span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        children<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token class-name">ListChangeListener</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span><span class="token punctuation">)</span> change <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">while</span><span class="token punctuation">(</span>change<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

                <span class="token keyword">if</span><span class="token punctuation">(</span>change<span class="token punctuation">.</span><span class="token function">wasAdded</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    change<span class="token punctuation">.</span><span class="token function">getAddedSubList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>t<span class="token operator">-></span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>
                        <span class="token keyword">new</span> <span class="token class-name">RecursiveTreeItem</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>graphicsFactory<span class="token punctuation">,</span> childrenFactory<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

                <span class="token keyword">if</span><span class="token punctuation">(</span>change<span class="token punctuation">.</span><span class="token function">wasRemoved</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    change<span class="token punctuation">.</span><span class="token function">getRemoved</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>t<span class="token operator">-></span><span class="token punctuation">{</span>
                        <span class="token keyword">final</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TreeItem</span><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span><span class="token punctuation">></span></span> itemsToRemove <span class="token operator">=</span> <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span>
                                <span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                                <span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                                <span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>treeItem <span class="token operator">-></span> treeItem<span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">)</span>
                                <span class="token punctuation">.</span><span class="token function">collect</span><span class="token punctuation">(</span><span class="token class-name">Collectors</span><span class="token punctuation">.</span><span class="token function">toList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                        <span class="token class-name">RecursiveTreeItem</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getChildren</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">removeAll</span><span class="token punctuation">(</span>itemsToRemove<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Thanks to <a href="https://twitter.com/gary_d_white/status/854533951070904320">Gary White</a> for finding and reporting this issue.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[mvvmFX 1.0.0]]></title>
            <link>https://www.lestard.eu/2015/mvvmfx-jaxenter/</link>
            <guid>https://www.lestard.eu/2015/mvvmfx-jaxenter/</guid>
            <pubDate>Fri, 20 Feb 2015 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Some days ago we have released the first stable release of our <a href="/projects/mvvmfx/">mvvmFX</a> library that helps you to
implement the <a href="https://en.wikipedia.org/wiki/Model_View_ViewModel">Model-View-ViewModel pattern</a> with JavaFX.</p>
<p>The new release can be used with Maven/Gradle:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">&lt;dependency>
        &lt;groupId>de.saxsys&lt;/groupId>
        &lt;artifactId>mvvmfx&lt;/artifactId>
        &lt;version>1.0.0&lt;/version>
&lt;/dependency></code></pre></div>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">compile 'de.saxsys:mvvmfx:1.0.0'</code></pre></div>
<p>Additionally Alex and me have written an
<a href="https://jaxenter.de/mvvmfx-model-view-viewmodel-mit-javafx-16262">article for jaxenter.de</a>. This is a german version.
An english version of the article will follow next week.</p>]]></description>
            <content:encoded><![CDATA[<p>Some days ago we have released the first stable release of our <a href="/projects/mvvmfx/">mvvmFX</a> library that helps you to
implement the <a href="https://en.wikipedia.org/wiki/Model_View_ViewModel">Model-View-ViewModel pattern</a> with JavaFX.</p>
<p>The new release can be used with Maven/Gradle:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">&lt;dependency>
        &lt;groupId>de.saxsys&lt;/groupId>
        &lt;artifactId>mvvmfx&lt;/artifactId>
        &lt;version>1.0.0&lt;/version>
&lt;/dependency></code></pre></div>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">compile 'de.saxsys:mvvmfx:1.0.0'</code></pre></div>
<p>Additionally Alex and me have written an
<a href="https://jaxenter.de/mvvmfx-model-view-viewmodel-mit-javafx-16262">article for jaxenter.de</a>. This is a german version.
An english version of the article will follow next week.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[JUG-GR: Model-View-* - UI design patterns in detail]]></title>
            <link>https://www.lestard.eu/2015/juggr-mvc/</link>
            <guid>https://www.lestard.eu/2015/juggr-mvc/</guid>
            <pubDate>Thu, 01 Jan 2015 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>On december 3, 2014 I gave another talk at the
<a href="http://www.jug-gr.de/2014/12/03/model-view-star.html">Java-User-Group Görlitz</a> with the title "Model-View-* :
UI-Design-Patterns im Detail".</p>
<p>The talk was all about the <strong>Model-View-Controller</strong> pattern and it's variants like <strong>Model-View-Presenter</strong> (in
different flavours) and <strong>Model-View-ViewModel</strong>. The example code was written in JavaFX. You can find the Code
<a href="https://github.com/manuel_mauky/model-view-star">here on github</a>. Of course I also presented the usage of our own MVVM
framework <a href="https://github.com/sialcasa/mvvmFX">mvvmFX</a>.</p>
<p>Additionally I spoke about the scope of UI patterns: On the one hand side you can see "MVC" at the abstraction level of
a single UI control. In the talk I used the example of a TextField control.</p>
<p>On the other hand you will often here people talking about "MVC" when they talk about the overall application
architecture. I compared the terms of MVC with the well-known
<a href="https://en.wikipedia.org/wiki/Multitier_architecture#Three-tier_architecture">Three-tier Architecture</a> and the less
common <a href="http://martinfowler.com/bliki/CQRS.html">CQRS architecture</a>.</p>]]></description>
            <content:encoded><![CDATA[<p>On december 3, 2014 I gave another talk at the
<a href="http://www.jug-gr.de/2014/12/03/model-view-star.html">Java-User-Group Görlitz</a> with the title "Model-View-* :
UI-Design-Patterns im Detail".</p>
<p>The talk was all about the <strong>Model-View-Controller</strong> pattern and it's variants like <strong>Model-View-Presenter</strong> (in
different flavours) and <strong>Model-View-ViewModel</strong>. The example code was written in JavaFX. You can find the Code
<a href="https://github.com/manuel_mauky/model-view-star">here on github</a>. Of course I also presented the usage of our own MVVM
framework <a href="https://github.com/sialcasa/mvvmFX">mvvmFX</a>.</p>
<p>Additionally I spoke about the scope of UI patterns: On the one hand side you can see "MVC" at the abstraction level of
a single UI control. In the talk I used the example of a TextField control.</p>
<p>On the other hand you will often here people talking about "MVC" when they talk about the overall application
architecture. I compared the terms of MVC with the well-known
<a href="https://en.wikipedia.org/wiki/Multitier_architecture#Three-tier_architecture">Three-tier Architecture</a> and the less
common <a href="http://martinfowler.com/bliki/CQRS.html">CQRS architecture</a>.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[EasyDI Example]]></title>
            <link>https://www.lestard.eu/2014/easy-di/</link>
            <guid>https://www.lestard.eu/2014/easy-di/</guid>
            <pubDate>Sun, 09 Nov 2014 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>This tutorial will show you the usage of Easy-DI. All files for this example can be found in the github-project
<a href="https://github.com/manuel_mauky/EasyDI/tree/master/src/test/java/eu/lestard/easydi/examples/coffee">in the package /src/test/java/eu/lestard/easydi/examples/coffee</a></p>
<p>Let's assume this class diagram for a coffee machine application:</p>
<p><img src="/files/pics/2014/easydi_example_classdiagram.png" alt="uml-class-diagram"></p>
<p>In this class diagram we can see the dependencies of each class: The <code class="language-text">CoffeeMachine</code> has a reference to the <code class="language-text">WaterTank</code>
and the <code class="language-text">CoffeePowderProvider</code>. The <code class="language-text">CoffeePowderProvider</code> has a reference to the <code class="language-text">BeanContainer</code> and to the <code class="language-text">Mill</code>.</p>
]]></description>
            <content:encoded><![CDATA[<p>This tutorial will show you the usage of Easy-DI. All files for this example can be found in the github-project
<a href="https://github.com/manuel_mauky/EasyDI/tree/master/src/test/java/eu/lestard/easydi/examples/coffee">in the package /src/test/java/eu/lestard/easydi/examples/coffee</a></p>
<p>Let's assume this class diagram for a coffee machine application:</p>
<p><img src="/files/pics/2014/easydi_example_classdiagram.png" alt="uml-class-diagram"></p>
<p>In this class diagram we can see the dependencies of each class: The <code class="language-text">CoffeeMachine</code> has a reference to the <code class="language-text">WaterTank</code>
and the <code class="language-text">CoffeePowderProvider</code>. The <code class="language-text">CoffeePowderProvider</code> has a reference to the <code class="language-text">BeanContainer</code> and to the <code class="language-text">Mill</code>.</p>
<!--more-->
<h2>1. Write your classes</h2>
<p>Let's start writing our classes. We begin with the ones that have no dependencies to other classes:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Mill</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">grind</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Mill: Let's start grinding"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BeanContainer</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">getBeans</span><span class="token punctuation">(</span><span class="token keyword">int</span> amount<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"BeanContainer: here you have "</span> <span class="token operator">+</span> amount <span class="token operator">+</span> <span class="token string">" beans"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">WaterTank</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"WaterTank:providing water"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now the rest. When a class needs an instance of another class we simply add a constructor parameter to the class:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CoffeePowderProvider</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">Mill</span> mill<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">BeanContainer</span> container<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">CoffeePowderProvider</span><span class="token punctuation">(</span><span class="token class-name">Mill</span> mill<span class="token punctuation">,</span> <span class="token class-name">BeanContainer</span> container<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>mill <span class="token operator">=</span> mill<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>container <span class="token operator">=</span> container<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">getPowder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeePowderProvider: Start making coffee powder."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        container<span class="token punctuation">.</span><span class="token function">getBeans</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        mill<span class="token punctuation">.</span><span class="token function">grind</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeePowderProvider: Here you have your coffee powder"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CoffeeMachine</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">CoffeePowderProvider</span> coffeePowderProvider<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">WaterTank</span> waterTank<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">CoffeeMachine</span><span class="token punctuation">(</span><span class="token class-name">CoffeePowderProvider</span> coffeePowderProvider<span class="token punctuation">,</span> <span class="token class-name">WaterTank</span> waterTank <span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>coffeePowderProvider <span class="token operator">=</span> coffeePowderProvider<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>waterTank <span class="token operator">=</span> waterTank<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: Start making coffee"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        waterTank<span class="token punctuation">.</span><span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        coffeePowderProvider<span class="token punctuation">.</span><span class="token function">getPowder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: I have all ingredients. Let's go"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: ..."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: Coffee is finished"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now we have all our "business" classes finished. The only thing that is missing is a class with a <code class="language-text">main</code> method to start
our program. In the main method we need to create all our instances and put them together:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CoffeeApp</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">Mill</span> mill <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Mill</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WaterTank</span> waterTank <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">WaterTank</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">BeanContainer</span> beanContainer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">CoffeePowderProvider</span> powderProvider <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CoffeePowderProvider</span><span class="token punctuation">(</span>mill<span class="token punctuation">,</span>beanContainer<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">CoffeeMachine</span> coffeeMachine <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CoffeeMachine</span><span class="token punctuation">(</span>powderProvider<span class="token punctuation">,</span>waterTank<span class="token punctuation">)</span><span class="token punctuation">;</span>

        coffeeMachine<span class="token punctuation">.</span><span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>When we run our example app we get this output:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">CoffeeMachine: Start making coffee
WaterTank:providing water
CoffeePowderProvider: Start making coffee powder.
BeanContainer: here you have 10 beans
Mill: Let's start grinding
CoffeePowderProvider: Here you have your coffee powder
CoffeeMachine: I have all ingredients. Let's go
CoffeeMachine: ...
CoffeeMachine: Coffee is finished</code></pre></div>
<p>And this is it: This is dependency injection. You don't even need a framework for dependency injection! This is
<em>Inversion of Control</em>. Instead of instantiating them by themselves, every class tells you what other classes it needs.
As you can see there is no big magic in DI.</p>
<p>But wait! There are at least two problems with this code: First of all, when your application grows you will end with a
big stack of constructor calls. And it's an annoying task to call constructors. Can't this be automated? Why can't a
computer do this? Yes this is what a DI-Framework is doing.</p>
<p>But the second problem is even worse: Our <code class="language-text">CoffeeApp</code> class has static references to <em>all</em> our classes. Every time you
make a change to one of your classes (rename it, move it to another package) or the dependencies of one of your classes
change the <code class="language-text">CoffeeApp</code> has to be changed too.</p>
<p>So let's se what Easy-DI can do for us.</p>
<h2>2. Use Easy-DI</h2>
<p>Introducing Easy-DI to our example is ...easy. Instead of calling constructors you only create an instance of <code class="language-text">EasyDI</code>
and get an instance of the <code class="language-text">CoffeeMachine</code> from it:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>args<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">EasyDI</span> easyDI <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">EasyDI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">CoffeeMachine</span> coffeeMachine <span class="token operator">=</span> easyDI<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">CoffeeMachine</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    coffeeMachine<span class="token punctuation">.</span><span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This is all we have to do. No annoying constructor calls and no static dependencies to all classes anymore.</p>
<p>And unlike some other DI-frameworks we didn't have to do any changes to our business classes. There was no need to add
annotations or other configuration (at least for this simple example).</p>
<p>To get an idea what EasyDI is doing under the hood we could add a <em>sysout</em> (<code class="language-text">System.out.println</code>) to all our
constructors like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Mill</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">Mill</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"new Mill()"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If we do this with all our classes and run the example we get this output:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">new Mill()
new BeanContainer()
new CoffeePowderProvider(...)
new WaterTank()
new CoffeeMachine(...)
CoffeeMachine: Start making coffee
WaterTank:providing water
CoffeePowderProvider: Start making coffee powder.
BeanContainer: here you have 10 beans
Mill: Let's start grinding
CoffeePowderProvider: Here you have your coffee powder
CoffeeMachine: I have all ingredients. Let's go
CoffeeMachine: ...
CoffeeMachine: Coffee is finished</code></pre></div>
<p>As you can see, EasyDI is doing the same as we have done by hand before: It's starting to instantiate the classes that
don't have dependencies.</p>
<h2>3. Singletons</h2>
<p>Our coffee machine is working. Let's implement some new features like a milk frother. The milk frother will use hot
steam to froth the milk. Therefore it needs a reference to the <code class="language-text">WaterTank</code>:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MilkFrother</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">WaterTank</span> waterTank<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">MilkFrother</span><span class="token punctuation">(</span><span class="token class-name">WaterTank</span> waterTank<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"new MilkFrother(...)"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>waterTank <span class="token operator">=</span> waterTank<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">makeMilkFroth</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        waterTank<span class="token punctuation">.</span><span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// heat the water up to get steam</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"MilkFrother: making milk froth"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Our <code class="language-text">CoffeeMachine</code> now looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CoffeeMachine</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">CoffeePowderProvider</span> coffeePowderProvider<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">WaterTank</span> waterTank<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">MilkFrother</span> frother<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token class-name">CoffeeMachine</span><span class="token punctuation">(</span><span class="token class-name">CoffeePowderProvider</span> coffeePowderProvider<span class="token punctuation">,</span> <span class="token class-name">WaterTank</span> waterTank<span class="token punctuation">,</span> <span class="token class-name">MilkFrother</span> frother <span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"new CoffeeMachine(...)"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>coffeePowderProvider <span class="token operator">=</span> coffeePowderProvider<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>waterTank <span class="token operator">=</span> waterTank<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>frother <span class="token operator">=</span> frother<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: Start making coffee"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        waterTank<span class="token punctuation">.</span><span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        coffeePowderProvider<span class="token punctuation">.</span><span class="token function">getPowder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        frother<span class="token punctuation">.</span><span class="token function">makeMilkFroth</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: I have all ingredients. Let's go"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: ..."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"CoffeeMachine: Coffee is finished"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Let's try this out:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">new Mill()
new BeanContainer()
new CoffeePowderProvider(...)
new WaterTank()
new WaterTank()
new MilkFrother(...)
new CoffeeMachine(...)
CoffeeMachine: Start making coffee
...
MilkFrother: making milk froth
...
CoffeeMachine: Coffee is finished</code></pre></div>
<p>But what is this? The constructor of the <code class="language-text">WaterTank</code> is called two times? That's bad. The reason is that by default
EasyDI will always create a new instance when one is needed. We have now two classes that depend on a water tank: The
<code class="language-text">CoffeeMachine</code> and the <code class="language-text">MilkFrother</code>.</p>
<p>To fix this we need to tell EasyDI that there should only be exactly one instance of the <code class="language-text">WaterTank</code>. The water tank
should be a <strong>Singleton</strong>. There are two ways of doing this:</p>
<h4>1. Add <code class="language-text">@Singleton</code> annotation to <code class="language-text">WaterTank</code></h4>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javax<span class="token punctuation">.</span>inject<span class="token punctuation">.</span></span><span class="token class-name">Singleton</span></span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Singleton</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">WaterTank</span> <span class="token punctuation">{</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>When EasyDI finds out that a class is annotated with <code class="language-text">javax.inject.Singleton</code> it will only create one instance and reuse
it everywhere it is needed.</p>
<h4>2. Use the <code class="language-text">EasyDI.markAsSingleton()</code> method.</h4>
<p>You can mark a class as singleton with the method <code class="language-text">EasyDI.markAsSingleton(&lt;yourclass>.class);</code>:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>args<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">EasyDI</span> easyDI <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">EasyDI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    easyDI<span class="token punctuation">.</span><span class="token function">markAsSingleton</span><span class="token punctuation">(</span><span class="token class-name">WaterTank</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">CoffeeMachine</span> coffeeMachine <span class="token operator">=</span> easyDI<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">CoffeeMachine</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    coffeeMachine<span class="token punctuation">.</span><span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The result is the same in both cases:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">new Mill()
new BeanContainer()
new CoffeePowderProvider(...)
new WaterTank()
new MilkFrother(...)
new CoffeeMachine(...)
CoffeeMachine: Start making coffee
...
MilkFrother: making milk froth
...
CoffeeMachine: Coffee is finished</code></pre></div>
<h4>When should I use @Singleton, when <code class="language-text">markAsSingleton</code>?</h4>
<p>In general I would recommend to use the <code class="language-text">@Singleton</code> annotation. This annotation is part of the <strong>JSR-330</strong>
specification. If you choose to switch to another DI framework in the future it's likely that it will support this
annotation as well and you probably won't have to change anything to get your singleton working again.</p>
<p>The <code class="language-text">markAsSingleton</code> method can be useful if you can't add the annotation for some reason. For example when the class
is part of a third-party library or you don't have access to the source files.</p>
<h2>4. Interfaces</h2>
<p>Our coffee machine business grows and now we like to add another variant of the coffee machine to our catalogue. The new
variant won't have a simple water tank anymore. Instead it will have a direct water supply.</p>
<p>To make our application flexible we add an interface <code class="language-text">WaterSupply</code> with two implementations: The old <code class="language-text">WaterTank</code> and our
new class <code class="language-text">DirectWaterSupply</code>.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">WaterSupply</span> <span class="token punctuation">{</span>
    <span class="token keyword">void</span> <span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token annotation punctuation">@Singleton</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">WaterTank</span> <span class="token keyword">implements</span> <span class="token class-name">WaterSupply</span><span class="token punctuation">{</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"WaterTank:providing water"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token annotation punctuation">@Singleton</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">DirectWaterSupply</span> <span class="token keyword">implements</span> <span class="token class-name">WaterSupply</span> <span class="token punctuation">{</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">getWater</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"DirectWaterSupply: get water from the water tap"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Additionally we change the type of the constructor parameters in <code class="language-text">MilkFrother</code> and <code class="language-text">CoffeeMachine</code>:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CoffeeMachine</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">CoffeeMachine</span><span class="token punctuation">(</span><span class="token class-name">CoffeePowderProvider</span> coffeePowderProvider<span class="token punctuation">,</span> <span class="token class-name">WaterSupply</span> waterSupply<span class="token punctuation">,</span> <span class="token class-name">MilkFrother</span> frother <span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MilkFrother</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">MilkFrother</span><span class="token punctuation">(</span><span class="token class-name">WaterSupply</span> waterSupply<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>But when we run our application like this we will get this exception:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">java.lang.IllegalStateException:
EasyDI can't create an instance of the class [interface WaterSupply].
It is an interface and there was no implementation class mapping defined for this type.
Please use the 'bindInterface' method of EasyDI to define what
implementing class should be used for a given interface.</code></pre></div>
<p>As the exception says, EasyDI can't know which of the implementing classes it should use when an <code class="language-text">WaterSupply</code> is
requested.</p>
<p>To define this use the method <code class="language-text">EasyDI.bindInterface</code>:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>args<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">EasyDI</span> easyDI <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">EasyDI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    easyDI<span class="token punctuation">.</span><span class="token function">bindInterface</span><span class="token punctuation">(</span><span class="token class-name">WaterSupply</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token class-name">WaterTank</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">CoffeeMachine</span> coffeeMachine <span class="token operator">=</span> easyDI<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">CoffeeMachine</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    coffeeMachine<span class="token punctuation">.</span><span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Now we get the expected output again:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">...
CoffeeMachine: Coffee is finished</code></pre></div>
<h2>5. Multiple Constructors</h2>
<p>EasyDI is expecting to find exactly one public constructor when it has to create an instance of a class. If for some
reason your class has more then one constructor, EasyDI can't know which one to use.</p>
<p>Look at this example:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BeanContainer</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"new BeanContainer()"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token keyword">int</span> initialAmount<span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>When you run the example you will get this exception:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">java.lang.IllegalStateException:
EasyDI can't create an instance of the class [class BeanContainer].
There are more than one public constructors so I don't know which to use.
Fix this by either make only one constructor public
or annotate exactly one constructor with the javax.inject.Inject annotation.</code></pre></div>
<p>You have to provide this information with the annotation <code class="language-text">javax.inject.Inject</code> like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javax<span class="token punctuation">.</span>inject<span class="token punctuation">.</span></span><span class="token class-name">Inject</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BeanContainer</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Inject</span>
    <span class="token keyword">public</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"new BeanContainer()"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token keyword">int</span> initialAmount<span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If there are more then one public constructors EasyDI will use the one that is annotated with <code class="language-text">@Inject</code>. Of cause you
may not annotate more then one constructor.</p>
<h2>6. Provider Methods</h2>
<p>Sometimes the shown features aren't sufficient for your use case. For example when you like to use a class from a
third-party library that has multiple constructors and you can't add an annotation to one of them.</p>
<p>Or the only way to get an instance of the third-party class is to use a factory method.</p>
<p>For these use cases you can define a <strong>Provider</strong> for a given type:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javax<span class="token punctuation">.</span>inject<span class="token punctuation">.</span></span><span class="token class-name">Provider</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>args<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">EasyDI</span> easyDI <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">EasyDI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    easyDI<span class="token punctuation">.</span><span class="token function">bindProvider</span><span class="token punctuation">(</span><span class="token class-name">BeanContainer</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Provider</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">BeanContainer</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token annotation punctuation">@Override</span>
            <span class="token keyword">public</span> <span class="token class-name">BeanContainer</span> <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">final</span> <span class="token class-name">BeanContainer</span> beanContainer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                beanContainer<span class="token punctuation">.</span><span class="token function">setAmount</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">return</span> beanContainer<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">CoffeeMachine</span> coffeeMachine <span class="token operator">=</span> easyDI<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">CoffeeMachine</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    coffeeMachine<span class="token punctuation">.</span><span class="token function">makeCoffee</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>With java 8 lambdas this can be written in a shorter way:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java">easyDI<span class="token punctuation">.</span><span class="token function">bindProvider</span><span class="token punctuation">(</span><span class="token class-name">BeanContainer</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">BeanContainer</span> beanContainer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BeanContainer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        beanContainer<span class="token punctuation">.</span><span class="token function">setAmount</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> beanContainer<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>With this configuration EasyDI will always call the given provider instance when an instance of <code class="language-text">BeanContainer</code> is
requested.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Dependency Injection in less then 50 lines of code]]></title>
            <link>https://www.lestard.eu/2014/dependency-injection-in-less-then-50-loc/</link>
            <guid>https://www.lestard.eu/2014/dependency-injection-in-less-then-50-loc/</guid>
            <pubDate>Thu, 06 Nov 2014 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>I'm a big fan of the Dependency Injection design pattern and I'm using it a lot. I'm saying "design pattern" because
when I'm thinking and talking about "DI" I don't think about frameworks, big containers and a lot of magic. Instead, for
me DI is a simple concept of how you write your classes and put them together.</p>
<p>In the past I've used many DI frameworks like Guice, CDI/Weld, EJB and Spring. In other use cases (for example my
SnakeFX game) I've done the DI by hand:</p>
<p>Simply put all dependencies of a class into the constructor of this class. In the main method you can now start to
instantiate the classes you need starting by the ones that have no dependencies and can therefore be instantiated
without constructor parameters needed. It's easy and this way you can't create cyclic dependencies by accident. Look at
an old version of the
<a href="https://github.com/manuel_mauky/SnakeFX/blob/58e61ef881431b1c9cdceadac62658d909fa652f/src/main/java/eu/lestard/snakefx/inject/DependencyInjector.java"><code class="language-text">DependencyInjector</code> class of SnakeFX</a>
to see what I mean.</p>
<p>Learning how to do the DI by hand was a real eye-opener for me. You can learn that DI is no magic at all and you will
lose all your fear from the big buzzword "Dependency Injection". It's nothing special. Simply a design pattern.</p>
]]></description>
            <content:encoded><![CDATA[<p>I'm a big fan of the Dependency Injection design pattern and I'm using it a lot. I'm saying "design pattern" because
when I'm thinking and talking about "DI" I don't think about frameworks, big containers and a lot of magic. Instead, for
me DI is a simple concept of how you write your classes and put them together.</p>
<p>In the past I've used many DI frameworks like Guice, CDI/Weld, EJB and Spring. In other use cases (for example my
SnakeFX game) I've done the DI by hand:</p>
<p>Simply put all dependencies of a class into the constructor of this class. In the main method you can now start to
instantiate the classes you need starting by the ones that have no dependencies and can therefore be instantiated
without constructor parameters needed. It's easy and this way you can't create cyclic dependencies by accident. Look at
an old version of the
<a href="https://github.com/manuel_mauky/SnakeFX/blob/58e61ef881431b1c9cdceadac62658d909fa652f/src/main/java/eu/lestard/snakefx/inject/DependencyInjector.java"><code class="language-text">DependencyInjector</code> class of SnakeFX</a>
to see what I mean.</p>
<p>Learning how to do the DI by hand was a real eye-opener for me. You can learn that DI is no magic at all and you will
lose all your fear from the big buzzword "Dependency Injection". It's nothing special. Simply a design pattern.</p>
<!--more-->
<h2>Dependency Injection Library</h2>
<p>Recently I started development of a new small JavaFX app and again the question was on how to do DI this time? While
doing DI by hand is possible, there are still downsides:</p>
<ol>
<li>It's an annoying task to stupidly call constructors.</li>
<li>The Dependency Injector class has static dependencies (import statements) to all involved classes. If you make
refactorings or change the dependencies of a class you need to adjust the Dependency Injector too.</li>
</ol>
<p>So which framework to choose? Most of them are cool for bigger applications. But there are always some sort of
configuration and other stuff to do before you can use them which isn't cool for small application.</p>
<p>This was the moment I had the idea of writing my own Dependency Injection library targeted at small applications. It
should be easy to use without configuration even when the consequence is a limited number of features.</p>
<p>And as it turned out it is really not that hard. With the restriction of only supporting constructor-based injection
(like I've done for DI-by-hand) I was able to write a DI library in less then 20 lines of code (without comments):</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token class-name">T</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> clazz<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">final</span> <span class="token class-name">Constructor</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">></span></span><span class="token punctuation">[</span><span class="token punctuation">]</span> constructors <span class="token operator">=</span> clazz<span class="token punctuation">.</span><span class="token function">getConstructors</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">if</span><span class="token punctuation">(</span>constructors<span class="token punctuation">.</span>length <span class="token operator">!=</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">IllegalStateException</span><span class="token punctuation">(</span><span class="token string">"Only one constructor allowed!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">final</span> <span class="token class-name">Constructor</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">></span></span> constructor <span class="token operator">=</span> constructors<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token keyword">final</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">></span></span> arguments <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span>constructor<span class="token punctuation">.</span><span class="token function">getParameters</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>parameter <span class="token operator">-></span> <span class="token punctuation">(</span><span class="token class-name">Object</span><span class="token punctuation">)</span> <span class="token function">getInstance</span><span class="token punctuation">(</span>parameter<span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span><span class="token function">collect</span><span class="token punctuation">(</span><span class="token class-name">Collectors</span><span class="token punctuation">.</span><span class="token function">toList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">try</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token class-name">T</span><span class="token punctuation">)</span> constructor<span class="token punctuation">.</span><span class="token function">newInstance</span><span class="token punctuation">(</span>arguments<span class="token punctuation">.</span><span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">IllegalStateException</span><span class="token punctuation">(</span><span class="token string">"Something went wrong :-("</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>First it checks that the given class has exactly one public constructor. After that I'm using the new Streaming-API of
Java 8 to recursively gather all instances for all parameters of the constructor. And the last thing is to create the
new instance of the requested class using the list of constructor parameters.</p>
<h2>Easy-DI</h2>
<p>Of cause there are some problems with this implementation. The biggest one is that cyclic dependencies aren't detected.
Instead a 'StackOverflowException' will be thrown by the JVM in this case.</p>
<p>To fix this I added two <code class="language-text">java.util.Set</code>s. The first one is used to store all requested classes and in the second one I'm
storing all classes that where successfully instantiated. When a class is requested for the first time, I'm adding it to
the first set and proceed with the method. When I'm able to create an instance of this class everything is cool and I'm
adding this class to the second set.</p>
<p>But when a class is requested that was already requested before but couldn't be instantiated yet, we have a problem.
This means that we are in a recursive call at the moment and we are still gathering the arguments for the requested
class. But when one of the arguments needs the requested class itself to be instantiated we have a cyclic dependency.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">EasyDI</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Class</span><span class="token punctuation">></span></span> requestedClasses <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Class</span><span class="token punctuation">></span></span> instantiableClasses <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@SuppressWarnings</span><span class="token punctuation">(</span><span class="token string">"unchecked"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> <span class="token class-name">T</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">></span></span> clazz<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">Constructor</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">></span></span><span class="token punctuation">[</span><span class="token punctuation">]</span> constructors <span class="token operator">=</span> clazz<span class="token punctuation">.</span><span class="token function">getConstructors</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span><span class="token punctuation">(</span>constructors<span class="token punctuation">.</span>length <span class="token operator">!=</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">IllegalStateException</span><span class="token punctuation">(</span><span class="token string">"Only one constructor allowed!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">final</span> <span class="token class-name">Constructor</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">></span></span> constructor <span class="token operator">=</span> constructors<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span><span class="token punctuation">(</span>requestedClasses<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>clazz<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>instantiableClasses<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>clazz<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">IllegalStateException</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
            requestedClasses<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>clazz<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">final</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">></span></span> arguments <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">stream</span><span class="token punctuation">(</span>constructor<span class="token punctuation">.</span><span class="token function">getParameters</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>parameter <span class="token operator">-></span> <span class="token punctuation">(</span><span class="token class-name">Object</span><span class="token punctuation">)</span> <span class="token function">getInstance</span><span class="token punctuation">(</span>parameter<span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span><span class="token function">collect</span><span class="token punctuation">(</span><span class="token class-name">Collectors</span><span class="token punctuation">.</span><span class="token function">toList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">try</span> <span class="token punctuation">{</span>

            <span class="token keyword">final</span> <span class="token class-name">Object</span> newInstance <span class="token operator">=</span> constructor<span class="token punctuation">.</span><span class="token function">newInstance</span><span class="token punctuation">(</span>arguments<span class="token punctuation">.</span><span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            instantiableClasses<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>clazz<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// mark the class as successfully instantiable.</span>
            <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token class-name">T</span><span class="token punctuation">)</span> newInstance<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">IllegalStateException</span><span class="token punctuation">(</span><span class="token string">"Something went wrong :-("</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>I have to admit that I'm not 100% sure that this check really finds every possible cyclic dependency but at least I
wasn't able to find any counterexample so I think this is fine.</p>
<p>At this state the DI library has 40 lines of code. The usage looks like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyService</span> <span class="token punctuation">{</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyExample</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">MyExample</span><span class="token punctuation">(</span><span class="token class-name">MyService</span> service<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">App</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">EasyDI</span> easyDI <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">EasyDI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">MyExample</span> example <span class="token operator">=</span> easyDI<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token class-name">MyExample</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// do something</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>As you can see there is no configuration needed. No annotations or other stuff for this simple example.</p>
<p>But there are still missing features for all day use cases: What happens when I'm using interfaces as dependency?</p>
<p>How can I define that from a certain class only one instance should be created and reused every time it is requested
(Singleton)?</p>
<p>What if I have more than one constructor?</p>
<p>What if I want to integrate third-party code that only offers a factory to obtain an instance.</p>
<p>And so I created a small github project for this library called "EasyDI" and implemented these features too. It's not
done in 40 LOC anymore and for some of these use cases there are annotations or configuration needed but the main goal
stays the same:</p>
<ul>
<li>For easy use cases there is no configuration needed.</li>
<li>For a little more advanced use cases the configuration is still easy.</li>
<li>And for really advanced and special use cases you need to use another full-featured DI-framework like Guice or CDI.</li>
</ul>
<p>In a future blog post I will show a full example of how to use EasyDI with all it's features.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[New release of Advanced-Bindings]]></title>
            <link>https://www.lestard.eu/2014/advanced-bindings-0.2.0/</link>
            <guid>https://www.lestard.eu/2014/advanced-bindings-0.2.0/</guid>
            <pubDate>Tue, 16 Sep 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Last week I've released a new minor version of my
<a href="https://github.com/manuel_mauky/advanced-bindings/releases/tag/v0.2.0">Advanced-Bindings</a> library. In this post I will
describe the new features in more detail.</p>
<h3>Logic Bindings</h3>
<p>In the standard JavaFX Bindings API there are methods to create bindings for the logical
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#or-javafx.beans.value.ObservableBooleanValue-javafx.beans.value.ObservableBooleanValue-"><em>OR</em></a>
and
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#and-javafx.beans.value.ObservableBooleanValue-javafx.beans.value.ObservableBooleanValue-"><em>AND</em></a>
operations. The drawback of these methods is that they can only be used to combine exactly two observable boolean
values.</p>
<p>In the new <a href="https://lestard.github.io/advanced-bindings/javadoc/0.2.0/">LogicBindings</a> class there are now methods to
create <em>OR</em> and <em>AND</em> bindings with a variable number of arguments.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">ObservableBooleanValue</span> a <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token class-name">ObservableBooleanValue</span> b <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token class-name">ObservableBooleanValue</span> c <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token class-name">ObservableBooleanValue</span> d <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token class-name">BooleanBinding</span> and <span class="token operator">=</span> <span class="token class-name">LogicBindings</span><span class="token punctuation">.</span><span class="token function">and</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">BooleanBinding</span> or <span class="token operator">=</span> <span class="token class-name">LogicBindings</span><span class="token punctuation">.</span><span class="token function">or</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
]]></description>
            <content:encoded><![CDATA[<p>Last week I've released a new minor version of my
<a href="https://github.com/manuel_mauky/advanced-bindings/releases/tag/v0.2.0">Advanced-Bindings</a> library. In this post I will
describe the new features in more detail.</p>
<h3>Logic Bindings</h3>
<p>In the standard JavaFX Bindings API there are methods to create bindings for the logical
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#or-javafx.beans.value.ObservableBooleanValue-javafx.beans.value.ObservableBooleanValue-"><em>OR</em></a>
and
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#and-javafx.beans.value.ObservableBooleanValue-javafx.beans.value.ObservableBooleanValue-"><em>AND</em></a>
operations. The drawback of these methods is that they can only be used to combine exactly two observable boolean
values.</p>
<p>In the new <a href="https://lestard.github.io/advanced-bindings/javadoc/0.2.0/">LogicBindings</a> class there are now methods to
create <em>OR</em> and <em>AND</em> bindings with a variable number of arguments.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">ObservableBooleanValue</span> a <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token class-name">ObservableBooleanValue</span> b <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token class-name">ObservableBooleanValue</span> c <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token class-name">ObservableBooleanValue</span> d <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token class-name">BooleanBinding</span> and <span class="token operator">=</span> <span class="token class-name">LogicBindings</span><span class="token punctuation">.</span><span class="token function">and</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">BooleanBinding</span> or <span class="token operator">=</span> <span class="token class-name">LogicBindings</span><span class="token punctuation">.</span><span class="token function">or</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<!--more-->
<h3>NumberBindings divideSafe</h3>
<p>We all have learned in school that you can't divide by zero. If you still do it, in java you get an
<code class="language-text">ArithmeticException</code>. To prevent it you have to check your divisor. You would probably write something like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">int</span> dividend <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token keyword">int</span> divisor <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token keyword">int</span> result<span class="token punctuation">;</span>

<span class="token keyword">if</span><span class="token punctuation">(</span>divisor <span class="token operator">!=</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    result <span class="token operator">=</span> dividend <span class="token operator">/</span> divisor<span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    result <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If your divisor is zero than the result is zero, too. Of cause this is wrong from the viewpoint of a mathematician but
it might be right for your usecase.</p>
<p>With the standard JavaFX Bindings API you can create a binding with a division, too. And again you have to worry about
the <code class="language-text">ArithmeticException</code>. If you do something like this you will probably have a bad time:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">IntegerProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">final</span> <span class="token class-name">NumberBinding</span> result <span class="token operator">=</span> <span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">divide</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> a<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>But no problem! Fortunately we can build IF-ELSE constructions with the Bindings API. You could try this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">IntegerProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">NumberBinding</span> result <span class="token operator">=</span> <span class="token class-name">Bindings</span>
    <span class="token punctuation">.</span><span class="token function">when</span><span class="token punctuation">(</span>a<span class="token punctuation">.</span><span class="token function">isEqualTo</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">otherwise</span><span class="token punctuation">(</span><span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">divide</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> a<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>But wait! This still produces an <code class="language-text">ArithmeticException</code>. The reason is that <code class="language-text">Bindings.divide(10,a)</code> is immediately
evaluated when the binding is created and at this point in time <code class="language-text">a</code> has a value of <code class="language-text">0</code>.</p>
<p>To help in such a situation I added a
<a href="https://lestard.github.io/advanced-bindings/javadoc/0.2.0/eu/lestard/advanced_bindings/api/NumberBindings.html#divideSafe-javafx.beans.value.ObservableIntegerValue-javafx.beans.value.ObservableIntegerValue-">divideSafe</a>
method (with some overloaded variants) to the Advanced-Bindings library. Now you can write the code like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">IntegerProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">NumberBinding</span> result <span class="token operator">=</span> <span class="token class-name">NumberBindings</span><span class="token punctuation">.</span><span class="token function">divideSafe</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> a<span class="token punctuation">)</span><span class="token punctuation">;</span>

a<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">assertThat</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>This won't throw an <code class="language-text">ArithmeticException</code> even if <code class="language-text">a</code> has a value of <code class="language-text">0</code>. In this case a default value of <code class="language-text">0</code> is used.
If you need another default value for your usecase there are overloaded variants of the <code class="language-text">divideSafe</code> method which accept
a third param for the default value (as observable).</p>
<h3>ObjectBindings map</h3>
<p>The third new feature is the
<a href="https://lestard.github.io/advanced-bindings/javadoc/0.2.0/eu/lestard/advanced_bindings/api/ObjectBindings.html#map-javafx.beans.value.ObservableValue-java.util.function.Function-">map binding</a>.
It's best described with an example: Think of a domain class <code class="language-text">Person</code>:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Person</span><span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> firstname<span class="token punctuation">;</span>

    <span class="token comment">// getter and setter</span>
<span class="token punctuation">}</span></code></pre></div>
<p>We have a UI with a master-detail view. In the master view we have a list of persons and you can select one of these
person objects. In the detail view we like to see all properties of the selected person.</p>
<p>In the UI controller we have an <code class="language-text">ObjectProperty&lt;Person> selectedPerson</code>. Now we like to have a StringBinding that always
contains the firstname of the currently selected person. If the user selects another person this binding should
automatically update. This can be done with the <code class="language-text">map</code> binding:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">ObjectProperty</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Person</span><span class="token punctuation">></span></span> selectedPerson <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleObjectProperty</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">ObjectBinding</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> firstname <span class="token operator">=</span> <span class="token class-name">ObjectBindings</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>selectedPerson<span class="token punctuation">,</span> person <span class="token operator">-></span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> person<span class="token punctuation">.</span><span class="token function">getFirstname</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>The <code class="language-text">map</code> method takes an observable value as first param and a mapping function as the second param. The return value
of the mapping function is used as the value for the binding. The example above uses a Java 8 lambda to define the
mapping function but this could be written even shorter with a method reference:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">ObjectBinding</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> firstname <span class="token operator">=</span> <span class="token class-name">ObjectBindings</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>selectedPerson<span class="token punctuation">,</span> <span class="token class-name">Person</span><span class="token operator">::</span><span class="token function">getFirstname</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<h4>Null Safety</h4>
<p>But there is one more thing with the <code class="language-text">map</code> binding: It's null-safe. To show what this means I'm creating a binding with
the standard JavaFX Bindings API that is doing <em>almost</em> the same:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">ObjectBinding</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> firstname <span class="token operator">=</span> <span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">createObjectBinding</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span> selectedPerson<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getFirstname</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>selectedPerson<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>The
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#createObjectBinding-java.util.concurrent.Callable-javafx.beans.Observable...-">createObjectBinding</a>
method takes a function as first param and an observable value as the second. In the example I'm calling <code class="language-text">get()</code> to get
the currently selected person object. After this I'm calling the firstname getter to get the value for the binding. It's
a little bit longer but besides of this it looks similar.</p>
<p>But wait! What is happening when no person is selected? When the <code class="language-text">selectedPerson</code> property has a value of <code class="language-text">null</code> this
binding will produce a <code class="language-text">NullPointerException</code>! To prevent this you would have to add a null check in the binding
function.</p>
<p>With the <code class="language-text">map</code> binding you don't need to think about a null check. The mapping function will only be applied when the
dependent observable has a value other than <code class="language-text">null</code>.</p>
<p>But what value does the created binding have when the dependent observable has a value of <code class="language-text">null</code>? By default the binding
will have a value of <code class="language-text">null</code> too. But there is an
<a href="https://lestard.github.io/advanced-bindings/javadoc/0.2.0/eu/lestard/advanced_bindings/api/ObjectBindings.html#map-javafx.beans.value.ObservableValue-java.util.function.Function-R-">overloaded version of the map binding method</a>
that takes a third param with a default value that is used in this case. So you can decide on your own what is the best
for your use case.</p>
<h3>Conclusion</h3>
<p>I hope you like the new features. To get the new version simple use gradle (or maven):</p>
<p>Gradle:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">compile 'eu.lestard:advanced-bindings:0.2.0'</code></pre></div>
<p>Maven:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">&lt;dependency>
    &lt;groupId>eu.lestard&lt;/groupId>
    &lt;artifactId>advanced-bindings&lt;/artifactId>
    &lt;version>0.2.0&lt;/version>
&lt;/dependency></code></pre></div>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Adjustable UI Brightness with JavaFX]]></title>
            <link>https://www.lestard.eu/2014/adjustable-ui-brightness/</link>
            <guid>https://www.lestard.eu/2014/adjustable-ui-brightness/</guid>
            <pubDate>Sat, 06 Sep 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Maybe some of you know or have already worked with <strong>Adobe</strong> products like <strong>Premier Pro</strong> or <strong>After Effects</strong>.</p>
<p>From the perspective of a UI developer there are many cool things about these products. For example you can seamlessly
fade the brightness of the UI and it looks great in every brightness level
(<a href="https://i.stack.imgur.com/Z269G.png">which seems to be a hard task</a>).</p>
<p>This is cool because there are good reasons for users to prefer either a dark or light interface. For example some
creative artists like to work in a dimmed office so that no light from outside is overlaying the colors picture/video
they are working on. In this situation a dark user interface is better then a light one because it's more comfortable
for the eyes.</p>
<p>On the other hand I know people how prefer a light and friendly user interface because a dark one would give them a
depressive fealing.</p>
<p>So it can be a big plus for the usability of your application when you allow the user to adjust the brightness of your
app.</p>
<h2>Adjustable Brightness in JavaFX</h2>
<p>Something like this can be done with <strong>JavaFX</strong> too. With JavaFX 8 there was a new default stylesheet created known as
<a href="http://hg.openjdk.java.net/openjfx/8u/rt/file/tip/modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css">modena</a>.</p>
<p>In this stylesheet there is a color definition named <code class="language-text">-fx-base</code> that is, as the name suggests, the base for all other
color definitions in the stylesheet.</p>
<p>When you adjust the value of <code class="language-text">-fx-base</code> all other colors will be adjusted automatically in relation to <code class="language-text">-fx-base</code>.</p>
<h3>Example</h3>
<p>The first thing to do is to create an IntegerProperty that will hold the brightness level in a range from 0 to 100%.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">IntegerProperty</span> brightness <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>After that we create a
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/StringExpression.html">StringExpression</a> (which is a
base class of <a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/StringBinding.html">StringBinding</a>) that
contains the style definition of <code class="language-text">-fx-base</code> with the value of our brightness property.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">DoubleBinding</span> colorValue <span class="token operator">=</span> brightness<span class="token punctuation">.</span><span class="token function">multiply</span><span class="token punctuation">(</span><span class="token number">2.55</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">StringExpression</span> styleString <span class="token operator">=</span>
    <span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"-fx-base:rgb(%1$.0f , %1$.0f, %1$.0f)"</span><span class="token punctuation">,</span> colorValue<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>For this task we can use the
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#format-java.lang.String-java.lang.Object...-">Bindings.format</a>
method that takes a format string and an observable value. In the example I'm using the <code class="language-text">rgb</code> css method to define the
color. This method takes the color information for every channel in a range from 0 to 255. For that reason I'm creating
a <code class="language-text">DoubleBinding</code> that contains the multiplication of our brightness property (from 0 to 100) with <code class="language-text">2.55</code> so that the
value range is correct.</p>
<p>The last step is to bind the style property of the root container of your application to the StringExpression with our
style definition.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Parent</span> root <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

root<span class="token punctuation">.</span><span class="token function">styleProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span>styleString<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>This way the styling of the application is adjusted everytime the brightness property changes.</p>
<p>I've created a small example app that shows the usage of this binding. In the app I have bound the <code class="language-text">brightness</code> property
to a slider so you can change the brightness level without interruption. To demonstrate the effect I created a dummy
form with some JavaFX controls.</p>
<h3>Dark:</h3>
<p><img src="https://github.com/manuel_mauky/javafx-brightness-example/raw/master/black.png" alt="dark"></p>
<h3>Medium:</h3>
<p><img src="https://github.com/manuel_mauky/javafx-brightness-example/raw/master/grey.png" alt="medium"></p>
<h3>Light:</h3>
<p><img src="https://github.com/manuel_mauky/javafx-brightness-example/raw/master/white.png" alt="light"></p>
<p>You can find the example code on github:
<a href="https://github.com/manuel_mauky/javafx-brightness-example">https://github.com/manuel_mauky/javafx-brightness-example</a>. Feel free
to use it in your own applications!</p>]]></description>
            <content:encoded><![CDATA[<p>Maybe some of you know or have already worked with <strong>Adobe</strong> products like <strong>Premier Pro</strong> or <strong>After Effects</strong>.</p>
<p>From the perspective of a UI developer there are many cool things about these products. For example you can seamlessly
fade the brightness of the UI and it looks great in every brightness level
(<a href="https://i.stack.imgur.com/Z269G.png">which seems to be a hard task</a>).</p>
<p>This is cool because there are good reasons for users to prefer either a dark or light interface. For example some
creative artists like to work in a dimmed office so that no light from outside is overlaying the colors picture/video
they are working on. In this situation a dark user interface is better then a light one because it's more comfortable
for the eyes.</p>
<p>On the other hand I know people how prefer a light and friendly user interface because a dark one would give them a
depressive fealing.</p>
<p>So it can be a big plus for the usability of your application when you allow the user to adjust the brightness of your
app.</p>
<h2>Adjustable Brightness in JavaFX</h2>
<p>Something like this can be done with <strong>JavaFX</strong> too. With JavaFX 8 there was a new default stylesheet created known as
<a href="http://hg.openjdk.java.net/openjfx/8u/rt/file/tip/modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css">modena</a>.</p>
<p>In this stylesheet there is a color definition named <code class="language-text">-fx-base</code> that is, as the name suggests, the base for all other
color definitions in the stylesheet.</p>
<p>When you adjust the value of <code class="language-text">-fx-base</code> all other colors will be adjusted automatically in relation to <code class="language-text">-fx-base</code>.</p>
<h3>Example</h3>
<p>The first thing to do is to create an IntegerProperty that will hold the brightness level in a range from 0 to 100%.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">IntegerProperty</span> brightness <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>After that we create a
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/StringExpression.html">StringExpression</a> (which is a
base class of <a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/StringBinding.html">StringBinding</a>) that
contains the style definition of <code class="language-text">-fx-base</code> with the value of our brightness property.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">DoubleBinding</span> colorValue <span class="token operator">=</span> brightness<span class="token punctuation">.</span><span class="token function">multiply</span><span class="token punctuation">(</span><span class="token number">2.55</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">StringExpression</span> styleString <span class="token operator">=</span>
    <span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"-fx-base:rgb(%1$.0f , %1$.0f, %1$.0f)"</span><span class="token punctuation">,</span> colorValue<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>For this task we can use the
<a href="http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Bindings.html#format-java.lang.String-java.lang.Object...-">Bindings.format</a>
method that takes a format string and an observable value. In the example I'm using the <code class="language-text">rgb</code> css method to define the
color. This method takes the color information for every channel in a range from 0 to 255. For that reason I'm creating
a <code class="language-text">DoubleBinding</code> that contains the multiplication of our brightness property (from 0 to 100) with <code class="language-text">2.55</code> so that the
value range is correct.</p>
<p>The last step is to bind the style property of the root container of your application to the StringExpression with our
style definition.</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">Parent</span> root <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

root<span class="token punctuation">.</span><span class="token function">styleProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span>styleString<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>This way the styling of the application is adjusted everytime the brightness property changes.</p>
<p>I've created a small example app that shows the usage of this binding. In the app I have bound the <code class="language-text">brightness</code> property
to a slider so you can change the brightness level without interruption. To demonstrate the effect I created a dummy
form with some JavaFX controls.</p>
<h3>Dark:</h3>
<p><img src="https://github.com/manuel_mauky/javafx-brightness-example/raw/master/black.png" alt="dark"></p>
<h3>Medium:</h3>
<p><img src="https://github.com/manuel_mauky/javafx-brightness-example/raw/master/grey.png" alt="medium"></p>
<h3>Light:</h3>
<p><img src="https://github.com/manuel_mauky/javafx-brightness-example/raw/master/white.png" alt="light"></p>
<p>You can find the example code on github:
<a href="https://github.com/manuel_mauky/javafx-brightness-example">https://github.com/manuel_mauky/javafx-brightness-example</a>. Feel free
to use it in your own applications!</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[SchachZWO Online]]></title>
            <link>https://www.lestard.eu/2014/schachzwo/</link>
            <guid>https://www.lestard.eu/2014/schachzwo/</guid>
            <pubDate>Sat, 28 Jun 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In the lecture "XML based applications" at the <a href="http://www.hszg.de/f-ei">HSZG</a> we were working on a project called
"SchachZWO Online". "Schach" is the german word for "chess" and "ZWO" is another word for "two" so (as you can guess)
this is a chess like online game.</p>
<h2>SchachZWO (offline)</h2>
<p><img src="http://www.schachzwo.de/wp-content/uploads/2013/12/9x9-front-slide.jpg" alt="screenshot from the official website"></p>
<p>The basic for the project is a board game that a game author from dresden has developed. In his "SchachZWO" you play on
a 7x7 or 9x9 board with some special figures: Instead of the rook and the queen you have the "Mann" (man) and "Frau"
(woman). Instead of the pawn you have the "Rocks" and instead of the king you have the "Zenit" (zenith). On the 9x9
board you have two additional figures with special movement capabilities: The "Wissen" (knowledge) and the "Glauben"
(faith).</p>
<p>One of the main differences between chess and "SchachZWO" is that there are more than one possibilities to win the game.
Beside the classical chess mate you win when you move your zenith to the middle field of the board. Only the zenith can
step on this field in the middle, all other figures aren't allowed to step on the field.</p>
<p>In the first place this rules might sound a little strange to you but it's realy fun to play the game. At the moment the
board game isn't available for buying but it will be in the near future. Fisit the website of the game author when you
like to know more: <a href="http://www.schachzwo.de/">http://www.schachzwo.de</a>.</p>
<h2>SchachZWO Online</h2>
<p><img src="https://github.com/manuel_mauky/schachzwo-online/raw/master/screenshot_schachzwo.png" alt="screenshot"></p>
<p>Our project for the lecture was to create an online multiplayer browser game version of this game. In the client we used
<a href="https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial">HTML5 canvas</a> together with
<a href="https://jquery.com/">JQuery</a> to draw the board and the figures. To create a modern Single-Page-Application we used
<a href="https://angularjs.org/">Angular.JS</a> and <a href="http://requirejs.org/">Require.JS</a> in the client.</p>
<p>On the server side we have a <a href="http://nodejs.org/">node.js</a> together with <a href="http://expressjs.com/">express.js</a>. There are
REST like webservices where the client can GET the current state of the board and can POST new moves.</p>
<p>To tell the client that the opponent has done a move we use
<a href="https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events">Server-Sent Events</a> to send
messages. The database connection was created in a generic manner to be able to replace the database implementation. At
the moment we have a <a href="http://www.mongodb.org/">MongoDB</a> and <a href="https://couchdb.apache.org/">CouchDB</a> implementation.</p>
<h2>State of Play</h2>
<p>The lecture is over and we finished the project. We have decided to put the source code on github:
<a href="https://github.com/manuel_mauky/schachzwo-online">https://github.com/manuel_mauky/schachzwo-online</a> and you can play the game
online at: <a href="http://schachzwo.inf.hszg.de">http://schachzwo.inf.hszg.de</a>.</p>
<p>Please note that this was the first Node.JS project for all of us. We aren't pros and we hadn't had much time to finish
this project so the source code will probably not be high quality. But of cause we always like to learn: When you have
suggestions on what we can do better please tell us!</p>
<p>Also note that the game is sort of a prototype. We hadn't had the time to do much quality assurance and testing so it's
best to see the hostet version as sort of a "BETA". When you find bugs please report them on github:
<a href="https://github.com/manuel_mauky/schachzwo-online/issues">https://github.com/manuel_mauky/schachzwo-online/issues</a>.</p>]]></description>
            <content:encoded><![CDATA[<p>In the lecture "XML based applications" at the <a href="http://www.hszg.de/f-ei">HSZG</a> we were working on a project called
"SchachZWO Online". "Schach" is the german word for "chess" and "ZWO" is another word for "two" so (as you can guess)
this is a chess like online game.</p>
<h2>SchachZWO (offline)</h2>
<p><img src="http://www.schachzwo.de/wp-content/uploads/2013/12/9x9-front-slide.jpg" alt="screenshot from the official website"></p>
<p>The basic for the project is a board game that a game author from dresden has developed. In his "SchachZWO" you play on
a 7x7 or 9x9 board with some special figures: Instead of the rook and the queen you have the "Mann" (man) and "Frau"
(woman). Instead of the pawn you have the "Rocks" and instead of the king you have the "Zenit" (zenith). On the 9x9
board you have two additional figures with special movement capabilities: The "Wissen" (knowledge) and the "Glauben"
(faith).</p>
<p>One of the main differences between chess and "SchachZWO" is that there are more than one possibilities to win the game.
Beside the classical chess mate you win when you move your zenith to the middle field of the board. Only the zenith can
step on this field in the middle, all other figures aren't allowed to step on the field.</p>
<p>In the first place this rules might sound a little strange to you but it's realy fun to play the game. At the moment the
board game isn't available for buying but it will be in the near future. Fisit the website of the game author when you
like to know more: <a href="http://www.schachzwo.de/">http://www.schachzwo.de</a>.</p>
<h2>SchachZWO Online</h2>
<p><img src="https://github.com/manuel_mauky/schachzwo-online/raw/master/screenshot_schachzwo.png" alt="screenshot"></p>
<p>Our project for the lecture was to create an online multiplayer browser game version of this game. In the client we used
<a href="https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial">HTML5 canvas</a> together with
<a href="https://jquery.com/">JQuery</a> to draw the board and the figures. To create a modern Single-Page-Application we used
<a href="https://angularjs.org/">Angular.JS</a> and <a href="http://requirejs.org/">Require.JS</a> in the client.</p>
<p>On the server side we have a <a href="http://nodejs.org/">node.js</a> together with <a href="http://expressjs.com/">express.js</a>. There are
REST like webservices where the client can GET the current state of the board and can POST new moves.</p>
<p>To tell the client that the opponent has done a move we use
<a href="https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events">Server-Sent Events</a> to send
messages. The database connection was created in a generic manner to be able to replace the database implementation. At
the moment we have a <a href="http://www.mongodb.org/">MongoDB</a> and <a href="https://couchdb.apache.org/">CouchDB</a> implementation.</p>
<h2>State of Play</h2>
<p>The lecture is over and we finished the project. We have decided to put the source code on github:
<a href="https://github.com/manuel_mauky/schachzwo-online">https://github.com/manuel_mauky/schachzwo-online</a> and you can play the game
online at: <a href="http://schachzwo.inf.hszg.de">http://schachzwo.inf.hszg.de</a>.</p>
<p>Please note that this was the first Node.JS project for all of us. We aren't pros and we hadn't had much time to finish
this project so the source code will probably not be high quality. But of cause we always like to learn: When you have
suggestions on what we can do better please tell us!</p>
<p>Also note that the game is sort of a prototype. We hadn't had the time to do much quality assurance and testing so it's
best to see the hostet version as sort of a "BETA". When you find bugs please report them on github:
<a href="https://github.com/manuel_mauky/schachzwo-online/issues">https://github.com/manuel_mauky/schachzwo-online/issues</a>.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Advanced-Bindings for JavaFX]]></title>
            <link>https://www.lestard.eu/2014/advanced-bindings/</link>
            <guid>https://www.lestard.eu/2014/advanced-bindings/</guid>
            <pubDate>Thu, 26 Jun 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>I'm a big fan of JavaFX's Properties and Data-Bindings. In my opinion, one of the most interesting part of the data
binding capabilities of JavaFX is that you can create a binding that represents a calculation of values. For example you
can create a binding that represents the addition of two integer properties:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javafx<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>binding<span class="token punctuation">.</span></span><span class="token class-name">Bindings</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token keyword">static</span> <span class="token import static"><span class="token namespace">eu<span class="token punctuation">.</span>lestard<span class="token punctuation">.</span>assertj<span class="token punctuation">.</span>javafx<span class="token punctuation">.</span>api<span class="token punctuation">.</span></span><span class="token class-name">Assertions</span><span class="token punctuation">.</span><span class="token static">assertThat</span></span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token annotation punctuation">@Test</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">IntegerProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">IntegerProperty</span> b <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">NumberBinding</span> c <span class="token operator">=</span> <span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>


    <span class="token function">assertThat</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">42</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    a<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">assertThat</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>There are binding method for basic operations like
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#add-double-javafx.beans.value.ObservableNumberValue-">add</a>,
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#subtract-double-javafx.beans.value.ObservableNumberValue-">subtract</a>,
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#multiply-javafx.beans.value.ObservableNumberValue-int-">multiply</a>,
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#divide-javafx.beans.value.ObservableNumberValue-javafx.beans.value.ObservableNumberValue-">divide</a>.
But what if you need some more specific operations like exponentiation or sine?</p>
<p>To fill this gap I have created a library called "<a href="https://github.com/manuel_mauky/advanced-bindings">advanced-bindings</a>"
that will become a collection of custom bindings that are needed to create application logic with data bindings. The
first step was to create binding implementations for all methods of
<a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">java.lang.Math</a>. This way you can do stuff like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token annotation punctuation">@Test</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testPow</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token class-name">DoubleProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDoubleProperty</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">DoubleProperty</span> b <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDoubleProperty</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">final</span> <span class="token class-name">DoubleBinding</span> pow <span class="token operator">=</span> <span class="token class-name">MathBindings</span><span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 3^2 = 9</span>
    <span class="token function">assertThat</span><span class="token punctuation">(</span>pow<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">9.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    a<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    b<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 5^3 = 125</span>
    <span class="token function">assertThat</span><span class="token punctuation">(</span>pow<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">125.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>In the future I will add more useful helpers and custom bindings. If you have ideas feel free to add an
<a href="https://github.com/manuel_mauky/advanced-bindings/issues">issue at github</a>.</p>
<p>I have uploaded the library to
<a href="http://search.maven.org/#artifactdetails%7Ceu.lestard%7Cadvanced-bindings%7C0.1.0%7Cjar">maven-central</a> so you can use it with
Gradle:</p>
<div class="gatsby-highlight" data-language="groovy"><pre class="language-groovy"><code class="language-groovy">compile <span class="token string">'eu.lestard:advanced-bindings:0.1.0'</span></code></pre></div>
<p>or with Maven:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>eu.lestard<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>advanced-bindings<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>0.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></code></pre></div>]]></description>
            <content:encoded><![CDATA[<p>I'm a big fan of JavaFX's Properties and Data-Bindings. In my opinion, one of the most interesting part of the data
binding capabilities of JavaFX is that you can create a binding that represents a calculation of values. For example you
can create a binding that represents the addition of two integer properties:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">javafx<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>binding<span class="token punctuation">.</span></span><span class="token class-name">Bindings</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token keyword">static</span> <span class="token import static"><span class="token namespace">eu<span class="token punctuation">.</span>lestard<span class="token punctuation">.</span>assertj<span class="token punctuation">.</span>javafx<span class="token punctuation">.</span>api<span class="token punctuation">.</span></span><span class="token class-name">Assertions</span><span class="token punctuation">.</span><span class="token static">assertThat</span></span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token annotation punctuation">@Test</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">IntegerProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">IntegerProperty</span> b <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleIntegerProperty</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token class-name">NumberBinding</span> c <span class="token operator">=</span> <span class="token class-name">Bindings</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>


    <span class="token function">assertThat</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">42</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    a<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">assertThat</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>There are binding method for basic operations like
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#add-double-javafx.beans.value.ObservableNumberValue-">add</a>,
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#subtract-double-javafx.beans.value.ObservableNumberValue-">subtract</a>,
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#multiply-javafx.beans.value.ObservableNumberValue-int-">multiply</a>,
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/binding/Bindings.html#divide-javafx.beans.value.ObservableNumberValue-javafx.beans.value.ObservableNumberValue-">divide</a>.
But what if you need some more specific operations like exponentiation or sine?</p>
<p>To fill this gap I have created a library called "<a href="https://github.com/manuel_mauky/advanced-bindings">advanced-bindings</a>"
that will become a collection of custom bindings that are needed to create application logic with data bindings. The
first step was to create binding implementations for all methods of
<a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">java.lang.Math</a>. This way you can do stuff like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token annotation punctuation">@Test</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testPow</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token class-name">DoubleProperty</span> a <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDoubleProperty</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">DoubleProperty</span> b <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDoubleProperty</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">final</span> <span class="token class-name">DoubleBinding</span> pow <span class="token operator">=</span> <span class="token class-name">MathBindings</span><span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 3^2 = 9</span>
    <span class="token function">assertThat</span><span class="token punctuation">(</span>pow<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">9.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    a<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    b<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 5^3 = 125</span>
    <span class="token function">assertThat</span><span class="token punctuation">(</span>pow<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">125.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>In the future I will add more useful helpers and custom bindings. If you have ideas feel free to add an
<a href="https://github.com/manuel_mauky/advanced-bindings/issues">issue at github</a>.</p>
<p>I have uploaded the library to
<a href="http://search.maven.org/#artifactdetails%7Ceu.lestard%7Cadvanced-bindings%7C0.1.0%7Cjar">maven-central</a> so you can use it with
Gradle:</p>
<div class="gatsby-highlight" data-language="groovy"><pre class="language-groovy"><code class="language-groovy">compile <span class="token string">'eu.lestard:advanced-bindings:0.1.0'</span></code></pre></div>
<p>or with Maven:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>eu.lestard<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>advanced-bindings<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>0.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></code></pre></div>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[ColorPuzzleFX]]></title>
            <link>https://www.lestard.eu/2014/colorpuzzlefx/</link>
            <guid>https://www.lestard.eu/2014/colorpuzzlefx/</guid>
            <pubDate>Mon, 09 Jun 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Again, I have rewritten one of my old games with JavaFX. This time I've created a JavaFX version of my old java swing
game <a href="/projects/colorpuzzle">ColorPuzzle</a> (yes I know, the name isn't very creative).</p>
<p><img src="https://raw.githubusercontent.com/lestard/ColorPuzzleFX/master/screenshot.png" alt="screenshot of the game"></p>
<p>The game mechanics are the same: You can switch the color of all fields under your control. Everytime you are switching
the active color, all fields in the direct neighbourhood of your own fields with that same color are going under your
control from now on. The goal is to bring all fields under your control with the fewest moves.</p>
<p>Before you ask: Yes, the game idea is not my invention, there are <a href="http://floodit.appspot.com/">many</a>
<a href="https://itunes.apple.com/us/app/paint-attack-everyones-favorite/id375374377?mt=8">games</a>
<a href="https://play.google.com/store/apps/details?id=com.labpixies.flood">of</a>
<a href="http://www.clixsense.com/en/Games/Puzzles/0/1086/Flood_it!">this</a> type out there and my version is only a clone. I
create games only because programming is fun and not to become the best game inventor :-)</p>
<p>The code is available on github: <a href="https://github.com/manuel_mauky/ColorPuzzleFX">https://github.com/manuel_mauky/ColorPuzzleFX</a>.</p>
<h3>Grid Component</h3>
<p>While the development of the game I have encapsulated the logic for manipulating and drawing the grid and extracted it
into it's own component. This way I was able to reuse the grid logic for other projects like
<a href="/projects/snakefx">SnakeFX</a>.</p>
<p>You can view the code for this grid component on github too
(<a href="https://github.com/manuel_mauky/Grid">https://github.com/manuel_mauky/Grid</a>) but it's not intended for wide usage at the moment
as documentation and testing far from production ready. It's more like a playground for me.</p>
<p>In another post I will describe the idea behind the grid component in more detail.</p>
<h3>MvvmFX</h3>
<p>Another reason to build the game was to create a simple example for our own UI framework <a href="/projects/mvvmfx">MvvmFX</a>.</p>]]></description>
            <content:encoded><![CDATA[<p>Again, I have rewritten one of my old games with JavaFX. This time I've created a JavaFX version of my old java swing
game <a href="/projects/colorpuzzle">ColorPuzzle</a> (yes I know, the name isn't very creative).</p>
<p><img src="https://raw.githubusercontent.com/lestard/ColorPuzzleFX/master/screenshot.png" alt="screenshot of the game"></p>
<p>The game mechanics are the same: You can switch the color of all fields under your control. Everytime you are switching
the active color, all fields in the direct neighbourhood of your own fields with that same color are going under your
control from now on. The goal is to bring all fields under your control with the fewest moves.</p>
<p>Before you ask: Yes, the game idea is not my invention, there are <a href="http://floodit.appspot.com/">many</a>
<a href="https://itunes.apple.com/us/app/paint-attack-everyones-favorite/id375374377?mt=8">games</a>
<a href="https://play.google.com/store/apps/details?id=com.labpixies.flood">of</a>
<a href="http://www.clixsense.com/en/Games/Puzzles/0/1086/Flood_it!">this</a> type out there and my version is only a clone. I
create games only because programming is fun and not to become the best game inventor :-)</p>
<p>The code is available on github: <a href="https://github.com/manuel_mauky/ColorPuzzleFX">https://github.com/manuel_mauky/ColorPuzzleFX</a>.</p>
<h3>Grid Component</h3>
<p>While the development of the game I have encapsulated the logic for manipulating and drawing the grid and extracted it
into it's own component. This way I was able to reuse the grid logic for other projects like
<a href="/projects/snakefx">SnakeFX</a>.</p>
<p>You can view the code for this grid component on github too
(<a href="https://github.com/manuel_mauky/Grid">https://github.com/manuel_mauky/Grid</a>) but it's not intended for wide usage at the moment
as documentation and testing far from production ready. It's more like a playground for me.</p>
<p>In another post I will describe the idea behind the grid component in more detail.</p>
<h3>MvvmFX</h3>
<p>Another reason to build the game was to create a simple example for our own UI framework <a href="/projects/mvvmfx">MvvmFX</a>.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[AssertJ-JavaFX]]></title>
            <link>https://www.lestard.eu/2014/assertj-javafx/</link>
            <guid>https://www.lestard.eu/2014/assertj-javafx/</guid>
            <pubDate>Sat, 31 May 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>As you probably already know I'm a big fan of the <a href="https://joel-costigliola.github.io/assertj/">AssertJ</a> library. That's
the reason I've done a <a href="/2014/juggr-assertj">talk about it at the JavaUserGroup Görlitz</a>.</p>
<p>I like the way you can write readable unit tests and are supported by the IDE because AssertJ is implemented as a
<a href="https://en.wikipedia.org/wiki/Fluent_interface">Fluent-API</a>.</p>
<p>In the past weeks I've written a package of assertions specially for JavaFX. With this assertions you can verify the
values of JavaFX Properties and Bindings.</p>
<p>With the normal AssertJ you would write something like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">DoubleProperty</span> x <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDoubleProperty</span><span class="token punctuation">(</span><span class="token number">10.13</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token function">assertThat</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isEqualTo</span><span class="token punctuation">(</span><span class="token number">10.13</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>With my extensions you don't need to call the <code class="language-text">.get()</code> all the time. Instead you can write:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token function">assertThat</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">10.13</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<h2>Project Info</h2>
<p>The project is hosted on github: <a href="https://github.com/manuel_mauky/assertj-javafx">https://github.com/manuel_mauky/assertj-javafx</a>.</p>
<p>I've already uploaded it to maven central so you can use it with gradle:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">testCompile 'eu.lestard:assertj-javafx:0.1.0'</code></pre></div>
<p>or maven:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>eu.lestard<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>assertj-javafx<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>0.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></code></pre></div>
<p>Tell me what you think. If you have ideas for new assertions that could be added feel free to add an issue in the
<a href="https://github.com/manuel_mauky/assertj-javafx/issues">issue tracker</a>.</p>]]></description>
            <content:encoded><![CDATA[<p>As you probably already know I'm a big fan of the <a href="https://joel-costigliola.github.io/assertj/">AssertJ</a> library. That's
the reason I've done a <a href="/2014/juggr-assertj">talk about it at the JavaUserGroup Görlitz</a>.</p>
<p>I like the way you can write readable unit tests and are supported by the IDE because AssertJ is implemented as a
<a href="https://en.wikipedia.org/wiki/Fluent_interface">Fluent-API</a>.</p>
<p>In the past weeks I've written a package of assertions specially for JavaFX. With this assertions you can verify the
values of JavaFX Properties and Bindings.</p>
<p>With the normal AssertJ you would write something like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name">DoubleProperty</span> x <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDoubleProperty</span><span class="token punctuation">(</span><span class="token number">10.13</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token function">assertThat</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isEqualTo</span><span class="token punctuation">(</span><span class="token number">10.13</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>With my extensions you don't need to call the <code class="language-text">.get()</code> all the time. Instead you can write:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token function">assertThat</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hasValue</span><span class="token punctuation">(</span><span class="token number">10.13</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<h2>Project Info</h2>
<p>The project is hosted on github: <a href="https://github.com/manuel_mauky/assertj-javafx">https://github.com/manuel_mauky/assertj-javafx</a>.</p>
<p>I've already uploaded it to maven central so you can use it with gradle:</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">testCompile 'eu.lestard:assertj-javafx:0.1.0'</code></pre></div>
<p>or maven:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>eu.lestard<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>assertj-javafx<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>0.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></code></pre></div>
<p>Tell me what you think. If you have ideas for new assertions that could be added feel free to add an issue in the
<a href="https://github.com/manuel_mauky/assertj-javafx/issues">issue tracker</a>.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[MvvmFX article in JavaMagazin]]></title>
            <link>https://www.lestard.eu/2014/mvvmfx_javamag/</link>
            <guid>https://www.lestard.eu/2014/mvvmfx_javamag/</guid>
            <pubDate>Wed, 07 May 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>In the <a href="https://jaxenter.de/Java-Magazin/Java-Magazin-614-173015">JavaMagazin 06/2014</a> there is an article about
<a href="/projects/mvvmfx">MvvmFX</a> written by <a href="http://www.alexander-casall.de/">Alex</a> and me.</p>
<p>In this article we describe the design pattern Model-View-ViewModel and show how you can apply it to your application
with our framework <a href="https://github.com/sialcasa/mvvmFX">MvvmFX</a>.</p>
<p>Additionally we were showing some of the internals of JavaFX and MvvmFX. For example I'm describing how the loading of
FXML files is done in JavaFX and how we hook up into this process to enable the usage of
<a href="https://github.com/sialcasa/mvvmFX/wiki/Dependency-Injection">Dependency Injection</a> frameworks.</p>
<p>Another part of the article is the combination of MvvmFX and <a href="/projects/synchronizefx">SynchronizeFX</a> and how we are
using it in our own applications at Saxonia Systems.</p>]]></description>
            <content:encoded><![CDATA[<p>In the <a href="https://jaxenter.de/Java-Magazin/Java-Magazin-614-173015">JavaMagazin 06/2014</a> there is an article about
<a href="/projects/mvvmfx">MvvmFX</a> written by <a href="http://www.alexander-casall.de/">Alex</a> and me.</p>
<p>In this article we describe the design pattern Model-View-ViewModel and show how you can apply it to your application
with our framework <a href="https://github.com/sialcasa/mvvmFX">MvvmFX</a>.</p>
<p>Additionally we were showing some of the internals of JavaFX and MvvmFX. For example I'm describing how the loading of
FXML files is done in JavaFX and how we hook up into this process to enable the usage of
<a href="https://github.com/sialcasa/mvvmFX/wiki/Dependency-Injection">Dependency Injection</a> frameworks.</p>
<p>Another part of the article is the combination of MvvmFX and <a href="/projects/synchronizefx">SynchronizeFX</a> and how we are
using it in our own applications at Saxonia Systems.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[JUG-GR: Better readable unit tests with AssertJ]]></title>
            <link>https://www.lestard.eu/2014/juggr-assertj/</link>
            <guid>https://www.lestard.eu/2014/juggr-assertj/</guid>
            <pubDate>Tue, 01 Apr 2014 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Last week I gave a talk about <a href="http://www.jug-gr.de/2014/04/02/assertj.html">better readable unit tests with AssertJ</a> at
the <a href="http://www.jug-gr.de/">Java User Group Görlitz</a>.</p>
<p>I talked about the benifit of readable unit tests and what frameworks there are for java developers to archive good unit
tests.</p>
<p>One of the main elements of unit tests are assertions. In JUnit we have the static methods <code class="language-text">assertEquals</code>,
<code class="language-text">assertNotNull</code> and so on. But these aren't making a good job when it comes to easy readable code. A better readable way
is to use the <code class="language-text">assertThat</code> method that comes with <em>Hamcrest</em> and is also part of the latest JUnit versions.</p>
<p>The problem with Hamcrest is that it is created out of many static methods which has several drawbacks. The biggest one
is the bad IDE support.</p>
<p>In the talk I showed the framework <a href="https://joel-costigliola.github.io/assertj/">AssertJ</a> which is an alternative to
hamcrest. It also uses a static <code class="language-text">assertThat</code> method as the entry point to an assertion but the rest of the API is
implemented as a fluent-API. This way the IDE is able to give suggestions of possible assertion methods based on the
type that was given as argument to the <code class="language-text">assertThat</code> method. Look at the following example:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java">    <span class="token class-name">String</span> message <span class="token operator">=</span> <span class="token string">"hello world, manuel"</span><span class="token punctuation">;</span>

    <span class="token function">assertThat</span><span class="token punctuation">(</span>message<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isNotEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">"hello"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">endsWith</span><span class="token punctuation">(</span><span class="token string">"manuel"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>With this example the IDE knows that 'message' is of type String and it can only suggest assertions that are making
sense for strings like <code class="language-text">startsWith</code> or <code class="language-text">endsWith</code>. For a parameter of type integer the IDE would instead suggest
assertions like <code class="language-text">isPositive</code> or <code class="language-text">isBetween(int start, int end)</code>.</p>
<p>I realy love this style of writing unit tests. In the talk I gave some other interesting examples of what AssertJ can do
for you.</p>]]></description>
            <content:encoded><![CDATA[<p>Last week I gave a talk about <a href="http://www.jug-gr.de/2014/04/02/assertj.html">better readable unit tests with AssertJ</a> at
the <a href="http://www.jug-gr.de/">Java User Group Görlitz</a>.</p>
<p>I talked about the benifit of readable unit tests and what frameworks there are for java developers to archive good unit
tests.</p>
<p>One of the main elements of unit tests are assertions. In JUnit we have the static methods <code class="language-text">assertEquals</code>,
<code class="language-text">assertNotNull</code> and so on. But these aren't making a good job when it comes to easy readable code. A better readable way
is to use the <code class="language-text">assertThat</code> method that comes with <em>Hamcrest</em> and is also part of the latest JUnit versions.</p>
<p>The problem with Hamcrest is that it is created out of many static methods which has several drawbacks. The biggest one
is the bad IDE support.</p>
<p>In the talk I showed the framework <a href="https://joel-costigliola.github.io/assertj/">AssertJ</a> which is an alternative to
hamcrest. It also uses a static <code class="language-text">assertThat</code> method as the entry point to an assertion but the rest of the API is
implemented as a fluent-API. This way the IDE is able to give suggestions of possible assertion methods based on the
type that was given as argument to the <code class="language-text">assertThat</code> method. Look at the following example:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java">    <span class="token class-name">String</span> message <span class="token operator">=</span> <span class="token string">"hello world, manuel"</span><span class="token punctuation">;</span>

    <span class="token function">assertThat</span><span class="token punctuation">(</span>message<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isNotEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">"hello"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">endsWith</span><span class="token punctuation">(</span><span class="token string">"manuel"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>With this example the IDE knows that 'message' is of type String and it can only suggest assertions that are making
sense for strings like <code class="language-text">startsWith</code> or <code class="language-text">endsWith</code>. For a parameter of type integer the IDE would instead suggest
assertions like <code class="language-text">isPositive</code> or <code class="language-text">isBetween(int start, int end)</code>.</p>
<p>I realy love this style of writing unit tests. In the talk I gave some other interesting examples of what AssertJ can do
for you.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[SnakeFX]]></title>
            <link>https://www.lestard.eu/2013/snakefx/</link>
            <guid>https://www.lestard.eu/2013/snakefx/</guid>
            <pubDate>Tue, 10 Dec 2013 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Writing games is a good way of learning a new programming language or framework. I've done this several times in the
past: <a href="2010/snake_js">JavaScript/Snake</a> , <a href="/2010/space_shooter_in_cpp">C++/Space-Shooter</a>,
<a href="/2012/color_puzzle_game">Java2D/ColorGame</a>.</p>
<p>This time I was interested in JavaFX 2 and again I was developing a little game as an example. Again I tried a "snake"
like game as you probably know from old mobile phones. As the player you are controling a Snake that eats food that is
laying around. Everytime you eat something to gather points and grow a little bit. The goal is to gather as many food as
you can without byting yourself in the tail. In my version of the game there are no walls: When you move outside of the
field on the left side you are immediatelly returning on the right side.</p>
<p><img src="https://raw.githubusercontent.com/lestard/SnakeFX/master/screenshot.png" alt="screenshot"></p>
<p>The development started in october 2012 with some experiments with JavaFX, FXML and dependency injection. The first
version of the game was based on maven and javaFX version 2. In november 2012 the first version of the game was ready.
It was based on maven and JavaFX in version 2. The dependency injection was implemented by hand without a DI framework.</p>
<p>After a long pause with no coding in may 2013 I returned to the project and started with a big refactoring. The code
wasn't realy nice and the coupling between the components of the game was relatively tight. The idea of the refactoring
was to encapsulate the state of the UI in a <strong>ViewModel</strong>. Another change was the usage of JSON for persisting
highscores instead of CSV. This way I was able to remove a lot of code for CSV parsing.</p>
<p>In november 2013 again I made some changes to the game after another pause. The biggest change is the use of <strong>Gradle</strong>
as build system instead of maven. I also done a big refactoring of the dependency injection system and simplified the
code of the program. Another big simplification was the usage of <strong>Java 8</strong> instead of Java 7.</p>
<p>The code of the game can be found on github: <a href="https://github.com/manuel_mauky/snakefx">https://github.com/manuel_mauky/snakefx</a></p>]]></description>
            <content:encoded><![CDATA[<p>Writing games is a good way of learning a new programming language or framework. I've done this several times in the
past: <a href="2010/snake_js">JavaScript/Snake</a> , <a href="/2010/space_shooter_in_cpp">C++/Space-Shooter</a>,
<a href="/2012/color_puzzle_game">Java2D/ColorGame</a>.</p>
<p>This time I was interested in JavaFX 2 and again I was developing a little game as an example. Again I tried a "snake"
like game as you probably know from old mobile phones. As the player you are controling a Snake that eats food that is
laying around. Everytime you eat something to gather points and grow a little bit. The goal is to gather as many food as
you can without byting yourself in the tail. In my version of the game there are no walls: When you move outside of the
field on the left side you are immediatelly returning on the right side.</p>
<p><img src="https://raw.githubusercontent.com/lestard/SnakeFX/master/screenshot.png" alt="screenshot"></p>
<p>The development started in october 2012 with some experiments with JavaFX, FXML and dependency injection. The first
version of the game was based on maven and javaFX version 2. In november 2012 the first version of the game was ready.
It was based on maven and JavaFX in version 2. The dependency injection was implemented by hand without a DI framework.</p>
<p>After a long pause with no coding in may 2013 I returned to the project and started with a big refactoring. The code
wasn't realy nice and the coupling between the components of the game was relatively tight. The idea of the refactoring
was to encapsulate the state of the UI in a <strong>ViewModel</strong>. Another change was the usage of JSON for persisting
highscores instead of CSV. This way I was able to remove a lot of code for CSV parsing.</p>
<p>In november 2013 again I made some changes to the game after another pause. The biggest change is the use of <strong>Gradle</strong>
as build system instead of maven. I also done a big refactoring of the dependency injection system and simplified the
code of the program. Another big simplification was the usage of <strong>Java 8</strong> instead of Java 7.</p>
<p>The code of the game can be found on github: <a href="https://github.com/manuel_mauky/snakefx">https://github.com/manuel_mauky/snakefx</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Datenpannen-Kalkulator]]></title>
            <link>https://www.lestard.eu/2013/datenpannen_kalkulator/</link>
            <guid>https://www.lestard.eu/2013/datenpannen_kalkulator/</guid>
            <pubDate>Sun, 01 Dec 2013 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>For the lecture "IT security management" at the university my fellow students and me have developed a programm called
"Datenpannen-Kalkulator". "Datenpanne" is the german word for "data loss" and means that you have lost some of your or
your companies data.</p>
<p>The programm calculates the costs of losing data or virus infections in your company based on some parameters like the
number of affected clients or your industrial sector. The calculation is based on existing statistics in which companies
were asked about the costs that were caused by security incidents.</p>
<p><img src="/files/pics/2013/datenpannen-calculator.png" alt="screenshot"></p>
<p>While it's obvious that the frontend of the application was developed with JavaFX (and the help of Afterburner.fx) the
calculation logic is done with JavaFX too. All calculations were implemented with JavaFX's properties and databinding
capabilities. At first this programming style is a little bit unusual because typically as a java delevoper you are used
to implement calculations in an imperative style.</p>
<p>But this style of programming has lots of advantages: It's relativelly easy to implement a "reactive" user interface.
The calculation logic is based on properties that are bound to the values of the input fields and the charts that are
visualizing the result are bound to the result properties. This means that a change in the input fields immediately
leads to a change of the calculated result values and this leads to an update of the displayed chart data. There is no
need for a "calculate" or "update" button. It's all done automatically.</p>
<p>The code of this project can be found on github:
<a href="https://github.com/manuel_mauky/datenpannen-calculator">https://github.com/manuel_mauky/datenpannen-calculator</a></p>]]></description>
            <content:encoded><![CDATA[<p>For the lecture "IT security management" at the university my fellow students and me have developed a programm called
"Datenpannen-Kalkulator". "Datenpanne" is the german word for "data loss" and means that you have lost some of your or
your companies data.</p>
<p>The programm calculates the costs of losing data or virus infections in your company based on some parameters like the
number of affected clients or your industrial sector. The calculation is based on existing statistics in which companies
were asked about the costs that were caused by security incidents.</p>
<p><img src="/files/pics/2013/datenpannen-calculator.png" alt="screenshot"></p>
<p>While it's obvious that the frontend of the application was developed with JavaFX (and the help of Afterburner.fx) the
calculation logic is done with JavaFX too. All calculations were implemented with JavaFX's properties and databinding
capabilities. At first this programming style is a little bit unusual because typically as a java delevoper you are used
to implement calculations in an imperative style.</p>
<p>But this style of programming has lots of advantages: It's relativelly easy to implement a "reactive" user interface.
The calculation logic is based on properties that are bound to the values of the input fields and the charts that are
visualizing the result are bound to the result properties. This means that a change in the input fields immediately
leads to a change of the calculated result values and this leads to an update of the displayed chart data. There is no
need for a "calculate" or "update" button. It's all done automatically.</p>
<p>The code of this project can be found on github:
<a href="https://github.com/manuel_mauky/datenpannen-calculator">https://github.com/manuel_mauky/datenpannen-calculator</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Mvvm with JavaFX in JavaMagazin by Alex]]></title>
            <link>https://www.lestard.eu/2013/mvvmfx_javamag_alex/</link>
            <guid>https://www.lestard.eu/2013/mvvmfx_javamag_alex/</guid>
            <pubDate>Thu, 28 Nov 2013 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>For the <a href="https://jaxenter.de/Java-Magazin/Java-Magazin-1113-167769">JavaMagazin 11/2013</a>
<a href="http://www.alexander-casall.de/">Alex</a> has written an article that describes some of the thoughts he had when he
initiated the <a href="/2013/mvvmfx/">mvvm-fx</a> library that I'm working on too. He shows how you can implement the MVVM design
pattern with JavaFX in a test-driven way. The code isn't specific to the mvvmfx library but shows the basic ideas of the
pattern.</p>]]></description>
            <content:encoded><![CDATA[<p>For the <a href="https://jaxenter.de/Java-Magazin/Java-Magazin-1113-167769">JavaMagazin 11/2013</a>
<a href="http://www.alexander-casall.de/">Alex</a> has written an article that describes some of the thoughts he had when he
initiated the <a href="/2013/mvvmfx/">mvvm-fx</a> library that I'm working on too. He shows how you can implement the MVVM design
pattern with JavaFX in a test-driven way. The code isn't specific to the mvvmfx library but shows the basic ideas of the
pattern.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[MvvmFX]]></title>
            <link>https://www.lestard.eu/2013/mvvmfx/</link>
            <guid>https://www.lestard.eu/2013/mvvmfx/</guid>
            <pubDate>Wed, 27 Nov 2013 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Today I like to introduce <a href="/2013/synchronizefx/">another</a> open source library that my workmate
<a href="http://www.alexander-casall.de/">Alexander Casall</a> an me are creating at Saxonia Systems. Alex had the idea to try out
the design pattern <a href="https://en.wikipedia.org/wiki/MVVM">"Model-View-ViewModel"</a> that was created by Microsoft engineers
for <a href="https://en.wikipedia.org/wiki/Windows_Presentation_Foundation">Windows Presentation Foundation (WPF)</a> and
<a href="https://en.wikipedia.org/wiki/Extensible_Application_Markup_Language">XAML</a> and that is also used by some JavaScript
frameworks like <a href="http://knockoutjs.com/">KnockoutJS</a>.</p>
<p>The design pattern uses some technical capabilities of a modern UI technolgy like (bi-directional) data-binding and
descriptive UI declaration to simplify the development of the UI and to make testing UI code easier.</p>
<p>JavaFX in version 2 supports both of these capabilities: It includes Properties and Data-Bindings and FXML, a xml
dialect to create the UI for JavaFX.</p>
<p>At the moment our MvvmFX-library is at the very beginnning. We are trying out what is possible and what is not. We would
be very pleased if you like to give it a try. You can find it on github:
<a href="https://github.com/sialcasa/mvvmFX">https://github.com/sialcasa/mvvmFX</a></p>
<h3>The MVVM Design Pattern</h3>
<p>Let's start with the <em>View</em>. With MVVM the view has to be silly. It may not contain any logic but only describe what is
visible in the UI.</p>
<p>The UI specific logic is developed only in the <em>ViewModel</em>. The viewmodel contains the whole state of the UI and the
logic that updates and changes this state. It provides the state to the outside in the form of <em>Properties</em>.</p>
<p>The view can now bind itself to the properties of the ViewModel. When the state of the viewmodel changes the view is
automatically updated because of the binding.</p>
<p>The viewmodel knows the <em>model</em>. How exactly the model is created isn't part of the MVVM pattern. It is the interface to
the business logic and the rest of the application. The viewmodel takes the informations that are needed to be presented
in the view from the model and brings that informations in the right form in which the view needs them.</p>
<p>A common example is a UI that should show the name of a person. The model has <code class="language-text">Person</code> instances that are containing
string variables for "forname" and "surname". In the UI you are expecting this informations to be presented in a nice
way. The viewmodel would take the person instance and concatenate the for- and surname to one single string that is
provided as a property "name". The view has a label that's textProperty is bound to the name property of the viewModel.</p>
<p>The design pattern defines a strict top-down visibility for the components. The View knows the ViewModel. The ViewModel
knows the Model but not the View. And the Model knows neither the View nor the ViewModel.</p>
<h3>Testing</h3>
<p>What is really cool about this design pattern is that the whole UI specific logic is only located in the viewmodel.
Conditions like "Is the button x disabled or enabled?" are developed in the viewmodel. The view doesn't know about this
conditions. It only knows that there is a button and that it's visibility property is bound to a boolean property in the
viewmodel. The view doesn't care about under which conditions this boolean property is true or false.</p>
<p>This enables you to unit-test your UI logic. The viewmodel is only a simple Java class. You don't need to boot-up the
whole application to perform difficult UI integration tests. JUnit is all you need.</p>]]></description>
            <content:encoded><![CDATA[<p>Today I like to introduce <a href="/2013/synchronizefx/">another</a> open source library that my workmate
<a href="http://www.alexander-casall.de/">Alexander Casall</a> an me are creating at Saxonia Systems. Alex had the idea to try out
the design pattern <a href="https://en.wikipedia.org/wiki/MVVM">"Model-View-ViewModel"</a> that was created by Microsoft engineers
for <a href="https://en.wikipedia.org/wiki/Windows_Presentation_Foundation">Windows Presentation Foundation (WPF)</a> and
<a href="https://en.wikipedia.org/wiki/Extensible_Application_Markup_Language">XAML</a> and that is also used by some JavaScript
frameworks like <a href="http://knockoutjs.com/">KnockoutJS</a>.</p>
<p>The design pattern uses some technical capabilities of a modern UI technolgy like (bi-directional) data-binding and
descriptive UI declaration to simplify the development of the UI and to make testing UI code easier.</p>
<p>JavaFX in version 2 supports both of these capabilities: It includes Properties and Data-Bindings and FXML, a xml
dialect to create the UI for JavaFX.</p>
<p>At the moment our MvvmFX-library is at the very beginnning. We are trying out what is possible and what is not. We would
be very pleased if you like to give it a try. You can find it on github:
<a href="https://github.com/sialcasa/mvvmFX">https://github.com/sialcasa/mvvmFX</a></p>
<h3>The MVVM Design Pattern</h3>
<p>Let's start with the <em>View</em>. With MVVM the view has to be silly. It may not contain any logic but only describe what is
visible in the UI.</p>
<p>The UI specific logic is developed only in the <em>ViewModel</em>. The viewmodel contains the whole state of the UI and the
logic that updates and changes this state. It provides the state to the outside in the form of <em>Properties</em>.</p>
<p>The view can now bind itself to the properties of the ViewModel. When the state of the viewmodel changes the view is
automatically updated because of the binding.</p>
<p>The viewmodel knows the <em>model</em>. How exactly the model is created isn't part of the MVVM pattern. It is the interface to
the business logic and the rest of the application. The viewmodel takes the informations that are needed to be presented
in the view from the model and brings that informations in the right form in which the view needs them.</p>
<p>A common example is a UI that should show the name of a person. The model has <code class="language-text">Person</code> instances that are containing
string variables for "forname" and "surname". In the UI you are expecting this informations to be presented in a nice
way. The viewmodel would take the person instance and concatenate the for- and surname to one single string that is
provided as a property "name". The view has a label that's textProperty is bound to the name property of the viewModel.</p>
<p>The design pattern defines a strict top-down visibility for the components. The View knows the ViewModel. The ViewModel
knows the Model but not the View. And the Model knows neither the View nor the ViewModel.</p>
<h3>Testing</h3>
<p>What is really cool about this design pattern is that the whole UI specific logic is only located in the viewmodel.
Conditions like "Is the button x disabled or enabled?" are developed in the viewmodel. The view doesn't know about this
conditions. It only knows that there is a button and that it's visibility property is bound to a boolean property in the
viewmodel. The view doesn't care about under which conditions this boolean property is true or false.</p>
<p>This enables you to unit-test your UI logic. The viewmodel is only a simple Java class. You don't need to boot-up the
whole application to perform difficult UI integration tests. JUnit is all you need.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[SynchronizeFX article in JavaMagazin]]></title>
            <link>https://www.lestard.eu/2013/synchronizefx_javamag/</link>
            <guid>https://www.lestard.eu/2013/synchronizefx_javamag/</guid>
            <pubDate>Mon, 12 Aug 2013 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>I'm very pleased that an article of my colleagues and me with the title "SynchronizeFX: Remote JavaFX Property Binding"
is released in the <a href="https://jaxenter.de/Java-Magazin/Java-Magazin-813-165099">JavaMagazin 08/2013</a>.</p>
<p><img src="/files/pics/2013/synchronizefx_javamag.png" alt="javamagazin"></p>
<p>In this article we describe the use cases that induced us to create the
<a href="https://github.com/saxsys/SynchronizeFX">SynchonizeFX</a> library and how we are using it in our own product
<a href="http://www.eteoboard.de">eteoBoard</a>. Additionally some of the implementation details are described and of cause a
little how-to is part of the article too.</p>]]></description>
            <content:encoded><![CDATA[<p>I'm very pleased that an article of my colleagues and me with the title "SynchronizeFX: Remote JavaFX Property Binding"
is released in the <a href="https://jaxenter.de/Java-Magazin/Java-Magazin-813-165099">JavaMagazin 08/2013</a>.</p>
<p><img src="/files/pics/2013/synchronizefx_javamag.png" alt="javamagazin"></p>
<p>In this article we describe the use cases that induced us to create the
<a href="https://github.com/saxsys/SynchronizeFX">SynchonizeFX</a> library and how we are using it in our own product
<a href="http://www.eteoboard.de">eteoBoard</a>. Additionally some of the implementation details are described and of cause a
little how-to is part of the article too.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Jax 2013]]></title>
            <link>https://www.lestard.eu/2013/jax2013/</link>
            <guid>https://www.lestard.eu/2013/jax2013/</guid>
            <pubDate>Sun, 26 May 2013 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>This blog post is about my visit at the JAX 2013 in Mainz, one of the biggest Java conferences of europe. As an
exception this time the post is written in german and not english.</p>
<p>In der letzten Woche hatte ich durch meinen <a href="http://www.saxsys.de">Arbeitgeber</a> die Möglichkeit, die JAX 2013, eine der
größten Java-Konverenzen Europas in Mainz zu besuchen. In diesem Blogpost möchte ich über Vorträge berichten, die ich
besucht habe.</p>
<h2>JavaFX</h2>
<h3>Enterprice Anwendungen mit JavaFX (8)</h3>
<p><strong>Adam Bien</strong> berichtete in seinem Vortrag "Enterprice Anwendungen mit JavaFX (8)" recht unterhaltsam von seinen
Erfahrungen mit Enterprice Anwendungen und den Dingen, die bei dieser Klasse von Anwendungen seiner Ansicht nach
relevant sind. Er kam zu dem Schluss, dass hier JavaFX in vielen Fällen eine lohnenswerte Alternative zu den klassischen
Webtechnologien sein kann.</p>
<p>Im Verlauf des Vortrags stellte er anschließend seine Vorstellung davon vor, wie Entwickler Oberflächen mit JavaFX
entwickeln sollten. Trotz anfänglicher Skepsis sieht er vor allem FXML, die XML-Basierte Beschreibungssprache für JavaFX
ab Version 2, als ein sehr gutes Werkzeug an. Mit FXML lässt sich eine Oberfläche deklarativ beschreiben und dynamisch
von JavaFX aus laden. In der FXML-Datei kann der Name einer Controller-Klasse angegeben werden, der dann von JavaFX
automatisch instanziiert wird und der per Dependency Injection die benötigten Referenzen auf UI-Elemente erhält. Adam
Bien sieht hier das Prinzip der Inversion of Control sehr gut umgesetzt.</p>
<p>Da für FXML-Dateien auch ein sehr reichhaltiger und ausgereifter WYSIWYG-Editor namens
<a href="http://www.oracle.com/technetwork/java/javafx/tools/index.html?ssSourceSiteId=ocomen">SceneBuilder</a> existiert, sieht er
diese Vorgehensweise bei der Entwicklung von Desktop-Oberflächen als vorteilhaft an.</p>
<p>Die einzige Lücke, die in diesem Mechanismus noch besteht, ist die Verwendung von echter Dependency Injection für die
Anbindung der Backend-Logik. Der <em>DI</em>-Mechanismus von JavaFX injected nämlich nur UI-Elemente aus der FXML-Datei in den
Controller, andere Abhängigkeiten wie Services werden nicht automatisch eingefügt. Da die Instanziierung des Controllers
ebenfalls von JavaFX übernommen wird, kann der Entwickler auch nicht einfach per händischer Dependency-Injection per
Konstruktor die Abhängigkeiten hineinreichen.</p>
<p>Glücklicherweise ist der <em>DI</em>-Mechanismus von JavaFX relativ leicht erweiterbar und so stellte Adam in seinem Vortrag
auch das von ihm entwickelte Mini-Framework <a href="http://afterburner.adam-bien.com/">Afterburner.fx</a> vor, welches einfache
<em>DI</em> auf simple Art und Weise umsetzt und dabei, wie andere <em>DI</em>-Frameworks auch, die 'javax.inject'-Annotationen
verwendet.</p>
<p>Wer schon immer mal sehen wollte, wie einfach ein <em>DI</em>-Framework sein kann, der sollte sich unbedingt den
<a href="https://github.com/AdamBien/afterburner.fx">Quellcode von Afterburner.fx auf Github</a> anschauen. Das ganze Framework
besteht nämlich nur aus 2 relativ kleinen Klassen.</p>
<h3>JavaFX vs. Html5</h3>
<p>Im Vortrag "JavaFX vs. Html5" zeigt <strong>Björn Müller</strong> einige Anwendungsfälle auf, bei denen HTML5 (in Kombination mit
JavaScript) seiner Ansicht nach nicht die passende UI-Technologie ist, sondern klassische Desktop-Oberflächen besser
geeignet sind. Er bezieht sich vor allem auf große, umfangreiche Business-Applikationen mit umfangreichen Eingabemasken
und mehreren Hundert Screens. Als Beispiele nennt er Anwendungen aus dem Bereich der Logistik und Lagerverwaltung.</p>
<p>Als Gründe nennt er nicht nur die nach wie vor bessere Performance von Desktop-UI's, sondern vor allem die
Entwicklungseffizienz, d.h. wie schnell die Entwickler die entsprechende Funktionalität liefern können.</p>
<p>Als eine mögliche Lösung für die Entwicklung großer Business-Applikationen stellte Björn anschließend das von ihm
entwickelte Framework <a href="http://www.captaincasa.com/">CaptainCasa</a> vor.</p>
<p>CaptainCasa stellt eine Verbindung des UI-Frameworks JavaFX mit dem Serverseitigen Komponenten-Modell von JavaServer
Faces her. Denn obwohl JSF in den meisten Fällen zur Entwicklung von HTML-Oberflächen genutzt wird, ist es prinzipiell
unabhängig von der tatsächlichen benutzten View-Technologie.</p>
<p>Die Serverseite kann damit klassisch mit JavaEE entwickelt werden, die UI wird mittels JSF und einer speziellen
Tag-Library umgesetzt. Auf Client-Seite kommt statt dem Webbrowser jedoch ein JavaFX-Renderer zum Einsatz. Die UI ist
damit nicht fest im Client implementiert sondern wird dynamisch auf Serverseite generiert und mittels eines
XML-Datenaustauschformats zum Client gesendet, welcher aus diesen Informationen die Oberfläche aufbaut. Eingaben des
Nutzers werden auf ähnliche Weise wieder zum Server gesendet und durchlaufen dort den bekannten JSF-Livecycle.</p>
<p>Für Entwickler, die bereits mit JSF zu tun hatten, ist der Lernaufwand deshalb relativ gering. Sie müssen sich nicht mit
den Details von JavaFX ausseinander setzen, sondern können ihre gewohnten Serverseitigen Technologien aus dem
JavaEE-Umfeld einsetzen. Neu ist lediglich die Tag-Library von CaptainCasa, die jedoch vom Prinzip her nicht wesentlich
anders funktioniert, als bekannte JSF-Libraries.</p>
<h3>CustomComponents in JavaFX</h3>
<p><strong>Gerrit Grunwald</strong> stellte in seinem Vortrag das wesentlich von ihm vorangetriebene Projekt
<a href="http://jfxtras.org/">JFXtras</a> vor, welches eine Sammelstelle für JavaFX-Customcontrols darstellt. Er zeigte, welche
Möglichkeiten JavaFX bietet um selbst Controls herzustellen oder vorhandene Controls anzupassen. Dazu zeigte er zunächst
den prinzipiellen Aufbau von JavaFX-Controls, welche Interfaces und Dateien zu einem Control gehören und wie diese
zusammenhängen. Allein dieser Einblick war für mich als Entwickler schon sehr spannend und lehrreich.</p>
<p>Als praktisches Beispiel nutzte er ein Control, welches eine LED-Leuchte darstellen sollte. Zum Erstellen der Grafiken
benutzte er ein Vektorgrafikprogramm, welches SVG exportieren konnte. Die SVG-Datei convertierte er mit einem speziellen
Tool in ein Format, welches direkt von JavaFX dargestellt werden kann und benutzte dieses als grafische Grundlage seines
Controls. Anschließend musste noch die Logik des Controls implementiert werden, was er natürlich mit JavaFX-Bindings
umsetzte.</p>
<h3>OpenDolphin</h3>
<p><strong>Dierk König</strong> hat in seinem Vortrag das von ihm mitentwickelte Framework <a href="http://open-dolphin.org">OpenDolphin</a>
vorgestellt. OpenDolphin ermöglicht es, eine Anwendung nach dem Shared
<a href="http://martinfowler.com/eaaDev/PresentationModel.html">Presentation-Model</a> Muster zu entwickeln. Dabei wird das
Presentation-Model, also sämtliche Daten, die die Benutzeroberfläche beschreiben, auf einem Server gehalten. Die
Oberfläche des Clients verbindet sich mit dem Server und bindet sich direkt an dieses Presentation-Model. Serverseitige
Änderungen an diesem Model sind dann unmittelbar auch auf Clientseite sichtbar. Das gleiche gilt äquivalent auch für
Änderungen des Clients, die sofort zum Server synchronisiert werden.</p>
<p>Werden mehrere Clients mit dem Server verbunden, wird dadurch die UI der Clients untereinander ebenfalls synchron
gehalten.</p>
<p>Dies war für mich auch der Hauptgrund, den Vortrag zu besuchen, da dieses ein ähnlicher Anwendungsfall ist, für den
meine Arbeitskollegen und ich auch unser Framework <a href="https://github.com/saxsys/SynchronizeFX">SynchronizeFX</a> erstellt
haben. In unserer Applikation kommt es ebenfalls auf eine Synchronisierung der UI zwischen mehreren Instanzen an.</p>
<p>Im Detail betrachtet hat OpenDolphin jedoch einen anderen Ansatz. Es lässt sich zwar mit JavaFX verbinden, arbeitet
intern jedoch mit einer eigenen Bindings-Implementierung, während unser Framework ausschließlich mit JavaFX-Bindings
arbeitet.</p>
<p>Während bei unserem Framework der Hauptaugenmerk auf eine einfache Integration in JavaFX-Anwendungen lag, sieht
OpenDolphin eines seiner wesentlichen Ziele darin, die leichte Austauschbarkeit von UI-Technologien zu unterstützen. Da
beim Shared-Presentation-Model die einzige Verbindung zwischen Client und Server das gemeinsame Datenmodell ist, lässt
sich dieses Ziel vergleichsweise gut erreichen.</p>
<p>In der Demo hat er ein Beispiel vorgeführt, bei dem eine JavaFX-Anwendung und eine HTML5/JavaScript-Anwendung
miteinander synchronisiert waren und jeweils die geänderten Daten des anderen Clients anzeigen konnten.</p>
<h2>JSF / CDI</h2>
<h3>Neues aus JavaServer Faces 2.2</h3>
<p>In diesem Vortrag hat <strong>Andy Bosch</strong> über Neuerungen im neuen JavaServer Faces Standard 2.2 berichtet. Er hat dabei 4
wichtige Haupt-Features im Detail erklärt und weitere Nebenfeatures genannt.</p>
<p>Die 4 "Big Ticked Features", wie er es nannte, sind:</p>
<h4>HTML5 Support</h4>
<p>Wie der Name vermuten lässt, handelt es sich hierbei um eine bessere Integration von HTML5-Features in JSF. Zwar war es
auch bisher schon möglich, mit JSF HTML5-Dokumente auszuliefern und auch die neue HTML5-Tags zur semantischen
Strukturierung von Webseiten ließen sich ohne weiteres benutzen.</p>
<p>Probleme gab es jedoch z.B. mit den von HTML5 definierten data-* Attributen, mit denen in HTML5 jedem Element beliebige
Meta-Informationen mitgeliefert werden können. Dies soll im neuen JSF besser unterstützt werden.</p>
<h4>Resource Library Contracts</h4>
<p>Für JSF 2.2 war ursprünglich geplant, Multi-Templating zu unterstützen, d.h. es sollte möglich sein, mehrere Themes für
eine Anwendung zu definieren und einfach, auch zur Laufzeit, auszutauschen. Ideen eines Marketplaces, auf dem Templates
und Themes gehandelt werden könnten, standen im Raum. Letztlich hat sich jedoch gezeigt, dass diese Ideen nicht alle in
der gesetzten Zeit umsetzbar waren. Gewissermaßen eine abgespeckte Version ist nun unter dem Namen "Resource Library
Contracts" im neuen JSF 2.2 Standard enthalten.</p>
<p>Mit Resource Library Contracts wird definiert, dass in einer JSF-Anwendung unter 'META-INF/contracts' Verzeichnisse
angelegt werden können, die einem Template entsprechen. In diesem Verzeichnis sollen alle zum Template gehörenden
Dateien untergebracht werden, also XHTML-, CSS-, JavaScript- und sonstige Dateien.</p>
<p>Es wird weiterhin ein gewisser Formalismus definiert, welchen Standards diese Templates folgen sollten, damit ein
einfaches Austauschen auch zur Laufzeit möglich ist. Dieser Formalismus ist allerdings nicht besonders streng, weshalb
nicht garantiert werden kann, dass das Austauschen ohne Anpassung funktioniert.</p>
<p>Letztlich ist es trotzdem die Aufgabe des Entwicklers, sicherzustellen, dass bestimmte Template-Abschnitte vernünftige
Bezeichner besitzen, die in allen Templates identisch sein müssen, damit Elemente ausgetauscht werden können.</p>
<h4>Faces Flows</h4>
<p>Mit Faces Flows soll es in Zukunft einfacher werden, Seiten zu implementieren, die eine festgelegte Abfolge besitzen,
wie zum Beispiel Wizards, Bestellprozesse oder ähnliches.</p>
<p>Dafür wird ein neuer CDI-Scope <em>FlowScope</em> definiert, der genauso lange gültig ist, wie die Seiten des Flows angezeigt
werden. Die Definition, welche Seiten zu einem Flow gehören, soll dabei deklarativ erfolgen, d.h. die einzele Seite
weiss nicht unbedingt, dass sie zu einem Flow gehört. Dies soll die Wiederverwendbarkeit erhöhen.</p>
<p>Neue JSF-Tags ermöglichen ausserdem die detailierte Steuerung des Flows z.B. mittels Bedingungen/Switch Anweisungen und
der Definition eines Start- und Ende-Punkts.</p>
<h5>Stateless Views</h5>
<p>Das "Stateless Views"-Feature wurde von Andy Bosch im Vortrag nicht sehr euphorisch vertreten. Er machte eher den
Eindruck, dass dieses Feature nicht wirklich wichtig oder sinnvoll wäre. Es geht darum, bestimmte Views zu definieren,
die keinen serverseitigen Zustand besitzen. Das Ziel dahinter ist, die Performance und den Speicherverbrauch zu
minimieren.</p>
<p>Andy hatte jedoch bezweifelt, dass Stateless-Views dazu beitragen können, diese Ziele nennenswert voranzubringen, da
schon der Partial-State-Saving-Mechanismus, der bei JSF 2 Einzug gehalten hat, den zu speichernden und übertragenden
Zustand auf ein nötiges Minimum reduziert.</p>
<p><a href="http://jdevelopment.nl/jsf-22/">Hier die gesamte Feature-Übersicht JSF 2.2</a>.</p>
<h3>Apache Deltaspike</h3>
<p><a href="https://deltaspike.apache.org/">Apache Deltaspike</a> ist eine Sammlung von Erweiterungen für "Contexts and Dependency
Injection" (CDI). Es ist aus den Projekten <a href="http://www.seamframework.org/">Seam 3</a> und
<a href="https://myfaces.apache.org/extensions/cdi/">Apache CODI</a> hervorgegangen und soll diese beerben. Im Vortrag von <strong>Mark
Stuberg</strong> wurde das Projekt vorgestellt und einige Beispiele gezeigt.</p>
<h3>Beyond PrettyFaces - Einführung in Rewrite</h3>
<p><strong>Christian Kaltepoth</strong> stellte in seinem Vortrag das Framework <a href="http://ocpsoft.org/rewrite/">Rewrite</a> vor, welches aus
dem JSF-Framework <a href="http://ocpsoft.org/prettyfaces/">PrettyFaces</a> hervorgegangen ist. PrettyFaces hatte mir schon in
einigen JSF-Projekten gute Dienste geleistet, weshalb es schön war, einmal direkt von einem der Entwickler einen
Einblick zu bekommen.</p>
<p>PrettyFaces ist eine Bibliothek für JavaServer Faces, die einen URL-Rewrite-Mechanismus bereitstellt, um die URLs, die
eine JSF-Anwendung benutzt, nach den Wünschen des Entwicklers anzupassen. Ziel ist es, die teils langen und "hässlichen"
URLs, die JSF von Haus aus nutzt, durch hübsche und kurze URLs zu ersetzen. Statt
'<a href="http://www.example.org/faces/article/overview.xhtml?articleId=1234">www.example.org/faces/article/overview.xhtml?articleId=1234</a>' könnte dann z.B. die URL 'www.example.org/articles/1234'
benutzt werden. Damit wird gleichzeitig die verwendete UI-Technologie ein wenig versteckt. Vor allem aber können so
Links erzielt werden, die sich als Bookmarks vernünftig speichern lassen.</p>
<p>"Rewrite" setzt dieses Ziel fort. Es wurde aus dem ursprünglichen Framework PrettyFaces herausgelöst und kann als
Nachfolger verstanden werden. Rewrite versteht sich nicht mehr nur als Erweiterung für JavaServer Faces sondern als
allgemeines URL-Rewriting-Framework für Java. Die Unterschiede, die auch im Vortrag gezeigt wurden, betreffen vor allem
die Art und Weise der Konfiguration. Bei PrettyFaces hat der Entwickler die Wahl zwischen einer XML-Konfigurationsdatei
und Annotationen direkt an den JSF-ManagedBeans. Da die letztere Variante aber sehr unübersichtlich ist und ein
zentraler Ort zur Übersicht über alle Rewrite-Regeln vorteilhaft ist, wurde bei uns in Projekten immer die
XML-Konfiguration eingesetzt. Diese hat jedoch auch ihre Nachteile, vor allem die geringe Flexibilität, mit der Regeln
geschrieben werden können.</p>
<p>Bei Rewrite wird dieses Problem gelöst, in dem eine Fluent-API zur Beschreibung der Regeln mitgeliefert wird. Damit kann
der Entwickler seine Regeln in Java-Code formulieren und ist bei Refactorings abgesichert. Er kann aber trotzdem alle
Regeln an einer zentralen Stelle im System sammeln oder aber auf verschiedene Klassen aufteilen, wenn das notwendig sein
sollte. Der Entwickler hat also die volle Kontrolle.</p>
<p>Aus meiner Sicht ist dieser Ansatz sehr vielversprechend und sollte unbedingt im Auge behalten werden.</p>
<p><a href="http://de.slideshare.net/chkal/beyond-prettyfaces-einfhrung-in-rewrite">Slides</a></p>
<h3>JSF Performance</h3>
<p>Im Vortrag von <strong>Thomas Asel</strong> wurden einige typische Performance-Probleme von JavaServer Faces aufgezeigt und mögliche
Lösungen analysiert.</p>
<p>Das potentielle Problem von JSF ist, dass auf Serverseite zu jedem Request ein relativ umfangreicher Lifecycle
durchlaufen wird, bei dem ein Komponenten-Baum der UI aufgebaut und bearbeitet wird.</p>
<p>Es stellte sich heraus, dass die Größe des Komponentenbaums einen entscheidenden Einfluss auf die Performance der
Applikation hat. Je größer der Komponentenbaum, desto länger braucht JSF für die Abarbeitung des Lifecycles.
Interessanter Weise gibt es hier offensichtlich starke Unterschiede zwischen den beiden JSF-Implementierungen. Bei der
Referenzimplementierung <strong>Mojarra</strong> kann man einen exponentiellen Zusammenhang zwischen der Größe des Komponentenbaums
und der Verarbeitungsdauer feststellen, was dazu führt, dass bei relativ großen UI's Mojarra recht lange braucht. Die
alternative Implementierung <strong>Apache MyFaces</strong> zeigt ein anderes Verhalten. Zum einen ist die Geschwindigkeit
durchgehend deutlich höher als bei Mojarra. Zum anderen ist hier ein Linearer Zusammenhang zwischen Größe des UI und
Verarbeitungsdauer zu sehen, was dazu führt, dass der Geschwindigkeitsvorteil umso größer ausfällt, je größer der
Komponentenbaum ist.</p>
<p>Aus diesen Erfahrungen können zwei Bausteine zur Verbesserung der Performance gewonnen werden:</p>
<ol>
<li>
<p>Wenn möglich, sollte Apache MyFaces als Implementierung gewählt werden. Dies ist allerdings nicht immer möglich.
Zwar kann bei allen Enterprise-Servern die JSF-Implementierung getauscht werden, oft sind hier jedoch praktische
Einschränkungen durch Support-Verträge gegeben, die verfallen wenn der Server umkonfiguriert wird.</p>
</li>
<li>
<p>Der Entwickler sollte unabhängig von der Implementierung die Größe des Komponentenbaums möglichst klein halten. Vor
allem bei Custom-Komponenten ist Vorsicht geboten. Zum Beispiel sollten reine Wrapper-Komponenten vermieden werden.</p>
</li>
</ol>
<p>Neben der reinen JSF-Verarbeitung existieren noch weitere Stellen, bei denen auf die Performance Einfluss genommen
werden kann. Vor allem die Übertragung von zahlreichen großen Dateien zum Client nimmt viel Zeit in Anspruch. Um diesem
Problem zu begegnen, können JavaScript- und CSS-Dateien zunächst zu je einer Datei zusammengefasst werden und diese
kombinierten Dateien "minifiziert" werden. Es wurde jedoch gezeigt, dass dabei auch Vorsicht geboten ist und umsichtig
geplant werden muss, um tatsächlich einen Vorteil zu erlangen. Würde man z.B. sämtliche JavaScript-Dateien des gesamten
Projekts zu einer einzelnen Datei kombinieren. Es wird jedoch in der Regel nicht überall sämtlicher Code benötigt
sondern nur ein Teil davon. Es bietet sich hier z.B. an, Bibliotheken wie jQuery und natürlich jsf.js, die
JavaScript-Library von JSF selbst, zu einer Datei zusammenzufassen, da dieser Code in der Regel überall gebraucht wird.</p>
<p>Wichtig ist auch die Integration der Kombinierungs- und Minifizierungsschritte in den Build-Prozess, da man während der
Entwicklung ja die Quelltexte in einem vernünftig lesbarem Format erhalten möchte. Im Vortrag wurden einige Tools
genannt, die diese Vorgänge z.B. in einen Maven-Build-Schritt erledigen.</p>
<p>Weiterführende Informationen zu den Performancemessungen sind
<a href="http://www.oio.de/public/java/studie-jsf-mojarra-myfaces-performance-vergleich.htm">hier</a> zu finden.</p>]]></description>
            <content:encoded><![CDATA[<p>This blog post is about my visit at the JAX 2013 in Mainz, one of the biggest Java conferences of europe. As an
exception this time the post is written in german and not english.</p>
<p>In der letzten Woche hatte ich durch meinen <a href="http://www.saxsys.de">Arbeitgeber</a> die Möglichkeit, die JAX 2013, eine der
größten Java-Konverenzen Europas in Mainz zu besuchen. In diesem Blogpost möchte ich über Vorträge berichten, die ich
besucht habe.</p>
<h2>JavaFX</h2>
<h3>Enterprice Anwendungen mit JavaFX (8)</h3>
<p><strong>Adam Bien</strong> berichtete in seinem Vortrag "Enterprice Anwendungen mit JavaFX (8)" recht unterhaltsam von seinen
Erfahrungen mit Enterprice Anwendungen und den Dingen, die bei dieser Klasse von Anwendungen seiner Ansicht nach
relevant sind. Er kam zu dem Schluss, dass hier JavaFX in vielen Fällen eine lohnenswerte Alternative zu den klassischen
Webtechnologien sein kann.</p>
<p>Im Verlauf des Vortrags stellte er anschließend seine Vorstellung davon vor, wie Entwickler Oberflächen mit JavaFX
entwickeln sollten. Trotz anfänglicher Skepsis sieht er vor allem FXML, die XML-Basierte Beschreibungssprache für JavaFX
ab Version 2, als ein sehr gutes Werkzeug an. Mit FXML lässt sich eine Oberfläche deklarativ beschreiben und dynamisch
von JavaFX aus laden. In der FXML-Datei kann der Name einer Controller-Klasse angegeben werden, der dann von JavaFX
automatisch instanziiert wird und der per Dependency Injection die benötigten Referenzen auf UI-Elemente erhält. Adam
Bien sieht hier das Prinzip der Inversion of Control sehr gut umgesetzt.</p>
<p>Da für FXML-Dateien auch ein sehr reichhaltiger und ausgereifter WYSIWYG-Editor namens
<a href="http://www.oracle.com/technetwork/java/javafx/tools/index.html?ssSourceSiteId=ocomen">SceneBuilder</a> existiert, sieht er
diese Vorgehensweise bei der Entwicklung von Desktop-Oberflächen als vorteilhaft an.</p>
<p>Die einzige Lücke, die in diesem Mechanismus noch besteht, ist die Verwendung von echter Dependency Injection für die
Anbindung der Backend-Logik. Der <em>DI</em>-Mechanismus von JavaFX injected nämlich nur UI-Elemente aus der FXML-Datei in den
Controller, andere Abhängigkeiten wie Services werden nicht automatisch eingefügt. Da die Instanziierung des Controllers
ebenfalls von JavaFX übernommen wird, kann der Entwickler auch nicht einfach per händischer Dependency-Injection per
Konstruktor die Abhängigkeiten hineinreichen.</p>
<p>Glücklicherweise ist der <em>DI</em>-Mechanismus von JavaFX relativ leicht erweiterbar und so stellte Adam in seinem Vortrag
auch das von ihm entwickelte Mini-Framework <a href="http://afterburner.adam-bien.com/">Afterburner.fx</a> vor, welches einfache
<em>DI</em> auf simple Art und Weise umsetzt und dabei, wie andere <em>DI</em>-Frameworks auch, die 'javax.inject'-Annotationen
verwendet.</p>
<p>Wer schon immer mal sehen wollte, wie einfach ein <em>DI</em>-Framework sein kann, der sollte sich unbedingt den
<a href="https://github.com/AdamBien/afterburner.fx">Quellcode von Afterburner.fx auf Github</a> anschauen. Das ganze Framework
besteht nämlich nur aus 2 relativ kleinen Klassen.</p>
<h3>JavaFX vs. Html5</h3>
<p>Im Vortrag "JavaFX vs. Html5" zeigt <strong>Björn Müller</strong> einige Anwendungsfälle auf, bei denen HTML5 (in Kombination mit
JavaScript) seiner Ansicht nach nicht die passende UI-Technologie ist, sondern klassische Desktop-Oberflächen besser
geeignet sind. Er bezieht sich vor allem auf große, umfangreiche Business-Applikationen mit umfangreichen Eingabemasken
und mehreren Hundert Screens. Als Beispiele nennt er Anwendungen aus dem Bereich der Logistik und Lagerverwaltung.</p>
<p>Als Gründe nennt er nicht nur die nach wie vor bessere Performance von Desktop-UI's, sondern vor allem die
Entwicklungseffizienz, d.h. wie schnell die Entwickler die entsprechende Funktionalität liefern können.</p>
<p>Als eine mögliche Lösung für die Entwicklung großer Business-Applikationen stellte Björn anschließend das von ihm
entwickelte Framework <a href="http://www.captaincasa.com/">CaptainCasa</a> vor.</p>
<p>CaptainCasa stellt eine Verbindung des UI-Frameworks JavaFX mit dem Serverseitigen Komponenten-Modell von JavaServer
Faces her. Denn obwohl JSF in den meisten Fällen zur Entwicklung von HTML-Oberflächen genutzt wird, ist es prinzipiell
unabhängig von der tatsächlichen benutzten View-Technologie.</p>
<p>Die Serverseite kann damit klassisch mit JavaEE entwickelt werden, die UI wird mittels JSF und einer speziellen
Tag-Library umgesetzt. Auf Client-Seite kommt statt dem Webbrowser jedoch ein JavaFX-Renderer zum Einsatz. Die UI ist
damit nicht fest im Client implementiert sondern wird dynamisch auf Serverseite generiert und mittels eines
XML-Datenaustauschformats zum Client gesendet, welcher aus diesen Informationen die Oberfläche aufbaut. Eingaben des
Nutzers werden auf ähnliche Weise wieder zum Server gesendet und durchlaufen dort den bekannten JSF-Livecycle.</p>
<p>Für Entwickler, die bereits mit JSF zu tun hatten, ist der Lernaufwand deshalb relativ gering. Sie müssen sich nicht mit
den Details von JavaFX ausseinander setzen, sondern können ihre gewohnten Serverseitigen Technologien aus dem
JavaEE-Umfeld einsetzen. Neu ist lediglich die Tag-Library von CaptainCasa, die jedoch vom Prinzip her nicht wesentlich
anders funktioniert, als bekannte JSF-Libraries.</p>
<h3>CustomComponents in JavaFX</h3>
<p><strong>Gerrit Grunwald</strong> stellte in seinem Vortrag das wesentlich von ihm vorangetriebene Projekt
<a href="http://jfxtras.org/">JFXtras</a> vor, welches eine Sammelstelle für JavaFX-Customcontrols darstellt. Er zeigte, welche
Möglichkeiten JavaFX bietet um selbst Controls herzustellen oder vorhandene Controls anzupassen. Dazu zeigte er zunächst
den prinzipiellen Aufbau von JavaFX-Controls, welche Interfaces und Dateien zu einem Control gehören und wie diese
zusammenhängen. Allein dieser Einblick war für mich als Entwickler schon sehr spannend und lehrreich.</p>
<p>Als praktisches Beispiel nutzte er ein Control, welches eine LED-Leuchte darstellen sollte. Zum Erstellen der Grafiken
benutzte er ein Vektorgrafikprogramm, welches SVG exportieren konnte. Die SVG-Datei convertierte er mit einem speziellen
Tool in ein Format, welches direkt von JavaFX dargestellt werden kann und benutzte dieses als grafische Grundlage seines
Controls. Anschließend musste noch die Logik des Controls implementiert werden, was er natürlich mit JavaFX-Bindings
umsetzte.</p>
<h3>OpenDolphin</h3>
<p><strong>Dierk König</strong> hat in seinem Vortrag das von ihm mitentwickelte Framework <a href="http://open-dolphin.org">OpenDolphin</a>
vorgestellt. OpenDolphin ermöglicht es, eine Anwendung nach dem Shared
<a href="http://martinfowler.com/eaaDev/PresentationModel.html">Presentation-Model</a> Muster zu entwickeln. Dabei wird das
Presentation-Model, also sämtliche Daten, die die Benutzeroberfläche beschreiben, auf einem Server gehalten. Die
Oberfläche des Clients verbindet sich mit dem Server und bindet sich direkt an dieses Presentation-Model. Serverseitige
Änderungen an diesem Model sind dann unmittelbar auch auf Clientseite sichtbar. Das gleiche gilt äquivalent auch für
Änderungen des Clients, die sofort zum Server synchronisiert werden.</p>
<p>Werden mehrere Clients mit dem Server verbunden, wird dadurch die UI der Clients untereinander ebenfalls synchron
gehalten.</p>
<p>Dies war für mich auch der Hauptgrund, den Vortrag zu besuchen, da dieses ein ähnlicher Anwendungsfall ist, für den
meine Arbeitskollegen und ich auch unser Framework <a href="https://github.com/saxsys/SynchronizeFX">SynchronizeFX</a> erstellt
haben. In unserer Applikation kommt es ebenfalls auf eine Synchronisierung der UI zwischen mehreren Instanzen an.</p>
<p>Im Detail betrachtet hat OpenDolphin jedoch einen anderen Ansatz. Es lässt sich zwar mit JavaFX verbinden, arbeitet
intern jedoch mit einer eigenen Bindings-Implementierung, während unser Framework ausschließlich mit JavaFX-Bindings
arbeitet.</p>
<p>Während bei unserem Framework der Hauptaugenmerk auf eine einfache Integration in JavaFX-Anwendungen lag, sieht
OpenDolphin eines seiner wesentlichen Ziele darin, die leichte Austauschbarkeit von UI-Technologien zu unterstützen. Da
beim Shared-Presentation-Model die einzige Verbindung zwischen Client und Server das gemeinsame Datenmodell ist, lässt
sich dieses Ziel vergleichsweise gut erreichen.</p>
<p>In der Demo hat er ein Beispiel vorgeführt, bei dem eine JavaFX-Anwendung und eine HTML5/JavaScript-Anwendung
miteinander synchronisiert waren und jeweils die geänderten Daten des anderen Clients anzeigen konnten.</p>
<h2>JSF / CDI</h2>
<h3>Neues aus JavaServer Faces 2.2</h3>
<p>In diesem Vortrag hat <strong>Andy Bosch</strong> über Neuerungen im neuen JavaServer Faces Standard 2.2 berichtet. Er hat dabei 4
wichtige Haupt-Features im Detail erklärt und weitere Nebenfeatures genannt.</p>
<p>Die 4 "Big Ticked Features", wie er es nannte, sind:</p>
<h4>HTML5 Support</h4>
<p>Wie der Name vermuten lässt, handelt es sich hierbei um eine bessere Integration von HTML5-Features in JSF. Zwar war es
auch bisher schon möglich, mit JSF HTML5-Dokumente auszuliefern und auch die neue HTML5-Tags zur semantischen
Strukturierung von Webseiten ließen sich ohne weiteres benutzen.</p>
<p>Probleme gab es jedoch z.B. mit den von HTML5 definierten data-* Attributen, mit denen in HTML5 jedem Element beliebige
Meta-Informationen mitgeliefert werden können. Dies soll im neuen JSF besser unterstützt werden.</p>
<h4>Resource Library Contracts</h4>
<p>Für JSF 2.2 war ursprünglich geplant, Multi-Templating zu unterstützen, d.h. es sollte möglich sein, mehrere Themes für
eine Anwendung zu definieren und einfach, auch zur Laufzeit, auszutauschen. Ideen eines Marketplaces, auf dem Templates
und Themes gehandelt werden könnten, standen im Raum. Letztlich hat sich jedoch gezeigt, dass diese Ideen nicht alle in
der gesetzten Zeit umsetzbar waren. Gewissermaßen eine abgespeckte Version ist nun unter dem Namen "Resource Library
Contracts" im neuen JSF 2.2 Standard enthalten.</p>
<p>Mit Resource Library Contracts wird definiert, dass in einer JSF-Anwendung unter 'META-INF/contracts' Verzeichnisse
angelegt werden können, die einem Template entsprechen. In diesem Verzeichnis sollen alle zum Template gehörenden
Dateien untergebracht werden, also XHTML-, CSS-, JavaScript- und sonstige Dateien.</p>
<p>Es wird weiterhin ein gewisser Formalismus definiert, welchen Standards diese Templates folgen sollten, damit ein
einfaches Austauschen auch zur Laufzeit möglich ist. Dieser Formalismus ist allerdings nicht besonders streng, weshalb
nicht garantiert werden kann, dass das Austauschen ohne Anpassung funktioniert.</p>
<p>Letztlich ist es trotzdem die Aufgabe des Entwicklers, sicherzustellen, dass bestimmte Template-Abschnitte vernünftige
Bezeichner besitzen, die in allen Templates identisch sein müssen, damit Elemente ausgetauscht werden können.</p>
<h4>Faces Flows</h4>
<p>Mit Faces Flows soll es in Zukunft einfacher werden, Seiten zu implementieren, die eine festgelegte Abfolge besitzen,
wie zum Beispiel Wizards, Bestellprozesse oder ähnliches.</p>
<p>Dafür wird ein neuer CDI-Scope <em>FlowScope</em> definiert, der genauso lange gültig ist, wie die Seiten des Flows angezeigt
werden. Die Definition, welche Seiten zu einem Flow gehören, soll dabei deklarativ erfolgen, d.h. die einzele Seite
weiss nicht unbedingt, dass sie zu einem Flow gehört. Dies soll die Wiederverwendbarkeit erhöhen.</p>
<p>Neue JSF-Tags ermöglichen ausserdem die detailierte Steuerung des Flows z.B. mittels Bedingungen/Switch Anweisungen und
der Definition eines Start- und Ende-Punkts.</p>
<h5>Stateless Views</h5>
<p>Das "Stateless Views"-Feature wurde von Andy Bosch im Vortrag nicht sehr euphorisch vertreten. Er machte eher den
Eindruck, dass dieses Feature nicht wirklich wichtig oder sinnvoll wäre. Es geht darum, bestimmte Views zu definieren,
die keinen serverseitigen Zustand besitzen. Das Ziel dahinter ist, die Performance und den Speicherverbrauch zu
minimieren.</p>
<p>Andy hatte jedoch bezweifelt, dass Stateless-Views dazu beitragen können, diese Ziele nennenswert voranzubringen, da
schon der Partial-State-Saving-Mechanismus, der bei JSF 2 Einzug gehalten hat, den zu speichernden und übertragenden
Zustand auf ein nötiges Minimum reduziert.</p>
<p><a href="http://jdevelopment.nl/jsf-22/">Hier die gesamte Feature-Übersicht JSF 2.2</a>.</p>
<h3>Apache Deltaspike</h3>
<p><a href="https://deltaspike.apache.org/">Apache Deltaspike</a> ist eine Sammlung von Erweiterungen für "Contexts and Dependency
Injection" (CDI). Es ist aus den Projekten <a href="http://www.seamframework.org/">Seam 3</a> und
<a href="https://myfaces.apache.org/extensions/cdi/">Apache CODI</a> hervorgegangen und soll diese beerben. Im Vortrag von <strong>Mark
Stuberg</strong> wurde das Projekt vorgestellt und einige Beispiele gezeigt.</p>
<h3>Beyond PrettyFaces - Einführung in Rewrite</h3>
<p><strong>Christian Kaltepoth</strong> stellte in seinem Vortrag das Framework <a href="http://ocpsoft.org/rewrite/">Rewrite</a> vor, welches aus
dem JSF-Framework <a href="http://ocpsoft.org/prettyfaces/">PrettyFaces</a> hervorgegangen ist. PrettyFaces hatte mir schon in
einigen JSF-Projekten gute Dienste geleistet, weshalb es schön war, einmal direkt von einem der Entwickler einen
Einblick zu bekommen.</p>
<p>PrettyFaces ist eine Bibliothek für JavaServer Faces, die einen URL-Rewrite-Mechanismus bereitstellt, um die URLs, die
eine JSF-Anwendung benutzt, nach den Wünschen des Entwicklers anzupassen. Ziel ist es, die teils langen und "hässlichen"
URLs, die JSF von Haus aus nutzt, durch hübsche und kurze URLs zu ersetzen. Statt
'<a href="http://www.example.org/faces/article/overview.xhtml?articleId=1234">www.example.org/faces/article/overview.xhtml?articleId=1234</a>' könnte dann z.B. die URL 'www.example.org/articles/1234'
benutzt werden. Damit wird gleichzeitig die verwendete UI-Technologie ein wenig versteckt. Vor allem aber können so
Links erzielt werden, die sich als Bookmarks vernünftig speichern lassen.</p>
<p>"Rewrite" setzt dieses Ziel fort. Es wurde aus dem ursprünglichen Framework PrettyFaces herausgelöst und kann als
Nachfolger verstanden werden. Rewrite versteht sich nicht mehr nur als Erweiterung für JavaServer Faces sondern als
allgemeines URL-Rewriting-Framework für Java. Die Unterschiede, die auch im Vortrag gezeigt wurden, betreffen vor allem
die Art und Weise der Konfiguration. Bei PrettyFaces hat der Entwickler die Wahl zwischen einer XML-Konfigurationsdatei
und Annotationen direkt an den JSF-ManagedBeans. Da die letztere Variante aber sehr unübersichtlich ist und ein
zentraler Ort zur Übersicht über alle Rewrite-Regeln vorteilhaft ist, wurde bei uns in Projekten immer die
XML-Konfiguration eingesetzt. Diese hat jedoch auch ihre Nachteile, vor allem die geringe Flexibilität, mit der Regeln
geschrieben werden können.</p>
<p>Bei Rewrite wird dieses Problem gelöst, in dem eine Fluent-API zur Beschreibung der Regeln mitgeliefert wird. Damit kann
der Entwickler seine Regeln in Java-Code formulieren und ist bei Refactorings abgesichert. Er kann aber trotzdem alle
Regeln an einer zentralen Stelle im System sammeln oder aber auf verschiedene Klassen aufteilen, wenn das notwendig sein
sollte. Der Entwickler hat also die volle Kontrolle.</p>
<p>Aus meiner Sicht ist dieser Ansatz sehr vielversprechend und sollte unbedingt im Auge behalten werden.</p>
<p><a href="http://de.slideshare.net/chkal/beyond-prettyfaces-einfhrung-in-rewrite">Slides</a></p>
<h3>JSF Performance</h3>
<p>Im Vortrag von <strong>Thomas Asel</strong> wurden einige typische Performance-Probleme von JavaServer Faces aufgezeigt und mögliche
Lösungen analysiert.</p>
<p>Das potentielle Problem von JSF ist, dass auf Serverseite zu jedem Request ein relativ umfangreicher Lifecycle
durchlaufen wird, bei dem ein Komponenten-Baum der UI aufgebaut und bearbeitet wird.</p>
<p>Es stellte sich heraus, dass die Größe des Komponentenbaums einen entscheidenden Einfluss auf die Performance der
Applikation hat. Je größer der Komponentenbaum, desto länger braucht JSF für die Abarbeitung des Lifecycles.
Interessanter Weise gibt es hier offensichtlich starke Unterschiede zwischen den beiden JSF-Implementierungen. Bei der
Referenzimplementierung <strong>Mojarra</strong> kann man einen exponentiellen Zusammenhang zwischen der Größe des Komponentenbaums
und der Verarbeitungsdauer feststellen, was dazu führt, dass bei relativ großen UI's Mojarra recht lange braucht. Die
alternative Implementierung <strong>Apache MyFaces</strong> zeigt ein anderes Verhalten. Zum einen ist die Geschwindigkeit
durchgehend deutlich höher als bei Mojarra. Zum anderen ist hier ein Linearer Zusammenhang zwischen Größe des UI und
Verarbeitungsdauer zu sehen, was dazu führt, dass der Geschwindigkeitsvorteil umso größer ausfällt, je größer der
Komponentenbaum ist.</p>
<p>Aus diesen Erfahrungen können zwei Bausteine zur Verbesserung der Performance gewonnen werden:</p>
<ol>
<li>
<p>Wenn möglich, sollte Apache MyFaces als Implementierung gewählt werden. Dies ist allerdings nicht immer möglich.
Zwar kann bei allen Enterprise-Servern die JSF-Implementierung getauscht werden, oft sind hier jedoch praktische
Einschränkungen durch Support-Verträge gegeben, die verfallen wenn der Server umkonfiguriert wird.</p>
</li>
<li>
<p>Der Entwickler sollte unabhängig von der Implementierung die Größe des Komponentenbaums möglichst klein halten. Vor
allem bei Custom-Komponenten ist Vorsicht geboten. Zum Beispiel sollten reine Wrapper-Komponenten vermieden werden.</p>
</li>
</ol>
<p>Neben der reinen JSF-Verarbeitung existieren noch weitere Stellen, bei denen auf die Performance Einfluss genommen
werden kann. Vor allem die Übertragung von zahlreichen großen Dateien zum Client nimmt viel Zeit in Anspruch. Um diesem
Problem zu begegnen, können JavaScript- und CSS-Dateien zunächst zu je einer Datei zusammengefasst werden und diese
kombinierten Dateien "minifiziert" werden. Es wurde jedoch gezeigt, dass dabei auch Vorsicht geboten ist und umsichtig
geplant werden muss, um tatsächlich einen Vorteil zu erlangen. Würde man z.B. sämtliche JavaScript-Dateien des gesamten
Projekts zu einer einzelnen Datei kombinieren. Es wird jedoch in der Regel nicht überall sämtlicher Code benötigt
sondern nur ein Teil davon. Es bietet sich hier z.B. an, Bibliotheken wie jQuery und natürlich jsf.js, die
JavaScript-Library von JSF selbst, zu einer Datei zusammenzufassen, da dieser Code in der Regel überall gebraucht wird.</p>
<p>Wichtig ist auch die Integration der Kombinierungs- und Minifizierungsschritte in den Build-Prozess, da man während der
Entwicklung ja die Quelltexte in einem vernünftig lesbarem Format erhalten möchte. Im Vortrag wurden einige Tools
genannt, die diese Vorgänge z.B. in einen Maven-Build-Schritt erledigen.</p>
<p>Weiterführende Informationen zu den Performancemessungen sind
<a href="http://www.oio.de/public/java/studie-jsf-mojarra-myfaces-performance-vergleich.htm">hier</a> zu finden.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[SynchronizeFX Demo and HowTo]]></title>
            <link>https://www.lestard.eu/2013/synchronizefx_example/</link>
            <guid>https://www.lestard.eu/2013/synchronizefx_example/</guid>
            <pubDate>Sun, 19 May 2013 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>I've done a little demo application and a step-by-step tutorial for <a href="/projects/synchronizefx/">SynchronizeFX</a>.</p>
<p>The demo consists of a small server application with a simple domain model and a client application that shows a slider
control that is synchronized.</p>
<p>On the server there is a domain model that contains a
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/property/DoubleProperty.html">DoubleProperty</a> named <code class="language-text">sliderValue</code>.
This model is transfered to the client applications and will be synchronized between the applications.</p>
<p>On the client we have a view containing a
<a href="http://download.java.net/jdk8/jfxdocs/javafx/scene/control/Slider.html">Slider control</a>. This control is bound
bidirectionally to the model value so that when the user is dragging the slider at first the value changes in the local
instance of the domain model and is synchronized to the server after that.</p>
<p>The SynchronizeFX library ensures that the domain model is synchonized automatically. This means that the change of one
client is instantly send to all other clients.</p>
<p><img src="/files/pics/2013/synchronizefx_demo_screenshot.png" alt="screenshot of the client"></p>
<p>The whole step-by-step tutorial and the source code can be seen at github:
<a href="https://github.com/saxsys/SynchronizeFX/tree/master/demos/sliderdemo">https://github.com/saxsys/SynchronizeFX/tree/master/demos/sliderdemo</a></p>]]></description>
            <content:encoded><![CDATA[<p>I've done a little demo application and a step-by-step tutorial for <a href="/projects/synchronizefx/">SynchronizeFX</a>.</p>
<p>The demo consists of a small server application with a simple domain model and a client application that shows a slider
control that is synchronized.</p>
<p>On the server there is a domain model that contains a
<a href="http://download.java.net/jdk8/jfxdocs/javafx/beans/property/DoubleProperty.html">DoubleProperty</a> named <code class="language-text">sliderValue</code>.
This model is transfered to the client applications and will be synchronized between the applications.</p>
<p>On the client we have a view containing a
<a href="http://download.java.net/jdk8/jfxdocs/javafx/scene/control/Slider.html">Slider control</a>. This control is bound
bidirectionally to the model value so that when the user is dragging the slider at first the value changes in the local
instance of the domain model and is synchronized to the server after that.</p>
<p>The SynchronizeFX library ensures that the domain model is synchonized automatically. This means that the change of one
client is instantly send to all other clients.</p>
<p><img src="/files/pics/2013/synchronizefx_demo_screenshot.png" alt="screenshot of the client"></p>
<p>The whole step-by-step tutorial and the source code can be seen at github:
<a href="https://github.com/saxsys/SynchronizeFX/tree/master/demos/sliderdemo">https://github.com/saxsys/SynchronizeFX/tree/master/demos/sliderdemo</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[SynchronizeFX]]></title>
            <link>https://www.lestard.eu/2013/synchronizefx/</link>
            <guid>https://www.lestard.eu/2013/synchronizefx/</guid>
            <pubDate>Wed, 01 May 2013 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>At <a href="http://www.saxsys.de/">saxsys</a> I'm part of a team that is developing a
<a href="http://www.eteoboard.de/de/">digital scrumboard with JavaFX</a>. One of the key features is the instant synchronization of
the UI state between different boards over the network. When you drag a task note at one of the boards it moves
instandly on the other board too.</p>
<p><img src="https://raw.github.com/saxsys/SynchronizeFX/master/src/site/resources/images/synchronizeFX_logo.png" alt="logo"></p>
<p>For this feature we had developed a small library and I'm very pleased that we can now release this library as a free
open source project called "SynchronizeFX". You can find the code at github:
<a href="https://github.com/saxsys/SynchronizeFX">https://github.com/saxsys/SynchronizeFX</a>.</p>
<p>The key idea is that we synchronize models that are build up on JavaFX's Properties. At the moment the synchronization
over the network is done with websockets but other technologies are possible too.</p>]]></description>
            <content:encoded><![CDATA[<p>At <a href="http://www.saxsys.de/">saxsys</a> I'm part of a team that is developing a
<a href="http://www.eteoboard.de/de/">digital scrumboard with JavaFX</a>. One of the key features is the instant synchronization of
the UI state between different boards over the network. When you drag a task note at one of the boards it moves
instandly on the other board too.</p>
<p><img src="https://raw.github.com/saxsys/SynchronizeFX/master/src/site/resources/images/synchronizeFX_logo.png" alt="logo"></p>
<p>For this feature we had developed a small library and I'm very pleased that we can now release this library as a free
open source project called "SynchronizeFX". You can find the code at github:
<a href="https://github.com/saxsys/SynchronizeFX">https://github.com/saxsys/SynchronizeFX</a>.</p>
<p>The key idea is that we synchronize models that are build up on JavaFX's Properties. At the moment the synchronization
over the network is done with websockets but other technologies are possible too.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Markdown formatted License files]]></title>
            <link>https://www.lestard.eu/2013/markdown_license_files/</link>
            <guid>https://www.lestard.eu/2013/markdown_license_files/</guid>
            <pubDate>Sun, 03 Mar 2013 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>I like markdown. And I like open source software. To combine both I created a
<a href="https://github.com/manuel_mauky/markdown_license_files">github repository</a> that contains some of the widespreaded free
software license files formatted with markdown. When you use this files in github projects with the file ending of ".md"
they are nicely formatted on the github page.</p>
<p>At the moment I have this license files in the repo:</p>
<ul>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/Apache%20License%20v2.md">Apache License v2</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/GPLv3.md">GPL v3</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/LGPLv2.md">LGPL v3</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/MIT.md">MIT</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/MPLv2.md">Mozilla Puplic License v2</a></li>
</ul>
<p>Feel free to copy them as you like.</p>
<p><img src="/files/pics/2013/markdown_license_screenshot.png" alt="screenshot from github"></p>]]></description>
            <content:encoded><![CDATA[<p>I like markdown. And I like open source software. To combine both I created a
<a href="https://github.com/manuel_mauky/markdown_license_files">github repository</a> that contains some of the widespreaded free
software license files formatted with markdown. When you use this files in github projects with the file ending of ".md"
they are nicely formatted on the github page.</p>
<p>At the moment I have this license files in the repo:</p>
<ul>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/Apache%20License%20v2.md">Apache License v2</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/GPLv3.md">GPL v3</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/LGPLv2.md">LGPL v3</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/MIT.md">MIT</a></li>
<li><a href="https://github.com/manuel_mauky/markdown_license_files/blob/master/MPLv2.md">Mozilla Puplic License v2</a></li>
</ul>
<p>Feel free to copy them as you like.</p>
<p><img src="/files/pics/2013/markdown_license_screenshot.png" alt="screenshot from github"></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Lecture 'Test-Driven-Development and Dependency Injection' at HS-ZIGR]]></title>
            <link>https://www.lestard.eu/2012/lecture_tdd/</link>
            <guid>https://www.lestard.eu/2012/lecture_tdd/</guid>
            <pubDate>Sun, 09 Dec 2012 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>I had the chance to give a lecture for students of the masters degree for computer science at the
<a href="http://www.hszg.de/f-ei/startseite.html">University of Applied Sciences Zittau / Görlitz</a>. The title of the course of
lectures was "Webdevelopment in practice" and my part was a lecture on the topic "Test driven Development and Dependency
Injection".</p>
<p>At first I talked about the advantages of automatic tests in professional software development. I described the
different types of tests like unit tests and integration tests. One of the main points was that "real" unit tests only
test the component itself and not the surrounding environment. To achive this you need to replace all dependencies of a
class with mock objects to be able to simulate an environment for your tests.</p>
<p>Based on this insight I described the design pattern <strong>dependency injection</strong> as this pattern is the best way to be able
to replace dependencies of a component. In the lecture I didn't use a framework for dependency injection but explained
how you can implement dependency injection by hand. I showed the different styles of dependency injection like
"constructor injection", "field injection" and "setter injection" and explained why in my opinion constructor injection
is the most advantageous choice.</p>
<p>After the basics I showed the test driven way of developing software. Writing your test before the implementation is
leading to better testable code and in most cases to lesser coupling between components. I personally think that one of
the biggest points of doing TDD is that it helps me to focus on the requirements of the software and not the
implementation. I think about how a class should be used by a developer. This leads to a better API for every class.</p>
<p>The last part of the lecture was a chapter about <strong>testing anti-patterns</strong>. I explained that using static methods in
java is only aceptable when they are stateless and there are no side-effects. Otherwise you can't be sure about the
state of your application when executing the test. The same is true for the <em>Singleton</em> design pattern.</p>
<p>Another testing anitpattern in my opinion is using <code class="language-text">final</code> for classes or methods as in this cases it is harder to use
mocking in the tests.</p>
<h3>Exercise</h3>
<p>In addition to the lecture there was an computer exercise afterwards. The students had to try out TDD in practice. The
exercise was taken from the german book <a href="http://sol.cs.hm.edu/dpunkt-java-praktikum">"Das Java-Praktikum"</a>
(<a href="http://www.dpunk.de">dpunkt.verlag</a>, 2008, from <em>Reinhard Schiedermeier</em> and <em>Klaus Köhler</em>). This is a book with
small exercises to learn and practise java programming. In the book it's not done with TDD but in my opinion the
exercises are great for this purpose.</p>
<p>The task was to write a class that encapsulates a specific point in time and gives the user and easy way to handle and
visualize this instance of time.</p>
<p>The code of the test and the implementation can be found on github:
<a href="https://github.com/manuel_mauky/tdd-example-clocktime">https://github.com/manuel_mauky/tdd-example-clocktime</a>.</p>]]></description>
            <content:encoded><![CDATA[<p>I had the chance to give a lecture for students of the masters degree for computer science at the
<a href="http://www.hszg.de/f-ei/startseite.html">University of Applied Sciences Zittau / Görlitz</a>. The title of the course of
lectures was "Webdevelopment in practice" and my part was a lecture on the topic "Test driven Development and Dependency
Injection".</p>
<p>At first I talked about the advantages of automatic tests in professional software development. I described the
different types of tests like unit tests and integration tests. One of the main points was that "real" unit tests only
test the component itself and not the surrounding environment. To achive this you need to replace all dependencies of a
class with mock objects to be able to simulate an environment for your tests.</p>
<p>Based on this insight I described the design pattern <strong>dependency injection</strong> as this pattern is the best way to be able
to replace dependencies of a component. In the lecture I didn't use a framework for dependency injection but explained
how you can implement dependency injection by hand. I showed the different styles of dependency injection like
"constructor injection", "field injection" and "setter injection" and explained why in my opinion constructor injection
is the most advantageous choice.</p>
<p>After the basics I showed the test driven way of developing software. Writing your test before the implementation is
leading to better testable code and in most cases to lesser coupling between components. I personally think that one of
the biggest points of doing TDD is that it helps me to focus on the requirements of the software and not the
implementation. I think about how a class should be used by a developer. This leads to a better API for every class.</p>
<p>The last part of the lecture was a chapter about <strong>testing anti-patterns</strong>. I explained that using static methods in
java is only aceptable when they are stateless and there are no side-effects. Otherwise you can't be sure about the
state of your application when executing the test. The same is true for the <em>Singleton</em> design pattern.</p>
<p>Another testing anitpattern in my opinion is using <code class="language-text">final</code> for classes or methods as in this cases it is harder to use
mocking in the tests.</p>
<h3>Exercise</h3>
<p>In addition to the lecture there was an computer exercise afterwards. The students had to try out TDD in practice. The
exercise was taken from the german book <a href="http://sol.cs.hm.edu/dpunkt-java-praktikum">"Das Java-Praktikum"</a>
(<a href="http://www.dpunk.de">dpunkt.verlag</a>, 2008, from <em>Reinhard Schiedermeier</em> and <em>Klaus Köhler</em>). This is a book with
small exercises to learn and practise java programming. In the book it's not done with TDD but in my opinion the
exercises are great for this purpose.</p>
<p>The task was to write a class that encapsulates a specific point in time and gives the user and easy way to handle and
visualize this instance of time.</p>
<p>The code of the test and the implementation can be found on github:
<a href="https://github.com/manuel_mauky/tdd-example-clocktime">https://github.com/manuel_mauky/tdd-example-clocktime</a>.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Coding-Content - TmpMail]]></title>
            <link>https://www.lestard.eu/2012/tmpmail/</link>
            <guid>https://www.lestard.eu/2012/tmpmail/</guid>
            <pubDate>Sun, 11 Nov 2012 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Coding doesn't only belongs to my day-to-day work but is also one of my favorite hobbies. And like other hobbies it's
fun to make a competition out of it. So last week I participated at the
<a href="http://www.coding-contest.de/">Leipziger coding contest</a>. There where 4 categories: PHP, JavaScript and two times Java.
I have chosen the second java category where the task was to develop a "fake email" application.</p>
<p>You can find the code here: <a href="https://github.com/manuel_mauky/tmpmail">https://github.com/manuel_mauky/tmpmail</a></p>
<h3>Task: Temporal email addresses</h3>
<p>The user of the application should be able to register herself with her private email address. After that the user can
create temporal email addresses whose messages are redirected to the private email address of the user.</p>
<p>There are several use cases for this application: First of all you can use this temporal email addresses for
registration at online shops, forums and so on where you don't want to use your private email address to prevent spam
emails.</p>
<p>Another use case would be to use this application for testing purposes by software developers. They could check whether
there own application is sending emails the correct way.</p>
<h3>Implementation</h3>
<p>My implementation is based on the JavaEE technology stack. I have used
<a href="https://www.eclipse.org/eclipselink/">JPA2/Eclipselink</a> as persistence framework with an <a href="http://hsqldb.org/">HSQLDB</a>
inmemory database.</p>
<p>Dependency-Injection is done by <a href="http://weld.cdi-spec.org/">CDI/Weld</a>. In addition I used the
<a href="http://www.seamframework.org/Seam3/SolderHome">Seam Solder library</a> to handle events of the servlet container.</p>
<p>The handling of SMTP is done with the <a href="https://code.google.com/p/subethasmtp/">SubethaSMTP</a> library.</p>
<p>The frontend is based on JSF 2.1 and <a href="https://myfaces.apache.org/">MyFaces</a> as implementation. Besides this
<a href="http://ocpsoft.org/prettyfaces/">PrettyFaces</a> and <a href="http://primefaces.org/">PrimeFaces</a> where used.</p>
<p>The whole application was developed test driven. For this purpose
<a href="https://github.com/alexruiz/fest-assert-2.x">FEST-Assert</a> and <a href="https://code.google.com/p/mockito/">Mockito</a> where used.
Additionally Weld-SE was used for integration tests.</p>
<hr>
<p>p.s. At the end I won the contest and got a Lenovo Thinkpad Edge as an award :-)</p>]]></description>
            <content:encoded><![CDATA[<p>Coding doesn't only belongs to my day-to-day work but is also one of my favorite hobbies. And like other hobbies it's
fun to make a competition out of it. So last week I participated at the
<a href="http://www.coding-contest.de/">Leipziger coding contest</a>. There where 4 categories: PHP, JavaScript and two times Java.
I have chosen the second java category where the task was to develop a "fake email" application.</p>
<p>You can find the code here: <a href="https://github.com/manuel_mauky/tmpmail">https://github.com/manuel_mauky/tmpmail</a></p>
<h3>Task: Temporal email addresses</h3>
<p>The user of the application should be able to register herself with her private email address. After that the user can
create temporal email addresses whose messages are redirected to the private email address of the user.</p>
<p>There are several use cases for this application: First of all you can use this temporal email addresses for
registration at online shops, forums and so on where you don't want to use your private email address to prevent spam
emails.</p>
<p>Another use case would be to use this application for testing purposes by software developers. They could check whether
there own application is sending emails the correct way.</p>
<h3>Implementation</h3>
<p>My implementation is based on the JavaEE technology stack. I have used
<a href="https://www.eclipse.org/eclipselink/">JPA2/Eclipselink</a> as persistence framework with an <a href="http://hsqldb.org/">HSQLDB</a>
inmemory database.</p>
<p>Dependency-Injection is done by <a href="http://weld.cdi-spec.org/">CDI/Weld</a>. In addition I used the
<a href="http://www.seamframework.org/Seam3/SolderHome">Seam Solder library</a> to handle events of the servlet container.</p>
<p>The handling of SMTP is done with the <a href="https://code.google.com/p/subethasmtp/">SubethaSMTP</a> library.</p>
<p>The frontend is based on JSF 2.1 and <a href="https://myfaces.apache.org/">MyFaces</a> as implementation. Besides this
<a href="http://ocpsoft.org/prettyfaces/">PrettyFaces</a> and <a href="http://primefaces.org/">PrimeFaces</a> where used.</p>
<p>The whole application was developed test driven. For this purpose
<a href="https://github.com/alexruiz/fest-assert-2.x">FEST-Assert</a> and <a href="https://code.google.com/p/mockito/">Mockito</a> where used.
Additionally Weld-SE was used for integration tests.</p>
<hr>
<p>p.s. At the end I won the contest and got a Lenovo Thinkpad Edge as an award :-)</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Talk about BeanValidation at JavaUserGroup Görlitz]]></title>
            <link>https://www.lestard.eu/2012/juggr_beanvalidation/</link>
            <guid>https://www.lestard.eu/2012/juggr_beanvalidation/</guid>
            <pubDate>Thu, 04 Oct 2012 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Once again I gave a <a href="http://www.jug-gr.de/2012/09/26/bean_validation.html">talk</a> at the
<a href="http://www.jug-gr.de">JavaUserGroup Görlitz</a>. This time the talk was about "<strong>JSR-303 BeanValidation</strong>".</p>
<p>BeanValidation is a part of JavaEE that is used for validation of data. You use java annotations to describe
restrictions and constraints for your java classes. The validator can then evaluate these annotations and give you an
answer whether your objects are "valid" or "invalid". At the moment there are 3 ways to use this validation.</p>
<ol>
<li>
<p>By hand. To do this you use an instance of the
<a href="http://jackson.codehaus.org/javadoc/bean-validation-api/1.0/javax/validation/Validator.html">Validator</a> class and
use the method
"<a href="http://jackson.codehaus.org/javadoc/bean-validation-api/1.0/javax/validation/Validator.html#validate(T,%20java.lang.Class...)">validate</a>".
As the result you get a collection of
<a href="http://jackson.codehaus.org/javadoc/bean-validation-api/1.0/javax/validation/ConstraintViolation.html">ConstraintViolation</a>
objects for every violation. When this collections is empty your object is considered to be valid.</p>
</li>
<li>
<p>When using JavaServer Faces 2 (JSF) as frontend framework validation can be done automatically. You have nothing to
do but to put an BeanValidation implementation
(<a href="http://www.hibernate.org/subprojects/validator.html">Hibernate Validator</a> or
<a href="http://bval.apache.org/">Apache BVal</a>) on the classpath or use an JavaEE compatible application server.</p>
</li>
<li>
<p>When you are using JavaPersistence API (JPA) to persist your data validation is also done automatically. Everytime
an Entity with BeanValidation annotations gets persisted by the EntityManager the validation is done in the first
place.</p>
</li>
</ol>
<p>In the talk I was showing some of the build-in annotations and how you can create your own custom constraints and custom
validators to fit your needs. I also showed how you could include the
<a href="http://commons.apache.org/validator/">Apache Commons Validator</a> into the BeanValidation framework.</p>
<p>The Example code is available on Github:
<a href="https://github.com/manuel_mauky/juggr_BeanValidation">https://github.com/manuel_mauky/juggr_BeanValidation</a></p>
<p>The slides are available <a href="/files/pdf/2012/BeanValidation_JUGGR.pdf">here</a> and on
<a href="https://docs.google.com/file/d/0B9UrDsNFgG9BTkY1V3Awd1pNdUk/edit?usp=sharing">Google-Drive</a></p>]]></description>
            <content:encoded><![CDATA[<p>Once again I gave a <a href="http://www.jug-gr.de/2012/09/26/bean_validation.html">talk</a> at the
<a href="http://www.jug-gr.de">JavaUserGroup Görlitz</a>. This time the talk was about "<strong>JSR-303 BeanValidation</strong>".</p>
<p>BeanValidation is a part of JavaEE that is used for validation of data. You use java annotations to describe
restrictions and constraints for your java classes. The validator can then evaluate these annotations and give you an
answer whether your objects are "valid" or "invalid". At the moment there are 3 ways to use this validation.</p>
<ol>
<li>
<p>By hand. To do this you use an instance of the
<a href="http://jackson.codehaus.org/javadoc/bean-validation-api/1.0/javax/validation/Validator.html">Validator</a> class and
use the method
"<a href="http://jackson.codehaus.org/javadoc/bean-validation-api/1.0/javax/validation/Validator.html#validate(T,%20java.lang.Class...)">validate</a>".
As the result you get a collection of
<a href="http://jackson.codehaus.org/javadoc/bean-validation-api/1.0/javax/validation/ConstraintViolation.html">ConstraintViolation</a>
objects for every violation. When this collections is empty your object is considered to be valid.</p>
</li>
<li>
<p>When using JavaServer Faces 2 (JSF) as frontend framework validation can be done automatically. You have nothing to
do but to put an BeanValidation implementation
(<a href="http://www.hibernate.org/subprojects/validator.html">Hibernate Validator</a> or
<a href="http://bval.apache.org/">Apache BVal</a>) on the classpath or use an JavaEE compatible application server.</p>
</li>
<li>
<p>When you are using JavaPersistence API (JPA) to persist your data validation is also done automatically. Everytime
an Entity with BeanValidation annotations gets persisted by the EntityManager the validation is done in the first
place.</p>
</li>
</ol>
<p>In the talk I was showing some of the build-in annotations and how you can create your own custom constraints and custom
validators to fit your needs. I also showed how you could include the
<a href="http://commons.apache.org/validator/">Apache Commons Validator</a> into the BeanValidation framework.</p>
<p>The Example code is available on Github:
<a href="https://github.com/manuel_mauky/juggr_BeanValidation">https://github.com/manuel_mauky/juggr_BeanValidation</a></p>
<p>The slides are available <a href="/files/pdf/2012/BeanValidation_JUGGR.pdf">here</a> and on
<a href="https://docs.google.com/file/d/0B9UrDsNFgG9BTkY1V3Awd1pNdUk/edit?usp=sharing">Google-Drive</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Maven Archetype for CDI and JSF]]></title>
            <link>https://www.lestard.eu/2012/cdi-archetype/</link>
            <guid>https://www.lestard.eu/2012/cdi-archetype/</guid>
            <pubDate>Sun, 23 Sep 2012 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Today I created a maven archetype for small JSF/CDI based applications. It creates a small web application that is
meaned to be run on a Servlet Container and not on a JavaEE Application Server.</p>
<p>As you know on a servlet container there are no implementations provided for JavaEE-API's like JavaServer Faces or
JavaPersistence API. Therefore I added the needed dependencies in the archetype.</p>
<p>In addition there are some Testing libraries like <a href="http://junit.org/">JUnit</a>,
<a href="https://code.google.com/p/mockito/">Mockito</a> and <a href="https://code.google.com/p/fest/">FEST-Assert</a> added too.</p>
<p>The configuration of the archetype is highly opinionated and contains the libraries I'm using regularly. It is intended
for my own usage but as it doesn't cost me anything to publish it to github you might find it usefull too.</p>
<p>Github: <a href="https://github.com/manuel_mauky/jsf-cdi-archetype">https://github.com/manuel_mauky/jsf-cdi-archetype</a></p>]]></description>
            <content:encoded><![CDATA[<p>Today I created a maven archetype for small JSF/CDI based applications. It creates a small web application that is
meaned to be run on a Servlet Container and not on a JavaEE Application Server.</p>
<p>As you know on a servlet container there are no implementations provided for JavaEE-API's like JavaServer Faces or
JavaPersistence API. Therefore I added the needed dependencies in the archetype.</p>
<p>In addition there are some Testing libraries like <a href="http://junit.org/">JUnit</a>,
<a href="https://code.google.com/p/mockito/">Mockito</a> and <a href="https://code.google.com/p/fest/">FEST-Assert</a> added too.</p>
<p>The configuration of the archetype is highly opinionated and contains the libraries I'm using regularly. It is intended
for my own usage but as it doesn't cost me anything to publish it to github you might find it usefull too.</p>
<p>Github: <a href="https://github.com/manuel_mauky/jsf-cdi-archetype">https://github.com/manuel_mauky/jsf-cdi-archetype</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Java Game ColorPuzzle]]></title>
            <link>https://www.lestard.eu/2012/color_puzzle_game/</link>
            <guid>https://www.lestard.eu/2012/color_puzzle_game/</guid>
            <pubDate>Sat, 02 Jun 2012 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Today I like to show you a little java game I have written roughly a year ago. Back in that time I was looking at the
<a href="http://en.wikipedia.org/wiki/Java_2D">Java-2D-API</a> and Swing/Canvas and thought that the best way to learn this stuff
is to write a little game. Thinking of an good example game idea was not that easy so I decided to recreate an existing
JavaScript game that I had played some time ago. The problem is that I can't remember what the original name was and
where I found this game. :-(</p>
<p><img src="/files/pics/2012/colorPuzzle.png" alt="screenshot"></p>
<p>The gameplay is easy: You have a grid of squares like a chessboard but not in black and white. Instead the squares are
randomly filled with one of 7 colors. At the beginning the player has control over the square in the top left corner.
With the buttons on the right (one for every color) you can change the color of the square(s) you control. When there is
a square with the same color in the direct neighbourhood of one of your controlled squares, this square is now also
controlled by you. When you now click on one of the color-buttons, all squares controlled by you are changing the color
again. The aim of the game is to control all squares with as little clicks as possible.</p>
<p>Like I said, the main reason to create the game was not to build a great new super game but to learn and exercise the
programming language and framework. The game was working more or less but there was an exception with the painting of
the component in rare cases. I wasn't able to find the real reason for this exception and so I haven't released the
game.</p>
<p>Since then I haven't worked on the game but some weeks ago I remembered the game and wanted to finish it. While looking
at the code I found some code smells and bad design. When I would build a game like this from scratch today I would do
many things differently.</p>
<p>As the first task I was looking at the unit-tests: I replaced <a href="http://www.easymock.org/">EasyMock</a> with
<a href="http://code.google.com/p/mockito/">Mockito</a> and changed all asserts to used
<a href="http://docs.codehaus.org/display/FEST/Fluent+Assertions+Module">FEST-Assert</a>. After this I refactored many classes and
splitted the code into smaller pieces. While I didn't know the concept of
<a href="http://en.wikipedia.org/wiki/Dependency_Injection">Dependency Injection</a> back in the time I created the game, nowadays
DI for me is one of the most important design patterns and so I modified the application to use
<a href="http://jcp.org/en/jsr/detail?id=299">CDI</a>/<a href="http://seamframework.org/Weld">WELD-SE</a>. I changed the whole event-mechanism
to also use the features of <a href="http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html/events.html">CDI-Events</a>. With
this modifications I was able to reduce the coupling between the components a lot.</p>
<p>The last modification was to change the way the canvas is repainted. The old version was using a game-loop with a
repaint-mechanism that was more suitable for games that need a high framerate. As this is not the case for this game I
changed it to used the default repaint mechanism of the swing components and removed the game loop. The exception that
irrirtated me at first was now gone and so I thought it would be the right time to "release" the game now.</p>
<p>Another reason to create the game was the idea to create something like an "artificial intelligence" (of cause it's not
realy intelligent or clever) that can solve the game. I liked to test many strategies to build AIs and let them play
against each other. I created a "Bogo" algorithm that chooses a color at random (referring to
<a href="http://en.wikipedia.org/wiki/Bogosort">BogoSort</a>) and a "Bruteforce" algorithm that tries every available color. At the
moment this artificial intelligence feature is disabled but probably in the future I will create a UI for this.</p>
<p>Have fun with the game. Before I forget, of course the Code is free software under the GPL and can be seen on
<a href="https://github.com/manuel_mauky/ColorPuzzle">github</a>. Feel free to look into it and tell me what you think.</p>]]></description>
            <content:encoded><![CDATA[<p>Today I like to show you a little java game I have written roughly a year ago. Back in that time I was looking at the
<a href="http://en.wikipedia.org/wiki/Java_2D">Java-2D-API</a> and Swing/Canvas and thought that the best way to learn this stuff
is to write a little game. Thinking of an good example game idea was not that easy so I decided to recreate an existing
JavaScript game that I had played some time ago. The problem is that I can't remember what the original name was and
where I found this game. :-(</p>
<p><img src="/files/pics/2012/colorPuzzle.png" alt="screenshot"></p>
<p>The gameplay is easy: You have a grid of squares like a chessboard but not in black and white. Instead the squares are
randomly filled with one of 7 colors. At the beginning the player has control over the square in the top left corner.
With the buttons on the right (one for every color) you can change the color of the square(s) you control. When there is
a square with the same color in the direct neighbourhood of one of your controlled squares, this square is now also
controlled by you. When you now click on one of the color-buttons, all squares controlled by you are changing the color
again. The aim of the game is to control all squares with as little clicks as possible.</p>
<p>Like I said, the main reason to create the game was not to build a great new super game but to learn and exercise the
programming language and framework. The game was working more or less but there was an exception with the painting of
the component in rare cases. I wasn't able to find the real reason for this exception and so I haven't released the
game.</p>
<p>Since then I haven't worked on the game but some weeks ago I remembered the game and wanted to finish it. While looking
at the code I found some code smells and bad design. When I would build a game like this from scratch today I would do
many things differently.</p>
<p>As the first task I was looking at the unit-tests: I replaced <a href="http://www.easymock.org/">EasyMock</a> with
<a href="http://code.google.com/p/mockito/">Mockito</a> and changed all asserts to used
<a href="http://docs.codehaus.org/display/FEST/Fluent+Assertions+Module">FEST-Assert</a>. After this I refactored many classes and
splitted the code into smaller pieces. While I didn't know the concept of
<a href="http://en.wikipedia.org/wiki/Dependency_Injection">Dependency Injection</a> back in the time I created the game, nowadays
DI for me is one of the most important design patterns and so I modified the application to use
<a href="http://jcp.org/en/jsr/detail?id=299">CDI</a>/<a href="http://seamframework.org/Weld">WELD-SE</a>. I changed the whole event-mechanism
to also use the features of <a href="http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html/events.html">CDI-Events</a>. With
this modifications I was able to reduce the coupling between the components a lot.</p>
<p>The last modification was to change the way the canvas is repainted. The old version was using a game-loop with a
repaint-mechanism that was more suitable for games that need a high framerate. As this is not the case for this game I
changed it to used the default repaint mechanism of the swing components and removed the game loop. The exception that
irrirtated me at first was now gone and so I thought it would be the right time to "release" the game now.</p>
<p>Another reason to create the game was the idea to create something like an "artificial intelligence" (of cause it's not
realy intelligent or clever) that can solve the game. I liked to test many strategies to build AIs and let them play
against each other. I created a "Bogo" algorithm that chooses a color at random (referring to
<a href="http://en.wikipedia.org/wiki/Bogosort">BogoSort</a>) and a "Bruteforce" algorithm that tries every available color. At the
moment this artificial intelligence feature is disabled but probably in the future I will create a UI for this.</p>
<p>Have fun with the game. Before I forget, of course the Code is free software under the GPL and can be seen on
<a href="https://github.com/manuel_mauky/ColorPuzzle">github</a>. Feel free to look into it and tell me what you think.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Another talk at the JUG Görlitz about JSF and CDI]]></title>
            <link>https://www.lestard.eu/2012/juggr_advanced_jsf_cdi/</link>
            <guid>https://www.lestard.eu/2012/juggr_advanced_jsf_cdi/</guid>
            <pubDate>Sat, 11 Feb 2012 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Last year I already gave a <a href="/2011/juggr_jsf_cdi">talk</a> about <strong>JavaServer Faces</strong> and <strong>Contexts and Dependency
Injection</strong> at the Java User Group Görlitz. At the
<a href="http://www.jug-gr.de/2012/01/25/jsf_cdi_advanced.html">january meeting</a> of the JUG Görlitz on january the 25th I gave
another talk building upon the last one. This time I explained some other features of JSF and CDI, namely:</p>
<ul>
<li>navigation in JSF</li>
<li>templates and reusing of facelets</li>
<li>Ajax with JSF</li>
<li>little example with PrimeFaces</li>
<li>CDI Producer</li>
<li>Observer Pattern with CDI</li>
</ul>]]></description>
            <content:encoded><![CDATA[<p>Last year I already gave a <a href="/2011/juggr_jsf_cdi">talk</a> about <strong>JavaServer Faces</strong> and <strong>Contexts and Dependency
Injection</strong> at the Java User Group Görlitz. At the
<a href="http://www.jug-gr.de/2012/01/25/jsf_cdi_advanced.html">january meeting</a> of the JUG Görlitz on january the 25th I gave
another talk building upon the last one. This time I explained some other features of JSF and CDI, namely:</p>
<ul>
<li>navigation in JSF</li>
<li>templates and reusing of facelets</li>
<li>Ajax with JSF</li>
<li>little example with PrimeFaces</li>
<li>CDI Producer</li>
<li>Observer Pattern with CDI</li>
</ul>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Problem with el-api in Eclipse/Maven/Tomcat]]></title>
            <link>https://www.lestard.eu/2011/problem_with_el-api/</link>
            <guid>https://www.lestard.eu/2011/problem_with_el-api/</guid>
            <pubDate>Sat, 10 Dec 2011 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Recently I have worked a lot on Java Web projects and today I got strange exceptions like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span></span>LinkageError</span><span class="token operator">:</span> loader constraint violation<span class="token operator">:</span>
when resolving <span class="token keyword">interface</span> method <span class="token string">"javax.servlet.jsp.JspApplicationContext.addELResolver(Ljavax/el/ELResolver;)V"</span>
the <span class="token keyword">class</span> loader
<span class="token punctuation">(</span>instance of  org<span class="token operator">/</span>apache<span class="token operator">/</span>catalina<span class="token operator">/</span>loader<span class="token operator">/</span><span class="token class-name">WebappClassLoader</span><span class="token punctuation">)</span>
of the current <span class="token keyword">class</span><span class="token punctuation">,</span> com<span class="token operator">/</span>sun<span class="token operator">/</span>faces<span class="token operator">/</span>config<span class="token operator">/</span><span class="token class-name">ConfigureListener</span><span class="token punctuation">,</span>
and the <span class="token keyword">class</span> loader <span class="token punctuation">(</span>instance of org<span class="token operator">/</span>apache<span class="token operator">/</span>catalina<span class="token operator">/</span>loader<span class="token operator">/</span><span class="token class-name">StandardClassLoader</span><span class="token punctuation">)</span> <span class="token keyword">for</span> resolved <span class="token keyword">class</span><span class="token punctuation">,</span>
javax<span class="token operator">/</span>servlet<span class="token operator">/</span>jsp<span class="token operator">/</span><span class="token class-name">JspApplicationContext</span><span class="token punctuation">,</span> have different <span class="token class-name">Class</span> objects
<span class="token keyword">for</span> the type javax<span class="token operator">/</span>el<span class="token operator">/</span><span class="token class-name">ELResolver</span> used in the signature</code></pre></div>
<p>The origin was a little helper method that should lookup a String value in the expression language context:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">private</span> <span class="token class-name">String</span> <span class="token function">getStringELValue</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">String</span> el<span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token class-name">String</span> result <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>

   <span class="token class-name">FacesContext</span> fc <span class="token operator">=</span> <span class="token class-name">FacesContext</span><span class="token punctuation">.</span><span class="token function">getCurrentInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token keyword">if</span> <span class="token punctuation">(</span>fc <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">String</span> value <span class="token operator">=</span> fc<span class="token punctuation">.</span><span class="token function">getApplication</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">evaluateExpressionGet</span><span class="token punctuation">(</span>fc<span class="token punctuation">,</span> el<span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>value<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
         result <span class="token operator">=</span> value<span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
   <span class="token punctuation">}</span>

   <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This methods depends on classes from the <strong>el-api.jar</strong>. This jar is provided by tomcat per default so you don't have to
provide it with your application but to be able to compile (and test) the code with maven you have to specify the
dependency in your project's pom.xml:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>javax.el<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>el-api<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>2.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>provided<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></code></pre></div>
<p>Line 5 (<code class="language-text">&lt;scope>provided&lt;/scope></code>) is important in this dependency definition because it tells maven to use the
el-api.jar to compile and test the application but not to put it in the WEB-INF/libs folder of the resulting
web-application because this jar is already provided by the server.</p>
<p>After a lot of investigation I found out that the maven-plugin of eclipse doesn't care about this scope declaration. The
result is that there are 2 copies of some classes on the classpath which causes the exception mentioned above.</p>
<p>The solution was to install the <strong>m2e-wtp</strong> plugin. As the name suggests this plugin does some kind of integration
between maven and the web tools platform (wtp). After installing this plugin you have to choose "Update Project
Configuration" in the maven sub-menu of your project. After this, everything was working perfectly. Maven was able to
build the application and run all tests and tomcat was able to deploy and run the application without any exceptions.</p>
<p>After installing the plugin I got some red crosses on my projects telling me that there are still some problems. The
reason for this was a wrong compiler setting. It seems that the new maven plugin tells the projects that they are of
java version 1.5 and not 1.6 as it should be. The solution was to explicitly configure the compiler setting in the
pom.xml:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>build</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugins</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugin</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>maven-compiler-plugin<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>2.3.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>configuration</span><span class="token punctuation">></span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>source</span><span class="token punctuation">></span></span>1.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>source</span><span class="token punctuation">></span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>target</span><span class="token punctuation">></span></span>1.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>target</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>configuration</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugin</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugins</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>build</span><span class="token punctuation">></span></span></code></pre></div>]]></description>
            <content:encoded><![CDATA[<p>Recently I have worked a lot on Java Web projects and today I got strange exceptions like this:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span></span>LinkageError</span><span class="token operator">:</span> loader constraint violation<span class="token operator">:</span>
when resolving <span class="token keyword">interface</span> method <span class="token string">"javax.servlet.jsp.JspApplicationContext.addELResolver(Ljavax/el/ELResolver;)V"</span>
the <span class="token keyword">class</span> loader
<span class="token punctuation">(</span>instance of  org<span class="token operator">/</span>apache<span class="token operator">/</span>catalina<span class="token operator">/</span>loader<span class="token operator">/</span><span class="token class-name">WebappClassLoader</span><span class="token punctuation">)</span>
of the current <span class="token keyword">class</span><span class="token punctuation">,</span> com<span class="token operator">/</span>sun<span class="token operator">/</span>faces<span class="token operator">/</span>config<span class="token operator">/</span><span class="token class-name">ConfigureListener</span><span class="token punctuation">,</span>
and the <span class="token keyword">class</span> loader <span class="token punctuation">(</span>instance of org<span class="token operator">/</span>apache<span class="token operator">/</span>catalina<span class="token operator">/</span>loader<span class="token operator">/</span><span class="token class-name">StandardClassLoader</span><span class="token punctuation">)</span> <span class="token keyword">for</span> resolved <span class="token keyword">class</span><span class="token punctuation">,</span>
javax<span class="token operator">/</span>servlet<span class="token operator">/</span>jsp<span class="token operator">/</span><span class="token class-name">JspApplicationContext</span><span class="token punctuation">,</span> have different <span class="token class-name">Class</span> objects
<span class="token keyword">for</span> the type javax<span class="token operator">/</span>el<span class="token operator">/</span><span class="token class-name">ELResolver</span> used in the signature</code></pre></div>
<p>The origin was a little helper method that should lookup a String value in the expression language context:</p>
<div class="gatsby-highlight" data-language="java"><pre class="language-java"><code class="language-java"><span class="token keyword">private</span> <span class="token class-name">String</span> <span class="token function">getStringELValue</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">String</span> el<span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token class-name">String</span> result <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>

   <span class="token class-name">FacesContext</span> fc <span class="token operator">=</span> <span class="token class-name">FacesContext</span><span class="token punctuation">.</span><span class="token function">getCurrentInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token keyword">if</span> <span class="token punctuation">(</span>fc <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">String</span> value <span class="token operator">=</span> fc<span class="token punctuation">.</span><span class="token function">getApplication</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">evaluateExpressionGet</span><span class="token punctuation">(</span>fc<span class="token punctuation">,</span> el<span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>value<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
         result <span class="token operator">=</span> value<span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
   <span class="token punctuation">}</span>

   <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This methods depends on classes from the <strong>el-api.jar</strong>. This jar is provided by tomcat per default so you don't have to
provide it with your application but to be able to compile (and test) the code with maven you have to specify the
dependency in your project's pom.xml:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>javax.el<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>el-api<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>2.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>provided<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></code></pre></div>
<p>Line 5 (<code class="language-text">&lt;scope>provided&lt;/scope></code>) is important in this dependency definition because it tells maven to use the
el-api.jar to compile and test the application but not to put it in the WEB-INF/libs folder of the resulting
web-application because this jar is already provided by the server.</p>
<p>After a lot of investigation I found out that the maven-plugin of eclipse doesn't care about this scope declaration. The
result is that there are 2 copies of some classes on the classpath which causes the exception mentioned above.</p>
<p>The solution was to install the <strong>m2e-wtp</strong> plugin. As the name suggests this plugin does some kind of integration
between maven and the web tools platform (wtp). After installing this plugin you have to choose "Update Project
Configuration" in the maven sub-menu of your project. After this, everything was working perfectly. Maven was able to
build the application and run all tests and tomcat was able to deploy and run the application without any exceptions.</p>
<p>After installing the plugin I got some red crosses on my projects telling me that there are still some problems. The
reason for this was a wrong compiler setting. It seems that the new maven plugin tells the projects that they are of
java version 1.5 and not 1.6 as it should be. The solution was to explicitly configure the compiler setting in the
pom.xml:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>build</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugins</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugin</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>maven-compiler-plugin<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>2.3.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>configuration</span><span class="token punctuation">></span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>source</span><span class="token punctuation">></span></span>1.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>source</span><span class="token punctuation">></span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>target</span><span class="token punctuation">></span></span>1.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>target</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>configuration</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugin</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugins</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>build</span><span class="token punctuation">></span></span></code></pre></div>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Talk at the JavaUserGroup Görlitz about JavaServer Faces 2]]></title>
            <link>https://www.lestard.eu/2011/juggr_jsf_cdi/</link>
            <guid>https://www.lestard.eu/2011/juggr_jsf_cdi/</guid>
            <pubDate>Fri, 02 Dec 2011 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>On November the 30th I gave a talk about "JavaServer Faces 2" and "Context and Dependency Injection (CDI)" at the Java
User Group Görlitz. I talked about some of the main features and concepts of JSF2 like <em>ManagedBeans</em>, <em>Facelets</em> and
the <em>Expression Language</em>. After that I gave a little introduction to CDI because in my opinion it harmonizes very good
with JSF2.</p>
<p>After the talk I developed a little example application that uses JSF2 and CDI on the projector. In this application the
user can add and store notes. The project uses maven for the dependency management.</p>
<p>You can download the slides and the project here:</p>
<ul>
<li><a href="/files/pdf/2011/JavaUserGroup_JSF2.pdf">JSF2 slides for JavaUserGroup Görlitz</a></li>
<li><a href="https://github.com/manuel_mauky/juggr_jsf_cdi">JSF2 project</a></li>
</ul>]]></description>
            <content:encoded><![CDATA[<p>On November the 30th I gave a talk about "JavaServer Faces 2" and "Context and Dependency Injection (CDI)" at the Java
User Group Görlitz. I talked about some of the main features and concepts of JSF2 like <em>ManagedBeans</em>, <em>Facelets</em> and
the <em>Expression Language</em>. After that I gave a little introduction to CDI because in my opinion it harmonizes very good
with JSF2.</p>
<p>After the talk I developed a little example application that uses JSF2 and CDI on the projector. In this application the
user can add and store notes. The project uses maven for the dependency management.</p>
<p>You can download the slides and the project here:</p>
<ul>
<li><a href="/files/pdf/2011/JavaUserGroup_JSF2.pdf">JSF2 slides for JavaUserGroup Görlitz</a></li>
<li><a href="https://github.com/manuel_mauky/juggr_jsf_cdi">JSF2 project</a></li>
</ul>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Interesting Blogs of two fellows of mine]]></title>
            <link>https://www.lestard.eu/2011/interesting_blogs/</link>
            <guid>https://www.lestard.eu/2011/interesting_blogs/</guid>
            <pubDate>Sun, 10 Jul 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Today I want to recommend the Blogs of two fellows of mine. First the
<a href="http://max-wielsch.blogspot.com/">blog of Max Wielsch</a> in which he writes about his experiences related to computer
science and software development. He is working at the same company as me and is proceeding a project I started
implementing at the beginning of the year which is called the <strong>"Human Task Service"</strong>. This is a Software which
integrates human interactions in
<a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service Oriented Architectures</a> (SOA). This is necessary
because <a href="http://en.wikipedia.org/wiki/Business_Process_Execution_Language">BPEL</a>, the standard to orchestrate
webservices to SOA's doesn't come with build in support for human interactions. Amoung other things, in his blog Max
describes one component of this Human Task Infrastructure in detail which is used to monitor the hole application.</p>
<p>The second blog I like to recommend is the <a href="http://raik-bieniek.blogspot.com/">blog of Raik Bieniek</a>. He is also one of
my fellows and in his blog he writes about <a href="http://en.wikipedia.org/wiki/Acceptance_testing">Acceptance Tests</a> with
internal DSLs. "DSL" stands for "Domain Specific Language" and means that there is a language (similar to programming
languages) with which a customer can write acceptance tests in his own words. He doesn't need to know technical things
and terms but can use terms from his own subject area. Raik developes a framework with which you can create such DSLs
for your desired subject. "Internal DSL" means that you use an existing programming language to build your DSL on top of
it. The benefit is that you can use features of this existing programming language. He uses for his framework the
programming language <a href="http://en.wikipedia.org/wiki/Groovy_%28programming_language%29">Groovy</a> which runs on the Java
Virtual Machine.</p>]]></description>
            <content:encoded><![CDATA[<p>Today I want to recommend the Blogs of two fellows of mine. First the
<a href="http://max-wielsch.blogspot.com/">blog of Max Wielsch</a> in which he writes about his experiences related to computer
science and software development. He is working at the same company as me and is proceeding a project I started
implementing at the beginning of the year which is called the <strong>"Human Task Service"</strong>. This is a Software which
integrates human interactions in
<a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service Oriented Architectures</a> (SOA). This is necessary
because <a href="http://en.wikipedia.org/wiki/Business_Process_Execution_Language">BPEL</a>, the standard to orchestrate
webservices to SOA's doesn't come with build in support for human interactions. Amoung other things, in his blog Max
describes one component of this Human Task Infrastructure in detail which is used to monitor the hole application.</p>
<p>The second blog I like to recommend is the <a href="http://raik-bieniek.blogspot.com/">blog of Raik Bieniek</a>. He is also one of
my fellows and in his blog he writes about <a href="http://en.wikipedia.org/wiki/Acceptance_testing">Acceptance Tests</a> with
internal DSLs. "DSL" stands for "Domain Specific Language" and means that there is a language (similar to programming
languages) with which a customer can write acceptance tests in his own words. He doesn't need to know technical things
and terms but can use terms from his own subject area. Raik developes a framework with which you can create such DSLs
for your desired subject. "Internal DSL" means that you use an existing programming language to build your DSL on top of
it. The benefit is that you can use features of this existing programming language. He uses for his framework the
programming language <a href="http://en.wikipedia.org/wiki/Groovy_%28programming_language%29">Groovy</a> which runs on the Java
Virtual Machine.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Hiding Toolbars for App-Tabs in Firefox]]></title>
            <link>https://www.lestard.eu/2011/hiding_toolbars_for_app_tabs/</link>
            <guid>https://www.lestard.eu/2011/hiding_toolbars_for_app_tabs/</guid>
            <pubDate>Mon, 27 Jun 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Some weeks ago I have written a little <a href="/2011/hide_toolsbars">Addon for Firefox</a> which lets you hide the toolbars for
domains. This was mainly aimed at App-Tabs introduced in Firefox 4. The Addon was working for me and some friends but
sadly the people on Firefox's Addonsite obviously couldn't get it to work and so it wasn't hostet on there.</p>
<p>Today I have read a <a href="https://wiki.mozilla.org/Firefox/Features/Toolbarless">wikipage</a> which stated that the Firefox
developers are working on a similar functionality for a future release of Firefox. I think that's great because this
feature is really usefull.</p>]]></description>
            <content:encoded><![CDATA[<p>Some weeks ago I have written a little <a href="/2011/hide_toolsbars">Addon for Firefox</a> which lets you hide the toolbars for
domains. This was mainly aimed at App-Tabs introduced in Firefox 4. The Addon was working for me and some friends but
sadly the people on Firefox's Addonsite obviously couldn't get it to work and so it wasn't hostet on there.</p>
<p>Today I have read a <a href="https://wiki.mozilla.org/Firefox/Features/Toolbarless">wikipage</a> which stated that the Firefox
developers are working on a similar functionality for a future release of Firefox. I think that's great because this
feature is really usefull.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[YouPay: Android/iPhone app for roommates and everyone else]]></title>
            <link>https://www.lestard.eu/2011/youpay/</link>
            <guid>https://www.lestard.eu/2011/youpay/</guid>
            <pubDate>Fri, 10 Jun 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>If you have ever lived in a flat-sharing community you probably know this situation: Everyone has a turn to do the
shopping from time to time. Today you go shopping for 12 € and the next time your roommate goes for only 8 € and tells
you that you are the next in line. That's not fair, isn't it?</p>
<p>Some friends of mine and me have thought of a solution for this problem: YouPay - An app where you and your friends can
enter your expenses and the app tells you who is the next in line. There is already an
<a href="http://itunes.apple.com/de/app/you-pay/id426425051?mt=8&#x26;affId=1771175&#x26;ign-mpt=uo%3D4">iPhone app</a> available, last week
the <a href="https://market.android.com/details?id=de.stefanheinze.youpay">Android</a> version was released and I'm working on an
web version of this app. At the moment I can't say when the webapp will be ready because I have also some other projects
I'm working on and there is some additional planing to do because the web version will have some extra functionality
compared to both smartphone apps (of cource I don't tell you more about this at the moment).</p>
<p>Please check out the apps if you are an iPhone or Android user and give feedback. Both Apps are free (this time only
free as in free beer).</p>
<p><img src="https://ssl.gstatic.com/android/market/de.stefanheinze.youpay/hi-256-0-f68ad7a449e661db29baed603c07452981814eab" alt="logo">
<img src="https://ssl.gstatic.com/android/market/de.stefanheinze.youpay/ss-3-1-8d4bc5decedabdcb30e91e6f91ab31a1e0968934" alt="screenshot"></p>]]></description>
            <content:encoded><![CDATA[<p>If you have ever lived in a flat-sharing community you probably know this situation: Everyone has a turn to do the
shopping from time to time. Today you go shopping for 12 € and the next time your roommate goes for only 8 € and tells
you that you are the next in line. That's not fair, isn't it?</p>
<p>Some friends of mine and me have thought of a solution for this problem: YouPay - An app where you and your friends can
enter your expenses and the app tells you who is the next in line. There is already an
<a href="http://itunes.apple.com/de/app/you-pay/id426425051?mt=8&#x26;affId=1771175&#x26;ign-mpt=uo%3D4">iPhone app</a> available, last week
the <a href="https://market.android.com/details?id=de.stefanheinze.youpay">Android</a> version was released and I'm working on an
web version of this app. At the moment I can't say when the webapp will be ready because I have also some other projects
I'm working on and there is some additional planing to do because the web version will have some extra functionality
compared to both smartphone apps (of cource I don't tell you more about this at the moment).</p>
<p>Please check out the apps if you are an iPhone or Android user and give feedback. Both Apps are free (this time only
free as in free beer).</p>
<p><img src="https://ssl.gstatic.com/android/market/de.stefanheinze.youpay/hi-256-0-f68ad7a449e661db29baed603c07452981814eab" alt="logo">
<img src="https://ssl.gstatic.com/android/market/de.stefanheinze.youpay/ss-3-1-8d4bc5decedabdcb30e91e6f91ab31a1e0968934" alt="screenshot"></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[OSGi and SpringDM workshop for the JavaUserGroup Görlitz]]></title>
            <link>https://www.lestard.eu/2011/juggr_osgi_springdm/</link>
            <guid>https://www.lestard.eu/2011/juggr_osgi_springdm/</guid>
            <pubDate>Sun, 01 May 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Last wednesday I have done a workshop for the Java User Group Görlitz with the topic "OSGi Serviceplatform und Spring
DM".</p>
<p><a href="http://en.wikipedia.org/wiki/Osgi">OSGi</a> is a specification for a service-based application framework for Java. While
in pure Java you use <a href="http://en.wikipedia.org/wiki/Java_package">packages</a> to encapsulate code, with OSGi you have
another abstraction layer called "bundles". These bundles can contain many packages and you can define that the bundle
"exports" some of these packages. Other bundles can than "import" these exported packages to use that code. You can
encapsulate different functionalities into different bundles.</p>
<p>One of the main features of OSGi is the ability to load a bundle at runtime. While the whole application is running you
can install, update, start, stop or uninstall a bundle. So when you change some code inside a bundle or you fix a bug,
the application don't have to be redeployed to get the new code running.</p>
<p>With Spring DM you can combine the features of OSGi with the
<a href="http://en.wikipedia.org/wiki/Spring_Framework">Spring framework</a>. This is a great combination to build modular business
applications in Java.</p>
<ul>
<li><a href="/files/pdf/2011/OSGi-Serviceplatform-und-SpringDM.pdf">Workshop OSGi und Spring DM (german) as pdf</a></li>
</ul>]]></description>
            <content:encoded><![CDATA[<p>Last wednesday I have done a workshop for the Java User Group Görlitz with the topic "OSGi Serviceplatform und Spring
DM".</p>
<p><a href="http://en.wikipedia.org/wiki/Osgi">OSGi</a> is a specification for a service-based application framework for Java. While
in pure Java you use <a href="http://en.wikipedia.org/wiki/Java_package">packages</a> to encapsulate code, with OSGi you have
another abstraction layer called "bundles". These bundles can contain many packages and you can define that the bundle
"exports" some of these packages. Other bundles can than "import" these exported packages to use that code. You can
encapsulate different functionalities into different bundles.</p>
<p>One of the main features of OSGi is the ability to load a bundle at runtime. While the whole application is running you
can install, update, start, stop or uninstall a bundle. So when you change some code inside a bundle or you fix a bug,
the application don't have to be redeployed to get the new code running.</p>
<p>With Spring DM you can combine the features of OSGi with the
<a href="http://en.wikipedia.org/wiki/Spring_Framework">Spring framework</a>. This is a great combination to build modular business
applications in Java.</p>
<ul>
<li><a href="/files/pdf/2011/OSGi-Serviceplatform-und-SpringDM.pdf">Workshop OSGi und Spring DM (german) as pdf</a></li>
</ul>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Fixed wrong behaviour in log4xul]]></title>
            <link>https://www.lestard.eu/2011/fixed_log4xul/</link>
            <guid>https://www.lestard.eu/2011/fixed_log4xul/</guid>
            <pubDate>Wed, 20 Apr 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Last week I was coding a little bit on my music player and as everytime I used my little logging-library
<a href="https://bitbucket.org/lestard/log4xul">log4xul</a>. Most of the time I have the Level of the logger set to "debug" so that
it prints every message. Because of this I haven't noticed that I have made a really embarrassing mistake with the
logging levels in Log4xul. I have mixed the hierarchy of the levels so that with the logging level set to "DEBUG" the
logger only prints this debug-messages while when set to "ERROR" it prints everything.</p>
<p>Of cause this is wrong because you want the exactly reverse thing: When the level is set to "DEBUG" you want to get
every message and with level set to "ERROR" you only want to get the error messages.</p>
<p>Now I have fixed this so the Log4xul should now work as expected.</p>
<h3>Log4Moz</h3>
<p>I have also found out that I have not searched enought for other logging frameworks at the time when I started to write
Log4xul. In the meantime I have found the <a href="https://wiki.mozilla.org/Labs/JS_Modules#Logging">Log4Moz framework</a> which is
made for logging within firefox extensions. It is a lot more similar to the "original"
<a href="https://logging.apache.org/log4j">Log4J</a> and gives you the possibility to create hierarchically structured loggers for
your files.</p>
<p>When I first used Log4Moz I was impressed and intended to use it in the future. But then I switched back to my own
logger because Log4Moz has no ability to print the messages in a textbox but only to the JSConsole and to a logfile.</p>
<p>I have tried to write my own TextboxAppender for Log4Moz but it only worked till I hit the reload-button. After this it
crashed. I don't know if it even would be possibile to write this kind of appender with the achitecture of Log4Moz.</p>]]></description>
            <content:encoded><![CDATA[<p>Last week I was coding a little bit on my music player and as everytime I used my little logging-library
<a href="https://bitbucket.org/lestard/log4xul">log4xul</a>. Most of the time I have the Level of the logger set to "debug" so that
it prints every message. Because of this I haven't noticed that I have made a really embarrassing mistake with the
logging levels in Log4xul. I have mixed the hierarchy of the levels so that with the logging level set to "DEBUG" the
logger only prints this debug-messages while when set to "ERROR" it prints everything.</p>
<p>Of cause this is wrong because you want the exactly reverse thing: When the level is set to "DEBUG" you want to get
every message and with level set to "ERROR" you only want to get the error messages.</p>
<p>Now I have fixed this so the Log4xul should now work as expected.</p>
<h3>Log4Moz</h3>
<p>I have also found out that I have not searched enought for other logging frameworks at the time when I started to write
Log4xul. In the meantime I have found the <a href="https://wiki.mozilla.org/Labs/JS_Modules#Logging">Log4Moz framework</a> which is
made for logging within firefox extensions. It is a lot more similar to the "original"
<a href="https://logging.apache.org/log4j">Log4J</a> and gives you the possibility to create hierarchically structured loggers for
your files.</p>
<p>When I first used Log4Moz I was impressed and intended to use it in the future. But then I switched back to my own
logger because Log4Moz has no ability to print the messages in a textbox but only to the JSConsole and to a logfile.</p>
<p>I have tried to write my own TextboxAppender for Log4Moz but it only worked till I hit the reload-button. After this it
crashed. I don't know if it even would be possibile to write this kind of appender with the achitecture of Log4Moz.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[How it works: Hide Toolbars in Firefox 4]]></title>
            <link>https://www.lestard.eu/2011/how_it_works_hide_toolbars/</link>
            <guid>https://www.lestard.eu/2011/how_it_works_hide_toolbars/</guid>
            <pubDate>Sat, 09 Apr 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Last week I finished my <a href="2011/hide_toolbars">HideToolbarsByURL</a> extension. Now I want to explain a little bit how it
works. Because I have used this technique in my other project I thought this could probably be usefull for other people
as well.</p>
<h3>Hide the Toolbar</h3>
<p>In Firefox 4 there was a new Addon-Manager introduced which opens itself in a new tab. If you have set your tabbar to be
on top of the navigation bar this addons-manager tab has no navigationbar or bookmarksbar. This is realized with the new
function <code class="language-text">hideChromeForLocation</code> of the <a href="https://developer.mozilla.org/en/XULBrowserWindow">XULBrowserWindow object</a>.
This function is called everytime a tab is shown e.g. when you open a new tab or you switch to another tab. This
function gets the current location (URL) of the tab as an argument of the type string. If this function returns true for
the location then the toolbars are hidden.</p>
<p>If you want to hide your URL too you have to override this function so it returns true for your location. But if you
simply replace this function with your own, other extensions and firefox itself wouldn't be able to use this feature
anymore. The <a href="https://developer.mozilla.org/en/Hiding_browser_chrome">recommended way</a> to get your location hidden is to
chain your implementation of this function with the original one.</p>
<p>First you save a reference of the original implementation. Then you can override the function with your own. You have to
determine if the given location is your desired location and return true. Otherwise call the original implementation.</p>
<div class="gatsby-highlight" data-language="javascript"><pre class="language-javascript"><code class="language-javascript"><span class="token keyword">var</span> old <span class="token operator">=</span> XULBrowserWindow<span class="token punctuation">.</span>hideChromeForLocation

<span class="token comment">//override the hideChrome funtion with our logic</span>
XULBrowserWindow<span class="token punctuation">.</span><span class="token function-variable function">hideChromeForLocation</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">aLocation</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token number">0</span> <span class="token operator">===</span> aLocation<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">"http://www.lestard.eu"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token boolean">true</span>
  <span class="token punctuation">}</span>
  <span class="token comment">//Call the original hideChrome-function</span>
  <span class="token keyword">return</span> <span class="token function">old</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>XULBrowserWindow<span class="token punctuation">,</span> aLocation<span class="token punctuation">)</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If the current location (<code class="language-text">aLocation</code>) starts with "<a href="http://www.lestard.eu">http://www.lestard.eu</a>" then return true and hide the Toolbars.
Otherwise call the old implementation with the <em>aLocation</em> as argument.</p>
<p>In my extension I put the URLs which should be hidden in an array. In my overridden hideChromeForLocation function I
look if the current Location is in that array or not. Because I only want to check the first part of the URL (the
domain) I use the nsIURI object from mozilla.</p>]]></description>
            <content:encoded><![CDATA[<p>Last week I finished my <a href="2011/hide_toolbars">HideToolbarsByURL</a> extension. Now I want to explain a little bit how it
works. Because I have used this technique in my other project I thought this could probably be usefull for other people
as well.</p>
<h3>Hide the Toolbar</h3>
<p>In Firefox 4 there was a new Addon-Manager introduced which opens itself in a new tab. If you have set your tabbar to be
on top of the navigation bar this addons-manager tab has no navigationbar or bookmarksbar. This is realized with the new
function <code class="language-text">hideChromeForLocation</code> of the <a href="https://developer.mozilla.org/en/XULBrowserWindow">XULBrowserWindow object</a>.
This function is called everytime a tab is shown e.g. when you open a new tab or you switch to another tab. This
function gets the current location (URL) of the tab as an argument of the type string. If this function returns true for
the location then the toolbars are hidden.</p>
<p>If you want to hide your URL too you have to override this function so it returns true for your location. But if you
simply replace this function with your own, other extensions and firefox itself wouldn't be able to use this feature
anymore. The <a href="https://developer.mozilla.org/en/Hiding_browser_chrome">recommended way</a> to get your location hidden is to
chain your implementation of this function with the original one.</p>
<p>First you save a reference of the original implementation. Then you can override the function with your own. You have to
determine if the given location is your desired location and return true. Otherwise call the original implementation.</p>
<div class="gatsby-highlight" data-language="javascript"><pre class="language-javascript"><code class="language-javascript"><span class="token keyword">var</span> old <span class="token operator">=</span> XULBrowserWindow<span class="token punctuation">.</span>hideChromeForLocation

<span class="token comment">//override the hideChrome funtion with our logic</span>
XULBrowserWindow<span class="token punctuation">.</span><span class="token function-variable function">hideChromeForLocation</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">aLocation</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token number">0</span> <span class="token operator">===</span> aLocation<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">"http://www.lestard.eu"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token boolean">true</span>
  <span class="token punctuation">}</span>
  <span class="token comment">//Call the original hideChrome-function</span>
  <span class="token keyword">return</span> <span class="token function">old</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>XULBrowserWindow<span class="token punctuation">,</span> aLocation<span class="token punctuation">)</span>
<span class="token punctuation">}</span></code></pre></div>
<p>If the current location (<code class="language-text">aLocation</code>) starts with "<a href="http://www.lestard.eu">http://www.lestard.eu</a>" then return true and hide the Toolbars.
Otherwise call the old implementation with the <em>aLocation</em> as argument.</p>
<p>In my extension I put the URLs which should be hidden in an array. In my overridden hideChromeForLocation function I
look if the current Location is in that array or not. Because I only want to check the first part of the URL (the
domain) I use the nsIURI object from mozilla.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Add-on submitted to AMO]]></title>
            <link>https://www.lestard.eu/2011/addon_submitted_to_amo/</link>
            <guid>https://www.lestard.eu/2011/addon_submitted_to_amo/</guid>
            <pubDate>Thu, 31 Mar 2011 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>I have finished my work on the "hide-toolbars-by-URL" extension and also submitted it to addons.mozilla.org (AMO). Now
they review the addon and look if it's working properly. Within the next days the review process should be finished and
then the addon would be visible on the addons-page.</p>
<p><s>But you can use the addon anyway because it is already available on AMO but not visible in the search-results. So to
use it you need the URL which is:
<a href="https://addons.mozilla.org/de/firefox/addon/hide-toolbars-by-url/">https://addons.mozilla.org/de/firefox/addon/hide-toolbars-by-url/</a></s></p>
<p>UPDATE: The link isn't working anymore. To use the add-on you will have to
<a href="https://github.com/manuel_mauky/Hide-Toolbars-by-URLs/blob/develop/hideToolbarsByURL.xpi">download</a> and install it on your
own from github.</p>
<p>The code is available at github:
<a href="https://github.com/manuel_mauky/Hide-Toolbars-by-URLs">https://github.com/manuel_mauky/Hide-Toolbars-by-URLs</a></p>
<p>Within the next days I want to write some lines on how the addon works so everybody who is interested in can use the
code.</p>]]></description>
            <content:encoded><![CDATA[<p>I have finished my work on the "hide-toolbars-by-URL" extension and also submitted it to addons.mozilla.org (AMO). Now
they review the addon and look if it's working properly. Within the next days the review process should be finished and
then the addon would be visible on the addons-page.</p>
<p><s>But you can use the addon anyway because it is already available on AMO but not visible in the search-results. So to
use it you need the URL which is:
<a href="https://addons.mozilla.org/de/firefox/addon/hide-toolbars-by-url/">https://addons.mozilla.org/de/firefox/addon/hide-toolbars-by-url/</a></s></p>
<p>UPDATE: The link isn't working anymore. To use the add-on you will have to
<a href="https://github.com/manuel_mauky/Hide-Toolbars-by-URLs/blob/develop/hideToolbarsByURL.xpi">download</a> and install it on your
own from github.</p>
<p>The code is available at github:
<a href="https://github.com/manuel_mauky/Hide-Toolbars-by-URLs">https://github.com/manuel_mauky/Hide-Toolbars-by-URLs</a></p>
<p>Within the next days I want to write some lines on how the addon works so everybody who is interested in can use the
code.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Hide Toolbars in Firefox 4]]></title>
            <link>https://www.lestard.eu/2011/hide_toolbars/</link>
            <guid>https://www.lestard.eu/2011/hide_toolbars/</guid>
            <pubDate>Sat, 26 Mar 2011 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>With the new <a href="http://www.mozilla.com/de/firefox/">Firefox 4 release</a> mozilla has introduced some interesting new
features and improvements. Particularly the changes to the GUI are interesting. Now you can pin a Tab as
"<a href="http://support.mozilla.com/de/kb/was-sind-app-tabs">App Tab</a>" and so the tab is pinned on the left side of the
tab-panel and you only see the favicon of this tab. I really like this for applications like google mail and google
calender but also for news pages I regularly read.</p>
<p>But there are also problems with this approach. Sometimes I forget that I'm in an AppTab and that I don't want to switch
to another page in this Tab. But because I have the URL-bar available it happens that I found another page in the Tab
where my "App" should be.</p>
<p>Another issue is that the main goal of the AppTabs is saving space. To support this, wouldn't it be cool to hide the
URL-bar and other toolbars when you are in an AppTab? You also couldn't change the location by accident. This is what I
thought and so I begun to write a little extension to enable this.</p>
<p>Happily mozilla introduced a <a href="https://developer.mozilla.org/en/Hiding_browser_chrome">technique to do exactly this</a>. For
example when you open the new Addon-Manager you see that it is opened in a new tab. If you have set your tabpanel to be
on top of the URL-bar you will see the toolbars hidden when you are inside of the Addon-Manager-tab. You can use this
technique for every page you want ... at least on paper. Sadly there is no GUI with which you could enable hiding for a
specified URL. This is what my extension is doing.</p>
<p>With my extension "Hide Toolbars by URL" you have a new entry in the context menu of every tab with which you can hide
this URL. The hiding is connected to the URL, not to the tab. So if you open the same URL in another tab it will also be
hidden. But because the exact URL will change when you use the page (i.e. when you follow a link on this domain you will
be at another URL) it wouldn't be really cool. So only the first part of the URL is used to determine if the tab should
be hidden. I only use "<a href="http://www.google.de">http://www.google.de</a>" - everything behind is cut of. So every "subpage" of "<a href="http://www.google.de">http://www.google.de</a>"
will be hidden. I'm not sure if this approach is the bests so I would love to get feedback for this. Probably I will
change this in the future.</p>
<p>Of cause the code is free and open source - you can get the code at
<a href="https://github.com/manuel_mauky/Hide-Toolbars-by-URLs">github.com</a>. There is also the xpi-file you need to install. I will
give this extension to the addon-page of mozilla and probably they will add this to there page so you can easily install
it the same way you install every extension.</p>]]></description>
            <content:encoded><![CDATA[<p>With the new <a href="http://www.mozilla.com/de/firefox/">Firefox 4 release</a> mozilla has introduced some interesting new
features and improvements. Particularly the changes to the GUI are interesting. Now you can pin a Tab as
"<a href="http://support.mozilla.com/de/kb/was-sind-app-tabs">App Tab</a>" and so the tab is pinned on the left side of the
tab-panel and you only see the favicon of this tab. I really like this for applications like google mail and google
calender but also for news pages I regularly read.</p>
<p>But there are also problems with this approach. Sometimes I forget that I'm in an AppTab and that I don't want to switch
to another page in this Tab. But because I have the URL-bar available it happens that I found another page in the Tab
where my "App" should be.</p>
<p>Another issue is that the main goal of the AppTabs is saving space. To support this, wouldn't it be cool to hide the
URL-bar and other toolbars when you are in an AppTab? You also couldn't change the location by accident. This is what I
thought and so I begun to write a little extension to enable this.</p>
<p>Happily mozilla introduced a <a href="https://developer.mozilla.org/en/Hiding_browser_chrome">technique to do exactly this</a>. For
example when you open the new Addon-Manager you see that it is opened in a new tab. If you have set your tabpanel to be
on top of the URL-bar you will see the toolbars hidden when you are inside of the Addon-Manager-tab. You can use this
technique for every page you want ... at least on paper. Sadly there is no GUI with which you could enable hiding for a
specified URL. This is what my extension is doing.</p>
<p>With my extension "Hide Toolbars by URL" you have a new entry in the context menu of every tab with which you can hide
this URL. The hiding is connected to the URL, not to the tab. So if you open the same URL in another tab it will also be
hidden. But because the exact URL will change when you use the page (i.e. when you follow a link on this domain you will
be at another URL) it wouldn't be really cool. So only the first part of the URL is used to determine if the tab should
be hidden. I only use "<a href="http://www.google.de">http://www.google.de</a>" - everything behind is cut of. So every "subpage" of "<a href="http://www.google.de">http://www.google.de</a>"
will be hidden. I'm not sure if this approach is the bests so I would love to get feedback for this. Probably I will
change this in the future.</p>
<p>Of cause the code is free and open source - you can get the code at
<a href="https://github.com/manuel_mauky/Hide-Toolbars-by-URLs">github.com</a>. There is also the xpi-file you need to install. I will
give this extension to the addon-page of mozilla and probably they will add this to there page so you can easily install
it the same way you install every extension.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Fortschritte beim Musikplayer]]></title>
            <link>https://www.lestard.eu/2011/progress_with_musicplayer/</link>
            <guid>https://www.lestard.eu/2011/progress_with_musicplayer/</guid>
            <pubDate>Wed, 09 Mar 2011 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Eine ganze weile schon habe ich hier nichts mehr geschrieben, was jedoch nicht heisst, dass ich völlig untätig war. Ich
habe in den letzten Wochen immer wieder Zeit gefunden, um an meiner Idee weiter zu arbeiten, eine eigene
Musik-Abspielsoftware zu entwickeln. Diese Fortschritte möchte ich nun auch hier im Blog kommunizieren.</p>
<p>Zunächst einmal etwas ernüchternd: Mein Programm spielt noch keine Musik ab. In der derzeitigen Form ist das Programm
nach wie vor eher eine Art Mockup oder GUI-Prototyp dar. Es zeigt, wie ich mir die Programmoberfläche vorstelle und
stellt auch einige Bedienkonzepte vor.</p>
<p>Realisiert ist der Player zur Zeit als Firefox-Addon und noch nicht als eigenständige Anwendung. Später wird der Player
aber auch ohne Firefox lauffähig sein. Ich möchte aber auch die Variante als Addon beibehalten, weil ich dies fǘr eine
Interessante Alternative halte.</p>
<p>Ich werde in den nächsten Tagen noch einmal in einem Artikel zusammenfassen, welche Ziele ich mir für das Projekt
gesetzt habe und welche Anforderungen ich erfüllen möchte. Auch werde ich dann erklären, warum ich einen eigenen Player
entwickeln möchte, obwohl es ja schon eine ganze
<a href="http://en.wikipedia.org/wiki/Comparison_of_audio_player_software">Reihe von Playersoftware</a> gibt. Ich möchte in der
nächsten Zeit öffters den aktuellen Stand des Projekts hier beschreiben und so den Projektverlauf dokumentieren. Daneben
habe ich ein <a href="https://github.com/manuel_mauky/ProtistPlayer">Projekt auf github.com</a> für den Player gestartet. Wer github.com
nicht kennt: Dies ist eine Projekt-Hostingseite, die auf dem
<a href="http://de.wikipedia.org/wiki/Verteilte_Versionsverwaltung#Verteilte_Versionsverwaltung">Verteilten Versionsverwaltungssystem</a>
git aufsetzt. <a href="http://de.wikipedia.org/wiki/Git">Git</a> ist von seinem Funktionsumfang und den dahinter liegenden
Konzepten mit <a href="http://de.wikipedia.org/wiki/Mercurial">Mercurial</a> vergleichbar, welches ich bisher verwendet habe. Ich
bin nach wie vor ein Fan von Mercurial, wollte aber aus verschiedenen Gründen auch einmal git und auch github
ausprobieren.</p>]]></description>
            <content:encoded><![CDATA[<p>Eine ganze weile schon habe ich hier nichts mehr geschrieben, was jedoch nicht heisst, dass ich völlig untätig war. Ich
habe in den letzten Wochen immer wieder Zeit gefunden, um an meiner Idee weiter zu arbeiten, eine eigene
Musik-Abspielsoftware zu entwickeln. Diese Fortschritte möchte ich nun auch hier im Blog kommunizieren.</p>
<p>Zunächst einmal etwas ernüchternd: Mein Programm spielt noch keine Musik ab. In der derzeitigen Form ist das Programm
nach wie vor eher eine Art Mockup oder GUI-Prototyp dar. Es zeigt, wie ich mir die Programmoberfläche vorstelle und
stellt auch einige Bedienkonzepte vor.</p>
<p>Realisiert ist der Player zur Zeit als Firefox-Addon und noch nicht als eigenständige Anwendung. Später wird der Player
aber auch ohne Firefox lauffähig sein. Ich möchte aber auch die Variante als Addon beibehalten, weil ich dies fǘr eine
Interessante Alternative halte.</p>
<p>Ich werde in den nächsten Tagen noch einmal in einem Artikel zusammenfassen, welche Ziele ich mir für das Projekt
gesetzt habe und welche Anforderungen ich erfüllen möchte. Auch werde ich dann erklären, warum ich einen eigenen Player
entwickeln möchte, obwohl es ja schon eine ganze
<a href="http://en.wikipedia.org/wiki/Comparison_of_audio_player_software">Reihe von Playersoftware</a> gibt. Ich möchte in der
nächsten Zeit öffters den aktuellen Stand des Projekts hier beschreiben und so den Projektverlauf dokumentieren. Daneben
habe ich ein <a href="https://github.com/manuel_mauky/ProtistPlayer">Projekt auf github.com</a> für den Player gestartet. Wer github.com
nicht kennt: Dies ist eine Projekt-Hostingseite, die auf dem
<a href="http://de.wikipedia.org/wiki/Verteilte_Versionsverwaltung#Verteilte_Versionsverwaltung">Verteilten Versionsverwaltungssystem</a>
git aufsetzt. <a href="http://de.wikipedia.org/wiki/Git">Git</a> ist von seinem Funktionsumfang und den dahinter liegenden
Konzepten mit <a href="http://de.wikipedia.org/wiki/Mercurial">Mercurial</a> vergleichbar, welches ich bisher verwendet habe. Ich
bin nach wie vor ein Fan von Mercurial, wollte aber aus verschiedenen Gründen auch einmal git und auch github
ausprobieren.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Log4xul - Erste Version fertig gestellt.]]></title>
            <link>https://www.lestard.eu/2010/log4xul_first_version/</link>
            <guid>https://www.lestard.eu/2010/log4xul_first_version/</guid>
            <pubDate>Tue, 21 Dec 2010 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Ich habe nun eine erste Version von log4xul fertig gestellt und bei
<a href="https://bitbucket.org/lestard/log4xul/overview">bitbucket</a> hochgeladen. Bisher ist nur ein ein Log-Modus implementiert,
bei dem die Meldungen ganz normal auf die JavaScript-Fehlerkonsole geschrieben werden. Ich habe als Log-Level DEBUG,
INFO, WARN, ERROR sowie OFF vorgesehen. DEBUG ist für reine Debugging-Meldungen vorgesehen, die während der Entwicklung
bei der Fehlersuche interessant sind. In der Regel könnte man diese Meldungen nach dem Finden des entsprechenden Fehlers
wieder entfernen.</p>
<p>INFO ist für allgemeine Informationen zum Ablauf des Programms gedacht. Für Warnungen, die zwar kritisch sein können,
jedoch das Programm nicht unbedingt am weiteren Ausführen hindern, ist das Level WARN gedacht. Sinnvoll ist dies auch
beim Auftreten von Exceptions, die jedoch noch behandelt werden konnten.</p>
<p>Mit ERROR werden Fehlermeldungen gekennzeichnet, die ein weiteres Ausführen des Programms in der Regel unmöglich machen.</p>
<p>Die Level sind hierarchisch in der Reihenfolge DEBUG > INFO > WARN > ERROR > OFF gestaffelt wobei DEBUG das allgemeinste
Level ist und alle anderen Level einschließt. Ist das Level beispielsweise auf DEBUG gestellt, werden alle Meldungen
angezeigt. Ist das Level dagegen beispielsweise auf WARN gestellt, werden nur Meldungen der Stufe WARN und ERROR
angezeigt, die darüber liegenden Meldungen der Stufe Info und Debug jedoch nicht.</p>
<p>Somit kann man beispielsweise während dem Entwickeln das Level auf DEBUG stellen und damit sämtliche Meldungen anzeigen
lassen. Wenn die Entwicklung abgeschlossen ist, stellt man das Level zurück auf WARN und blendet damit alle DEBUG- und
INFO-Meldungen aus und lässt nur die kritischen ERROR- und WARN-Meldungen anzeigen. Mit OFF wird das Logging komplett
abgestellt.</p>
<h3>Demo-Addon</h3>
<p>Log4xul ansich ist kein Addon sondern nur eine JavaScript-Bibliothek, die in ein Addon eingebunden werden kann. Um dies
zu demonstrieren, habe ich ein Demo-Addon geschrieben, welches die Bibliothek verwendet. Dabei sind in der GUI bereits
weitere Logging-Modi (bei Log4j werden diese "Appender" genannt weshalb ich die Bezeichnung übernommen habe) vorgesehen,
die aber erst noch implementiert werden müssen.</p>
<p>Man wählt in der Demo die Appender aus, die man testen möchte und stellt den LogLevel ein. Mit einem Klick auf "Log"
wird die Meldung, die man in das Textfeld eingibt, geloggt. Intern werden dabei log-Aufrufe für alle Level ausgeführt,
es werden aber nur die jenigen angezeigt, dessen Level eingestellt ist.</p>
<p>Um auf die Demo zuzugreifen muss diese mit der xpi-Datei installiert werden. Danach kann die Demo über die Adresszeile
unter der URL <strong>"chrome://log4xul/content/log4xul_demo.xul"</strong> aufgerufen werden. Das Addon ist zwar prinzipiell
kompatibel zur Firefox-Version 4, allerdings ist dort die JavaScript-Konsole wohl etwas umgebaut worden, sodass aktuell
keine Meldungen angezeigt werden. Ausserdem fehlen noch Addons wie Console2 für FF4, die einen vernünftigen Umgang mit
der JavaScript-Console bieten.</p>
<p>Zu finden ist das Addon inklusive der Bibliothek unter
<a href="https://bitbucket.org/lestard/log4xul/overview">https://bitbucket.org/lestard/log4xul/overview</a></p>
<p>Viel Spaß beim Ausprobieren.</p>]]></description>
            <content:encoded><![CDATA[<p>Ich habe nun eine erste Version von log4xul fertig gestellt und bei
<a href="https://bitbucket.org/lestard/log4xul/overview">bitbucket</a> hochgeladen. Bisher ist nur ein ein Log-Modus implementiert,
bei dem die Meldungen ganz normal auf die JavaScript-Fehlerkonsole geschrieben werden. Ich habe als Log-Level DEBUG,
INFO, WARN, ERROR sowie OFF vorgesehen. DEBUG ist für reine Debugging-Meldungen vorgesehen, die während der Entwicklung
bei der Fehlersuche interessant sind. In der Regel könnte man diese Meldungen nach dem Finden des entsprechenden Fehlers
wieder entfernen.</p>
<p>INFO ist für allgemeine Informationen zum Ablauf des Programms gedacht. Für Warnungen, die zwar kritisch sein können,
jedoch das Programm nicht unbedingt am weiteren Ausführen hindern, ist das Level WARN gedacht. Sinnvoll ist dies auch
beim Auftreten von Exceptions, die jedoch noch behandelt werden konnten.</p>
<p>Mit ERROR werden Fehlermeldungen gekennzeichnet, die ein weiteres Ausführen des Programms in der Regel unmöglich machen.</p>
<p>Die Level sind hierarchisch in der Reihenfolge DEBUG > INFO > WARN > ERROR > OFF gestaffelt wobei DEBUG das allgemeinste
Level ist und alle anderen Level einschließt. Ist das Level beispielsweise auf DEBUG gestellt, werden alle Meldungen
angezeigt. Ist das Level dagegen beispielsweise auf WARN gestellt, werden nur Meldungen der Stufe WARN und ERROR
angezeigt, die darüber liegenden Meldungen der Stufe Info und Debug jedoch nicht.</p>
<p>Somit kann man beispielsweise während dem Entwickeln das Level auf DEBUG stellen und damit sämtliche Meldungen anzeigen
lassen. Wenn die Entwicklung abgeschlossen ist, stellt man das Level zurück auf WARN und blendet damit alle DEBUG- und
INFO-Meldungen aus und lässt nur die kritischen ERROR- und WARN-Meldungen anzeigen. Mit OFF wird das Logging komplett
abgestellt.</p>
<h3>Demo-Addon</h3>
<p>Log4xul ansich ist kein Addon sondern nur eine JavaScript-Bibliothek, die in ein Addon eingebunden werden kann. Um dies
zu demonstrieren, habe ich ein Demo-Addon geschrieben, welches die Bibliothek verwendet. Dabei sind in der GUI bereits
weitere Logging-Modi (bei Log4j werden diese "Appender" genannt weshalb ich die Bezeichnung übernommen habe) vorgesehen,
die aber erst noch implementiert werden müssen.</p>
<p>Man wählt in der Demo die Appender aus, die man testen möchte und stellt den LogLevel ein. Mit einem Klick auf "Log"
wird die Meldung, die man in das Textfeld eingibt, geloggt. Intern werden dabei log-Aufrufe für alle Level ausgeführt,
es werden aber nur die jenigen angezeigt, dessen Level eingestellt ist.</p>
<p>Um auf die Demo zuzugreifen muss diese mit der xpi-Datei installiert werden. Danach kann die Demo über die Adresszeile
unter der URL <strong>"chrome://log4xul/content/log4xul_demo.xul"</strong> aufgerufen werden. Das Addon ist zwar prinzipiell
kompatibel zur Firefox-Version 4, allerdings ist dort die JavaScript-Konsole wohl etwas umgebaut worden, sodass aktuell
keine Meldungen angezeigt werden. Ausserdem fehlen noch Addons wie Console2 für FF4, die einen vernünftigen Umgang mit
der JavaScript-Console bieten.</p>
<p>Zu finden ist das Addon inklusive der Bibliothek unter
<a href="https://bitbucket.org/lestard/log4xul/overview">https://bitbucket.org/lestard/log4xul/overview</a></p>
<p>Viel Spaß beim Ausprobieren.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Promote JS]]></title>
            <link>https://www.lestard.eu/2010/promote_js/</link>
            <guid>https://www.lestard.eu/2010/promote_js/</guid>
            <pubDate>Tue, 14 Dec 2010 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Heute bin ich auf ein interessantes Projekt namens "Promote JS" aufmerksam geworden, welches sich zum Ziel gesetzt hat,
gute JavaScript-Dokumentationen zu fördern. Das Problem ist dabei nicht, dass es nicht solche erstklassigen
Dokumentationen gäbe, sondern dass diese bei der normalen Sucher in den Googleergebnissen ziemlich weit hinten
erscheinen. In den ersten Ergebnissen sind dagegen meistens nur mittelmäßige, mit Werbung überflutete und
unübersichtliche Hilfeseiten. Erstklassige Dokumentationen wie die vom Mozilla-Developer-Center (MDC) sind oft erst
weiter unten zu finden.</p>
<p><img src="http://static.jsconf.us/promotejsh.gif" alt="logo"></p>
<p>Da die Suchergebnisse bei Google bekanntlich unter anderem von der Anzahl der Verlinkungen abhängen, soll durch
PromoteJS dazu aufgerufen werden, eben diese guten Dokumentationen auf dem eigenem Blog zu verlinken. Auf diese Weise
soll die Dokumentation von MDC in den Suchergebnissen nach oben steigen. Da mir das MDC schon unzählige Male weiter
geholfen hat und ich von der Qualität der Dokumentation überzeugt bin, halte ich das für eine gute Idee und möchte mich
daran beteiligen. An der Seite gibts deshalb ab sofort einen Button, der auf ein Thema in der MDC-Dokumentation
verlinkt.</p>
<p>Den Link zum PromoteJS-Projekt gibts hier: <a href="http://promotejs.com/">http://promotejs.com/</a></p>]]></description>
            <content:encoded><![CDATA[<p>Heute bin ich auf ein interessantes Projekt namens "Promote JS" aufmerksam geworden, welches sich zum Ziel gesetzt hat,
gute JavaScript-Dokumentationen zu fördern. Das Problem ist dabei nicht, dass es nicht solche erstklassigen
Dokumentationen gäbe, sondern dass diese bei der normalen Sucher in den Googleergebnissen ziemlich weit hinten
erscheinen. In den ersten Ergebnissen sind dagegen meistens nur mittelmäßige, mit Werbung überflutete und
unübersichtliche Hilfeseiten. Erstklassige Dokumentationen wie die vom Mozilla-Developer-Center (MDC) sind oft erst
weiter unten zu finden.</p>
<p><img src="http://static.jsconf.us/promotejsh.gif" alt="logo"></p>
<p>Da die Suchergebnisse bei Google bekanntlich unter anderem von der Anzahl der Verlinkungen abhängen, soll durch
PromoteJS dazu aufgerufen werden, eben diese guten Dokumentationen auf dem eigenem Blog zu verlinken. Auf diese Weise
soll die Dokumentation von MDC in den Suchergebnissen nach oben steigen. Da mir das MDC schon unzählige Male weiter
geholfen hat und ich von der Qualität der Dokumentation überzeugt bin, halte ich das für eine gute Idee und möchte mich
daran beteiligen. An der Seite gibts deshalb ab sofort einen Button, der auf ein Thema in der MDC-Dokumentation
verlinkt.</p>
<p>Den Link zum PromoteJS-Projekt gibts hier: <a href="http://promotejs.com/">http://promotejs.com/</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Log4xul - Projekt bei Bitbucket angelegt]]></title>
            <link>https://www.lestard.eu/2010/log4xul_project_at_bitbucket/</link>
            <guid>https://www.lestard.eu/2010/log4xul_project_at_bitbucket/</guid>
            <pubDate>Thu, 09 Dec 2010 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Vor kurzem hatte ich schon die Idee für ein XUL-<a href="http://de.wikipedia.org/wiki/Apache_Logging">Logging-Framework</a>
geäussert. In der vergangenen Woche habe ich schon ein wenig daran gearbeitet und bin auch zu ersten Ergebnissen
gekommen. Ein solches Projekt macht aber natürlich nur dann Sinn, wenn es als OpenSource für jedermann zur Verfügung
steht. Um das zu ermöglichen, habe ich heute bei <a href="http://bitbucket.org/">bitbucket.org</a> dafür ein Projekt erzeugt.</p>
<p>Für die, die bitbucket nicht kennen: Bitbucket.org ist eine Plattform zur gemeinsamen Entwicklung von freier Software,
vergleichbar mit github oder dem etwas älteren sourceforge. Bitbucket setzt auf das verteilte Versionsverwaltungssystem
<a href="http://de.wikipedia.org/wiki/Mercurial">Mercurial</a> (kurz 'hg' genannt). Jeder kann den Programmcode online im Browser
betrachten oder ihn sich per hg auf den eigenen Rechner ziehen.</p>
<p>Zum gegenwärtigen Zeitpunkt ist aber noch kein Code im Repository zu finden. Dies werde ich entweder heute Abend oder am
Wochenende noch erledigen.</p>
<p>Die URL zum Projekt ist: <a href="https://bitbucket.org/lestard/log4xul">https://bitbucket.org/lestard/log4xul</a></p>]]></description>
            <content:encoded><![CDATA[<p>Vor kurzem hatte ich schon die Idee für ein XUL-<a href="http://de.wikipedia.org/wiki/Apache_Logging">Logging-Framework</a>
geäussert. In der vergangenen Woche habe ich schon ein wenig daran gearbeitet und bin auch zu ersten Ergebnissen
gekommen. Ein solches Projekt macht aber natürlich nur dann Sinn, wenn es als OpenSource für jedermann zur Verfügung
steht. Um das zu ermöglichen, habe ich heute bei <a href="http://bitbucket.org/">bitbucket.org</a> dafür ein Projekt erzeugt.</p>
<p>Für die, die bitbucket nicht kennen: Bitbucket.org ist eine Plattform zur gemeinsamen Entwicklung von freier Software,
vergleichbar mit github oder dem etwas älteren sourceforge. Bitbucket setzt auf das verteilte Versionsverwaltungssystem
<a href="http://de.wikipedia.org/wiki/Mercurial">Mercurial</a> (kurz 'hg' genannt). Jeder kann den Programmcode online im Browser
betrachten oder ihn sich per hg auf den eigenen Rechner ziehen.</p>
<p>Zum gegenwärtigen Zeitpunkt ist aber noch kein Code im Repository zu finden. Dies werde ich entweder heute Abend oder am
Wochenende noch erledigen.</p>
<p>Die URL zum Projekt ist: <a href="https://bitbucket.org/lestard/log4xul">https://bitbucket.org/lestard/log4xul</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Logging in XUL-Anwendungen]]></title>
            <link>https://www.lestard.eu/2010/logging_in_xul_applications/</link>
            <guid>https://www.lestard.eu/2010/logging_in_xul_applications/</guid>
            <pubDate>Tue, 30 Nov 2010 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>In meiner Freizeit bastel ich ja öffters mal mit XUL und Firefox-Addons herum. Da ich ja eigentlich Java-Programmierer
bin, habe ich mich auch an die ein oder andere Annehmlichkeit gewöhnt, die dort üblich ist. Eine dieser Annehmlichkeiten
ist das <a href="http://en.wikipedia.org/wiki/Java_Logging_Frameworks">Logging</a>, das ja quasi in jedem Projekt wie
selbstverständlich mit benutzt wird.</p>
<p>Der Logger ist ein Programmteil, dem man einfache Meldungen mitgeben kann, welche dieser bei der Ausführung anzeigt. Man
kann dabei verschiedene Wichtigkeits-Stufen für einzelne Meldungen bestimmen und so festlegen, ob eine Meldung nun "nur"
ein Debug-Hinweis ist oder gar einen schweren Fehler anzeigt. Vor der Ausführung kann man dann auch einstellen, ob man
diesmal nur schwere Fehler sehen möchte oder auch unwichtige Meldungen. Wenn man seine Software z.B. fertig zum Kunden
gibt, sollte man diesen schließlich vor reinen Entwickler-Hinweisen verschonen, während man beim Entwickeln gerne die
ein oder andere Statusmeldung sehen möchte.</p>
<p>Wie gesagt: In Java üblich, bei XUL aber zumindest in der Standardausführung des XUL-Runners nicht vorgesehen bzw.
zumindest nicht in diesem Funktionsumfang. Bei meinen bisherigen Basteleien in XUL war einer der Ersten Schritte deshalb
immer, mir erstmal eine eigene kleine Logger-Funktion zu schreiben, die Meldungen in einem Text-Feld in der GUI ausgibt.
Den Funktionsumfang wie oben beschrieben hatte ich dabei natürlich nicht, obwohl das ja eigentlich schon auch praktisch
wäre.</p>
<p>Aus diesem Grund bin ich der Sache mal nachgegangen und bin auf zwei Logging-Frameworks für JavaScript gestoßen. Zum
einen <a href="http://de.wikipedia.org/wiki/Log4js">Log4JS</a>, welches ebenfalls wie <a href="http://de.wikipedia.org/wiki/Log4j">Log4J</a> -
der Quasi-Standard bei JAVA - vom Apache-Team entwickelt wird. Zum anderen <a href="http://log4javascript.org/">Log4JavaScript</a>.
Beide machten beim testen in einer Webseite eine gute Figur jedoch funktionierte die Einbindung in XUL nicht so
wirklich. Das ist natürlich verständlich, da der Fokus der Frameworks natürlich bei HTML-Dokumenten liegt und diese
darauf ausgelegt sind. Ein Großteil der Funktionalität der Frameworks wird für XUL auch nicht benötigt. So kann Log4JS
z.B. Logmeldungen über AJAX an einen Server übertragen. Dies ist für Webseiten durchaus interessant, macht aus meiner
Sicht für XUL-Anwendungen oder BrowserAddons aber wenig Sinn.</p>
<p>Die Überlegung ging deshalb in die Richtung, aus meinen eigenen kleinen Logger-Basteleien eventuell ein auf XUL
angepasstes Logging-Framework zu entwickeln. Wenn die Freizeit das zulässt, wäre dies eins meiner nächsten Projekte.</p>]]></description>
            <content:encoded><![CDATA[<p>In meiner Freizeit bastel ich ja öffters mal mit XUL und Firefox-Addons herum. Da ich ja eigentlich Java-Programmierer
bin, habe ich mich auch an die ein oder andere Annehmlichkeit gewöhnt, die dort üblich ist. Eine dieser Annehmlichkeiten
ist das <a href="http://en.wikipedia.org/wiki/Java_Logging_Frameworks">Logging</a>, das ja quasi in jedem Projekt wie
selbstverständlich mit benutzt wird.</p>
<p>Der Logger ist ein Programmteil, dem man einfache Meldungen mitgeben kann, welche dieser bei der Ausführung anzeigt. Man
kann dabei verschiedene Wichtigkeits-Stufen für einzelne Meldungen bestimmen und so festlegen, ob eine Meldung nun "nur"
ein Debug-Hinweis ist oder gar einen schweren Fehler anzeigt. Vor der Ausführung kann man dann auch einstellen, ob man
diesmal nur schwere Fehler sehen möchte oder auch unwichtige Meldungen. Wenn man seine Software z.B. fertig zum Kunden
gibt, sollte man diesen schließlich vor reinen Entwickler-Hinweisen verschonen, während man beim Entwickeln gerne die
ein oder andere Statusmeldung sehen möchte.</p>
<p>Wie gesagt: In Java üblich, bei XUL aber zumindest in der Standardausführung des XUL-Runners nicht vorgesehen bzw.
zumindest nicht in diesem Funktionsumfang. Bei meinen bisherigen Basteleien in XUL war einer der Ersten Schritte deshalb
immer, mir erstmal eine eigene kleine Logger-Funktion zu schreiben, die Meldungen in einem Text-Feld in der GUI ausgibt.
Den Funktionsumfang wie oben beschrieben hatte ich dabei natürlich nicht, obwohl das ja eigentlich schon auch praktisch
wäre.</p>
<p>Aus diesem Grund bin ich der Sache mal nachgegangen und bin auf zwei Logging-Frameworks für JavaScript gestoßen. Zum
einen <a href="http://de.wikipedia.org/wiki/Log4js">Log4JS</a>, welches ebenfalls wie <a href="http://de.wikipedia.org/wiki/Log4j">Log4J</a> -
der Quasi-Standard bei JAVA - vom Apache-Team entwickelt wird. Zum anderen <a href="http://log4javascript.org/">Log4JavaScript</a>.
Beide machten beim testen in einer Webseite eine gute Figur jedoch funktionierte die Einbindung in XUL nicht so
wirklich. Das ist natürlich verständlich, da der Fokus der Frameworks natürlich bei HTML-Dokumenten liegt und diese
darauf ausgelegt sind. Ein Großteil der Funktionalität der Frameworks wird für XUL auch nicht benötigt. So kann Log4JS
z.B. Logmeldungen über AJAX an einen Server übertragen. Dies ist für Webseiten durchaus interessant, macht aus meiner
Sicht für XUL-Anwendungen oder BrowserAddons aber wenig Sinn.</p>
<p>Die Überlegung ging deshalb in die Richtung, aus meinen eigenen kleinen Logger-Basteleien eventuell ein auf XUL
angepasstes Logging-Framework zu entwickeln. Wenn die Freizeit das zulässt, wäre dies eins meiner nächsten Projekte.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Konsolen-Spaceshooter in C++]]></title>
            <link>https://www.lestard.eu/2010/space_shooter_in_cpp/</link>
            <guid>https://www.lestard.eu/2010/space_shooter_in_cpp/</guid>
            <pubDate>Fri, 01 Oct 2010 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Die letzten zwei Wochen habe ich an einem C'/C++-Kurs an der Hochschule teilgenommen und dabei einiges gelernt. In der
zweiten Woche war es angedacht, während der Übungsstunden ein eigenes Projekt in C++ zu entwickeln. Ich habe mich dafür
entschieden einen Konsolenbasierten Raumschiff-Shooter zu entwickeln. Man steuert sein Raumschiff und muss ankommende
Gegner abschießen. Anfangs kommen nur einzelne Gegner ins Sichtfeld aber im späteren Spielverlauf werden es immer mehr.
Der Spieler darf dabei keinen Gegner vorbei lassen und natürlich jeden Zusammenstoß vermeiden. Screenshot vom Spiel</p>
<p><img src="/files/pics/2010/spaceShooter1.png" alt="Screenshot"></p>
<p>Entwickelt habe ich das Spiel wie gesagt in C++. Wer sich den Quellcode anschauen möchte, kann dies natürlich gerne tun,
da das Spiel wie immer als freie OpenSource-Software zur Verfügung gestellt wird. Leider war ich während der Übung auf
die Hochschul-Rechner beschränkt, welche nur mit Windows laufen. Folglich ist das Spiel auf einem Windows-System
entwickelt und kompiliert worden. Vermutlich ist es in diesem Zustand nicht unter Linux kompilierbar, da einige
Windows-Spezifische Funktionen benutzt wurden. Wenn es die Zeit zulässt, möchte ich aber noch Linux-Kompatibilität
sicherstellen.</p>
<p><a href="/files/bin/2010/SpaceShooter.zip">Download Spiel + Sources</a></p>
<p><a href="http://cpp.chrfa.de/cpp">Link zum C-Kurs</a></p>]]></description>
            <content:encoded><![CDATA[<p>Die letzten zwei Wochen habe ich an einem C'/C++-Kurs an der Hochschule teilgenommen und dabei einiges gelernt. In der
zweiten Woche war es angedacht, während der Übungsstunden ein eigenes Projekt in C++ zu entwickeln. Ich habe mich dafür
entschieden einen Konsolenbasierten Raumschiff-Shooter zu entwickeln. Man steuert sein Raumschiff und muss ankommende
Gegner abschießen. Anfangs kommen nur einzelne Gegner ins Sichtfeld aber im späteren Spielverlauf werden es immer mehr.
Der Spieler darf dabei keinen Gegner vorbei lassen und natürlich jeden Zusammenstoß vermeiden. Screenshot vom Spiel</p>
<p><img src="/files/pics/2010/spaceShooter1.png" alt="Screenshot"></p>
<p>Entwickelt habe ich das Spiel wie gesagt in C++. Wer sich den Quellcode anschauen möchte, kann dies natürlich gerne tun,
da das Spiel wie immer als freie OpenSource-Software zur Verfügung gestellt wird. Leider war ich während der Übung auf
die Hochschul-Rechner beschränkt, welche nur mit Windows laufen. Folglich ist das Spiel auf einem Windows-System
entwickelt und kompiliert worden. Vermutlich ist es in diesem Zustand nicht unter Linux kompilierbar, da einige
Windows-Spezifische Funktionen benutzt wurden. Wenn es die Zeit zulässt, möchte ich aber noch Linux-Kompatibilität
sicherstellen.</p>
<p><a href="/files/bin/2010/SpaceShooter.zip">Download Spiel + Sources</a></p>
<p><a href="http://cpp.chrfa.de/cpp">Link zum C-Kurs</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Mp3 nach Ogg konvertieren unter Linux]]></title>
            <link>https://www.lestard.eu/2010/mp3_to_ogg_converting/</link>
            <guid>https://www.lestard.eu/2010/mp3_to_ogg_converting/</guid>
            <pubDate>Sun, 11 Jul 2010 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Neulich hatte ich das Verlangen, meine digitale Musiksammlung mal etwas genauer unter die Lupe zu nehmen und etwas
auszumisten. Ich wollte nicht direkt die Musikdateien löschen sondern nur all die anderen Dateien, die dort noch so
rumspuken und eigentlich nicht benötigt werden, wie z.B. Albumcover, Playlisten und Text/NFO-Dateien. Mit der
Kommandozeile unter Linux und Befehlen wie</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">find . -type f -iname "*.mp3" | wc -l (gibt die Anzahl aller mp3-Dateien an)</code></pre></div>
<p>war es leicht, ein paar Statistische Aussagen zu meiner Sammlung zu treffen. Letztlich musste ich feststellen, dass 95 %
meiner Musikdateien im mp3-Format vorliegen und nur 1% im freien
<a href="https://secure.wikimedia.org/wikipedia/de/wiki/Vorbis">ogg-vorbis</a>-Format. Damit war die Idee geboren, meine gesamte
Musiksammlung in eben dieses freie Format umzuwandeln. Warum? 1. Weil ich es kann. 2. Weil ich es interessant finde, auf
die suche nach (halb-)automatischen Möglichkeiten für diese Aufgabe zu gehen und 3. Weil Freie Formate Rocken.</p>
<p>Nun gibt es natürlich Programme, die solche Konvertierungen in einem Rutsch ausführen können. Dummer weise sind oft die
Möglichkeiten der Einflussnahme etwas begrenzt. Vor allem die Bitrate bereitete mir Sorgen. Natürlich wird die
Audio-Qualität bei so einem Vorgang nicht besser - im Gegenteil. Um dieses Problem möglichst gering zu halten, könnte
man natürlich einfach alle Dateien mit 320 kbps oder mehr konvertieren. Nur stellt sich hier die Frage, ob sich das bei
Dateien, die im Ausgangsformat lediglich 128 kbps besitzen, überhaupt lohnt. Der Unterschied bei der Dateigröße ist
schließlich beträchtlich.</p>
<p>Ideal wäre also, wenn man festlegen kann, das z.B. Dateien mit einer Ausgangsbitrate von 128 kbps dann mit 192 kbps ins
OGG-Format konvertiert werden. Dateien mit 192 Ausgangsbitrate werden nach 256 kbps gewandelt und Dateien mit höherer
Bitrate (320 z.B.) bekommen eine noch höhere neue Bitrate.</p>
<p>Eine solche Abstufung erlauben die üblichen Programme leider nicht. Als Informatiker öffnet man bei solchen
Gelegenheiten natürlich sofort die Entwicklungsumgebung und versucht etwas eigenes zu basteln. Ich habe mir in dem
Zusammenhang zum ersten mal die Programmiersprache Python angeschaut. Nach einigem Rumprobieren bin ich dem Ziel sogar
etwas näher gekommen - mein Script konnte alle Mp3s rekursiv einlesen und zumindest schonmal ins WAV-Format
zwischenspeichern und die ID3-Tags aufheben. Die OGG-Konvertieren hätte hier nur noch angeschlossen werden müssen.
Allerdings hat mich dann doch die Lust verlassen und ich habe mir vorgenommen, das ganze später weiter zubasteln.</p>
<p>Am Ende kam mir dann jedoch noch eine andere Idee: Foobar2000. Foobar ist nämlich nicht nur ein super Abspielprogramm
sondern kann auch alle möglichen Formate in alle möglichen anderen Formate konvertieren. Und was hier wichtig ist: Ich
kann natürlich auch meine gesamte Mp3-Sammlung auf einmal einlesen und dann nach der Bitrate Sortieren. Und schon kann
ich selektiv konvertieren. Und direkt wurde mir wieder bewusst, wie sehr foobar2000 unter Linux fehlt.</p>]]></description>
            <content:encoded><![CDATA[<p>Neulich hatte ich das Verlangen, meine digitale Musiksammlung mal etwas genauer unter die Lupe zu nehmen und etwas
auszumisten. Ich wollte nicht direkt die Musikdateien löschen sondern nur all die anderen Dateien, die dort noch so
rumspuken und eigentlich nicht benötigt werden, wie z.B. Albumcover, Playlisten und Text/NFO-Dateien. Mit der
Kommandozeile unter Linux und Befehlen wie</p>
<div class="gatsby-highlight" data-language="text"><pre class="language-text"><code class="language-text">find . -type f -iname "*.mp3" | wc -l (gibt die Anzahl aller mp3-Dateien an)</code></pre></div>
<p>war es leicht, ein paar Statistische Aussagen zu meiner Sammlung zu treffen. Letztlich musste ich feststellen, dass 95 %
meiner Musikdateien im mp3-Format vorliegen und nur 1% im freien
<a href="https://secure.wikimedia.org/wikipedia/de/wiki/Vorbis">ogg-vorbis</a>-Format. Damit war die Idee geboren, meine gesamte
Musiksammlung in eben dieses freie Format umzuwandeln. Warum? 1. Weil ich es kann. 2. Weil ich es interessant finde, auf
die suche nach (halb-)automatischen Möglichkeiten für diese Aufgabe zu gehen und 3. Weil Freie Formate Rocken.</p>
<p>Nun gibt es natürlich Programme, die solche Konvertierungen in einem Rutsch ausführen können. Dummer weise sind oft die
Möglichkeiten der Einflussnahme etwas begrenzt. Vor allem die Bitrate bereitete mir Sorgen. Natürlich wird die
Audio-Qualität bei so einem Vorgang nicht besser - im Gegenteil. Um dieses Problem möglichst gering zu halten, könnte
man natürlich einfach alle Dateien mit 320 kbps oder mehr konvertieren. Nur stellt sich hier die Frage, ob sich das bei
Dateien, die im Ausgangsformat lediglich 128 kbps besitzen, überhaupt lohnt. Der Unterschied bei der Dateigröße ist
schließlich beträchtlich.</p>
<p>Ideal wäre also, wenn man festlegen kann, das z.B. Dateien mit einer Ausgangsbitrate von 128 kbps dann mit 192 kbps ins
OGG-Format konvertiert werden. Dateien mit 192 Ausgangsbitrate werden nach 256 kbps gewandelt und Dateien mit höherer
Bitrate (320 z.B.) bekommen eine noch höhere neue Bitrate.</p>
<p>Eine solche Abstufung erlauben die üblichen Programme leider nicht. Als Informatiker öffnet man bei solchen
Gelegenheiten natürlich sofort die Entwicklungsumgebung und versucht etwas eigenes zu basteln. Ich habe mir in dem
Zusammenhang zum ersten mal die Programmiersprache Python angeschaut. Nach einigem Rumprobieren bin ich dem Ziel sogar
etwas näher gekommen - mein Script konnte alle Mp3s rekursiv einlesen und zumindest schonmal ins WAV-Format
zwischenspeichern und die ID3-Tags aufheben. Die OGG-Konvertieren hätte hier nur noch angeschlossen werden müssen.
Allerdings hat mich dann doch die Lust verlassen und ich habe mir vorgenommen, das ganze später weiter zubasteln.</p>
<p>Am Ende kam mir dann jedoch noch eine andere Idee: Foobar2000. Foobar ist nämlich nicht nur ein super Abspielprogramm
sondern kann auch alle möglichen Formate in alle möglichen anderen Formate konvertieren. Und was hier wichtig ist: Ich
kann natürlich auch meine gesamte Mp3-Sammlung auf einmal einlesen und dann nach der Bitrate Sortieren. Und schon kann
ich selektiv konvertieren. Und direkt wurde mir wieder bewusst, wie sehr foobar2000 unter Linux fehlt.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Musikplayer]]></title>
            <link>https://www.lestard.eu/2010/musicplayer/</link>
            <guid>https://www.lestard.eu/2010/musicplayer/</guid>
            <pubDate>Fri, 09 Jul 2010 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Hin und wieder habe ich in der letzten Woche Zeit gefunden, um an meinem Musikplayer weiter zu werkeln. Der Grund, warum
ich das Projekt wieder hervorgekramt habe ist, dass ich vor einiger Zeit sowohl auf dem Notebook als auch auf meinem PC
komplett auf <a href="http://www.linuxmint.com/">Linux Mint</a> umgestiegen bin und Windows nur noch ein Schattendasein fristet und
ich deshalb wieder aufs neue feststellen muss, dass die Linux-Musikplayer leider nicht meinen Geschmack treffen und
<a href="http://www.foobar2000.org/">Foobar2000</a> über <a href="http://www.winehq.org/">Wine</a> auch nicht sonderlich gut läuft.</p>
<p>Einen eigenen Musikplayer zu entwickeln ist allerdings auch nicht ganz so einfach. Vor allem die Grund-Funktionalität,
nämlich das Abspielen einer mp3 ist nicht so ohne weiteres hinprogrammiert, zumindest wenn man wie ich wenig Ahnung von
C oder C++ hat, denn mit bloßem JavaScript lässt sich keine Mp3 abspielen. Da mein Player aber in jedem Fall
<a href="http://www.fsf.org/">frei</a> und <a href="http://www.opensource.org/">OpenSource</a> sein wird, ergeben sich einige Vorteile bei der
Entwicklung. Ich kann auf Programmcode anderer freier Projekte zurückgreifen und mir anschauen, wie andere Leute das
machen.</p>
<p>Es gibt ein paar ähnliche Projekte, die ebenfalls auf Mozillas XUL aufbauen. Hier ist als erstes natürlich
<a href="http://www.getsongbird.com/">Songbird</a> zu nennen, der jedoch von seinem Konzept und der Funktionalität her nicht meinen
Vorstellungen entspricht. Es war jedoch trotzdem interessant, den
<a href="http://wiki.songbirdnest.com/Developer/Articles/Getting_Started/Core_Player_Development/Checkout_the_Code#Get_the_Trunk">Quellcode</a>
zu lesen, allerdings ist es nicht so einfach, den Überblick zu behalten bei der großen Anzahl an Funktionen, die
Songbird mitbringt.</p>
<p>Es existieren aber noch weitere freie Multimedia-Player auf XUL-Basis. "<a href="http://xulplayer.sourceforge.net/">XULPlayer</a>"
ist ein universeller Video- und Audio-Player, der auf der <a href="http://www.mplayerhq.hu/">MPlayer-Bibliothek</a> aufbaut. Leider
wird der XULPlayer auch nur für Windows entwickelt.</p>
<p>Eine weitere Alternative wäre <a href="http://www.idle-hacking.com/2005/06/xul-music-02/">XULMusic</a>, der noch am ehesten meinen
Vorstellungen entspricht, wenn es darum geht, auf dem Code aufzubauen. Leider ist genau dieser nicht mehr Verfügbar.
Zwar kann man auf den XUL- und JavaScript-Code direkt zugreifen, da dieser ja nicht kompiliert wird, jedoch auf den Code
der zugrunde liegenden GStreamer-Bibliothek kann nicht so einfach zu gegriffen werden. Leider funktioniert die Version
nicht korrekt, was vermutlich daran liegt, dass dieses Projekt schon ein paar Jahre ohne Aktualisierungen auf dem Buckel
hat.</p>
<p>Aktuell teste ich deshalb einige Varianten, um innerhalb einer XUL-Applikation Audio-Dateien abzuspielen und dies per
JavaScript zu steuern.</p>]]></description>
            <content:encoded><![CDATA[<p>Hin und wieder habe ich in der letzten Woche Zeit gefunden, um an meinem Musikplayer weiter zu werkeln. Der Grund, warum
ich das Projekt wieder hervorgekramt habe ist, dass ich vor einiger Zeit sowohl auf dem Notebook als auch auf meinem PC
komplett auf <a href="http://www.linuxmint.com/">Linux Mint</a> umgestiegen bin und Windows nur noch ein Schattendasein fristet und
ich deshalb wieder aufs neue feststellen muss, dass die Linux-Musikplayer leider nicht meinen Geschmack treffen und
<a href="http://www.foobar2000.org/">Foobar2000</a> über <a href="http://www.winehq.org/">Wine</a> auch nicht sonderlich gut läuft.</p>
<p>Einen eigenen Musikplayer zu entwickeln ist allerdings auch nicht ganz so einfach. Vor allem die Grund-Funktionalität,
nämlich das Abspielen einer mp3 ist nicht so ohne weiteres hinprogrammiert, zumindest wenn man wie ich wenig Ahnung von
C oder C++ hat, denn mit bloßem JavaScript lässt sich keine Mp3 abspielen. Da mein Player aber in jedem Fall
<a href="http://www.fsf.org/">frei</a> und <a href="http://www.opensource.org/">OpenSource</a> sein wird, ergeben sich einige Vorteile bei der
Entwicklung. Ich kann auf Programmcode anderer freier Projekte zurückgreifen und mir anschauen, wie andere Leute das
machen.</p>
<p>Es gibt ein paar ähnliche Projekte, die ebenfalls auf Mozillas XUL aufbauen. Hier ist als erstes natürlich
<a href="http://www.getsongbird.com/">Songbird</a> zu nennen, der jedoch von seinem Konzept und der Funktionalität her nicht meinen
Vorstellungen entspricht. Es war jedoch trotzdem interessant, den
<a href="http://wiki.songbirdnest.com/Developer/Articles/Getting_Started/Core_Player_Development/Checkout_the_Code#Get_the_Trunk">Quellcode</a>
zu lesen, allerdings ist es nicht so einfach, den Überblick zu behalten bei der großen Anzahl an Funktionen, die
Songbird mitbringt.</p>
<p>Es existieren aber noch weitere freie Multimedia-Player auf XUL-Basis. "<a href="http://xulplayer.sourceforge.net/">XULPlayer</a>"
ist ein universeller Video- und Audio-Player, der auf der <a href="http://www.mplayerhq.hu/">MPlayer-Bibliothek</a> aufbaut. Leider
wird der XULPlayer auch nur für Windows entwickelt.</p>
<p>Eine weitere Alternative wäre <a href="http://www.idle-hacking.com/2005/06/xul-music-02/">XULMusic</a>, der noch am ehesten meinen
Vorstellungen entspricht, wenn es darum geht, auf dem Code aufzubauen. Leider ist genau dieser nicht mehr Verfügbar.
Zwar kann man auf den XUL- und JavaScript-Code direkt zugreifen, da dieser ja nicht kompiliert wird, jedoch auf den Code
der zugrunde liegenden GStreamer-Bibliothek kann nicht so einfach zu gegriffen werden. Leider funktioniert die Version
nicht korrekt, was vermutlich daran liegt, dass dieses Projekt schon ein paar Jahre ohne Aktualisierungen auf dem Buckel
hat.</p>
<p>Aktuell teste ich deshalb einige Varianten, um innerhalb einer XUL-Applikation Audio-Dateien abzuspielen und dies per
JavaScript zu steuern.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Snake Game in JavaScript]]></title>
            <link>https://www.lestard.eu/2010/snake_js/</link>
            <guid>https://www.lestard.eu/2010/snake_js/</guid>
            <pubDate>Thu, 01 Jul 2010 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Die Langeweile am Wochenende hat mich dazu gebracht, einen Snake-Klon zu schreiben. Wer einmal ein altes Nokia-Handy
besessen hat. kennt das Spiel sicher noch, aber auch auf anderen Plattformen ist das Spiel - manchmal in Abgewandter
Form - anzutreffen. Aktuell gibt es im Netz jede Menge Flash-Klone und auch im Ubuntu-Repository befinden sich einige
Varianten (KTron z.B.).</p>
<p>Wirklich zufrieden bin ich damit aber nicht so ganz. Oft wird das simple Spielkonzept durch anderes Zeugs erweitert oder
gar verfälscht. Ich persönlich mag da lieber das alte simple Snake haben. Eine Schlage, ein Spielfeld an dessen Rändern
man durch schlüpfen kann um an der anderen Seite wieder heraus zu kommen und ein einfaches kleines Etwas, das man
fressen kann um zu wachsen.</p>
<p>Hier gibt es zwar Flashvarianten, die genau das mitbringen aber ... naja es ist halt nur Flash. Irgendwie Uncool halt.
Deshalb und vor allem eben wie Eingangs erwähnt aus Langeweile hab ich mich an eine HTML+JavaScript-Variante gesetzt.</p>
<p>Das Spiel funktioniert soweit, es kann aber sein, dass noch hier und da Fehler stecken. Zwar ist es bei dieser Art von
Onlinegames für die meisten unerheblich aber ich sags trotzdem dazu: Der Quellcode steht natürlich frei zur Verfügung
und kann von jedem angeschaut und verändert werden. Auch kann das Spiel gerne auf eigene Webseiten hochgeladen werden.
Über Feedback freue ich mich natürlich auch sehr. Viel Spaß</p>
<p><a href="/files/misc/2010/snakejs/">Link zum Spiel</a></p>]]></description>
            <content:encoded><![CDATA[<p>Die Langeweile am Wochenende hat mich dazu gebracht, einen Snake-Klon zu schreiben. Wer einmal ein altes Nokia-Handy
besessen hat. kennt das Spiel sicher noch, aber auch auf anderen Plattformen ist das Spiel - manchmal in Abgewandter
Form - anzutreffen. Aktuell gibt es im Netz jede Menge Flash-Klone und auch im Ubuntu-Repository befinden sich einige
Varianten (KTron z.B.).</p>
<p>Wirklich zufrieden bin ich damit aber nicht so ganz. Oft wird das simple Spielkonzept durch anderes Zeugs erweitert oder
gar verfälscht. Ich persönlich mag da lieber das alte simple Snake haben. Eine Schlage, ein Spielfeld an dessen Rändern
man durch schlüpfen kann um an der anderen Seite wieder heraus zu kommen und ein einfaches kleines Etwas, das man
fressen kann um zu wachsen.</p>
<p>Hier gibt es zwar Flashvarianten, die genau das mitbringen aber ... naja es ist halt nur Flash. Irgendwie Uncool halt.
Deshalb und vor allem eben wie Eingangs erwähnt aus Langeweile hab ich mich an eine HTML+JavaScript-Variante gesetzt.</p>
<p>Das Spiel funktioniert soweit, es kann aber sein, dass noch hier und da Fehler stecken. Zwar ist es bei dieser Art von
Onlinegames für die meisten unerheblich aber ich sags trotzdem dazu: Der Quellcode steht natürlich frei zur Verfügung
und kann von jedem angeschaut und verändert werden. Auch kann das Spiel gerne auf eigene Webseiten hochgeladen werden.
Über Feedback freue ich mich natürlich auch sehr. Viel Spaß</p>
<p><a href="/files/misc/2010/snakejs/">Link zum Spiel</a></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Songbird nicht mehr für Linux]]></title>
            <link>https://www.lestard.eu/2010/no_songbird_for_linux/</link>
            <guid>https://www.lestard.eu/2010/no_songbird_for_linux/</guid>
            <pubDate>Mon, 05 Apr 2010 22:00:00 GMT</pubDate>
            <description><![CDATA[<p>Vor einiger Zeit hatte ich hier an dieser Stelle die Idee vorgestellt, eine eigene Musik-Abspielsoftware zu schreiben
oder aber eine Vorhandene freie Software auf meine Bedürfnisse anzupassen. Kurz gesagt ging es darum, dass der
Musikplayer foobar2000 einige wirklich überragende und leider auch einzigartige Funktionalitäten bietet, leider jedoch
nicht freie Software ist und auch nur für Windows zur Verfügung steht.</p>
<p>Was also Fehlt ist ein Player, der für alle relevanten Betriebssysteme (mindestens Windows und Linux) zur Verfügung
steht, dabei aber viele gute Ideen von foobar2000 übernimmt, jedoch möglichst die weniger guten Ideen und
Verhaltensweisen der üblichen Player, nicht übernimmt. Dazu eine Möglichst simple Konzeptionelle Grundlage auf Basis von
Playlisten statt einer Medienbibliothek.</p>
<p>Zunächst stand die Idee im Raum, einen eigenen Player von Grund auf neu zu entwickeln. Hier könnten grundsätzliche
Entscheidungen von Grund auf getroffen werden ohne auf Abhängigkeiten vorhanderer Software rücksicht nehmen zu müssen.
Die andere Möglichkeit, die mir in den Sinn kam ist, eine vorhandene freie Playersoftware den eigenen Bedürfnissen
anzupassen. Dafür ist freie Software ja schließlich da.</p>
<p>Als Fan von Mozilla-Technologien bietete sich hier natürlich Songbird an, welcher ja komplett auf eben jener
Mozilla-Plattform aufbaut, und deshalb neue Funktionalität auch über Erweiterungen eingefügt werden könnte. Zwar ist
Songbird ziemlich überladen mit unnötigen Funktionen, diese könnten jedoch zum großen Teil genauso auch wieder
rausgenommen werden. So weit bisher.</p>
<p>Nun musste ich jedoch mit einer Mischung aus Entsetzen und Enttäuschung lesen, dass das Songbird-Team die Unterstützung
für ihre Linux-Version einstellt
(<a href="http://www.heise.de/open/meldung/Songbird-nicht-mehr-fuer-Linux-971220.html">Quelle: Heise Open</a>). Zwar wird es
weiterhin Releases für Linux geben, diese werden jedoch nicht mehr getestet und neue Features werden nicht mehr
Unterstützt. Für meinen Teil hat sich damit die Frage letztlich geklärt, welchen der oben kurz erwähnten Wege ich
bevorzugen würde. Zwar ist es realistisch gesehen, natürlich weiterhin möglich, Songbird auch auf Linux zu benutzen und
wenn man auf neue Features verzichten kann, ist dies Sicher kein Problem. Jedoch macht sich das Team mit dieser
Entscheidung nicht unbedingt sympatischer. Eine aktive Unterstützung in Form von beigesteuerten Erweiterungen, macht so
natürlich keinen Spaß mehr.</p>
<p>Da ich aktuell mit meinem Praktikum beschäftigt bin, ist diese Programmidee aber ohnehin erstmal noch Zukunftsmusik.
Jedoch beschäftige ich mich in meinem Praktikum auch mit dem Mozilla-Framework und der Arbeit mit XML - beides Dinge,
die für die Entwicklung eines solchen Players von Vorteil sein dürften. Gerade die Verarbeitung von XML sollte für einen
Playlist-Orientierten Player wichtig seien.</p>]]></description>
            <content:encoded><![CDATA[<p>Vor einiger Zeit hatte ich hier an dieser Stelle die Idee vorgestellt, eine eigene Musik-Abspielsoftware zu schreiben
oder aber eine Vorhandene freie Software auf meine Bedürfnisse anzupassen. Kurz gesagt ging es darum, dass der
Musikplayer foobar2000 einige wirklich überragende und leider auch einzigartige Funktionalitäten bietet, leider jedoch
nicht freie Software ist und auch nur für Windows zur Verfügung steht.</p>
<p>Was also Fehlt ist ein Player, der für alle relevanten Betriebssysteme (mindestens Windows und Linux) zur Verfügung
steht, dabei aber viele gute Ideen von foobar2000 übernimmt, jedoch möglichst die weniger guten Ideen und
Verhaltensweisen der üblichen Player, nicht übernimmt. Dazu eine Möglichst simple Konzeptionelle Grundlage auf Basis von
Playlisten statt einer Medienbibliothek.</p>
<p>Zunächst stand die Idee im Raum, einen eigenen Player von Grund auf neu zu entwickeln. Hier könnten grundsätzliche
Entscheidungen von Grund auf getroffen werden ohne auf Abhängigkeiten vorhanderer Software rücksicht nehmen zu müssen.
Die andere Möglichkeit, die mir in den Sinn kam ist, eine vorhandene freie Playersoftware den eigenen Bedürfnissen
anzupassen. Dafür ist freie Software ja schließlich da.</p>
<p>Als Fan von Mozilla-Technologien bietete sich hier natürlich Songbird an, welcher ja komplett auf eben jener
Mozilla-Plattform aufbaut, und deshalb neue Funktionalität auch über Erweiterungen eingefügt werden könnte. Zwar ist
Songbird ziemlich überladen mit unnötigen Funktionen, diese könnten jedoch zum großen Teil genauso auch wieder
rausgenommen werden. So weit bisher.</p>
<p>Nun musste ich jedoch mit einer Mischung aus Entsetzen und Enttäuschung lesen, dass das Songbird-Team die Unterstützung
für ihre Linux-Version einstellt
(<a href="http://www.heise.de/open/meldung/Songbird-nicht-mehr-fuer-Linux-971220.html">Quelle: Heise Open</a>). Zwar wird es
weiterhin Releases für Linux geben, diese werden jedoch nicht mehr getestet und neue Features werden nicht mehr
Unterstützt. Für meinen Teil hat sich damit die Frage letztlich geklärt, welchen der oben kurz erwähnten Wege ich
bevorzugen würde. Zwar ist es realistisch gesehen, natürlich weiterhin möglich, Songbird auch auf Linux zu benutzen und
wenn man auf neue Features verzichten kann, ist dies Sicher kein Problem. Jedoch macht sich das Team mit dieser
Entscheidung nicht unbedingt sympatischer. Eine aktive Unterstützung in Form von beigesteuerten Erweiterungen, macht so
natürlich keinen Spaß mehr.</p>
<p>Da ich aktuell mit meinem Praktikum beschäftigt bin, ist diese Programmidee aber ohnehin erstmal noch Zukunftsmusik.
Jedoch beschäftige ich mich in meinem Praktikum auch mit dem Mozilla-Framework und der Arbeit mit XML - beides Dinge,
die für die Entwicklung eines solchen Players von Vorteil sein dürften. Gerade die Verarbeitung von XML sollte für einen
Playlist-Orientierten Player wichtig seien.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[xmlSlides - Aktueller Stand]]></title>
            <link>https://www.lestard.eu/2010/xmlSlides_current_status/</link>
            <guid>https://www.lestard.eu/2010/xmlSlides_current_status/</guid>
            <pubDate>Thu, 25 Mar 2010 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Vor einiger Zeit hatte ich ja bereits ein paar Ideen und Entwürfe für meine Präsentations-Software für Browser
vorgestellt. Mittlerweile hat sich einiges getan bzw. geändert.</p>
<p>Zunächst einmal: Ich bearbeite dieses Projekt nun im Rahmen meines Praktikums und meiner Abschlussarbeit an der
Hochschule. Das heisst vor allem, dass das Projekt nun nicht mehr nur ein kleines Hobby-Projekt für zwischendurch ist,
das ich vieleicht irgendwann einmal fertig stelle, sondern dass ich aktuell in Vollzeit daran arbeite und es in jedem
Fall in absehbarer Zeit vorzeigbare Ergebnisse geben wird. Ich möchte ja schließlich mein Studium und die
Abschlussarbeit vernünftig abschließen.</p>
<p>Eine weitere Konsequenz daraus ist, dass ich viele Sachen nicht mehr "einfach so" programmieren kann, wie es mir grade
passt, sondern ich tiefgreifendere Untersuchungen anstellen muss, damit wirklich ein vernünftiges Ergebniss herauskommt.
Eine erste Konsequenz daraus ist, dass ich einen Großteil der bisherigen Arbeit über Bord geworfen habe und das ganze
von Grund auf neu plane. Die Anforderungen bleiben jedoch weitestgehend gleich, nur der Lösungsweg verändert sich etwas.</p>
<p>Im ersten Schritt verzichte ich nun auf eine selbstentwickelte XML-Sprache und werde stattdessen eine bereits bestehende
XML-Sprache zurückgreifen. Welche konkret steht aber aktuell noch nicht ganz fest. Auf der einen Seite ist das
<a href="https://de.wikipedia.org/wiki/DocBook">DocBook</a>-Format für Technische Dokumentationen eine etablierte Technologie und
bietet auch eine Art
<a href="http://docbook.org/schemas/5x-custom.html#slides">Spezialisierung für die Beschreibung von Präsentationen</a>. Der
Nachteil dieser Variante ist jedoch, dass das Format unglaublich komplex ist und sehr sehr viele Elemente enthält, die
ich in meiner Software nicht benötige. Die hohe Komplexität spricht auch gegen eine der Hauptanforderungen nach
Einfachheit und Nutzerfreundlichkeit. Man könnte jedoch auch nur einen Teil des DocBook-Slides-Formates implementieren
und auf den Rest verzichten. Diese Lösung hat allerdings auch ihre Schattenseiten.</p>
<p>Eine andere recht vielversprechende Technologie ist das
<a href="http://www.mulberrytech.com/walkthewalk.html">Slide-Format von MulberryTech</a>. Dieses Format bietet nicht so viele
Elemente wie das DocBook-Format und ist damit nicht so komplex. Aus meiner Sicht sind die vorhandenen Elemente teilweise
auch sinnvoller bezeichnet, was verständlich ist da es speziell für Folienpräsentationen entwickelt ist. Die
Dokumentation der Elemente innerhalb der Dokument-Typ-Definition ist auch sehr vorbildlich. Einziger Wehrmutstropfen ist
bei diesem Format jedoch, dass es letzlich auch eine Eigenentwicklung eines Unternehmens ist und kein Etablierter
Standard wie DocBook.</p>
<h3>Die Plattform</h3>
<p>Was vermutlich gleich bleiben wird im Vergleich zu den alten Konzepten, ist die Plattform. Ich werde das Programm mit
großer Wahrscheinlichkeit als Firefox-Plugin entwickeln. Hierfür habe ich bereits an einem Entwurf für die Oberfläche
gearbeitet.</p>
<p>Es wäre jedoch auch eine Webbasierte Lösung denkbar, bei der der Nutzer auf einer Webseite einen Editor vorfindet und
seine Präsentationen erstellen kann. Dies könnte dann auch direkt mit einem Hosting-Angebot verknüpft werden, bei der
die erstellten Präsentationen auf dem Server verbleiben und der Nutzer eine URL zu seiner Präsentation zur Verfügung
gestellt bekommt, über die er die Präsentation jederzeit direkt ansehen kann.</p>
<p>Wie genau die Lösung aussehen wird, muss ich noch genau entscheiden. Wie gesagt: Da es sich hierbei nun um ein Projekt
im Wissenschaftlichen Rahmen handelt, müssen solche Entscheidungen natürlich sehr viel Detailierter behandelt und die
Abwägung zwischen Technologien mit Bedacht getroffen werden.</p>]]></description>
            <content:encoded><![CDATA[<p>Vor einiger Zeit hatte ich ja bereits ein paar Ideen und Entwürfe für meine Präsentations-Software für Browser
vorgestellt. Mittlerweile hat sich einiges getan bzw. geändert.</p>
<p>Zunächst einmal: Ich bearbeite dieses Projekt nun im Rahmen meines Praktikums und meiner Abschlussarbeit an der
Hochschule. Das heisst vor allem, dass das Projekt nun nicht mehr nur ein kleines Hobby-Projekt für zwischendurch ist,
das ich vieleicht irgendwann einmal fertig stelle, sondern dass ich aktuell in Vollzeit daran arbeite und es in jedem
Fall in absehbarer Zeit vorzeigbare Ergebnisse geben wird. Ich möchte ja schließlich mein Studium und die
Abschlussarbeit vernünftig abschließen.</p>
<p>Eine weitere Konsequenz daraus ist, dass ich viele Sachen nicht mehr "einfach so" programmieren kann, wie es mir grade
passt, sondern ich tiefgreifendere Untersuchungen anstellen muss, damit wirklich ein vernünftiges Ergebniss herauskommt.
Eine erste Konsequenz daraus ist, dass ich einen Großteil der bisherigen Arbeit über Bord geworfen habe und das ganze
von Grund auf neu plane. Die Anforderungen bleiben jedoch weitestgehend gleich, nur der Lösungsweg verändert sich etwas.</p>
<p>Im ersten Schritt verzichte ich nun auf eine selbstentwickelte XML-Sprache und werde stattdessen eine bereits bestehende
XML-Sprache zurückgreifen. Welche konkret steht aber aktuell noch nicht ganz fest. Auf der einen Seite ist das
<a href="https://de.wikipedia.org/wiki/DocBook">DocBook</a>-Format für Technische Dokumentationen eine etablierte Technologie und
bietet auch eine Art
<a href="http://docbook.org/schemas/5x-custom.html#slides">Spezialisierung für die Beschreibung von Präsentationen</a>. Der
Nachteil dieser Variante ist jedoch, dass das Format unglaublich komplex ist und sehr sehr viele Elemente enthält, die
ich in meiner Software nicht benötige. Die hohe Komplexität spricht auch gegen eine der Hauptanforderungen nach
Einfachheit und Nutzerfreundlichkeit. Man könnte jedoch auch nur einen Teil des DocBook-Slides-Formates implementieren
und auf den Rest verzichten. Diese Lösung hat allerdings auch ihre Schattenseiten.</p>
<p>Eine andere recht vielversprechende Technologie ist das
<a href="http://www.mulberrytech.com/walkthewalk.html">Slide-Format von MulberryTech</a>. Dieses Format bietet nicht so viele
Elemente wie das DocBook-Format und ist damit nicht so komplex. Aus meiner Sicht sind die vorhandenen Elemente teilweise
auch sinnvoller bezeichnet, was verständlich ist da es speziell für Folienpräsentationen entwickelt ist. Die
Dokumentation der Elemente innerhalb der Dokument-Typ-Definition ist auch sehr vorbildlich. Einziger Wehrmutstropfen ist
bei diesem Format jedoch, dass es letzlich auch eine Eigenentwicklung eines Unternehmens ist und kein Etablierter
Standard wie DocBook.</p>
<h3>Die Plattform</h3>
<p>Was vermutlich gleich bleiben wird im Vergleich zu den alten Konzepten, ist die Plattform. Ich werde das Programm mit
großer Wahrscheinlichkeit als Firefox-Plugin entwickeln. Hierfür habe ich bereits an einem Entwurf für die Oberfläche
gearbeitet.</p>
<p>Es wäre jedoch auch eine Webbasierte Lösung denkbar, bei der der Nutzer auf einer Webseite einen Editor vorfindet und
seine Präsentationen erstellen kann. Dies könnte dann auch direkt mit einem Hosting-Angebot verknüpft werden, bei der
die erstellten Präsentationen auf dem Server verbleiben und der Nutzer eine URL zu seiner Präsentation zur Verfügung
gestellt bekommt, über die er die Präsentation jederzeit direkt ansehen kann.</p>
<p>Wie genau die Lösung aussehen wird, muss ich noch genau entscheiden. Wie gesagt: Da es sich hierbei nun um ein Projekt
im Wissenschaftlichen Rahmen handelt, müssen solche Entscheidungen natürlich sehr viel Detailierter behandelt und die
Abwägung zwischen Technologien mit Bedacht getroffen werden.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[xmlSlides: Erster Entwurf der XML-Sprache und erstes XSL-Stylesheet]]></title>
            <link>https://www.lestard.eu/2009/xmlSlides_first_draft_xml_and_xsl/</link>
            <guid>https://www.lestard.eu/2009/xmlSlides_first_draft_xml_and_xsl/</guid>
            <pubDate>Mon, 28 Dec 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Ich habe einen ersten Entwurf der zugrunde liegenden XML-Sprache für mein Programm "xmlSlides" entwickelt. Damit wird
noch lange nicht der volle Funktionsumfang von HTML-Präsentationen abgedeckt, jedoch lassen sich simple Präsentationen
bereits erstellen.</p>
<p>In meinem Programm sollen Präsentationen, genauer gesagt nur der Inhalt der Präsentation in einer XML-Datei abgelegt
werden. Diese XML-Datei beschreibt in möglichst abstrakter Form den reinen Content der Folien. Im Anschluss wird mit
Hilfe von XML Transformationen aus der XML-Datei die eigentliche XHTML-Präsentation erstellt. Diese Vorgehensweise hat
den Vorteil, dass das eigentliche Ausgabeformat nur durch das verwendete XSL-Stylesheet festgelegt wird. Es können also
auch verschiedene XLS-Stylesheets für verschiedene Ausgabeformen angeboten werden. In erster Linie sollen damit die
verschiedenen HTML-Präsentations-Technologien, wie <a href="http://meyerweb.com/eric/tools/s5/">S5</a>,
<a href="http://icant.co.uk/domslides/">DOMSlides</a> oder <a href="http://goessner.net/articles/slideous/">Slideous</a> abgedeckt werden.
Jedoch sind auch Exporte nach PDF und sogar OpenOffice-Impress und MS-Powerpoint 2007 (beide sind ebenfalls XML-Formate)
denkbar - wobei die beiden letztgenannten und insbesondere MS-Powerpoint ziemlich unwahrscheinlich sind.</p>
<p>Für das XML-Format habe ich ein entsprechendes XML-Schema entwickelt, wechels wie bereits erwähnt, noch unvollständig
ist.</p>
<h3>Das XML-Dokument</h3>
<p>Ein Beispielhaftes XML-Dokument könnte so aussehen:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token prolog">&lt;?xml-stylesheet type="text/xsl" href="xmlslides.xsl" ?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slides</span> <span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span>
        <span class="token attr-name"><span class="token namespace">xsi:</span>noNamespaceSchemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>xmlslides.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">></span></span>Vortrag<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>author</span><span class="token punctuation">></span></span>Manuel<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>author</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slide</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>headline</span><span class="token punctuation">></span></span>Folie 1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>headline</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>contentBox</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>text</span><span class="token punctuation">></span></span>Hallo Welt<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>text</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>text</span><span class="token punctuation">></span></span>Das ist die erste Folie<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>text</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>contentBox</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slide</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slide</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>headline</span><span class="token punctuation">></span></span>Folie 2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>headline</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>contentBox</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>text</span><span class="token punctuation">></span></span>Servus zur zweiten Folie<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>text</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>contentBox</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slide</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slides</span><span class="token punctuation">></span></span></code></pre></div>
<p>Darin gibt es einen <em>head</em> und einen <em>body</em> ähnlich wie in HTML. Im head wird der Titel und der Autor der Präsentation
definiert. Hier werde ich in Zukunft noch weitere Angaben hinzufügen.</p>
<p>Im Body-Bereich werden die eigentlichen Folien beschrieben. Jede Folie wird von einem <code class="language-text">&lt;slide></code>-Element umschlossen. Als
erstes kann jede Folie eine Überschrift mit dem Element <code class="language-text">&lt;headline></code> enthalten. Im Anschluss folgt der eigentliche
Inhalt der Folie in einem <code class="language-text">&lt;contentBox></code>-Element. Dieses Element soll in Zukunft ein Attribut align bekommen, welches
die Werte horizontal oder vertical annehmen kann. Damit soll bestimmt werden, ob die innerhalb der ContentBox
definierten Elemente Horizontal oder Vertikal angeordnet werden sollen.</p>
<p>Innerhalb der ContentBox folgen die eigentlichen Elemente zur Anzeige auf der Folie. Aktuell ist hier nur das Element
<code class="language-text">&lt;text></code> zur Anzeige von normalen Text definiert. Hier folgen in Zukunft aber noch weitere Elemente für Listen, Bilder,
Tabellen oder Code-Abschnitte.</p>
<p>Jedes dieser Elemente soll von dem align-Attribut der Umschließenden ContentBox beeinflusst werden. So werden entweder
alle Elemente untereinander oder Nebeneinander angezeigt.</p>
<h3>XSL-Transformation</h3>
<p>Wenn das XML-Dokument mit der Abstrakten Beschreibung der Folien fertig ist, muss es mit Hilfe eines XSL-Stylesheet in
die entsprechende Anzeigefähige Form gebracht werden. Aktuell benutze ich als Anzeige-Technologie Slideous mit minimalen
Erweiterungen und einem von mir erstellten Template. Später sollen aber natürlich ncoh weitere Technologien wie S5
unterstützt werden.</p>
<p>Das XSL-Stylesheet sieht folgender Maßen aus:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>stylesheet</span> <span class="token attr-name">version</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1.0<span class="token punctuation">"</span></span>
                <span class="token attr-name"><span class="token namespace">xmlns:</span>xsl</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/1999/XSL/Transform<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>template</span> <span class="token attr-name">match</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slides/head/title<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">http-equiv</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Content-Type<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text/html; charset=iso-8859-1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>author<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>attribute</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>content<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slides/head/author<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>attribute</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>meta</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>date<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>19.12.2009<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>autoincrement<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>false<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>

     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text/css<span class="token punctuation">"</span></span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slideous/slideous.css<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slideous/slideous.js<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text/javascript<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>statusbar<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>float:right;<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>margin-right:4em;font-weight:bold;<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slideidx<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span> of {$slidecount}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>prevslidebutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>previous slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#171;">&amp;#171;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>nextslidebutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>next slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#187;">&amp;#187;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>incfontbutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>content<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>A+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>decfontbutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>first slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>A-<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>select</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>tocbox<span class="token punctuation">"</span></span> <span class="token attr-name">size</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>option</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>option</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>select</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>

       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>eos<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#189;">&amp;#189;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>
         <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>attribute</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>title<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>{$location},{$date}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>attribute</span><span class="token punctuation">></span></span>{$title}, {$author}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>for-each</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slides/body/slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span>
         <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>headline<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span>
         <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span>
           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>for-each</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contentBox/text<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
             <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>.<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span>
           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>for-each</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>for-each</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>template</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>stylesheet</span><span class="token punctuation">></span></span></code></pre></div>
<p>Als Ergebnis kommt dann folgende Präsentation heraus:</p>
<ul>
<li>xml-Transformation (benötigt XSLT-Fähigen Browser z.B. Firefox oder moderne IE): test.xml</li>
<li>fertiges HTML-Dokument: test.html</li>
</ul>
<p>Zum testen kann man in modernen Browsern mit XSLT-Unterstützung (IE ab version 6?, Firefox,...) das entsprechende
XML-Dokument direkt im Browser laden. Sofern das XSL-Stylesheet im selben Verzeichnis liegt, sollte als Ergebnis direkt
das transformierte XHTML-Dokument, sprich die Präsentation im Browser erscheinen. Natürlich müssen dafür auch die
Dateien (CSS, JS, Grafiken) von Slideous vorhanden sein. Alles zusammen habe ich als ZIP-Archiv hier zum Download bereit
gestellt: xmlslides_01.zip</p>
<p>Wie eingangs erwähnt, ist der Funktionsumfang noch äusserst rudimentär. Jedoch als prinzipielle Machbarkeitsstudie ist
es für mich der erste Schritt in die richtige Richtung. Für Kritik und Hinweise bin ich wie immer Dankbar, vor allem was
das XML-Schema und allgemein meine Vorstellung des XML-Dokuments angeht.</p>]]></description>
            <content:encoded><![CDATA[<p>Ich habe einen ersten Entwurf der zugrunde liegenden XML-Sprache für mein Programm "xmlSlides" entwickelt. Damit wird
noch lange nicht der volle Funktionsumfang von HTML-Präsentationen abgedeckt, jedoch lassen sich simple Präsentationen
bereits erstellen.</p>
<p>In meinem Programm sollen Präsentationen, genauer gesagt nur der Inhalt der Präsentation in einer XML-Datei abgelegt
werden. Diese XML-Datei beschreibt in möglichst abstrakter Form den reinen Content der Folien. Im Anschluss wird mit
Hilfe von XML Transformationen aus der XML-Datei die eigentliche XHTML-Präsentation erstellt. Diese Vorgehensweise hat
den Vorteil, dass das eigentliche Ausgabeformat nur durch das verwendete XSL-Stylesheet festgelegt wird. Es können also
auch verschiedene XLS-Stylesheets für verschiedene Ausgabeformen angeboten werden. In erster Linie sollen damit die
verschiedenen HTML-Präsentations-Technologien, wie <a href="http://meyerweb.com/eric/tools/s5/">S5</a>,
<a href="http://icant.co.uk/domslides/">DOMSlides</a> oder <a href="http://goessner.net/articles/slideous/">Slideous</a> abgedeckt werden.
Jedoch sind auch Exporte nach PDF und sogar OpenOffice-Impress und MS-Powerpoint 2007 (beide sind ebenfalls XML-Formate)
denkbar - wobei die beiden letztgenannten und insbesondere MS-Powerpoint ziemlich unwahrscheinlich sind.</p>
<p>Für das XML-Format habe ich ein entsprechendes XML-Schema entwickelt, wechels wie bereits erwähnt, noch unvollständig
ist.</p>
<h3>Das XML-Dokument</h3>
<p>Ein Beispielhaftes XML-Dokument könnte so aussehen:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token prolog">&lt;?xml-stylesheet type="text/xsl" href="xmlslides.xsl" ?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slides</span> <span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span>
        <span class="token attr-name"><span class="token namespace">xsi:</span>noNamespaceSchemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>xmlslides.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">></span></span>Vortrag<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>author</span><span class="token punctuation">></span></span>Manuel<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>author</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slide</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>headline</span><span class="token punctuation">></span></span>Folie 1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>headline</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>contentBox</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>text</span><span class="token punctuation">></span></span>Hallo Welt<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>text</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>text</span><span class="token punctuation">></span></span>Das ist die erste Folie<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>text</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>contentBox</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slide</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slide</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>headline</span><span class="token punctuation">></span></span>Folie 2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>headline</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>contentBox</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>text</span><span class="token punctuation">></span></span>Servus zur zweiten Folie<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>text</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>contentBox</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slide</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slides</span><span class="token punctuation">></span></span></code></pre></div>
<p>Darin gibt es einen <em>head</em> und einen <em>body</em> ähnlich wie in HTML. Im head wird der Titel und der Autor der Präsentation
definiert. Hier werde ich in Zukunft noch weitere Angaben hinzufügen.</p>
<p>Im Body-Bereich werden die eigentlichen Folien beschrieben. Jede Folie wird von einem <code class="language-text">&lt;slide></code>-Element umschlossen. Als
erstes kann jede Folie eine Überschrift mit dem Element <code class="language-text">&lt;headline></code> enthalten. Im Anschluss folgt der eigentliche
Inhalt der Folie in einem <code class="language-text">&lt;contentBox></code>-Element. Dieses Element soll in Zukunft ein Attribut align bekommen, welches
die Werte horizontal oder vertical annehmen kann. Damit soll bestimmt werden, ob die innerhalb der ContentBox
definierten Elemente Horizontal oder Vertikal angeordnet werden sollen.</p>
<p>Innerhalb der ContentBox folgen die eigentlichen Elemente zur Anzeige auf der Folie. Aktuell ist hier nur das Element
<code class="language-text">&lt;text></code> zur Anzeige von normalen Text definiert. Hier folgen in Zukunft aber noch weitere Elemente für Listen, Bilder,
Tabellen oder Code-Abschnitte.</p>
<p>Jedes dieser Elemente soll von dem align-Attribut der Umschließenden ContentBox beeinflusst werden. So werden entweder
alle Elemente untereinander oder Nebeneinander angezeigt.</p>
<h3>XSL-Transformation</h3>
<p>Wenn das XML-Dokument mit der Abstrakten Beschreibung der Folien fertig ist, muss es mit Hilfe eines XSL-Stylesheet in
die entsprechende Anzeigefähige Form gebracht werden. Aktuell benutze ich als Anzeige-Technologie Slideous mit minimalen
Erweiterungen und einem von mir erstellten Template. Später sollen aber natürlich ncoh weitere Technologien wie S5
unterstützt werden.</p>
<p>Das XSL-Stylesheet sieht folgender Maßen aus:</p>
<div class="gatsby-highlight" data-language="xml"><pre class="language-xml"><code class="language-xml"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>stylesheet</span> <span class="token attr-name">version</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1.0<span class="token punctuation">"</span></span>
                <span class="token attr-name"><span class="token namespace">xmlns:</span>xsl</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/1999/XSL/Transform<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>template</span> <span class="token attr-name">match</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slides/head/title<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">http-equiv</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Content-Type<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text/html; charset=iso-8859-1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>author<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>attribute</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>content<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slides/head/author<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>attribute</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>meta</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>date<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>19.12.2009<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>autoincrement<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>false<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>

     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text/css<span class="token punctuation">"</span></span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slideous/slideous.css<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slideous/slideous.js<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text/javascript<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>statusbar<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>float:right;<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>margin-right:4em;font-weight:bold;<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slideidx<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span> of {$slidecount}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>prevslidebutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>previous slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#171;">&amp;#171;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>nextslidebutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>next slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#187;">&amp;#187;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>incfontbutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>content<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>A+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>decfontbutton<span class="token punctuation">"</span></span> <span class="token attr-name">title</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>first slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>A-<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>select</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>tocbox<span class="token punctuation">"</span></span> <span class="token attr-name">size</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>option</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>option</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>select</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>

       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>eos<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#189;">&amp;#189;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>
         <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>attribute</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>title<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>{$location},{$date}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>attribute</span><span class="token punctuation">></span></span>{$title}, {$author}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>for-each</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>slides/body/slide<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span>
         <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>headline<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span>
         <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span>
           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>for-each</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contentBox/text<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
             <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">xsl:</span>value-of</span> <span class="token attr-name">select</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>.<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span>
           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>for-each</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
       <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>for-each</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>template</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">xsl:</span>stylesheet</span><span class="token punctuation">></span></span></code></pre></div>
<p>Als Ergebnis kommt dann folgende Präsentation heraus:</p>
<ul>
<li>xml-Transformation (benötigt XSLT-Fähigen Browser z.B. Firefox oder moderne IE): test.xml</li>
<li>fertiges HTML-Dokument: test.html</li>
</ul>
<p>Zum testen kann man in modernen Browsern mit XSLT-Unterstützung (IE ab version 6?, Firefox,...) das entsprechende
XML-Dokument direkt im Browser laden. Sofern das XSL-Stylesheet im selben Verzeichnis liegt, sollte als Ergebnis direkt
das transformierte XHTML-Dokument, sprich die Präsentation im Browser erscheinen. Natürlich müssen dafür auch die
Dateien (CSS, JS, Grafiken) von Slideous vorhanden sein. Alles zusammen habe ich als ZIP-Archiv hier zum Download bereit
gestellt: xmlslides_01.zip</p>
<p>Wie eingangs erwähnt, ist der Funktionsumfang noch äusserst rudimentär. Jedoch als prinzipielle Machbarkeitsstudie ist
es für mich der erste Schritt in die richtige Richtung. Für Kritik und Hinweise bin ich wie immer Dankbar, vor allem was
das XML-Schema und allgemein meine Vorstellung des XML-Dokuments angeht.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Musik Player: Songbird oder selbst entwickeln]]></title>
            <link>https://www.lestard.eu/2009/musicplayer_songbird_or_self/</link>
            <guid>https://www.lestard.eu/2009/musicplayer_songbird_or_self/</guid>
            <pubDate>Sat, 26 Dec 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Nicht erst seit Gestern bin ich auf der Suche nach einer tollen Musik-Abspielsoftware, die alle meine Anforderungen
erfüllt. Bisher war die Suche aber nicht wirklich Erfolgreich. Bisher habe ich vor allem den Player "foobar2000"
benutzt, welcher von Art und Umfang der Funktionen überaus Großartig ist. Wer möchte kann eine (ziemlich schnelle)
MedienDatenbank benutzten - muss aber nicht. Ich persönlich bin da wohl ein bisschen Altmodisch und bevorzuge die
Klassischen Playlisten. Diese lassen sich in Foobar2000 sehr intuitiv steuern. Man kann mehrere Playlisten anlegen und
in Tabs ordnen. Das ganze in einer simplen, praktischen und unaufdringlichen grafischen Gestaltung. Prima. Doch leider
wird das Bild meiner Meinung nach durch 2 Fakten etwas getrübt, wobei der eine Fakt wohl aus dem anderen folgt: Erstens:
Foobar2000 ist keine freie OpenSource-Software, zumindest nicht komplett. Und zweitens, was wesentlich relevanter ist:
Foobar2000 läuft nur unter Windows und nicht unter Linux. Die Musik-Player, die ich bisher unter Linux ausprobiert habe,
können leider Foobar2000 nicht das Wasser reichen - zumindest was meine Bedürfnisse angeht.</p>
<h3>SongBird</h3>
<p>Hoffnung habe ich geschöpft, als ich vom Player "Songbird" hörte. Dieser basiert auf Mozillas XUL-Technologie, was eine
ganze Reihe positiver Eigenschaften nach sich zieht. Er läuft unter Windows genauso wie unter Linux. Die Anpassbarkeit
über Plugins sollte auf einfachste Art und Weise funktionieren und das Mozilla-Toolkit bietet jede Menge Potetial was
die Gestaltung der Oberfläche und den Funktionsumfang angeht.</p>
<p>Songbird möchte eine Art "MusikBrowser" sein, jedoch verschenkt er jede Menge Potential. Das fängt schon bei den Tabs
an. Tabs sind für Browser heute eine alltägliche Funktion und so bietet auch Songbird tabs. Jedoch kann ich meine
MusikPlayliste ausschließlich im ersten Tab ablegen. Alle weiteren Tabs sind ausschließlich für das Besuchen von
Webseiten gedacht. Warum kann ich nicht (ähnlich simple wie in Foobar2000) meine verschiedenen Wiedergabelisten in
jeweils einen Tab ablegen?</p>
<p>Und wo wir bei den Wiedergabelisten sind. Wieso ist es so umständlich, überhaupt eine Playlist zu erzeugen? Als ich
Songbird ausprobiert habe, hatte ich ständig das Gefühl, dass ich unbedingt auf die Musikdatenbank angewiesen bin. Ohne
Musikdatenbank, nur mit simplen Playlisten zu arbeiten erschien mir unglaublich umständlich. Schade. Weiter geht das
ganze mit dem Layout. Leider ist es nicht ohneweiteres möglich, ungewollte Oberflächenelemente, wie z.B. die
Seitenleiste der Mediathek, einfach auszublenden.</p>
<p>Die eigentlichen Schwächen im Vergleich zu Foobar2000 zeigen sich jedoch erst bei genauerem Hinsehen: Wärend ich bei
Foobar2000 nicht nur die komplette Oberfläche (inklusive Menüs) frei gestalten sondern auch ALLE Funktionen, die
irgendwo im Player stecken auch über Tastatur-Shortcuts steuern kann, sind die Möglichkeiten bei Songbird hier dürftig.
Nur für ein knappes Dutzend Funktionen lassen sich Tastaturkürzel belegen. Diese aber dazu teilweise noch mit
Einschränkungen. So ist es in Foobar2000 ohne Probleme möglich, Tastaturkürzel für das Abspielen von Songs auf den
Nummernblog zu legen. In Songbird ist dies so nicht möglich. Ich muss zwingend eine Sondertaste zusätzlich angeben. Das
ist sicherlich gut gemeint, für mich persönlich stellt das aber ein ärgerliche Einschränkung dar.</p>
<p>Ein weiteres, eigentlich total simples Feature, welches ich bei Foobar2000 lieben gelernt habe sind die Funktionen
"Playback follows Cursor" und "Cursor Follows Playback". Wenn ich in der Playlist einen Song markiere, dann wird dieser
als nächstes abgespielt. Somit kann ich den aktuellen Song noch fertig hören und Foobar2000 springt danach selbstständig
zu der Stelle in der aktuellen Playlist (oder in anderen Playlists), an der ich weiter hören möchte. Ein unglaublich
simples aber trotzdem cooles Feature, welches ich sonst noch bei keinem anderen Musikplayer gefunden habe.</p>
<h3>Die Lösung?</h3>
<p>Technisch ist Songbird wirklich klasse. Die XUL-Plattform ist meiner Meinung nach eine wirklich gute Wahl bei der
Entwicklung von dieser Art von Software. Vor allem für die vielen Internet-Funktionen, die Songbird implementiert ist
diese Plattform hervorragend geeignet. Offensichtlich gehöre ich wohl leider nicht so ganz zur Zielgruppe von Songbird.
Meine Idee war also, Songbird durch geeignete Plugins so zu erweitern, dass er meine Anforderungen doch erfüllt.
Entweder Plugins von anderen Programmierern oder von mir selbst programmierte Plugins. Nach einigen Suchen bin ich da
mittlerweile jedoch ein wenig Skeptisch geworden da Foobar2000 und Songbird scheinbar völlig andere Zielgruppen
ansprechen und der Aufbau von Songbird in einer ganz andere Richtung geht.</p>
<p>Damit war die Idee geboren, eventuell eben selbst eine MusikPlayer-Software zu schreiben, die genau meine Bedürfnisse
erfüllt. Nicht mehr und nicht weniger. Da Songbird freie OpenSource-Software ist wäre es ja Möglich, gewisse
Grundfunktionalitäten wie das reine Abspielen von MP3s in eine eigene Anwendung zu übernehmen. Als Plattform würde ich
selbstverständlich auch Mozillas XUL einsetzen und den Player natürlich auch unter einer freien OpenSource-Lizenz
veröffentlichen. Ob und Wann ich diese Player-Software wirklich schreibe, weiss ich aber aktuell noch nicht. Die Idee
ist zumindest da und wenn sich die Zeit finden lässt, dann setze ich diese vieleicht auch um. Mal Schauen :-)</p>]]></description>
            <content:encoded><![CDATA[<p>Nicht erst seit Gestern bin ich auf der Suche nach einer tollen Musik-Abspielsoftware, die alle meine Anforderungen
erfüllt. Bisher war die Suche aber nicht wirklich Erfolgreich. Bisher habe ich vor allem den Player "foobar2000"
benutzt, welcher von Art und Umfang der Funktionen überaus Großartig ist. Wer möchte kann eine (ziemlich schnelle)
MedienDatenbank benutzten - muss aber nicht. Ich persönlich bin da wohl ein bisschen Altmodisch und bevorzuge die
Klassischen Playlisten. Diese lassen sich in Foobar2000 sehr intuitiv steuern. Man kann mehrere Playlisten anlegen und
in Tabs ordnen. Das ganze in einer simplen, praktischen und unaufdringlichen grafischen Gestaltung. Prima. Doch leider
wird das Bild meiner Meinung nach durch 2 Fakten etwas getrübt, wobei der eine Fakt wohl aus dem anderen folgt: Erstens:
Foobar2000 ist keine freie OpenSource-Software, zumindest nicht komplett. Und zweitens, was wesentlich relevanter ist:
Foobar2000 läuft nur unter Windows und nicht unter Linux. Die Musik-Player, die ich bisher unter Linux ausprobiert habe,
können leider Foobar2000 nicht das Wasser reichen - zumindest was meine Bedürfnisse angeht.</p>
<h3>SongBird</h3>
<p>Hoffnung habe ich geschöpft, als ich vom Player "Songbird" hörte. Dieser basiert auf Mozillas XUL-Technologie, was eine
ganze Reihe positiver Eigenschaften nach sich zieht. Er läuft unter Windows genauso wie unter Linux. Die Anpassbarkeit
über Plugins sollte auf einfachste Art und Weise funktionieren und das Mozilla-Toolkit bietet jede Menge Potetial was
die Gestaltung der Oberfläche und den Funktionsumfang angeht.</p>
<p>Songbird möchte eine Art "MusikBrowser" sein, jedoch verschenkt er jede Menge Potential. Das fängt schon bei den Tabs
an. Tabs sind für Browser heute eine alltägliche Funktion und so bietet auch Songbird tabs. Jedoch kann ich meine
MusikPlayliste ausschließlich im ersten Tab ablegen. Alle weiteren Tabs sind ausschließlich für das Besuchen von
Webseiten gedacht. Warum kann ich nicht (ähnlich simple wie in Foobar2000) meine verschiedenen Wiedergabelisten in
jeweils einen Tab ablegen?</p>
<p>Und wo wir bei den Wiedergabelisten sind. Wieso ist es so umständlich, überhaupt eine Playlist zu erzeugen? Als ich
Songbird ausprobiert habe, hatte ich ständig das Gefühl, dass ich unbedingt auf die Musikdatenbank angewiesen bin. Ohne
Musikdatenbank, nur mit simplen Playlisten zu arbeiten erschien mir unglaublich umständlich. Schade. Weiter geht das
ganze mit dem Layout. Leider ist es nicht ohneweiteres möglich, ungewollte Oberflächenelemente, wie z.B. die
Seitenleiste der Mediathek, einfach auszublenden.</p>
<p>Die eigentlichen Schwächen im Vergleich zu Foobar2000 zeigen sich jedoch erst bei genauerem Hinsehen: Wärend ich bei
Foobar2000 nicht nur die komplette Oberfläche (inklusive Menüs) frei gestalten sondern auch ALLE Funktionen, die
irgendwo im Player stecken auch über Tastatur-Shortcuts steuern kann, sind die Möglichkeiten bei Songbird hier dürftig.
Nur für ein knappes Dutzend Funktionen lassen sich Tastaturkürzel belegen. Diese aber dazu teilweise noch mit
Einschränkungen. So ist es in Foobar2000 ohne Probleme möglich, Tastaturkürzel für das Abspielen von Songs auf den
Nummernblog zu legen. In Songbird ist dies so nicht möglich. Ich muss zwingend eine Sondertaste zusätzlich angeben. Das
ist sicherlich gut gemeint, für mich persönlich stellt das aber ein ärgerliche Einschränkung dar.</p>
<p>Ein weiteres, eigentlich total simples Feature, welches ich bei Foobar2000 lieben gelernt habe sind die Funktionen
"Playback follows Cursor" und "Cursor Follows Playback". Wenn ich in der Playlist einen Song markiere, dann wird dieser
als nächstes abgespielt. Somit kann ich den aktuellen Song noch fertig hören und Foobar2000 springt danach selbstständig
zu der Stelle in der aktuellen Playlist (oder in anderen Playlists), an der ich weiter hören möchte. Ein unglaublich
simples aber trotzdem cooles Feature, welches ich sonst noch bei keinem anderen Musikplayer gefunden habe.</p>
<h3>Die Lösung?</h3>
<p>Technisch ist Songbird wirklich klasse. Die XUL-Plattform ist meiner Meinung nach eine wirklich gute Wahl bei der
Entwicklung von dieser Art von Software. Vor allem für die vielen Internet-Funktionen, die Songbird implementiert ist
diese Plattform hervorragend geeignet. Offensichtlich gehöre ich wohl leider nicht so ganz zur Zielgruppe von Songbird.
Meine Idee war also, Songbird durch geeignete Plugins so zu erweitern, dass er meine Anforderungen doch erfüllt.
Entweder Plugins von anderen Programmierern oder von mir selbst programmierte Plugins. Nach einigen Suchen bin ich da
mittlerweile jedoch ein wenig Skeptisch geworden da Foobar2000 und Songbird scheinbar völlig andere Zielgruppen
ansprechen und der Aufbau von Songbird in einer ganz andere Richtung geht.</p>
<p>Damit war die Idee geboren, eventuell eben selbst eine MusikPlayer-Software zu schreiben, die genau meine Bedürfnisse
erfüllt. Nicht mehr und nicht weniger. Da Songbird freie OpenSource-Software ist wäre es ja Möglich, gewisse
Grundfunktionalitäten wie das reine Abspielen von MP3s in eine eigene Anwendung zu übernehmen. Als Plattform würde ich
selbstverständlich auch Mozillas XUL einsetzen und den Player natürlich auch unter einer freien OpenSource-Lizenz
veröffentlichen. Ob und Wann ich diese Player-Software wirklich schreibe, weiss ich aber aktuell noch nicht. Die Idee
ist zumindest da und wenn sich die Zeit finden lässt, dann setze ich diese vieleicht auch um. Mal Schauen :-)</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Mockup - 'LestardMusicPlayer']]></title>
            <link>https://www.lestard.eu/2009/mockup_lestard_music_player/</link>
            <guid>https://www.lestard.eu/2009/mockup_lestard_music_player/</guid>
            <pubDate>Sat, 26 Dec 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Über die Feiertage habe ich ein wenig Zeit gehabt und an einem Mockup für einen Musikplayer gearbeitet. Als Plattform
habe ich wiedermal Mozillas XUL gewählt. Das GUI ist an meine Konfiguration von Foobar2000 angelegt.</p>
<p>Wie gesagt handelt es sich nur um ein Mockup. Jegliche Programmlogik fehlt noch völlig. Weder lässt sich Musik abspielen
noch die Playlists direkt bearbeiten. Es dient nur als Test und Beispiel für die Programmoberfläche.</p>
<p>Das Mockup gibt es hier zum Download</p>
<p>Hier ein Screenshot:</p>
<p><img src="/files/pics/2009/lestardMusicPlayer_screenshot.png" alt="Screenshot"></p>]]></description>
            <content:encoded><![CDATA[<p>Über die Feiertage habe ich ein wenig Zeit gehabt und an einem Mockup für einen Musikplayer gearbeitet. Als Plattform
habe ich wiedermal Mozillas XUL gewählt. Das GUI ist an meine Konfiguration von Foobar2000 angelegt.</p>
<p>Wie gesagt handelt es sich nur um ein Mockup. Jegliche Programmlogik fehlt noch völlig. Weder lässt sich Musik abspielen
noch die Playlists direkt bearbeiten. Es dient nur als Test und Beispiel für die Programmoberfläche.</p>
<p>Das Mockup gibt es hier zum Download</p>
<p>Hier ein Screenshot:</p>
<p><img src="/files/pics/2009/lestardMusicPlayer_screenshot.png" alt="Screenshot"></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Vortrag XUL bei der LinuxUserGroup Görlitz]]></title>
            <link>https://www.lestard.eu/2009/talk_linuxUserGroup_xul/</link>
            <guid>https://www.lestard.eu/2009/talk_linuxUserGroup_xul/</guid>
            <pubDate>Sun, 06 Dec 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Für die LinuxUserGroup an der Hochschule habe ich einen Vortrag zum Thema <strong>XUL</strong> und Entwicklung von Anwendungen auf
Basis des <strong>MozillaApplicationFrameworks</strong> sowie Erstellung von <strong>Plugins für den Firefox</strong> gehalten.</p>
<p>Die Vortragsfolien sind mit xhtml, css und JavaScript erstellt und können deshalb auch direkt im Internet angeschaut
werden. Ich hab die Folien hier verlinkt: Vortrag XUL</p>
<p>Nebenbei bemerkt: Die Folien entsprechen beispielhaft dem, was mit meinem geplanten Programm
<a href="/tags/#xmlslides">xmlSlides</a> erstellbar sein wird. Diese Folien hier habe ich per Hand geschrieben jedoch soll es in
Zukunft möglich sein, soetwas mit meinem Programm auf einfache Weise erstellen zu lassen.</p>]]></description>
            <content:encoded><![CDATA[<p>Für die LinuxUserGroup an der Hochschule habe ich einen Vortrag zum Thema <strong>XUL</strong> und Entwicklung von Anwendungen auf
Basis des <strong>MozillaApplicationFrameworks</strong> sowie Erstellung von <strong>Plugins für den Firefox</strong> gehalten.</p>
<p>Die Vortragsfolien sind mit xhtml, css und JavaScript erstellt und können deshalb auch direkt im Internet angeschaut
werden. Ich hab die Folien hier verlinkt: Vortrag XUL</p>
<p>Nebenbei bemerkt: Die Folien entsprechen beispielhaft dem, was mit meinem geplanten Programm
<a href="/tags/#xmlslides">xmlSlides</a> erstellbar sein wird. Diese Folien hier habe ich per Hand geschrieben jedoch soll es in
Zukunft möglich sein, soetwas mit meinem Programm auf einfache Weise erstellen zu lassen.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[Hochschule-Cluster]]></title>
            <link>https://www.lestard.eu/2009/univertity_cluster/</link>
            <guid>https://www.lestard.eu/2009/univertity_cluster/</guid>
            <pubDate>Fri, 06 Nov 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Im Rahmen eines Forschungsprojekts an der Hochschule Zittau/Görlitz beschäftigen wir uns mit der Einrichtung,
Installation und Konfiguration eines Cluster-Computers zu Lehr- und Forschungszwecken. Als Hardware-Grundlage dienen uns
dabei 10 Minicomputer mit Intel-Atom-Prozessor, je 2GB Arbeitsspeicher und jeweils 300 GB Festplatte. Die Technik hat
uns die Hochschule finanziert.</p>
<p>Die 10 Computer sind aktuell über reguläre Netzwerk-Kabel in einem geswitchten Netzwerk miteinander verbunden. Als
Software versuchen wir vorwiegend Freie Software einzusetzen. Als Betriebssystem kommt Debian-Linux zum Einsatz.</p>
<p>Zur Entwicklung von verteilter Software ist aktuell auf allen Maschinen eine Java-VM installiert. In einem regulären
Studienprojekt befassen wir uns aktuell mit der Anpassung einer Data-Mining-Software um diese parallelisiert auf dem
Cluster auszuführen.</p>]]></description>
            <content:encoded><![CDATA[<p>Im Rahmen eines Forschungsprojekts an der Hochschule Zittau/Görlitz beschäftigen wir uns mit der Einrichtung,
Installation und Konfiguration eines Cluster-Computers zu Lehr- und Forschungszwecken. Als Hardware-Grundlage dienen uns
dabei 10 Minicomputer mit Intel-Atom-Prozessor, je 2GB Arbeitsspeicher und jeweils 300 GB Festplatte. Die Technik hat
uns die Hochschule finanziert.</p>
<p>Die 10 Computer sind aktuell über reguläre Netzwerk-Kabel in einem geswitchten Netzwerk miteinander verbunden. Als
Software versuchen wir vorwiegend Freie Software einzusetzen. Als Betriebssystem kommt Debian-Linux zum Einsatz.</p>
<p>Zur Entwicklung von verteilter Software ist aktuell auf allen Maschinen eine Java-VM installiert. In einem regulären
Studienprojekt befassen wir uns aktuell mit der Anpassung einer Data-Mining-Software um diese parallelisiert auf dem
Cluster auszuführen.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[DemoRecorder]]></title>
            <link>https://www.lestard.eu/2009/demorecorder/</link>
            <guid>https://www.lestard.eu/2009/demorecorder/</guid>
            <pubDate>Wed, 04 Nov 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Dieses Programm richtet sich an Hobbyfilmer, die mit CounterStrike:Source GameVideos herstellen möchten. Dabei nimmt das
Programm den sonst mühseligen Prozess des Aufnehmens aus dem Spiel ab. Allerdings handelt es sich aktuell noch um eine
frühe Alpha-Version. Es sind noch nicht alle Funktionen implementiert und getestet ist die Software auch noch nicht
ausführlich. Die Benutzung geschieht deshalb auf eigene Gefahr.</p>
<p>Lestards DemoRecorder wird als freies OpenSource-Projekt unter der MPL/GPL veröffentlicht.</p>
<p>Beschreibung</p>
<p>Das Aufnehmen von VideoSzenen aus dem Spiel ist relativ Zeitaufwendig und Umständlich. Die in der Source-Engine
eingebaute Aufnahmefunktion kann mit einer beliebig einstellbaren Framerate aufnehmen und schreibt dabei jede Frame
einzeln auf die Festplatte. Dieses Vorgehen hat einige starke Vorteile: Zum einen werden Ruckler oder FPS-Schwankungen
innerhalb des Videos vermieden, zum anderen ist es damit Möglich, mehr oder weniger unabhängig von der Leistungsfähig
des Systems mit sehr guten Grafikeinstellungen aufzunehmen. Da die Framerate beliebig einstellbar ist, sind auch extreme
Zeitlupen kein Problem.</p>
<p>Der Nachteil dieser Methode ist jedoch, dass der Aufnahmeprozess sehr lange braucht. So sind bei entsprechenden
Frameraten Aufnahmezeiten von einer halben Stunde pro Szene keine Seltenheit. Wärend diesem Aufnehmen kann man den
Rechner nicht benutzen sondern ist zum Zuschauen verdammt. Nach dem Aufnehmen hat man tausende Bilddateien auf der
Festplatte, welche man nun noch mit VirtualDub zu einer AVI-Datei umwandeln muss. Das alles ist etwas mühselig.</p>
<p>Mit meinem DemoRecorder ist es möglich, diesen Aufnahmeprozess zu Automatisieren. Man wählt seine Demo-Dateien aus, gibt
an, in welchem Bereich jeweils aufgenommen werden soll, macht seine Einstellungen und drückt auf "Record". Den Rest
erledigt mein Programm. Es nimmt eine Szene nach der Anderen auf und nach einiger Zeit hat man alle Videodateien auf der
Platte. Zwar dauert die Aufnahme mit meinem DemoRecorder genauso lange und auch hier ist der Rechner wärend dem
Aufnehmen nicht benutzbar, der Vorteil ist aber, dass man nicht dabei sitzen braucht und nach jeder Szene von Hand die
Aufnahme der nächsten Szenen zu starten. Die Aufnahme, auch mit mehreren Dateien geht automatisch. Man könnte hier z.B.
die Aufnahme starten und derweil Einkaufen gehen oder sonst was machen und nach einiger Zeit kommt man zum PC zurück und
hat alle Szenen im Kasten, und zwar direkt im AVI-Format. Das Umwandeln der Screenshots übernimmt das Programm nämlich
auch selbstständig.</p>
<p>Ein Problem, was allerdings auch hier bestehen bleibt, ist die Dateigröße der Videodateien. Diese werden unkomprimiert
auf der Festplatte abgelegt. Eine recht hohe Auflösung und hohe Framerate tuen ihr übriges. So sind Dateigrößen von
mehreren Gigabyte für Videoclips von wenigen Sekunden, keine Seltenheit. Die Oben genannten Vorteile werden durch diesen
Nachteil etwas teuer erkauft. Wer jedoch Wert auf Qualitativ hochwertige Aufnahmen macht, wird dieses Problem jedoch
gerne in Kauf nehmen. Komprimierung ist in der Regel auch mit starken Qualitätsverlusten behaftet, welche eben hier
nicht zu befürchten sind. Unschlagbar wird die Bildqualität aber vor allem dadurch, dass Frame per Frame auf die
Festplatte geschrieben wird und das Spiel beim Aufnehmen die Geschwindigkeit eben an diesen Aufnahmeprozess anpasst. Das
beim normalen Spielen übliche Abwägen zwischen hohen Grafikoptionen und flüssigem FPS fällt hier weg. Die Optionen
können bis zum Anschlag gestellt werden da die Framerate sowieso konstant gehalten wird. Technisches</p>
<p>Das Programm basiert auf dem Mozilla Application Framework. Die Benutzeroberfläche ist mit XUL (XML Userinterface
Language) entwickelt. Das Programm läuft in der XULRunner-Laufzeitumgebung. Als Programmiersprache kommt vor allem
JavaScript zum Einsatz.</p>
<p>Zur Umwandlung der TGA-Bilddateien in eine AVI-Datei wird VirtualDub benutzt, welches im Paket auch mitgeliefert wird.
Ausserdem benutze ich zur Dateiarbeit eine Bibliothek aus dem XUL-Explorer-Projekt. Dieses ist, genau wie VirtualDub und
auch meine eigenes Projekt, Freie OpenSource-Software weshalb das Mitliefern bzw. Benutzen kein Problem darstellt.</p>
<p>Als Lizenz kommt wahlweise die GPL und/oder die MPL zum Einsatz. Als Programmier-Neuling erhoffe ich mir daraus,
Feedback von Erfahrenen Programmierern zu bekommen. Aktueller Stand</p>
<p>Aktuell befindet sich die Software in einem frühen Alpha-Stadium. Die Aufnahme und das Umwandeln der Bilder zu einer
AVI-Datei funktioniert bereits. Aktuell jedoch nur mit einer einzelnen Datei und noch nicht im Stapelbetrieb. Durch
entsprechende Kapselung der Funktionen sollte dies aber unkompliziert nachrüstbar sei.</p>
<p>Das Programm ist noch nicht ausführlich getestet. Es kann deshalb noch zu einigen Fehlern kommen. Da ich auf Prozesse
(counterstrike:Source und VirtualDub) zugreife, kann ich Probleme die damit zusammenhängen nicht ausschließen. In der
Entwicklung ist es z.B: hin und wieder vorgekommen, dass das Spiel beim Aufnehmen eingefroren ist und ich den Rechner
neustarten musste.</p>
<p>Der anfangs geplante 3D-Kamerapfad-Export werde ich nun nicht mehr realisieren, da mstHavoc und das Team von AdvancedFX
diese Funktion mittlerweile in wesentlich besserer Form im Rahmen ihres HLAE-Projekts implementiert haben.</p>
<p>Für FirefoxNutzer: Da die Oberfläche in XUL geschrieben ist, lässt sich diese auch im Firefox-Browser darstellen. Hier
der Link Andere Browser werden mit dem Link jedoch nicht klar kommen.</p>
<p>Für alle andere habe ich einen Screenshot gemacht: Die aktuelle Benutzeroberfläche</p>
<p>Die aktuelle Benutzeroberfläche Was für die Zukunft geplant ist</p>
<p>Für die Zukunft sind noch einige Zusatzfunktionen geplant. Vor allem möchte ich Einstellungsprofile ermöglichen. Der
Nutzer soll seine Einstellungen und auch Customdateien in einem Aufnahme-Profil speichern können. Das Kopieren und
anschließende Aufräumen der Customdateien übernimmt der DemoRecorder.</p>
<p>In einer späteren Version könnte die Möglichkeit implementiert werden, mit der ganze Videos automatisch erstellt werden
könnten. Mit Hilfe von AviSynth wäre es möglich, den kompletten Schnitt programmgesteuert auszuführen. Der Nutzer könnte
dazu ein Musikstück auswählen und mit einer Tagging-Funktion, gewisse Spannungsgeladene Momente der Musik taggen. An
diesen Highlights könnte sich ein Algorithmus beim Schneiden orientieren. Aus einem Pool von Kamerafahrten könnten
Aufnahmen für Intro und Outro erstellt werden.</p>
<p>Dieses Automatische Schnittsystem würde aber vor allem eine Machbarkeitsstudie darstellen. Es wäre schließlich ziemlich
langweilig, wenn Alle Videos nur noch Algorithmisch erzeugt werden. Aus Programmierersicht stellt dies jedoch eine
interessante Aufgabe dar. Dies liegt aber noch in weiter Zukunft und ist bisher nicht weiter als eine Idee.</p>]]></description>
            <content:encoded><![CDATA[<p>Dieses Programm richtet sich an Hobbyfilmer, die mit CounterStrike:Source GameVideos herstellen möchten. Dabei nimmt das
Programm den sonst mühseligen Prozess des Aufnehmens aus dem Spiel ab. Allerdings handelt es sich aktuell noch um eine
frühe Alpha-Version. Es sind noch nicht alle Funktionen implementiert und getestet ist die Software auch noch nicht
ausführlich. Die Benutzung geschieht deshalb auf eigene Gefahr.</p>
<p>Lestards DemoRecorder wird als freies OpenSource-Projekt unter der MPL/GPL veröffentlicht.</p>
<p>Beschreibung</p>
<p>Das Aufnehmen von VideoSzenen aus dem Spiel ist relativ Zeitaufwendig und Umständlich. Die in der Source-Engine
eingebaute Aufnahmefunktion kann mit einer beliebig einstellbaren Framerate aufnehmen und schreibt dabei jede Frame
einzeln auf die Festplatte. Dieses Vorgehen hat einige starke Vorteile: Zum einen werden Ruckler oder FPS-Schwankungen
innerhalb des Videos vermieden, zum anderen ist es damit Möglich, mehr oder weniger unabhängig von der Leistungsfähig
des Systems mit sehr guten Grafikeinstellungen aufzunehmen. Da die Framerate beliebig einstellbar ist, sind auch extreme
Zeitlupen kein Problem.</p>
<p>Der Nachteil dieser Methode ist jedoch, dass der Aufnahmeprozess sehr lange braucht. So sind bei entsprechenden
Frameraten Aufnahmezeiten von einer halben Stunde pro Szene keine Seltenheit. Wärend diesem Aufnehmen kann man den
Rechner nicht benutzen sondern ist zum Zuschauen verdammt. Nach dem Aufnehmen hat man tausende Bilddateien auf der
Festplatte, welche man nun noch mit VirtualDub zu einer AVI-Datei umwandeln muss. Das alles ist etwas mühselig.</p>
<p>Mit meinem DemoRecorder ist es möglich, diesen Aufnahmeprozess zu Automatisieren. Man wählt seine Demo-Dateien aus, gibt
an, in welchem Bereich jeweils aufgenommen werden soll, macht seine Einstellungen und drückt auf "Record". Den Rest
erledigt mein Programm. Es nimmt eine Szene nach der Anderen auf und nach einiger Zeit hat man alle Videodateien auf der
Platte. Zwar dauert die Aufnahme mit meinem DemoRecorder genauso lange und auch hier ist der Rechner wärend dem
Aufnehmen nicht benutzbar, der Vorteil ist aber, dass man nicht dabei sitzen braucht und nach jeder Szene von Hand die
Aufnahme der nächsten Szenen zu starten. Die Aufnahme, auch mit mehreren Dateien geht automatisch. Man könnte hier z.B.
die Aufnahme starten und derweil Einkaufen gehen oder sonst was machen und nach einiger Zeit kommt man zum PC zurück und
hat alle Szenen im Kasten, und zwar direkt im AVI-Format. Das Umwandeln der Screenshots übernimmt das Programm nämlich
auch selbstständig.</p>
<p>Ein Problem, was allerdings auch hier bestehen bleibt, ist die Dateigröße der Videodateien. Diese werden unkomprimiert
auf der Festplatte abgelegt. Eine recht hohe Auflösung und hohe Framerate tuen ihr übriges. So sind Dateigrößen von
mehreren Gigabyte für Videoclips von wenigen Sekunden, keine Seltenheit. Die Oben genannten Vorteile werden durch diesen
Nachteil etwas teuer erkauft. Wer jedoch Wert auf Qualitativ hochwertige Aufnahmen macht, wird dieses Problem jedoch
gerne in Kauf nehmen. Komprimierung ist in der Regel auch mit starken Qualitätsverlusten behaftet, welche eben hier
nicht zu befürchten sind. Unschlagbar wird die Bildqualität aber vor allem dadurch, dass Frame per Frame auf die
Festplatte geschrieben wird und das Spiel beim Aufnehmen die Geschwindigkeit eben an diesen Aufnahmeprozess anpasst. Das
beim normalen Spielen übliche Abwägen zwischen hohen Grafikoptionen und flüssigem FPS fällt hier weg. Die Optionen
können bis zum Anschlag gestellt werden da die Framerate sowieso konstant gehalten wird. Technisches</p>
<p>Das Programm basiert auf dem Mozilla Application Framework. Die Benutzeroberfläche ist mit XUL (XML Userinterface
Language) entwickelt. Das Programm läuft in der XULRunner-Laufzeitumgebung. Als Programmiersprache kommt vor allem
JavaScript zum Einsatz.</p>
<p>Zur Umwandlung der TGA-Bilddateien in eine AVI-Datei wird VirtualDub benutzt, welches im Paket auch mitgeliefert wird.
Ausserdem benutze ich zur Dateiarbeit eine Bibliothek aus dem XUL-Explorer-Projekt. Dieses ist, genau wie VirtualDub und
auch meine eigenes Projekt, Freie OpenSource-Software weshalb das Mitliefern bzw. Benutzen kein Problem darstellt.</p>
<p>Als Lizenz kommt wahlweise die GPL und/oder die MPL zum Einsatz. Als Programmier-Neuling erhoffe ich mir daraus,
Feedback von Erfahrenen Programmierern zu bekommen. Aktueller Stand</p>
<p>Aktuell befindet sich die Software in einem frühen Alpha-Stadium. Die Aufnahme und das Umwandeln der Bilder zu einer
AVI-Datei funktioniert bereits. Aktuell jedoch nur mit einer einzelnen Datei und noch nicht im Stapelbetrieb. Durch
entsprechende Kapselung der Funktionen sollte dies aber unkompliziert nachrüstbar sei.</p>
<p>Das Programm ist noch nicht ausführlich getestet. Es kann deshalb noch zu einigen Fehlern kommen. Da ich auf Prozesse
(counterstrike:Source und VirtualDub) zugreife, kann ich Probleme die damit zusammenhängen nicht ausschließen. In der
Entwicklung ist es z.B: hin und wieder vorgekommen, dass das Spiel beim Aufnehmen eingefroren ist und ich den Rechner
neustarten musste.</p>
<p>Der anfangs geplante 3D-Kamerapfad-Export werde ich nun nicht mehr realisieren, da mstHavoc und das Team von AdvancedFX
diese Funktion mittlerweile in wesentlich besserer Form im Rahmen ihres HLAE-Projekts implementiert haben.</p>
<p>Für FirefoxNutzer: Da die Oberfläche in XUL geschrieben ist, lässt sich diese auch im Firefox-Browser darstellen. Hier
der Link Andere Browser werden mit dem Link jedoch nicht klar kommen.</p>
<p>Für alle andere habe ich einen Screenshot gemacht: Die aktuelle Benutzeroberfläche</p>
<p>Die aktuelle Benutzeroberfläche Was für die Zukunft geplant ist</p>
<p>Für die Zukunft sind noch einige Zusatzfunktionen geplant. Vor allem möchte ich Einstellungsprofile ermöglichen. Der
Nutzer soll seine Einstellungen und auch Customdateien in einem Aufnahme-Profil speichern können. Das Kopieren und
anschließende Aufräumen der Customdateien übernimmt der DemoRecorder.</p>
<p>In einer späteren Version könnte die Möglichkeit implementiert werden, mit der ganze Videos automatisch erstellt werden
könnten. Mit Hilfe von AviSynth wäre es möglich, den kompletten Schnitt programmgesteuert auszuführen. Der Nutzer könnte
dazu ein Musikstück auswählen und mit einer Tagging-Funktion, gewisse Spannungsgeladene Momente der Musik taggen. An
diesen Highlights könnte sich ein Algorithmus beim Schneiden orientieren. Aus einem Pool von Kamerafahrten könnten
Aufnahmen für Intro und Outro erstellt werden.</p>
<p>Dieses Automatische Schnittsystem würde aber vor allem eine Machbarkeitsstudie darstellen. Es wäre schließlich ziemlich
langweilig, wenn Alle Videos nur noch Algorithmisch erzeugt werden. Aus Programmierersicht stellt dies jedoch eine
interessante Aufgabe dar. Dies liegt aber noch in weiter Zukunft und ist bisher nicht weiter als eine Idee.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[SimpleVBlog - Studentisches Projekt]]></title>
            <link>https://www.lestard.eu/2009/simpleVBlog_project/</link>
            <guid>https://www.lestard.eu/2009/simpleVBlog_project/</guid>
            <pubDate>Wed, 04 Nov 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Im Rahmen eines Projekts an der Hochschule erstellen wir eine Videoblog-Engine mit Hilfe von JavaEE-Technologien.
Konzeptionell möchten wir eine möglichst schlanke und einfach benutzbare Software schaffen, welche ohne komplizierte
Administrations-Backend auskommt. Als Technologien kommen JSF 1.2, Facelets, IceFaces und Hibernate zum Einsatz.</p>
<p>An dem Projekt sind Beteiligt: Tobias Gaertner, Markus Fleck, Torsten Schröter, Marcus Waschke und meine Wenigkeit.</p>
<p>Zu meinen Aufgaben im Team gehören die Grafische Gestaltung der Oberfläche, die Entwicklung der Oberfläche mit Facelets
sowie IceFaces und die Programmierung einiger Seitenelemente für die Anzeige und Editierung der Blogeinträge.</p>
<p><img src="/files/pics/2009/simplevblog.png" alt="screenshot"></p>]]></description>
            <content:encoded><![CDATA[<p>Im Rahmen eines Projekts an der Hochschule erstellen wir eine Videoblog-Engine mit Hilfe von JavaEE-Technologien.
Konzeptionell möchten wir eine möglichst schlanke und einfach benutzbare Software schaffen, welche ohne komplizierte
Administrations-Backend auskommt. Als Technologien kommen JSF 1.2, Facelets, IceFaces und Hibernate zum Einsatz.</p>
<p>An dem Projekt sind Beteiligt: Tobias Gaertner, Markus Fleck, Torsten Schröter, Marcus Waschke und meine Wenigkeit.</p>
<p>Zu meinen Aufgaben im Team gehören die Grafische Gestaltung der Oberfläche, die Entwicklung der Oberfläche mit Facelets
sowie IceFaces und die Programmierung einiger Seitenelemente für die Anzeige und Editierung der Blogeinträge.</p>
<p><img src="/files/pics/2009/simplevblog.png" alt="screenshot"></p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
        <item>
            <title><![CDATA[FreeSoftwareAlternatives - Studentisches Projekt]]></title>
            <link>https://www.lestard.eu/2009/free_software_alternatives_project/</link>
            <guid>https://www.lestard.eu/2009/free_software_alternatives_project/</guid>
            <pubDate>Wed, 04 Nov 2009 23:00:00 GMT</pubDate>
            <description><![CDATA[<p>Im Fach "Knowledge Media Design" entwickeln wir prototypisch ein Webangebot, welches über Freie Software als Alternative
für übliche (properitäre) Windows-Software informiert. Das Angebot richtet sich vor allem an Windows-Nutzer, die sich
auf der einen Seite für Freie Software interessieren und diese auch gerne nutzen möchten, den Schritt zu einem komplett
freien Betriebssystem wie Linux (noch) nicht waagen möchten.</p>
<p>Der Nutzer soll auf unserer Webseite informationen und vor allem Alternativ-Vorschläge für Software erhalten. Der
Umstieg soll dem Nutzer durch erweiterte Informationen sowie Tutorials erleichert werden. Am Rande soll auch über die
Beweggründe und Vorteile von Freier Software eingegangen werden. Das Webangebot soll jedoch nicht Belehrend oder gar
Aufdringlich wirken sondern schlicht und einfach Alternativen aufzeigen.</p>
<p>Bei diesem Projekt fungiere ich als Teamleiter. Weitere Aufgaben sind die Erstellung und Betreuung eines an das Projekt
angelegten Youtube-Channels, welcher die Videotutorials beinhalten soll. Die Integration der Youtube-Videos in unser
Webangebot ist ebenfalls meine Aufgabe. Des weiteren werde ich bei der Entwicklung der Programmcodes in PHP behilflich
sein.</p>
<p>Aktuelle Ergebnisse kann ich noch nicht präsentieren, da das Projekt noch in seiner Anfangsphase steckt.</p>]]></description>
            <content:encoded><![CDATA[<p>Im Fach "Knowledge Media Design" entwickeln wir prototypisch ein Webangebot, welches über Freie Software als Alternative
für übliche (properitäre) Windows-Software informiert. Das Angebot richtet sich vor allem an Windows-Nutzer, die sich
auf der einen Seite für Freie Software interessieren und diese auch gerne nutzen möchten, den Schritt zu einem komplett
freien Betriebssystem wie Linux (noch) nicht waagen möchten.</p>
<p>Der Nutzer soll auf unserer Webseite informationen und vor allem Alternativ-Vorschläge für Software erhalten. Der
Umstieg soll dem Nutzer durch erweiterte Informationen sowie Tutorials erleichert werden. Am Rande soll auch über die
Beweggründe und Vorteile von Freier Software eingegangen werden. Das Webangebot soll jedoch nicht Belehrend oder gar
Aufdringlich wirken sondern schlicht und einfach Alternativen aufzeigen.</p>
<p>Bei diesem Projekt fungiere ich als Teamleiter. Weitere Aufgaben sind die Erstellung und Betreuung eines an das Projekt
angelegten Youtube-Channels, welcher die Videotutorials beinhalten soll. Die Integration der Youtube-Videos in unser
Webangebot ist ebenfalls meine Aufgabe. Des weiteren werde ich bei der Entwicklung der Programmcodes in PHP behilflich
sein.</p>
<p>Aktuelle Ergebnisse kann ich noch nicht präsentieren, da das Projekt noch in seiner Anfangsphase steckt.</p>]]></content:encoded>
            <author>manuel.mauky@gmail.com (Manuel Mauky)</author>
        </item>
    </channel>
</rss>