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.github.sevntu.checkstyle.internal.ChecksTest.java

private static void validateEclipseCsMetaXmlFileRule(String pkg, Class<?> module, Set<Node> children)
        throws Exception {
    final String moduleName = module.getSimpleName();
    final Set<String> properties = getFinalProperties(module);
    final Set<Field> fieldMessages = CheckUtil.getCheckMessages(module);
    final Set<String> messages = new TreeSet<>();

    for (Field fieldMessage : fieldMessages) {
        // below is required for package/private classes
        if (!fieldMessage.isAccessible()) {
            fieldMessage.setAccessible(true);
        }/*  w ww  . j a  v a 2 s  .c o m*/

        messages.add(fieldMessage.get(null).toString());
    }

    for (Node child : children) {
        final NamedNodeMap attributes = child.getAttributes();

        switch (child.getNodeName()) {
        case "alternative-name":
            final Node internalNameNode = attributes.getNamedItem("internal-name");

            Assert.assertNotNull(
                    pkg + " checkstyle-metadata.xml must contain an internal name for " + moduleName,
                    internalNameNode);

            final String internalName = internalNameNode.getTextContent();

            Assert.assertEquals(
                    pkg + " checkstyle-metadata.xml requires a valid internal-name for " + moduleName,
                    module.getName(), internalName);
            break;
        case "description":
            Assert.assertEquals(pkg + " checkstyle-metadata.xml requires a valid description for " + moduleName,
                    "%" + moduleName + ".desc", child.getTextContent());
            break;
        case "property-metadata":
            final String propertyName = attributes.getNamedItem("name").getTextContent();

            Assert.assertTrue(pkg + " checkstyle-metadata.xml has an unknown parameter for " + moduleName + ": "
                    + propertyName, properties.remove(propertyName));

            final Node firstChild = child.getFirstChild().getNextSibling();

            Assert.assertNotNull(pkg + " checkstyle-metadata.xml requires atleast one child for " + moduleName
                    + ", " + propertyName, firstChild);
            Assert.assertEquals(pkg + " checkstyle-metadata.xml should have a description for the "
                    + "first child of " + moduleName + ", " + propertyName, "description",
                    firstChild.getNodeName());
            Assert.assertEquals(pkg + " checkstyle-metadata.xml requires a valid description for " + moduleName
                    + ", " + propertyName, "%" + moduleName + "." + propertyName, firstChild.getTextContent());
            break;
        case "message-key":
            final String key = attributes.getNamedItem("key").getTextContent();

            Assert.assertTrue(
                    pkg + " checkstyle-metadata.xml has an unknown message for " + moduleName + ": " + key,
                    messages.remove(key));
            break;
        default:
            Assert.fail(pkg + " checkstyle-metadata.xml unknown node for " + moduleName + ": "
                    + child.getNodeName());
            break;
        }
    }

    for (String property : properties) {
        Assert.fail(pkg + " checkstyle-metadata.xml missing parameter for " + moduleName + ": " + property);
    }

    for (String message : messages) {
        Assert.fail(pkg + " checkstyle-metadata.xml missing message for " + moduleName + ": " + message);
    }
}

From source file:io.fabric8.kubernetes.api.ParseTest.java

public static <T> T assertParseExampleFile(String fileName, Class<T> clazz) throws Exception {
    File exampleFile = new File(getKubernetesExamplesDir(), fileName);
    assertFileExists(exampleFile);/*from w  w  w.j  a v a  2 s  .  c om*/
    Object answer = OBJECT_MAPPER.readerFor(clazz).readValue(exampleFile);
    assertNotNull("Null returned while unmarshalling " + exampleFile, answer);
    LOG.info("Parsed: " + fileName + " as: " + answer);
    assertTrue("Is not an instance of " + clazz.getSimpleName() + " was: " + answer.getClass().getName(),
            clazz.isInstance(answer));
    return clazz.cast(answer);
}

From source file:net.rcarz.jiraclient.agile.AgileResource.java

/**
 * Retrieves all boards visible to the session user.
 *
 * @param restclient REST client instance
 * @param type       The type of the object to deserialize.
 * @param url        The URL to call.//from  w ww . j a  v  a  2  s.  c o m
 * @param listName   The name of the list of items in the JSON response.
 * @return a list of boards
 * @throws JiraException when the retrieval fails
 */
static <T extends AgileResource> List<T> list(RestClient restclient, Class<T> type, String url, String listName)
        throws JiraException {

    JSON result;
    try {
        result = restclient.get(url);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve a list of " + type.getSimpleName() + " : " + url, ex);
    }

    return getResourceArray(type, result, restclient, listName);
}

From source file:net.sf.firemox.xml.XmlConfiguration.java

/**
 * Return the method name corresponding to the specified TAG.
 * //from  w  w w. jav  a2 s . com
 * @param tagName
 * @return the method name corresponding to the specified TAG.
 */
