Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.

 

 
 

 

For those of you running Virtual Server 2005, try out the tool VMRCPlus. You can download it here. With this tool, you got everything you need out of the box, the administration access over IIS is not needed anymore.

image

image

Source

 

 

 
 

 

Generics are very useful. But sometimes, they don’t fullfil all required needs. Today, I had a small problem. Over the parameter of a method, a Class definition was passed. In the method, I had to cast an object of type Object into a concrete type (the concrete type was T, defined by Generics). The easiest way is to put the cast between a try and catch block. This will work, no question. But in my piece of code, a try and catch block wasn’t very nice. For this reason, I tried to check, if the object o is of the type clazz. Unfortunately, instanceof doesn’t work with dynamic defined classes. But there is a simple solution: just use the method isAssignableFrom.

private void test(Class<?> clazz) {
  // the Object o is from somewhere...
 
  if (o instanceof clazz) {
    // does not working
  } 
 
  if (o.getClass().isAssignableFrom(clazz)) {
    // is working
  }
}

 

 

 
 

 

I just found a really good Quick Reference sheet about the Design Patterns from the GoF (Gang of Four). Have a look at this blog.

 

 

 
 

 

Today I stumbled upon a nice solution, to use the Collections.EMPTY_LIST with Generics. Just use the method emptyList with Generics instead of the constant value.

For example:

Collections.<String> emtpyList();

 

 

 
 

 

We use JiBX in our current project and had the problem, that JiBX won’t trim whitespaces automatically. For example, a XML tag like <test> asdf  </test> get’s stored as “ asdf  “ instead of “asdf”.

To solve this problem, we created an user-defined formatter for Strings.

package ch.stefanjaeger.formatter; 
public class StringFormatter { 
  public static String trimString(String untrimmed) { 
    return untrimmed.trim(); 
  } 
}

Now just update the binding file of JiBX and JiBX will trim whitespaces:

<format 
deserializer="ch.stefanjaeger.formatter.StringFormatter.trimString" 
type="java.lang.String" />

 

 

 

« Newer PostsOlder Posts »