Utils.java 1.52 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.osgi.framework.Bundle
 */
package com.adobe.granite.jmx.internal;

import java.util.HashMap;
import java.util.Map;
import org.osgi.framework.Bundle;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public abstract class Utils {
    private static final Map<String, Class<?>> PRIMITIVES = new HashMap();

    public static Class<?> loadClass(String type, Bundle bundle) throws ClassNotFoundException {
        if (PRIMITIVES.containsKey(type)) {
            return PRIMITIVES.get(type);
        }
        return bundle.loadClass(type);
    }

    public static Class<?> loadClass(String type, ClassLoader loader) throws ClassNotFoundException {
        if (PRIMITIVES.containsKey(type)) {
            return PRIMITIVES.get(type);
        }
        return loader.loadClass(type);
    }

    public static Class<?> getArrayType(Class<?> clazz) {
        return clazz.isArray() ? Utils.getArrayType(clazz.getComponentType()) : clazz;
    }

    public static int getArrayDim(Class<?> clazz) {
        return clazz.isArray() ? 1 + Utils.getArrayDim(clazz.getComponentType()) : 0;
    }

    static {
        PRIMITIVES.put("boolean", Boolean.TYPE);
        PRIMITIVES.put("byte", Byte.TYPE);
        PRIMITIVES.put("short", Short.TYPE);
        PRIMITIVES.put("int", Integer.TYPE);
        PRIMITIVES.put("long", Long.TYPE);
        PRIMITIVES.put("float", Float.TYPE);
        PRIMITIVES.put("double", Double.TYPE);
    }
}