Example usage for java.lang Class getSimpleName

List of usage examples for java.lang Class getSimpleName

Introduction

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

Prototype

public String getSimpleName() 

Source Link

Document

Returns the simple name of the underlying class as given in the source code.

Usage

From source file:com.jadarstudios.rankcapes.bukkit.CapePackValidator.java

/**
 * Validates an Animated cape node./*  w  ww  .  ja  va2 s  .c  om*/
 *
 * @param node the node thought to be an Animated cape node
 *
 * @throws InvalidCapePackException thrown if the node is invalid.
 */
public static void validateAnimatedCapeNode(Map node) throws InvalidCapePackException {
    for (Map.Entry<String, Class<?>> possibleField : ANIMATED_FIELDS.entrySet()) {
        Object jsonField = node.get(possibleField.getKey());
        Class field = possibleField.getValue();
        if (jsonField != null && !field.isInstance(jsonField)) {
            throw new InvalidCapePackException(
                    String.format("The value \"%s\" is not valid for key \"%s\" which requires a \"%s\" value",
                            jsonField, possibleField.getKey(), field.getSimpleName()));
        }
    }
}

From source file:com.jlfex.hermes.common.utils.Reflections.java

/**
 * ??, Class?./*from w  w w  . j a va2s .  c  o  m*/
 * , Object.class.
 * 
 * public UserDao extends HibernateDao<User,Long>
 * 
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
@SuppressWarnings("rawtypes")
public static Class getClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if ((index >= params.length) || (index < 0)) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:com.enation.eop.sdk.utils.ReflectionUtils.java

public static Class getInterfaceClassGenricType(final Class clazz, final int index) {

    Type[] genTypes = clazz.getGenericInterfaces();
    if (genTypes == null || genTypes.length == 0) {
        logger.warn(clazz.getSimpleName() + "'s not impl interface ");
        return Object.class;
    }//  ww w.ja v a 2s.  co m

    if (!(genTypes[0] instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genTypes[0]).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:cn.com.qiqi.order.utils.Reflections.java

/**
 * ??, Class?./*ww w . ja v  a  2s. com*/
 * , Object.class.
 * 
 * public UserDao extends HibernateDao<User,Long>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
@SuppressWarnings("rawtypes")
public static Class getClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:gr.abiss.calipso.jpasearch.specifications.GenericSpecifications.java

/**
 * Dynamically create a specification for the given class and restriction
 * /*  w  w w  .j av a2  s  . c  om*/
 * @param searchTerm
 * @return
 */
public static Specification matchAll(final Class clazz, final Restriction searchTerms) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("matchAll, entity: " + clazz.getSimpleName() + ", searchTerms: " + searchTerms);
    }
    return new Specification<Persistable>() {
        @Override
        public Predicate toPredicate(Root<Persistable> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return GenericSpecifications.getPredicate(clazz, searchTerms, root, cb);
        }

    };
}

From source file:edu.stanford.epad.common.plugins.impl.ClassFinderTestUtils.java

/**
 * /*from  w  w w .  java  2 s  .c o m*/
 * @param clazz Class
 * @return String
 */
public static String readJarManifestForClass(Class<?> clazz) {
    StringBuilder sb = new StringBuilder();
    InputStream manifestInputStream = null;

    try {

        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (!classPath.startsWith("jar")) {
            // Class not from JAR
            return "Class " + className + " not from jar file.";
        }

        String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
        manifestInputStream = new URL(manifestPath).openStream();
        Manifest manifest = new Manifest(manifestInputStream);
        Attributes attr = manifest.getMainAttributes();
        // String value = attr.getValue("Manifest-Version");

        Set<Object> keys = attr.keySet();
        for (Object currKey : keys) {
            String currValue = attr.getValue(currKey.toString());
            if (currValue != null) {
                sb.append(currKey.toString()).append(" : ").append(currValue).append("\n");
            } else {
                sb.append(currKey.toString()).append(": Didn't have a value");
            }
        }
    } catch (Exception e) {
        logger.warning("Failed to read manifest for " + clazz.getSimpleName(), e);
    } finally {
        IOUtils.closeQuietly(manifestInputStream);
    }
    return sb.toString();
}

From source file:com.brienwheeler.lib.spring.beans.AutowireUtils.java

public static <T> Collection<T> getAutowireBeans(ApplicationContext applicationContext, Class<T> clazz,
        Log log) {/*from   ww w  .j av  a 2s. c  om*/
    ValidationUtils.assertNotNull(applicationContext, "applicationContext cannot be null");
    ValidationUtils.assertNotNull(clazz, "clazz cannot be null");
    ValidationUtils.assertNotNull(log, "log cannot be null");

    Map<String, T> beans = applicationContext.getBeansOfType(clazz);
    if (beans.size() > 0) {
        log.info("autowiring " + beans.size() + " " + clazz.getSimpleName());
    }
    return beans.values();
}

From source file:com.vanstone.common.util.ReflectionUtils.java

/**
 * ??,Class?. , Object.class./*from www.ja va2 s  . c  o m*/
 * 
 * public UserDao extends HibernateDao<User,Long>
 * 
 * @param clazz
 *            clazz The class to introspect
 * @param index
 *            the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be
 *         determined
 */
@SuppressWarnings("rawtypes")
public static Class getSuperClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        LOG.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        LOG.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        LOG.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:com.phoenixnap.oss.ramlapisync.naming.NamingHelper.java

/**
 * Convert a class name into its restful Resource representation.
 *
 * eg. MonitorServiceImpl becomes Monitor
 *
 * @param clazz The Class to name/*from   ww w.  j  av  a 2 s. c o m*/
 * @return The name for this class
 */
public static String convertClassName(Class<?> clazz) {
    String convertedName = clazz.getSimpleName();
    boolean clean = true;
    do {
        Matcher cleaner = CLASS_SUFFIXES_TO_CLEAN.matcher(convertedName);
        if (cleaner.matches()) {
            if (cleaner.group(1) != null && cleaner.group(1).length() > 0) {
                convertedName = cleaner.group(1);
            }
        } else {
            clean = false;
        }
    } while (clean);
    return StringUtils.uncapitalize(convertedName);
}

From source file:com.jaeksoft.searchlib.analysis.ClassFactory.java

/**
 * //  ww  w. j a v a  2 s  .  c  o m
 * @param config
 * @param factoryClass
 * @return
 * @throws SearchLibException
 */
protected static <T extends ClassFactory> T createInstance(Config config, Class<T> factoryClass)
        throws SearchLibException {
    try {
        T o = factoryClass.newInstance();
        o.setParams(config, factoryClass.getPackage().getName(), factoryClass.getSimpleName());
        o.initProperties();
        return o;
    } catch (InstantiationException e) {
        throw new SearchLibException(e);
    } catch (IllegalAccessException e) {
        throw new SearchLibException(e);
    } catch (IOException e) {
        throw new SearchLibException(e);
    }
}