private Template toTemplate(Type arrayType, Type genericBaseType, Class baseClass, int dim) {
        if (dim == 1) {
            if (baseClass == boolean.class) {
                return BooleanArrayTemplate.getInstance();
            } else if (baseClass == short.class) {
                return ShortArrayTemplate.getInstance();
            } else if (baseClass == int.class) {
                return IntegerArrayTemplate.getInstance();
            } else if (baseClass == long.class) {
                return LongArrayTemplate.getInstance();
            } else if (baseClass == float.class) {
                return FloatArrayTemplate.getInstance();
            } else if (baseClass == double.class) {
                return DoubleArrayTemplate.getInstance();
            } else if (baseClass == byte.class) {
                return ByteArrayTemplate.getInstance();
            } else {
                Template baseTemplate = registry.lookup(genericBaseType);
                return new ObjectArrayTemplate(baseClass, baseTemplate);
            }
        } else if (dim == 2) {
            Class componentClass = Array.newInstance(baseClass, 0).getClass();
            Template componentTemplate = toTemplate(arrayType, genericBaseType, baseClass, dim - 1);
            return new ReflectionMultidimentionalArrayTemplate(componentClass, componentTemplate);
        } else {
            ReflectionMultidimentionalArrayTemplate componentTemplate =
                (ReflectionMultidimentionalArrayTemplate) toTemplate(arrayType, genericBaseType, baseClass, dim - 1);
            Class componentClass = Array.newInstance(componentTemplate.getComponentClass(), 0).getClass();
            return new ReflectionMultidimentionalArrayTemplate(componentClass, componentTemplate);
        }
    }