torsdag 20 oktober 2011

Create instance of class with no public constructor

private T instantiateEscenicObject(Class type, Map fields) throws InstantiationException {
T instance = null;
Constructor[] constructors = type.getDeclaredConstructors();

for (int i = 0; i < constructors.length; i++) {
Constructor constructor = constructors[i];
try {
instance = (T) constructor.newInstance();
} catch (Exception e) {

if (instance == null) {
throw new InstantiationException("Could not instantiate class " + type.getName());

for (String key : fields.keySet()) {
ReflectionTestUtils.setField(instance, key, fields.get(key));

return instance;

tisdag 26 oktober 2010

Checkout folder without children with Subversion

Sometimes you need to checkout a child directory without checking out other children. For doing this you need to checkout the parent folder with the -N argument, which means that the folder will be checked out without any content. After that you can just make a update for the specific child folder.

1. svn co -N "parentFolder"
2. cd "parentFolder"
3. svn update "childFolder"

One other option is to directly checkout the actual folder without parent, but that would be too easy. ;)

1. svn co "projectParent/parentFolde/childFolder/"

tisdag 17 augusti 2010

Readable Freemarker code with <#compress>

In Freemarker the use of compress-tag can make the code more readable since you are allowed to use extra rows for grouping code blocks without having the rows presented on the layout.

From Freemarker manual as follows:

<#assign x = "    moo  \n\n   ">
1 2 3 4 5
test only

I said, test only


will output

(1 2 3 4 5
test only
I said, test only)