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:Main.java

public static void processInstantiationExceptions(Throwable e, Class clazz) throws IllegalAccessException {
    throw new IllegalAccessException(e.getMessage() + " class name:" + ((clazz != null) ? clazz.getName() : "")
            + " maybe you use this class as inner "
            + "class, so we cant instantiate that outer from that, or maybe private modifier exist");

}

From source file:com.glaf.activiti.executionlistener.factory.ExecutionListenerTypes.java

public static void addExecutionListener(Class<?> clazz) {
    String name = clazz.getName();
    executionListeners.put(name, clazz);
}

From source file:ArrayGrowTest.java

/**
 * A convenience method to print all elements in an array
 * //from ww  w  . jav a 2  s.  co m
 * @param a
 *          the array to print. It can be an object array or a primitive type
 *          array
 */
static void arrayPrint(Object a) {
    Class cl = a.getClass();
    if (!cl.isArray())
        return;
    Class componentType = cl.getComponentType();
    int length = Array.getLength(a);
    System.out.print(componentType.getName() + "[" + length + "] = { ");
    for (int i = 0; i < Array.getLength(a); i++)
        System.out.print(Array.get(a, i) + " ");
    System.out.println("}");
}

From source file:Main.java

public static String parseClassType(Class<?> classInst) {
    String classType = "";
    String className = classInst.getName();
    // Primitive type
    if (className.equals("void"))
        classType = "V";
    else if (className.equals("byte"))
        classType = "B";
    else if (className.equals("short"))
        classType = "S";
    else if (className.equals("int"))
        classType = "I";
    else if (className.equals("long"))
        classType = "L";
    else if (className.equals("float"))
        classType = "F";
    else if (className.equals("double"))
        classType = "D";
    else if (className.equals("char"))
        classType = "C";
    else if (className.equals("boolean"))
        classType = "Z";
    // Class type
    else if (className.indexOf(".") != -1) {
        classType = className.replace(".", "/");
        if (className.indexOf(";") == -1)
            classType = classType + ";";
        if (className.indexOf("L") == -1)
            classType = "L" + classType;
    } else// ww  w  . jav a 2  s.c  o m
        classType = className;

    return classType;
}

From source file:grails.plugin.springsecurity.acl.util.ProxyUtils.java

protected static boolean isJavassistProxy(Class<?> clazz) {
    for (Class<?> i : clazz.getInterfaces()) {
        if (i.getName().contains("org.hibernate.proxy.HibernateProxy")) {
            return true;
        }//from  ww w  . j av a  2 s  .c om
    }
    return false;
}

From source file:Main.java

/**
 * Look up a field in a class and set it to accessible. The result is cached.
 * If the field was not found, a {@link NoSuchFieldError} will be thrown.
 *//*w w w.jav a 2 s .  c  o  m*/
public static Field findField(Class<?> clazz, String fieldName) {
    StringBuilder sb = new StringBuilder(clazz.getName());
    sb.append('#');
    sb.append(fieldName);
    String fullFieldName = sb.toString();

    if (fieldCache.containsKey(fullFieldName)) {
        Field field = fieldCache.get(fullFieldName);
        if (field == null)
            throw new NoSuchFieldError(fullFieldName);
        return field;
    }

    try {
        Field field = findFieldRecursiveImpl(clazz, fieldName);
        field.setAccessible(true);
        fieldCache.put(fullFieldName, field);
        return field;
    } catch (NoSuchFieldException e) {
        fieldCache.put(fullFieldName, null);
        throw new NoSuchFieldError(fullFieldName);
    }
}

From source file:Main.java

public static Object getData(Context context, String fileName, String key, Class clazz) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    if (clazz.getName().equals(String.class.getName())) {
        return sharedPreferences.getString(key, "");
    } else if (clazz.getName().equals(Integer.class.getName())) {
        return sharedPreferences.getInt(key, 0);
    } else if (clazz.getName().equals(Float.class.getName())) {
        return sharedPreferences.getFloat(key, 0);
    } else if (clazz.getName().equals(Long.class.getName())) {
        return sharedPreferences.getLong(key, 0);
    } else {//from w  w w  . j a  va 2s . c o  m
        return sharedPreferences.getBoolean(key, false);
    }
}

From source file:com.idocbox.common.log.impl.IdocboxLogFactory.java

/**
 * Convenience method to return a named logger, without the application
 * having to care about factories.//from   w w w  .java2s .  co m
 *
 * @param clazz Class from which a log name will be derived
 */
@SuppressWarnings("unchecked")
public static IdocboxLog getLog(Class clazz) {
    IdocboxLog log = null;
    if (null != clazz) {
        log = new IdocboxLogger(clazz.getName());
    } else {
        log = new IdocboxLogger();
    }

    return log;
}

From source file:com.impetus.kundera.graph.ObjectGraphUtils.java

/**
 * /*from  w  w w .  j av  a  2  s  .  c  o  m*/
 * @param pk
 * @param objectClass
 * @return
 */
public static String getNodeId(Object pk, Class<?> objectClass) {
    StringBuffer strBuffer = new StringBuffer(objectClass.getName());
    strBuffer.append(Constants.NODE_ID_SEPARATOR);
    strBuffer.append(pk);
    return strBuffer.toString();
}

From source file:com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilterTest.java

private static DefaultConfiguration createFilterConfig(Class<?> classObj) {
    return new DefaultConfiguration(classObj.getName());
}