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.expressui.core.util.StringUtil.java

/**
 * Generates a debug ID that is inserted into the HTML, which can be useful finding elements in a tool like FireBug.
 *
 * @param prefix        prefix to prepend to debug ID
 * @param mainComponent component to add debug ID to, debug ID contains this component's class name
 * @param subComponent  includes object hashcode from subcomponent to ensure uniqueness
 * @param suffix        suffix to append to debug ID
 * @return debug ID/*from ww  w  .  j a v  a2s . com*/
 */
public static String generateDebugId(String prefix, Object mainComponent, AbstractComponent subComponent,
        String suffix) {
    Class currentClass = mainComponent.getClass();
    String simpleName = currentClass.getSimpleName();
    return prefix + "-" + StringUtil.hyphenateCamelCase(simpleName) + "-" + suffix + "-"
            + subComponent.hashCode();
}

From source file:org.javelin.sws.ext.bind.SweJaxbContextFactory.java

/**
 * <p>Determines mapped classes in the context path and invokes {@link #createContext(Class[], Map)}</p>
 * <p>JAXB-RI uses {@code ObjectFactory} class and/or {@code jaxb.index} file</p>
 * <p>see: com.sun.xml.bind.v2.ContextFactory.createContext(String, ClassLoader, Map<String, Object>)</p>
 * //from   www  .  jav a2  s.  c om
 * @param contextPath
 * @param classLoader
 * @param properties
 * @return
 * @throws IOException 
 */
public static JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
        throws IOException {
    Assert.notNull(contextPath, "The contextPath should not be null");

    PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(
            classLoader);
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);

    List<Class<?>> classes = new LinkedList<Class<?>>();
    // scan the package(s)
    String[] packages = StringUtils.tokenizeToStringArray(contextPath, ":");
    for (String pkg : packages) {
        log.trace("Scanning package: {}", pkg);
        Resource[] resources = resourcePatternResolver
                .getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                        + ClassUtils.convertClassNameToResourcePath(pkg) + "/*.class");
        for (Resource classResource : resources) {
            MetadataReader mdReader = metadataReaderFactory.getMetadataReader(classResource);
            Class<?> cls = ClassUtils.resolveClassName(mdReader.getClassMetadata().getClassName(), classLoader);
            if (cls.getSimpleName().equals("package-info")) {
                XmlSchema xmlSchema = AnnotationUtils.getAnnotation(cls.getPackage(), XmlSchema.class);
                String namespace = xmlSchema == null || xmlSchema.namespace() == null
                        ? NamespaceUtils.packageNameToNamespace(cls.getPackage())
                        : xmlSchema.namespace();
                log.trace(" - found package-info: {}, namespace: {}", cls.getPackage().getName(), namespace);
            } else {
                log.trace(" - found class: {}", mdReader.getClassMetadata().getClassName());
                classes.add(cls);
            }
        }
    }

    return createContext(classes.toArray(new Class[0]), properties);
}

From source file:de.tudarmstadt.ukp.dkpro.core.testing.IOTestRunner.java

public static void testOneWay(Class<? extends CollectionReader> aReader, String aExpectedFile, String aFile,
        Object... aExtraParams) throws Exception {
    String outputFolder = aReader.getSimpleName() + "-" + FilenameUtils.getBaseName(aFile);
    if (DkproTestContext.get() != null) {
        outputFolder = DkproTestContext.get().getTestOutputFolderName();
    }/* w  w w.  ja  v a 2 s  .c om*/
    File output = new File("target/test-output/" + outputFolder + "/dump.txt");

    Object[] extraParams = aExtraParams;
    extraParams = ArrayUtils.add(extraParams, CasDumpWriter.PARAM_TARGET_LOCATION);
    extraParams = ArrayUtils.add(extraParams, output);
    extraParams = ArrayUtils.add(extraParams, CasDumpWriter.PARAM_SORT);
    extraParams = ArrayUtils.add(extraParams, true);

    testOneWay2(aReader, CasDumpWriter.class, aExpectedFile, "dump.txt", aFile, extraParams);
}

