/**
 * Licensed to the Austrian Association for Software Tool Integration (AASTI)
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. The AASTI licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openengsb.ui.admin.model;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("serial")
public class MethodId implements Serializable {
    private String name;
    private List<String> argumentTypes = new ArrayList<String>();

    private static final Map<String, Class<?>> PRIMITIVES = new HashMap<String, Class<?>>();
    {
        PRIMITIVES.put("int", int.class);
        PRIMITIVES.put("long", long.class);
        PRIMITIVES.put("boolean", boolean.class);
        PRIMITIVES.put("byte", byte.class);
        PRIMITIVES.put("short", short.class);
        PRIMITIVES.put("char", char.class);
        PRIMITIVES.put("float", float.class);
        PRIMITIVES.put("double", double.class);
        PRIMITIVES.put("void", void.class);
    }

    public MethodId(Method method) {
        setName(method.getName());
        for (Class<?> type : method.getParameterTypes()) {
            argumentTypes.add(type.getName());
        }
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getArgumentTypes() {
        return this.argumentTypes;
    }

    public void setArgumentTypes(List<String> argumentTypes) {
        this.argumentTypes = argumentTypes;
    }

    public Class<?>[] getArgumentTypesAsClasses() {
        Class<?>[] result = new Class<?>[argumentTypes.size()];
        int i = 0;
        for (String s : argumentTypes) {
            try {
                result[i] = PRIMITIVES.get(s);
                if (result[i] == null) {
                    result[i] = Class.forName(s);
                }
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
            i++;
        }
        return result;
    }

    @Override
    public String toString() {
        StringBuffer result = new StringBuffer();
        result.append(name);
        result.append('(');
        boolean first = true;
        for (String s : argumentTypes) {
            if (first) {
                first = false;
            } else {
                result.append(", ");
            }
            result.append(s);
        }
        result.append(')');
        return result.toString();
    }

}

@@ -973,60 +973,56 @@
 til.
-HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
+List;%0A%0Aimport org.apache.commons.lang.ClassUtils
 ;%0A%0A@
@@ -1192,522 +1192,8 @@
 );%0A%0A
-    private static final Map%3CString, Class%3C?%3E%3E PRIMITIVES = new HashMap%3CString, Class%3C?%3E%3E();%0A    %7B%0A        PRIMITIVES.put(%22int%22, int.class);%0A        PRIMITIVES.put(%22long%22, long.class);%0A        PRIMITIVES.put(%22boolean%22, boolean.class);%0A        PRIMITIVES.put(%22byte%22, byte.class);%0A        PRIMITIVES.put(%22short%22, short.class);%0A        PRIMITIVES.put(%22char%22, char.class);%0A        PRIMITIVES.put(%22float%22, float.class);%0A        PRIMITIVES.put(%22double%22, double.class);%0A        PRIMITIVES.put(%22void%22, void.class);%0A    %7D%0A%0A
     
@@ -1428,21 +1428,16 @@
  return 
-this.
 name;%0A  
@@ -1573,21 +1573,16 @@
  return 
-this.
 argument
@@ -1935,135 +1935,60 @@
 %5D = 
-PRIMITIVES.get(s);%0A                if (result%5Bi%5D == null) %7B%0A                    result%5Bi%5D = Class.forName(s);%0A                %7D
+ClassUtils.getClass(getClass().getClassLoader(), s);
 %0A   

replace primitive-handling in Testclient with ClassUtils