Moved
6. Mai 2008This blog has moved to danielrohe.wordpress.com
This blog has moved to danielrohe.wordpress.com
Weekends are supposed to be nice with sunshine and warm temperatures, not so in Atlanta! Over the last weeks every day during the week had plenty of sunshine. Only on weekends it started to rain.
So I started looking at Struts2. Because of the example application the first steps are quite simple. Starting a web application with Maven2 is no problem anymore. I got the application with a different model running in less than 2 hours (needed to write the domain objects and services to access them over the database).
But then it started getting more complicated. First I moved the datasource to the JNDI tree in Tomcat6 by replacing the data-source definition from Spring2.0 and moving it into the context.xml file for Tomcat. By doing this I also had to copy the JDBC driver over to Tomcats lib folder. Then I tried to bind the EntityManager or EntityManagerFactory to the JNDI tree. It seemed quite simple, simply add some elements to the web.xml descriptor. The Servlet 2.5 specification has some elements but Tomcat doesn’t recognize them. So I spent reading more than 3 hours and downloaded the sources for investigations. It doesn’t helped, Tomcat refuses these elements. So I went back to use Spring2.0 for the entity manager.
Now Spring2.5 is out (great, yeah, …). So upgrading should be as easy as changing some numbers in Mavens pom.xml. It’s just that spring-jpa is integrated into spring-orm and when using jee:jndi-lookup somehow Spring wants to use a JDBC transaction manager. So include spring-jdbc and everything works.
A nice thing I also got my hands in is Dojo because of the Ajax capability of the simple application. From a 10 minute view it looks like an interesting messaging system in a single web page.
But now that the weekend is close to be over, back to real work
.
While searching for information on JPA I stumbled over the EclipseLink project. Which is the reference implementation for the upcoming JPA 2.0 specification. This seems quite interesting how Oracle distributes its classes. Because it is mainly the code base of Oracle TopLink. First it was part of the Oracle Application Server, then Oracle open sourced a small part of it called TopLink Essentials and it became a reference implementation for JPA 1.0. At this time I started to recognize TopLink as a valuable product. First it is much smaller than Hibernate and second it is the reference implementation. And now after reading that Oracle open sourced the complete TopLink product it will be a much more valuable product I’m gonna use
. Also the integration with the search library Compass makes it an even player to the combination of Hibernate and Hibernate Search.
When people at Eclipse also get the distribution of TopLink with Maven and people at TopLink the database integration (especially the sequence generator for PostgreSQL) done right. I’m going to advocate more and more the usage of TopLink.
I switched from Ant to Maven some time ago because it is easy to setup a project with Maven. Ok, I had my common Ant scripts, so it was also easy
. But when it comes to projects with a multi-module structure then Maven can be a really good or evil friend. Currently I’m working in a multi-module project with more than ten modules. And sometimes Maven makes life not easier.
The question about structuring the project came up very often. But in the end the solution can be nice and easy. It really only depends on what is written in which POM file. The first thing is to use a sibling module for the overall root POM which defines all dependencies and project settings. This module is created once and has everytime a fixed version number. In the root of the project there can be a POM file only defining the modules for people doing building the overall project.
Inside the module there can also again be modules. Then inside the module there should also be a child sub-module which defines the dependencies and project settings and a base POM file in the root containing only the modules element. The POM files in the sub-modules of a module don’t use the POM file of the module, but instead the POM file from the sibling sub-module with all dependencies and project settings. Also the version number of the module is defined only there.
Java has three components (with SwingX one more) which uses a selection model. There is the JList, JTable, JTree and J(X)TreeTable. The selection model maintains the set of selected elements and the anchor and lead selection. The anchor and lead do not need to be part of the set of selected elements. Changing the selection requires the invocation of either the setSelectionXXX, addSelectionXXX or removeSelectionXXX methods.
The user changes the selection either through the keyboard or the mouse. Based on what modifier keys he presses the selection change behaves different. If he doesn’t use any modifier or the shift key the setSelectionXXX method will be invoked for all cases. If he uses the ctrl key either add- or removeSelectionXXX will be invoked based on whether the elements where part of the selection or not.
If he doesn’t use any modifier there will only be one element which should be selected. The selection model should clear the set of selected elements and add this element. It should also set the anchor and lead selection to this element.
If he presses the shift key then the first element will be the element of the anchor selection. The selection model should clear the set of selected elements and add the elements between the given index0 and index1. The anchor selection is the element at index0 (first element in path array) and the lead selection is the one at index1 (last element in path array).
If he presses the ctrl key and the selection should be removed (invocation of removeSelectionXXX) the elements between index0 and index1 should be removed from the set of selected elements. The anchor selection is the element at index0 and the lead selection is the one at index1. In this case the elements of the anchor and lead selection are not part of the set of selected elements. If the user presses the ctrl key and the selection should be added (invocation of addSelectionXXX) the elements between index0 and index1 should be added to the set of selected elements. The anchor selection is the element at index0 and the lead selection the one at index1. The element of the anchor and lead selection are part of the set of selected elements.
What if some elements shouldn’t be part of the set of selected elements? The solution depends on how a selection change should behave. If the selection should follow the common scheme, then the anchor should be the beginning of the last contiguous interval which is part of the selection and the lead is the end of the last contiguous interval. The next selection would then start from the anchor. This also works with adding or removing elements from the selection. Removing elements is quite easy because there doesn’t need to be a verification. When setting or adding elements the set of selected/added elements has to be computed based on the anchor and lead selection. When adding elements the anchor and lead of the current selection need to be used, in the other case it is the first and last element of the selection. Caution must be used because the order is important, it defines whether the user selected up or down and also is input to the computation of the new anchor and lead selection! The anchor and lead is then the beginning and end of the last contiguous interval in the set of selected elements.
Based on this explanation I think it is really hard to understand how a selection works (should behave), especially when elements should be left out in between. Should the next selection start at the last interval or somewhere else?
Java and the need for Dependency Injection
Somehow, I agree with the writer that Spring can be very intrusive and is much too big. As soon as you start using it, you are bound to it and with all components its already about 20MB. The positive argument is that it helps a lot in writing clean separated, testable code. For me the main reason to use Spring is to have an IoC container that manages bigger components. But often people go too far in using Spring by putting everything into the container either through configuration or annotation. This as I can see leads again to unmanageable code which is the opposite of the intention of DI.
With JEE 5 Sun has made a great step in simplifying the technology stack. Using annotations to declare specific cross-cutting concerns (transactions) and resource injections helps a lot. Still developer should know at least for resouce injection how it is mapped to the JNDI tree. So they understand how this can also be solved by other solutions (ServiceLocator).
I would like to see the Spring container moving towards the JEE specification by supporting all JEE annotations as well as their own especially with respect to transactions. So people can write code once and run it in different containers (JEE, Spring, etc.).
Nach längerer Abwesenheit mal wieder etwas von meinen Ausflügen. Letzte Woche haben ich und einige Kollegen Las Vegas und den Grand Canyon besucht.
Las Vegas ist einfach ein riesiges Vergnügungsgebiet. Übernachtet haben wir alle in der schwarzen Pyramide des Luxors. Während der paar Tage habe ich den Strip mehr als 2mal abgelaufen und mir dabei die Hotels und Sehenswürdigkeiten angesehen. Man muss auf jedenfall einmal am Tag und einmal in der Nacht langlaufen, um die Unterschiede zu erkennen.
http://picasaweb.google.com/rohe.daniel/LasVegas
An einem Tag haben wir auch einen Ausflug (im wahrsten Sinne des Wortes turbulenten Flug) zum Grand Canyon gemacht.
One big problem in Swing applications is the execution of long running operations. The Swing Application Framework has a small solution with their Task and TaskService. But the problem remains when also Runnable objects should be executed and the user interface be blocked.
I looked at the common way of executing Runnable objects in Java 6 and found Executor and its child interfaces and implementing classes in java.util.concurrent. So this seems to be a good starting point for a solution.
I extended the ExecutorService interface and provided notifications about adding, removing a command and also about the execution or rejection of a command. This interface is implemented by an extension of ThreadPoolExecutor called SwingThreadPoolExecutor which manages the blocking of user input during execution.
Doing it this way allows me to also block the user interface for a Runnable or SwingWorker. Also the blocking dialog can show a list of all currently executing commands like the progress dialog of Eclipse and the user can cancel commands if required. Another problem is often that there can be two or more blocking dialogs when there are multiple commands that need a blocking dialog. This can be solved by having an implementation of InputBlocker in the service which counts the number of commands that need the dialog up when the command is added and down when it is removed. At one the dialog is shown and at zero it is hidden. Also the SwingWorker or Task doesn’t need to maintain an input blocker because the service maintains it.
A special service can be used for deferring loading large results for lists, tables and trees. The model uses the service to lookup elements/rows or cells/nodes inside a Runnable and post the runnable to the service. The service automatically blocks the input on the user interface component when looking up an object.
I took some time to look at the BeansBinding JSR and how to work with it. Therefore I used some parts of my small Swing application framework to create simple user interfaces. First to note is that the BeansBinding goes a completely different approach than JGoodies Binding. Instead of wrapping your model in an adapter or presentation model, with BeansBinding the model is a first class object on which the application works.
After the frame was displayed the first time, I’ve needed to refactor everything a little bit. First the application itself is managed by an OSGI service (ApplicationManager). Here I use the idiom of having a public interface. The interface is exportet and visible to other packages and an internal implementation which is hidden inside the bundle. Also the service registers itself as bundle listener to show the frame after the bundle is started and dispose the frame when the bundle is stopped.
Also I started creating the managing interface for the content of the application. In the application everything is displayed in the main frame. So one can think of having different pages which are shown in the main frame.
Beside this I added some more projects with which I can create bundles for 3rd party libraries like Apache Commons Lang, JPA, etc.