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

private static String getJaxpImplementationInfo(String componentName, Class componentClass) {
    CodeSource source = componentClass.getProtectionDomain().getCodeSource();
    return MessageFormat.format("{0} implementation: {1} loaded from: {2}", componentName,
            componentClass.getName(), source == null ? "Java Runtime" : source.getLocation());
}

From source file:app.core.Db.java

public static <T extends PersistentObject> List<T> findAll(Class<T> entityClass) {
    return (List<T>) createQuery("from " + entityClass.getName()).list();
}

From source file:com.shelfmap.stepsfinder.CandidateStepsFactory.java

public static URL codeLocationFromParentPackage(Class<?> codeLocationClass) {
    String simpleName = codeLocationClass.getSimpleName() + ".class";
    String pathOfClass = codeLocationClass.getName().replace(".", "/") + ".class";
    URL classResource = codeLocationClass.getClassLoader().getResource(pathOfClass);
    String codeLocationPath = removeEnd(classResource.getFile(), simpleName);
    return codeLocationFromPath(codeLocationPath);
}

From source file:com.github.mjeanroy.springmvc.view.mustache.commons.ClassUtils.java

/**
 * Get annotation method value./*  w w w . j av a 2  s  . c  o  m*/
 *
 * @param importingClassMetadata Metadata.
 * @param annotationClass        Annotation class to look for.
 * @param name                   Name of method.
 * @param defaultValue           Default value if original value is null.
 * @param <T>                    Type of returned value.
 * @return Annotation value, or default value if original value is null.
 */
@SuppressWarnings("unchecked")
public static <T> T getAnnotationValue(AnnotationMetadata importingClassMetadata, Class annotationClass,
        String name, T defaultValue) {
    Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(annotationClass.getName());
    return attributes != null && attributes.containsKey(name) ? (T) attributes.get(name) : defaultValue;
}

From source file:Main.java

private static boolean isTypeMatch(Class<?> paramClass, Class<? extends Object> paramClass1) {
    if (paramClass.equals(paramClass1))
        return true;
    if (paramClass.isPrimitive()) {
        if ((paramClass.getName().equals("int")) && (paramClass1.getName().equals("java.lang.Integer")))
            return true;
        if ((paramClass.getName().equals("long")) && (paramClass1.getName().equals("java.lang.Long")))
            return true;
        if ((paramClass.getName().equals("float")) && (paramClass1.getName().equals("java.lang.Float")))
            return true;
        if ((paramClass.getName().equals("double")) && (paramClass1.getName().equals("java.lang.Double")))
            return true;
        if ((paramClass.getName().equals("char")) && (paramClass1.getName().equals("java.lang.Character")))
            return true;
        if ((paramClass.getName().equals("byte")) && (paramClass1.getName().equals("java.lang.Byte")))
            return true;
        if ((paramClass.getName().equals("short")) && (paramClass1.getName().equals("java.lang.Short")))
            return true;
        if ((paramClass.getName().equals("boolean")) && (paramClass1.getName().equals("java.lang.Boolean")))
            return true;
    }/*w w w. jav  a 2 s.  c o m*/
    return false;
}

From source file:Main.java

/**
 * Check whether the given class is visible in the given ClassLoader.
 *
 * @param clazz       the class to check (typically an interface)
 * @param classLoader the ClassLoader to check against (may be {@code null},
 *                    in which case this method will always return {@code true})
 *//* w  ww.ja  v  a 2  s.  com*/
public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
    if (classLoader == null) {
        return true;
    }
    try {
        Class<?> actualClass = classLoader.loadClass(clazz.getName());
        return (clazz == actualClass);
        // Else: different interface class found...
    } catch (ClassNotFoundException ex) {
        // No interface class found...
        return false;
    }
}

From source file:ShowClass.java

public static String typeName(Class t) {
    String brackets = "";
    while (t.isArray()) {
        brackets += "[]";
        t = t.getComponentType();/*from   w w  w .jav a2s  .  c  o  m*/
    }
    String name = t.getName();
    int pos = name.lastIndexOf('.');
    if (pos != -1)
        name = name.substring(pos + 1);
    return name + brackets;
}

From source file:com.github.mjeanroy.springmvc.uadetector.commons.ClassUtils.java

/**
 * Get annotation method value.//from w  ww.j a v a 2 s . c  o m
 *
 * @param importingClassMetadata Metadata.
 * @param annotationClass        Annotation class to look for.
 * @param name                   Name of method.
 * @param defaultValue           Default value if original value is null.
 * @param <T>                    Type of returned value.
 * @return Annotation value, or default value if original value is null.
 */
public static <T> T getAnnotationValue(AnnotationMetadata importingClassMetadata, Class annotationClass,
        String name, T defaultValue) {
    Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(annotationClass.getName());
    T value = (T) attributes.get(name);
    if (value == null) {
        value = defaultValue;
    }
    return value;
}

From source file:com.springframework.core.io.support.SpringFactoriesLoader.java

/**
 * Load the fully qualified class names of factory implementations of the
 * given type from {@value #FACTORIES_RESOURCE_LOCATION}, using the given
 * class loader./*from ww w  .j a va 2  s  .c  o  m*/
 * @param factoryClass the interface or abstract class representing the factory
 * @param classLoader the ClassLoader to use for loading resources; can be
 * {@code null} to use the default
 * @see #loadFactories
 * @throws IllegalArgumentException if an error occurs while loading factory names
 */
public static List<String> loadFactoryNames(Class<?> factoryClass, ClassLoader classLoader) {
    String factoryClassName = factoryClass.getName();
    try {
        Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION)
                : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
        List<String> result = new ArrayList<String>();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
            String factoryClassNames = properties.getProperty(factoryClassName);
            result.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(factoryClassNames)));
        }
        return result;
    } catch (IOException ex) {
        throw new IllegalArgumentException("Unable to load [" + factoryClass.getName()
                + "] factories from location [" + FACTORIES_RESOURCE_LOCATION + "]", ex);
    }
}

From source file:org.reusables.test.SpringTestUtils.java

/**
 * Get a single bean form the context with the given type.
 * //from ww  w . j ava 2s .co m
 * @param <T> Type of the bean.
 * @param ctx The Spring context.
 * @param type Type of the bean.
 * @return The bean with the given type.
 */
public static <T> T getBeanByType(final ApplicationContext ctx, final Class<T> type) {
    final String[] names = ctx.getBeanNamesForType(type);
    Validate.isTrue(names.length == 1,
            "Number of beans of type '" + type.getName() + "' found: " + names.length);
    return (T) ctx.getBean(names[0]);
}