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:cherry.foundation.type.EnumCodeUtil.java

public static <C, E extends Code<C>> CodeMap<C, E> getCodeMap(final Class<E> type, final E defaultValue) {
    return new CodeMap<C, E>() {

        private Log log = LogFactory.getLog(type);
        private Map<C, E> map = getMap(type);

        @Override//from   w  w  w .  j a  v  a 2 s  .c o m
        public E get(C code) {
            E e = map.get(code);
            if (e == null) {
                checkArgument(defaultValue != null, "No matching enum %s for %s", type.getSimpleName(), code);
                if (log.isDebugEnabled()) {
                    log.debug("No matching enum {0} for {1}", type.getSimpleName(), code);
                }
                return defaultValue;
            }
            return e;
        }
    };
}

From source file:nc.noumea.mairie.appock.core.utility.AppockUtil.java

public static String getSimpleNameOfClass(@SuppressWarnings("rawtypes") Class clazz) {
    if (clazz == null) {
        return null;
    }//  w w w  .j a v a2  s .com
    String result = clazz.getSimpleName();
    String marqueur = "_$$"; // quelquefois le simple name contient _$$ suivi d'une chane gnre, cette mthode permet de ne pas en tenir compte
    if (result.contains(marqueur)) {
        result = result.substring(0, result.indexOf(marqueur));
    }
    return result;
}

From source file:com.appspresso.api.AxLog.java

private static String getTagName(Class<?> klass) {
    if (klass == null) {
        return DEF_TAG;
    }//from   w w w .ja va 2s. c o m
    StringBuilder result = new StringBuilder(MAX_TAG_LEN);
    String className = klass.getSimpleName();
    result.append(className);
    String packageName = klass.getPackage().getName();
    for (String token : packageName.split(".")) {
        if (className.length() > MAX_TAG_LEN) {
            result.insert(0, "..");
            break;
        }
        result.insert(0, token.charAt(0)).insert(0, '.');
    }
    return result.toString();
}

From source file:org.apache.aries.blueprint.plugin.model.Bean.java

public static String getBeanName(Class<?> clazz) {
    Component component = clazz.getAnnotation(Component.class);
    Named named = clazz.getAnnotation(Named.class);
    if (component != null && !"".equals(component.value())) {
        return component.value();
    } else if (named != null && !"".equals(named.value())) {
        return named.value();
    } else {/*from w ww.j  av  a 2s.  c  o  m*/
        String name = clazz.getSimpleName();
        return getBeanNameFromSimpleName(name);
    }
}

From source file:com.alta189.bukkit.script.event.EventScanner.java