static XmlToMDB getXmlClass(String tagName, Map<String, XmlToMDB> instances, Class<?> nameSpaceCall) {
    if (!nameSpaceCall.getSimpleName().startsWith("Xml"))
        throw new InternalError("Caller should be an Xml class : " + nameSpaceCall);

    XmlToMDB nodeClass = instances.get(tagName);
    if (nodeClass != null) {
        return nodeClass;
    }

    String simpleClassName = StringUtils.capitalize(tagName.replaceAll("-", ""));
    String packageName = nameSpaceCall.getPackage().getName();
    String namespace = nameSpaceCall.getSimpleName().substring(3).toLowerCase();
    String className = packageName + "." + namespace + "." + simpleClassName;
    XmlToMDB result;
    try {
        result = (XmlToMDB) Class.forName(className).newInstance();
    } catch (Throwable e) {
        Class<?> mdbClass = null;
        simpleClassName = WordUtils.capitalize(tagName.replaceAll("-", " ")).replaceAll(" ", "");
        try {
            result = (XmlToMDB) Class.forName(packageName + "." + namespace + "." + simpleClassName)
                    .newInstance();
        } catch (Throwable e1) {
            try {
                className = StringUtils.chomp(packageName, ".xml") + "." + namespace + "." + simpleClassName;
                mdbClass = Class.forName(className);
                if (!mdbClass.isAnnotationPresent(XmlTestElement.class)) {
                    result = (XmlToMDB) mdbClass.newInstance();
                } else {
                    result = getAnnotedBuilder(mdbClass, tagName, packageName, namespace);
                }
            } catch (Throwable ei2) {
                error("Unsupported " + namespace + " '" + tagName + "'");
                result = DummyBuilder.instance();
            }
        }
    }
    instances.put(tagName, result);
    return result;
}

From source file:com.evolveum.midpoint.web.util.WebModelUtils.java

public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, String oid,
        Collection<SelectorOptions<GetOperationOptions>> options, PageBase page, Task task,
        OperationResult result) {// ww  w  . j a v  a  2s.  co  m
    LOGGER.debug("Loading {} with oid {}, options {}", new Object[] { type.getSimpleName(), oid, options });

    OperationResult subResult;
    if (result != null) {
        subResult = result.createMinorSubresult(OPERATION_LOAD_OBJECT);
    } else {
        subResult = new OperationResult(OPERATION_LOAD_OBJECT);
    }
    PrismObject<T> object = null;
    try {
        if (options == null) {
            options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
        } else {
            GetOperationOptions getOpts = SelectorOptions.findRootOptions(options);
            if (getOpts == null) {
                options.add(new SelectorOptions<GetOperationOptions>(GetOperationOptions.createResolveNames()));
            } else {
                getOpts.setResolveNames(Boolean.TRUE);
            }
        }
        //           .createResolveNames();
        object = page.getModelService().getObject(type, oid, options, task, subResult);
    } catch (AuthorizationException e) {
        // Not authorized to access the object. This is probably caused by a reference that
        // point to an object that the current user cannot read. This is no big deal.
        // Just do not display that object.
        subResult.recordHandledError(e);
        LOGGER.debug("User {} is not authorized to read {} {}", task.getOwner().getName(), type.getSimpleName(),
                oid);
        return null;
    } catch (Exception ex) {
        subResult.recordFatalError("WebModelUtils.couldntLoadObject", ex);
        LoggingUtils.logException(LOGGER, "Couldn't load object", ex);
    } finally {
        subResult.computeStatus();
    }

    if (result == null && WebMiscUtil.showResultInPage(subResult)) {
        page.showResultInSession(subResult);
    }

    LOGGER.debug("Loaded with result {}", new Object[] { subResult });

    return object;
}

From source file:edu.usu.sdl.openstorefront.util.ReflectionUtil.java

/**
 * Check for class to see if it's a collection class
 *
 * @param checkClass//from  ww  w .  ja va2 s. co  m
 * @return
 */
public static boolean isCollectionClass(Class checkClass) {
    Objects.requireNonNull(checkClass, "Class is required");

    boolean collection = false;
    if (checkClass.getSimpleName().equalsIgnoreCase(List.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Map.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Collection.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Queue.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Set.class.getSimpleName())) {
        collection = true;
    }
    return collection;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
@SuppressWarnings("unchecked")
public static <T> T convert(String string, Class<T> type) {
    try {//from   www. j ava  2  s. c o m
        if (string == null || string.trim().length() == 0) {
            return null;
        }
        if (type.getName().equals("java.util.Date")) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            return (T) dateFormat.parse(string);

        }
        if (type.getName().equals("java.sql.Date")) {
            return (T) new java.sql.Date(java.sql.Date.parse(string));
        }
        if (type.getSimpleName().equals("Calendar")) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dateFormat.parse(string));
            return (T) calendar;
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

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

@SuppressWarnings("unchecked")
private static String getDescription(Object o) {
    Class c = null;//from www.j av a 2s.c  o  m
    Method m = null;
    if (o instanceof Class && ((c = (Class) o).getAnnotation(TestDescription.class)) != null) {
        return ((TestDescription) c.getAnnotation(TestDescription.class)).value();
    } else if (o instanceof Method && ((m = (Method) o).getAnnotation(TestDescription.class)) != null) {
        StringBuffer sb = new StringBuffer();
        for (Class a : Lists.newArrayList(Before.class, After.class, Test.class, Ignore.class,
                Parameters.class)) {
            if (m.getAnnotation(a) != null)
                sb.append("  @").append(String.format("%-9.9s", a.getSimpleName())).append(" ");
        }
        return sb.append(" ").append(((TestDescription) m.getAnnotation(TestDescription.class)).value())
                .toString();
    }
    return "";
}

From source file:com.evolveum.midpoint.schema.util.ObjectTypeUtil.java

public static String getShortTypeName(Class<? extends ObjectType> type) {
    ObjectTypes objectTypeType = ObjectTypes.getObjectType(type);
    if (objectTypeType != null) {
        return objectTypeType.getQName().getLocalPart();
    } else {//from   w  w  w  .j a va  2 s. com
        return type.getSimpleName();
    }
}

From source file:com.austin.base.commons.util.ReflectUtil.java

/**
 * ??,Class?. public BookManager extends GenricManager<Book>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or <code>Object.class</code> if cannot be determined
 *///from  w ww.ja  va  2 s  .co  m
public static Class getSuperClassGenricType(Class clazz, 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];
}