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.googlecode.blaisemath.app.MenuConfig.java

/** 
 * Reads menu components from file.//  w w w .  ja va  2 s . c om
 * @param cls class with associated resource
 * @return map, where values are either nested maps, or lists of strings representing actions
 * @throws IOException if there's an error reading from the config file
 */
public static Map<String, Object> readConfig(Class cls) throws IOException {
    String path = "resources/" + cls.getSimpleName() + MENU_SUFFIX + ".yml";
    URL rsc = cls.getResource(path);
    checkNotNull(rsc, "Failed to locate " + path);
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(rsc, Map.class);
}

From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithJDBCImpl.java

public static String table(Class<?> entityClass) {
    String table = entityClass.getSimpleName();
    if (entityClass.isAnnotationPresent(Entity.class)) {
        String t = ((Entity) entityClass.getAnnotation(Entity.class)).name();
        if (org.apache.commons.lang.StringUtils.isNotEmpty(t)) {
            table = t;/*from   www  . j  a  va2  s .c  om*/
        }
    }
    return table;
}

From source file:com.jythonui.server.BUtil.java

public static Object construct(Class cl) {
    Constructor[] c = cl.getConstructors();
    // assume there is only default constructor
    try {//from   w w  w  . ja  v  a  2s  .c  o m
        return c[0].newInstance();
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        errorMess(L(), IErrorCode.ERRORCODE119, ILogMess.CANNOTINITIATEOBJECT, e, cl.getSimpleName());

    }
    return null;
}

From source file:com.ghy.common.util.reflection.ReflectionUtils.java

/**
 * ??, Class?.//from  www . jav  a 2  s.  c  om
 * , 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
 */
public static Class<?> getSuperClassGenricType(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:it.uniroma2.sag.kelp.data.representation.structure.StructureElementFactory.java

/**
 * Returns the identifier of a given class
 * //from  ww  w . ja v a2  s .co m
 * @param c
 *            the class whose identifier is requested
 * @return the class identifier
 */
public static String getStructureElementIdentifier(Class<? extends StructureElement> c) {
    String structureElementAbbreviation;
    if (c.isAnnotationPresent(JsonTypeName.class)) {
        JsonTypeName info = c.getAnnotation(JsonTypeName.class);
        structureElementAbbreviation = info.value();

    } else {
        structureElementAbbreviation = c.getSimpleName().toUpperCase();
    }
    return structureElementAbbreviation;
}

From source file:com.eucalyptus.upgrade.TestHarness.java

@SuppressWarnings({ "static-access" })
private static void printHelp(Options opts) {
    try {/*from w  w w.j  av  a 2s  .  co m*/
        PrintWriter out = new PrintWriter(System.out);
        HelpFormatter help = new HelpFormatter();
        help.setArgName("TESTS");
        help.printHelp(out, LINE_BYTES, "java -jar test.jar", "Options controlling the test harness.", opts, 2,
                4, "", true);
        Multimap<Class, Method> testMethods = getTestMethods();
        help = new HelpFormatter();
        help.setLongOptPrefix("");
        help.setOptPrefix("");
        help.setSyntaxPrefix("");
        help.setLeftPadding(0);
        Options testOptions = new Options();
        for (Class c : testMethods.keySet()) {
            testOptions.addOption(
                    OptionBuilder.withDescription(getDescription(c)).withLongOpt(c.getSimpleName()).create());
            for (Method m : testMethods.get(c)) {
                testOptions.addOption(OptionBuilder.withDescription(getDescription(m))
                        .withLongOpt(c.getSimpleName() + "." + m.getName()).create());
            }
        }
        help.printHelp(out, LINE_BYTES, " ", "Tests:", testOptions, 0, 2, "", false);
        out.flush();
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.KayentaService.java

private static AbstractCanaryServiceIntegration getServiceIntegrationByClass(Canary canary,
        Class<? extends AbstractCanaryServiceIntegration> serviceIntegrationClass) {
    return canary.getServiceIntegrations().stream()
            .filter(s -> serviceIntegrationClass.isAssignableFrom(s.getClass())).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("Canary service integration of type "
                    + serviceIntegrationClass.getSimpleName() + " not found."));
}

From source file:com.springsource.insight.plugin.ldap.LdapOperationCollectionAspectTestSupport.java

private static File resolveApacheWorkDir(Class<?> anchorClass) {
    // see ApacheDSContainer#afterPropertiesSet
    String apacheWorkDir = System.getProperty("apacheDSWorkDir");
    if (apacheWorkDir != null) {
        LOG.info(/*from   ww w  . j a v a2  s  .  co  m*/
                "resolveApacheWorkDir(" + anchorClass.getSimpleName() + ") using pre-defined " + apacheWorkDir);
        return new File(apacheWorkDir);
    }

    File targetDir = FileUtil.detectTargetFolder(anchorClass);
    if (targetDir == null) {
        throw new IllegalStateException("No target folder for " + anchorClass.getSimpleName());
    }

    targetDir = new File(targetDir, "apacheDSWorkDir");
    LOG.info("resolveApacheWorkDir(" + anchorClass.getSimpleName() + ") location: " + targetDir);
    return targetDir;
}

From source file:cross.io.PropertyFileGenerator.java

/**
 * Creates a property file for the given class, containing those fields,
 * which are annotated by {@link cross.annotations.Configurable}.
 *
 * @param className/* ww  w.j a v  a 2 s . com*/
 * @param basedir
 */
public static void createProperties(String className, File basedir) {
    Class<?> c;
    try {
        c = PropertyFileGenerator.class.getClassLoader().loadClass(className);
        LoggerFactory.getLogger(PropertyFileGenerator.class).info("Class: {}", c.getName());
        PropertiesConfiguration pc = createProperties(c);
        if (!basedir.exists()) {
            basedir.mkdirs();
        }
        try {
            pc.save(new File(basedir, c.getSimpleName() + ".properties"));
        } catch (ConfigurationException ex) {
            LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", ex.getLocalizedMessage());
        }
    } catch (ClassNotFoundException e) {
        LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", e.getLocalizedMessage());
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <S, D extends S> D[] downcastToArray(Collection<S> source, Class<D> destClass) {
    D[] dest = (D[]) Array.newInstance(destClass, source.size());
    Iterator<S> it = source.iterator();
    for (int i = 0; i < dest.length; i++) {
        S s = it.next();/*from  w  ww. ja va 2 s . c o  m*/
        if (destClass.isAssignableFrom(s.getClass()))
            dest[i] = (D) s;
        else
            throw new IllegalArgumentException("Could not downcast element from class "
                    + s.getClass().getSimpleName() + " to " + destClass.getSimpleName());
    }
    return dest;
}