Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

In this page you can find the example usage for java.lang Class getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:com.gargoylesoftware.htmlunit.gae.GAETestRunner.java

private static Class<?> getClassFromGAELikeClassLoader(final Class<?> klass) {
    final ClassLoader gaeLikeLoader = new GAELikeClassLoader();
    try {//from   ww  w. jav  a2  s.  co  m
        return gaeLikeLoader.loadClass(klass.getName());
    } catch (final ClassNotFoundException e) {
        throw new RuntimeException(
                "Can't find existing test class through GAELikeClassLoader: " + klass.getName());
    }
}

From source file:Main.java

public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*from ww  w  . ja va2 s .  co  m*/
    }
    return false;
}

From source file:org.jdbcluster.clustertype.ClusterTypeFactory.java

static public <T extends ClusterType> T newInstance(Class<? extends ICluster> clazz)
        throws ClusterTypeException {

    Assert.notNull(clazz, "Class  may not be null");

    String ct = ClusterTypeBase.getClusterTypeConfig().getClusterTypeFromClass(clazz.getName());
    return newInstance(ct);
}

From source file:com.xpfriend.fixture.cast.temp.PojoUtil.java

private static String find(String name, Object bean) {
    if (Strings.isEmpty(name)) {
        return name;
    }//from  ww w.  ja  v a 2s .  co m

    if (bean instanceof DynaBean) {
        DynaClass dynaClass = ((DynaBean) bean).getDynaClass();
        if (dynaClass.getDynaProperty(name) != null) {
            return name;
        }
        return PropertyNames.find(dynaClass, name);
    }

    Class<?> beanClass = bean.getClass();
    PropertyNames propertyNames = propertyNamesMap.get(beanClass.getName());
    if (propertyNames == null) {
        PropertyUtilsBean propertyUtil = TypeConverter.getBeanUtils().getPropertyUtils();
        propertyNames = new PropertyNames(propertyUtil, beanClass);
    }
    return propertyNames.find(name);
}

From source file:Main.java

public static boolean isServiceRunning(Class<?> serviceClass, Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*from  w w w .  j a va  2s. c o m*/
    }
    return false;
}

From source file:com.dapeng.dao.orm.GenericsUtils.java

/**
 * cglib AOP, ?Class./*from  w  w w . ja va2 s . com*/
 */
public static Class<?> getUserClass(Class<?> clazz) {
    if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && !Object.class.equals(superClass)) {
            return superClass;
        }
    }
    return clazz;
}

From source file:fr.opensagres.xdocreport.core.logging.LogUtils.java

/**
 * Get a Logger with the associated default resource bundle for the class.
 * //  w  ww . j  a  v  a  2s .  c om
 * @param cls the Class to contain the Logger
 * @return an appropriate Logger
 */
public static Logger getLogger(Class<?> cls) {
    return createLogger(cls.getName());
}

From source file:Main.java

/**
 * @param ctx/*from  w  w w . jav a 2 s .c o m*/
 * @param serviceClass
 * @return
 */
public static boolean isServiceRunning(Context ctx, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
private static Map<String, Class> getClassFields(Class clazz, boolean includeParentClass) {

    Map<String, Class> map = new HashMap<String, Class>();

    Field[] fields = clazz.getDeclaredFields();

    for (Field field : fields) {

        map.put(clazz.getName() + "." + field.getName(), field.getType());// field.getType()

    }//www .  j  av a 2 s .  c  o  m

    if (includeParentClass)

        getParentClassFields(map, clazz.getSuperclass());

    return map;

}

From source file:com.jetyun.pgcd.rpc.reflect.ClassAnalyzer.java

/**
 * Analyze a class and create a ClassData object containing all of the
 * public methods (both static and non-static) in the class.
 * //from ww w  .  j a v  a  2  s .co m
 * @param clazz
 *            class to be analyzed.
 * 
 * @return a ClassData object containing all the public static and
 *         non-static methods that can be invoked on the class.
 */
private static ClassData analyzeClass(Class clazz) {
    log.info("analyzing " + clazz.getName());
    Method methods[] = clazz.getMethods();
    ClassData cd = new ClassData();
    cd.clazz = clazz;

    // Create temporary method map
    HashMap staticMethodMap = new HashMap();
    HashMap methodMap = new HashMap();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }
        int mod = methods[i].getModifiers();
        if (!Modifier.isPublic(mod)) {
            continue;
        }
        Class param[] = method.getParameterTypes();

        // don't count locally resolved args
        int argCount = 0;
        for (int n = 0; n < param.length; n++) {
            if (LocalArgController.isLocalArg(param[n])) {
                continue;
            }
            argCount++;
        }

        MethodKey mk = new MethodKey(method.getName(), argCount);
        ArrayList marr = (ArrayList) methodMap.get(mk);
        if (marr == null) {
            marr = new ArrayList();
            methodMap.put(mk, marr);
        }
        marr.add(method);
        if (Modifier.isStatic(mod)) {
            marr = (ArrayList) staticMethodMap.get(mk);
            if (marr == null) {
                marr = new ArrayList();
                staticMethodMap.put(mk, marr);
            }
            marr.add(method);
        }
    }
    cd.methodMap = new HashMap();
    cd.staticMethodMap = new HashMap();
    // Convert ArrayLists to arrays
    Iterator i = methodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.methodMap.put(mk, marr.get(0));
        } else {
            cd.methodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    i = staticMethodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.staticMethodMap.put(mk, marr.get(0));
        } else {
            cd.staticMethodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    return cd;
}