From source file:com.coupa.api.impl.DefaultRepository.java

private static String makeResourceUrl(Class<?> resourceClass) {
    return "/" + Noun.pluralOf(camelCaseToRubyCase(resourceClass.getSimpleName()).toLowerCase());
}

From source file:com.antsdb.saltedfish.sql.mysql.InstructionGenerator.java

@SuppressWarnings("unchecked")
static public Generator<ParseTree> getGenerator(ParseTree ctx) throws OrcaException {
    Class<?> klass = ctx.getClass();
    Generator<ParseTree> generator = _generatorByName.get(klass);
    if (generator == null) {
        String key = StringUtils.removeStart(klass.getSimpleName(), "MysqlParser$");
        key = StringUtils.removeEnd(key, "Context");
        key += "Generator";
        try {//from  ww  w .  ja  va  2 s. c o  m
            key = InstructionGenerator.class.getPackage().getName() + "." + key;
            Class<?> generatorClass = Class.forName(key);
            generator = (Generator<ParseTree>) generatorClass.newInstance();
            _generatorByName.put(klass, generator);
        } catch (Exception x) {
            throw new OrcaException("instruction geneartor is not found: " + key, x);
        }
    }
    return generator;
}

From source file:com.anathema_roguelike.main.utilities.Utils.java

public static String getName(Object obj) {

    Class<?> cls = classify(obj);

    String defaultValue = cls.getSimpleName();

    return getProperty(names, obj, splitCamelCase(defaultValue));
}

From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java

public static PropertiesConfiguration getConfig(String basePath, Class clazze) {
    PropertiesConfiguration pc = null;/*from   w  w  w .  j  a v a2s .c om*/

    String className = clazze.getSimpleName();

    File basePathObj = new File(basePath);
    File fileCfg = new File(basePathObj, className + PROPERTIES);

    try {

        if (!basePathObj.exists()) {
            if (basePathObj.mkdirs()) {
                logger.info(basePath + " created!!!");
            }
        } else {

            logger.info(basePath + " already exists skipping!!!");

            if (!fileCfg.exists()) {

                FileUtils.touch(fileCfg);
                logger.info(fileCfg.getName() + " created!!!");
            } else {

                logger.info(fileCfg.getName() + " already exists skipping!!!");
            }
        }

        pc = new PropertiesConfiguration(fileCfg);
        pc.setReloadingStrategy(new FileChangedReloadingStrategy());
        //            pc.setAutoSave(true);
        pc.setDelimiterParsingDisabled(false);

        logger.info(fileCfg.getName() + " loaded!!!");

    } catch (IOException e) {
        logger.error("Error creating config file or directory for class: " + className, e);
    } catch (ConfigurationException ex) {
        logger.error("Error getting/initializacion config for class: " + className, ex);
    }

    return pc;
}

From source file:com.prowidesoftware.deprecation.DeprecationUtils.java

@SuppressWarnings("rawtypes")
private static String notice(final Class clazz, final String method) {
    StringBuilder note = new StringBuilder();
    note.append("The API ").append(clazz.getSimpleName());
    if (method != null) {
        note.append("#").append(method);
    }//ww w.j  a v a 2  s. c o  m
    note.append(" is deprecated. ");
    return note.toString();
}

From source file:Main.java

public static void parseBeanToXmlFileByJAXB(String path, Object bean, Class clase) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(clase);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    JAXBElement<Object> rootElement = new JAXBElement<Object>(new QName(clase.getSimpleName()), clase, bean);
    marshaller.marshal(rootElement, new FileOutputStream(path));
}

From source file:com.khs.sherpa.util.Util.java

public static String getObjectName(Class<?> type) {
    String name = null;/* w ww  .  ja v  a  2  s  . c  o  m*/
    if (type.isAnnotationPresent(Endpoint.class)) {
        name = type.getAnnotation(Endpoint.class).value();
    }

    if (StringUtils.isEmpty(name)) {
        name = type.getSimpleName();
    }
    return name;
}