public static Object instantiate(String tag, Class[] types, Object[] params)
        throws IllegalArgumentException {
        Class<?> messageClass;
        try {
            messageClass = Class.forName(tag);
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to find class " + tag
                + ": " + e.toString());
        }
        Constructor<?> constructor;
        try {
            constructor = messageClass.getDeclaredConstructor(types);
        } catch (Exception e) {
            String p = "Unable to find constructor " + tag + "(";
            for (int i = 0; i < types.length; i++) {
                p += " " + types[i].toString();
            }
            p += " ): ";
            throw new IllegalArgumentException(p + e.toString());
        }
        Object instance;
        try {
            instance = constructor.newInstance(params);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to construct " + tag
                + ": " + e.toString());
        }
        return instance;
    }