public static void writeEvents() {
    File file = new File(BScript.getInstance().getDataFolder(), "events.txt");
    if (file.exists()) {
        file.delete();//from ww  w.  j a  v  a 2s .  c o  m
    }

    if (file.getParentFile() != null && !file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
    }
    StringBuilder builder = new StringBuilder();
    builder.append("Bukkit Event Classes").append(LINE_SEPARATOR).append("####################")
            .append(LINE_SEPARATOR).append(LINE_SEPARATOR);

    for (Map.Entry<String, Class<? extends Event>> entry : bukkitEvent.entrySet()) {
        String className = entry.getValue().getCanonicalName();
        if (className == null) {
            className = entry.getValue().getName();
        }
        builder.append("Full Name: ").append(className).append(LINE_SEPARATOR).append("Simple Name: ")
                .append(entry.getKey()).append(LINE_SEPARATOR).append(LINE_SEPARATOR);
    }

    builder.append("Plugin Event Classes").append(LINE_SEPARATOR).append("####################")
            .append(LINE_SEPARATOR).append(LINE_SEPARATOR);

    for (Map.Entry<Plugin, Set<Class<? extends Event>>> entry : pluginEvents.entrySet()) {

        builder.append("Plugin: ").append(entry.getKey().getName()).append(LINE_SEPARATOR)
                .append("---------------------").append(LINE_SEPARATOR).append(LINE_SEPARATOR);

        for (Class<? extends Event> clazz : entry.getValue()) {
            String className = clazz.getCanonicalName();
            if (className == null) {
                className = clazz.getName();
            }
            String simpleName = clazz.getSimpleName();
            builder.append("Full Name: ").append(entry.getKey().getName()).append(":").append(className)
                    .append(LINE_SEPARATOR).append("Simple Name: ").append(entry.getKey().getName()).append(":")
                    .append(simpleName);

            if (simpleNameEvents.get(simpleName) != null) {
                builder.append(LINE_SEPARATOR).append("Simplest Name: ").append(simpleName);
            }
            builder.append(LINE_SEPARATOR).append(LINE_SEPARATOR);
        }
    }
    builder.append(LINE_SEPARATOR);
    try {
        FileUtils.write(file, builder.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java

public static IInternalNameNode loadNameNode(Class<? extends IInternalNameNode> type, URI location)
        throws ReflectiveOperationException {
    Constructor<? extends IInternalNameNode> nameNodeConstructor;
    try {/*ww  w .  j  a v  a 2 s.c  om*/
        nameNodeConstructor = type.getConstructor(URI.class);
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException(type.getName() + " does not have a constructor of the form "
                + type.getSimpleName() + "(" + URI.class.getName() + ")");
    }

    return nameNodeConstructor.newInstance(location);
}

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

/**
 * Retrieves all boards visible to the session user.
 *
 * @param restclient REST client instance
 * @return a list of boards/*w  w w . ja v  a  2  s  .  c  o m*/
 * @throws JiraException when the retrieval fails
 */
static <T extends AgileResource> T get(RestClient restclient, Class<T> type, String url) throws JiraException {

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

    return getResource(type, result, restclient);
}

From source file:io.selendroid.standalone.builder.SelendroidServerBuilder.java

public static String getJarVersionNumber() {
    Class clazz = SelendroidStandaloneDriver.class;
    String className = clazz.getSimpleName() + ".class";
    String classPath = clazz.getResource(className).toString();
    String version = "";

    if (!classPath.startsWith("jar")) {
        // Class not from JAR
        if (classPath.startsWith("file") && classPath.contains("target")) {
            try {
                version = getVersionFromPom(classPath.substring(5, classPath.lastIndexOf("target")));
            } catch (Exception e) {
                e.printStackTrace();//from   www . j  a  va2 s  .co m
                return "";
            }
        } else
            return "dev";
    } else {
        try {
            version = getVersionFromManifest(classPath);
        } catch (IOException e) {
            return "";
        }
    }
    return version;
}

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

public static <T extends ObjectType> void deleteObject(Class<T> type, String oid, ModelExecuteOptions options,
        OperationResult result, PageBase page, PrismObject<UserType> principal) {
    LOGGER.debug("Deleting {} with oid {}, options {}", new Object[] { type.getSimpleName(), oid, options });

    OperationResult subResult;//from   w ww.j  av a 2  s  . c  o  m
    if (result != null) {
        subResult = result.createMinorSubresult(OPERATION_DELETE_OBJECT);
    } else {
        subResult = new OperationResult(OPERATION_DELETE_OBJECT);
    }
    try {
        Task task = page.createSimpleTask(result.getOperation(), principal);

        ObjectDelta delta = new ObjectDelta(type, ChangeType.DELETE, page.getPrismContext());
        delta.setOid(oid);

        page.getModelService().executeChanges(WebMiscUtil.createDeltaCollection(delta), options, task,
                subResult);
    } catch (Exception ex) {
        subResult.recordFatalError("WebModelUtils.couldntDeleteObject", ex);
        LoggingUtils.logException(LOGGER, "Couldn't delete object", ex);
    } finally {
        subResult.computeStatus();
    }

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

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

From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.ReconfigurationPacket.java

public static void assertPacketTypeChecks(ReconfigurationPacket.PacketType type, String packetName,
        Class<?> target, String handlerMethodPrefix) {
    String errMsg = "Method " + handlerMethodPrefix + packetName + " does not exist in "
            + target.getSimpleName();
    try {/* w  w w.  j av a2s  .  com*/
        // System.out.println(type + " : " + packetName + " : " +
        // handlerMethodPrefix+packetName);
        if (packetName != null)
            assert (target.getMethod(handlerMethodPrefix + packetName, getPacketTypeClass(type),
                    ProtocolTask[].class) != null) : errMsg;
    } catch (NoSuchMethodException nsme) {
        System.err.println(errMsg);
        nsme.printStackTrace();
    }
}