Fancy tooltips in Eclipse

Tooltips are quick way to add information to a widget that received the users attention. While one can argue about the pros and cons of tooltips this post focuses on the style of tooltips once you decided to use them.

Continue reading

Some thoughts on software testing

If you are working as a software developer in a project based development environment you will, hopefully, encounter the day the customer wants to see the result that was promised to him. The worst thing that can happen is that after months of development you finally end up in a scenario of it is not working or it is not what we need. Sure there are numerous reasons of why this happened and what types development process you could have used. But often quality management and software development definitions are written once and never lived as described. developers consider it a burden that is unnecessary and is blocking them in their daily task of creating new functionality.

Continue reading

Access to WMI in Java using Eclipse SWT OLE integration

Today I ran into a problem which could easily solved using a short WMI query. The problem was that the query must be executed within a Java UI application. Googling for a solution I came only up with either quite some ugly workarounds (like generating a VBScript fragment, forking off the VBScript runtime and parsing the result) or some full blown COM/DCOM interfaces (like J-Integra or J-Interop). Although I really like J-Interop (we are using it for DCOM when accessing OPC server in OpenSCADA Utgard) it has some drawbacks. For J-Interop every access (even local access) is a network based access. Since J-Interop only supports DCOM it is free of any platform specific code but required the machine to be accessible using “remoting” functionality (DCOM). Since I wanted to query the WMI from a UI application and I am sure that the WMI query will stay on the Win32 version of the application I was not keen on adding “remoting” as a requirement to the UI application.

After some digging I remembered that SWT brings an OLE interface which provides direct COM access. So I started poking around and finally come up with a solution that works quite well.

For the impatient: The full source code is available from github https://github.com/ctron/wmisample and the screenshot is here.

Continue reading

Eclipse Install Issue

I just stumbled over a strange issue when installing an additional plugin into a fresh Eclipse installation:
An error occurred while collecting items to be installed
session context was:(profile=SDKProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
No repository found containing: osgi.bundle,org.eclipse.team.cvs.ssh,3.2.100.I20090508-2000

I was unable to add any new plugin and searching Google for help was not successfull. There was an issue somewhere in the Eclipse Bugzilla that the plugin org.eclipse.team.cvs.ssh was optional and no longer installed or required. Seems that P2 thinks the somewhat required for the installation process.

ButI found one hint that deactivating the option “Contact all update sites during install to find required software” helps. And it did.

Screenshot of Eclipse Dialog

Workaround for LoadTimeWeaver issue with JBoss 6 and Spring 3

A possible workaround for the LTW issue that appeared in JBoss 6 using Spring 3 (SPR-7887) is to add an empty jboss-scanning.xml file to EAR and WAR files.

The reason to this issue as explained by one comment that JBoss pre-loads classes when scanning for annotations. Which triggers the class loader before Spring has a chance to add the AspectJ transformer to the class loader. The LTW support of Spring loads fine but after all classes are loaded.

Adding the empty jboss-scanning.xml to EAR and WAR files will skip the scanning for the modules and trigger the transformer later.

Example for jboss-scanning.xml:

[sourcecode language=”xml”]
<?xml version="1.0" encoding="UTF-8"?>

<scanning xmlns="urn:jboss:scanning:1.0">
</scanning>
[/sourcecode]

Thanks to Marius Bogoevici and Costin Leau for looking into this issue.

Name that pattern

In my day to day work I encounter several interesting programming pattern that I don’t have a name for. Maybe you have?! So name the following pattern:

[sourcecode language=”java”]
if ( !trans.getWeights ().isEmpty () )
{
final Collection<Weight> weightList = trans.getWeights ();
WeightVo weightVo = null;
for ( final Weight weight : weightList )
{
weightVo = getWeightDao ().toWeightVo ( weight );
break;
}
truckVo.setWeightVo ( weightVo );
}
[/sourcecode]

While one can argue if this one-liner is more readable and understandable:

[sourcecode language=”java”]
truckVo.setWeightVo ( trans.getWeights().isEmpty() ? null : getWeightDao ().toWeightVo ( trans.getWeights().get ( 0 ) ) );
[/sourcecode]

The following definitely is:

[sourcecode language=”java”]
if ( !trans.getWeights ().isEmpty () )
{
truckVo.setWeightVo ( getWeightDao ().toWeightVo ( trans.getWeights().get ( 0 ) ) );
}
[/sourcecode]

Combo viewer requirements

Today I tried to create a combo viewer in Eclipse with a different approach than the it seems the widgets was designed. I have an object which has to main properties an ID and a descriptive name. While this is nothing unusual following requirements seems to be:

The list of the combo box should show the label while the text input field of the combo box should show the id of the object. Using Eclipse Databinding this seems to be an impossible task (if you know a way please post it at stackoverflow). Continue reading

Hello world!

After upgrading my server and cleanup up stuff I thought it would be nice to work a little bit on the homepage again. Since iWeb seems to be stuck and I am working mostly on Linux now I though it would be interesting to give WordPress a try.

Let’s see what happens …

Reading Object Streams in OSGi

Reading an object from an ObjectInputStream is easy. But using OSGi it can be a little bit more difficult. Due to the class loader system of OSGi the ObjectInputStream might not know the class that was stored. Assume you have a Bundle A, B and C. B provides the storing capabilities that stores objects somewhere and C provides the data object itself. Now if A tells B to store some object from C this will not be a problem, since the object class is attached to the object instance. But reading back the object will result in a ClassNotFoundException since B has no reference to C and therefore does not know any classes of C.

One solution of course would be to add a dependency from B to C. But that is probably not what you want. Another way would be using Eclipses “Buddy” policies workaround for problems like this. In this case the bundle B would declare itself capable of working with the buddy system and C would declare itself a “buddy of B”. This turns around the reference. While this is a possible way if you cannot change the logic in B (like existing third party libraries that have to be used) it also has some drawbacks. First of all you commit to using Eclipse/Equinox since this is not covered by OSGi. Also you still have to declare those dependencies from C to B.

On the other hand you can sub-class the ObjectInputStream and override “resolveClass” to let the bundle resolve the class instead of the “current” classloader. Passing the bundle A to that input stream you would have all the classes you need.

Check out the following sample implementation:


import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

import org.osgi.framework.Bundle;

/**
 * An object input stream which loads its classes from the provided bundle.
 * @author Jens Reimann
 *
 */
public class BundleObjectInputStream extends ObjectInputStream
{
    private final Bundle bundle;

    public BundleObjectInputStream ( final InputStream in, final Bundle bundle ) throws IOException
    {
        super ( in );
        this.bundle = bundle;
    }

    @Override
    protected Class<?> resolveClass ( final ObjectStreamClass desc ) throws IOException, ClassNotFoundException
    {
        return this.bundle.loadClass ( desc.getName () );
    }

}