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:lcmc.logger.LoggerFactory.java

public static Logger getLogger(final Class<?> clazz) {
    Logger logger;/*w w  w .  j a  v a 2s  .  co  m*/
    final String name = clazz.getName();
    synchronized (LoggerFactory.class) {
        logger = LOGGER_MAP.get(name);
        if (logger == null) {
            logger = new Logger(name);
            LOGGER_MAP.put(name, logger);
        }
    }
    return logger;
}

From source file:dungeonrunner.system.util.Log.java

private static String format(Class cls, String method, String message, Object... objects) {
    return String.format("%s [%s]: %s", cls.getName(), method, String.format(message, objects));
}

From source file:Main.java

public static <T> void assertInstanceOf(@NonNull T object, @NonNull Class<?> clazz,
        @NonNull String parameterName) throws AssertionError {
    check(!clazz.isInstance(object), parameterName + " is not instance of " + clazz.getName() + ".");
}

From source file:Main.java

/**
 * Convenience method for obtaining most non-null human readable properties
 * of a JComponent.  Array properties are not included.
 * <P>/*from  ww w  . j  a v a 2  s  .co m*/
 * Implementation note:  The returned value is a HashMap.  This is subject
 * to change, so callers should code against the interface Map.
 * 
 * @param component the component whose proerties are to be determined
 * @return the class and value of the properties
 */
public static Map<Object, Object> getProperties(JComponent component) {
    Map<Object, Object> retVal = new HashMap<>();
    Class<?> clazz = component.getClass();
    Method[] methods = clazz.getMethods();
    Object value = null;
    for (Method method : methods) {
        if (method.getName().matches("^(is|get).*") && method.getParameterTypes().length == 0) {
            try {
                Class<?> returnType = method.getReturnType();
                if (returnType != void.class && !returnType.getName().startsWith("[")
                        && !setExclude.contains(method.getName())) {
                    String key = method.getName();
                    value = method.invoke(component);
                    if (value != null && !(value instanceof Component)) {
                        retVal.put(key, value);
                    }
                }
                // ignore exceptions that arise if the property could not be accessed
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            }
        }
    }
    return retVal;
}

From source file:com.haulmont.cuba.core.sys.persistence.DbmsSpecificFactory.java

public static <T> T create(Class<T> intf, String dbmsType, String dbmsVersion) {
    String intfName = intf.getName();
    String packageName = intfName.substring(0, intfName.lastIndexOf('.') + 1);

    String name = packageName + StringUtils.capitalize(dbmsType) + dbmsVersion + intf.getSimpleName();
    Class<?> aClass;/*from   w  w  w.  ja v  a2s  . c  om*/
    try {
        aClass = ReflectionHelper.loadClass(name);
    } catch (ClassNotFoundException e) {
        name = packageName + StringUtils.capitalize(dbmsType) + intf.getSimpleName();
        try {
            aClass = ReflectionHelper.loadClass(name);
        } catch (ClassNotFoundException e1) {
            throw new RuntimeException("Error creating " + intfName + " implementation", e1);
        }
    }
    try {
        //noinspection unchecked
        return (T) aClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException("Error creating " + intfName + " implementation", e);
    }
}

From source file:kieker.common.logging.LogFactory.java

/**
 * Delivers the log for the given class or creates a new one if it doesn't exist already.
 * //w  w w . j a  v a  2  s  .  c  o  m
 * @param clazz
 *            The corresponding class.
 * 
 * @return A logger for the given class.
 */
public static final Log getLog(final Class<?> clazz) {
    return LogFactory.getLog(clazz.getName());
}

From source file:com.seleritycorp.common.base.logging.LogFactory.java

/**
 * Gets the non-permanent Log for a given Class
 *
 * <p>Non-permanent logs will get deleted after some time, and not retained
 * forever./*from  w  ww.j  a  v  a 2 s . c o  m*/
 *
 * @param clazz The clazz to get the {@code Log} instance for.
 * @return The non-permanent log for {@code clazz}
 * @exception LogConfigurationException if no suitable {@code Log} instance
 *            can be returned.
 */
public static Log getLog(@SuppressWarnings("rawtypes") Class clazz) throws LogConfigurationException {
    return getLog(clazz.getName());
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

static public String classShortName(Class<?> cls) {
    String tmp = cls.getName();
    int i = tmp.lastIndexOf('.');
    tmp = tmp.substring(i + 1);/* w  ww  . j  a v a2  s .co  m*/
    return tmp;
}

From source file:gridool.deployment.GridGetClassTask.java

/**
 * @return outer class//  w ww  .  j  av a2 s  .  c om
 */
private static ClassData addEnclosingClass(ClassData classData, Class<?> enclosingClass) throws GridException {
    final String clsName = enclosingClass.getName();
    final byte[] b;
    try {
        b = ClassUtils.getClassAsBytes(enclosingClass);
    } catch (IOException e) {
        String msg = "Failed serializing a class: " + enclosingClass.getName();
        LogFactory.getLog(GridGetClassTask.class).error(msg, e);
        throw new GridException(msg, e);
    }
    final long timestamp = ClassUtils.getLastModified(enclosingClass);
    ClassData outerClazz = new ClassData(clsName, b, timestamp);
    classData.setEnclosingClass(outerClazz);
    return outerClazz;
}

From source file:Main.java

public static long JavaToUnoType(Object obj, long fallbackTypePtr, boolean typeHasFallbackClass)
        throws ClassNotFoundException {
    Class<?> firstCls = obj.getClass();
    Long unoTypePtr = unoTypes.get(firstCls.getName());
    if (unoTypePtr != null) {
        return (long) unoTypePtr;
    } else {/* w w w  .  j av a 2  s. c  o  m*/
        if (typeHasFallbackClass) {
            Class<?> itf = unoFallbacks.get(fallbackTypePtr);
            if (itf == null) {
                throw new ClassNotFoundException(
                        "BINDING CLASS NOT FOUND (unoFallbacks): Not found for unoTypePtr:" + fallbackTypePtr);
            }
            Class<?> currentCls = firstCls;
            while (true) {
                if ((!itf.equals(currentCls)) && itf.isAssignableFrom(currentCls)) {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        unoTypes.put(firstCls.getName(), potential);
                        return (long) potential;
                    }
                } else {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
            }
        } else {
            Class<?> currentCls = firstCls;
            while (true) {
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                } else {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        if (Modifier.isAbstract(currentCls.getModifiers())) {
                            Long fallbackClassPtr = unoFallbacksClassToPtr.get(currentCls);
                            if (fallbackClassPtr != null) {
                                unoTypes.put(firstCls.getName(), fallbackClassPtr);
                                return fallbackClassPtr;
                            }
                        } else {
                            unoTypes.put(firstCls.getName(), potential);
                            return (long) potential;
                        }
                    }
                }
            }
        }
    }
}