Example usage for java.lang Class getCanonicalName

List of usage examples for java.lang Class getCanonicalName

Introduction

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

Prototype

public String getCanonicalName() 

Source Link

Document

Returns the canonical name of the underlying class as defined by the Java Language Specification.

Usage

From source file:com.dsh105.commodus.Affirm.java

public static void checkInstanceOf(Class<?> type, Object instance, boolean allowNull) {
    Affirm.notNull(type);/*from   www . ja  v  a2s. com*/
    if (!allowNull) {
        Affirm.notNull(instance);
    }
    if (!type.isAssignableFrom(instance.getClass())) {
        throwException(new IllegalStateException(
                instance.getClass().getCanonicalName() + " must be a subclass of " + type.getCanonicalName()));
    }
}

From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java

private static Class<?> findModule(Set<Class<?>> modules, String classPath) {
    Class<?> result = null;

    for (Class<?> module : modules) {
        if (module.getCanonicalName().equals(classPath)) {
            result = module;/* w  ww .ja  v  a2s  .com*/
            break;
        }
    }

    return result;
}

From source file:com.github.fge.jsonschema.library.KeywordBuilder.java

private static Constructor<? extends KeywordValidator> getConstructor(final String name,
        final Class<? extends KeywordValidator> c) {
    try {// w  ww .  j av a 2s.  c om
        return c.getConstructor(JsonNode.class);
    } catch (NoSuchMethodException ignored) {
        throw new IllegalArgumentException(
                BUNDLE.printf("noAppropriateConstructor", name, c.getCanonicalName()));
    }
}

From source file:com.eucalyptus.entities.PersistenceContexts.java

static void addSharedEntity(Class entity) {
    if (!isDuplicate(entity)) {
        EventRecord.here(PersistenceContextDiscovery.class, EventType.PERSISTENCE_ENTITY_REGISTERED, "shared",
                entity.getCanonicalName()).trace();
        sharedEntities.add(entity);//from  w  ww . j  a va 2s  .c  o m
    }
}

From source file:atg.tools.dynunit.util.ComponentUtil.java

/**
 * Creates a new component properties file at {@code output} using the class {@code klass} and configured with the
 * given {@code properties}. This method is generally useful when you have a properties file already and wish to
 * overwrite it./*from w w  w  . j av  a2 s  .  c om*/
 *
 * @param output
 *         The component properties file to write to.
 * @param klass
 *         Class of component to create.
 * @param properties
 *         Any properties to set in the component properties file.
 *
 * @return The provided {@code output} component properties file.
 *
 * @throws IOException
 *         if {@code output} couldn't be written to.
 */
public static File newComponentForFile(final File output, final Class<?> klass, final Properties properties)
        throws IOException {
    logger.entry(output, klass, properties);
    newComponentForFile(output, klass.getCanonicalName(), properties);
    return logger.exit(output);
}

From source file:Main.java

/**
 * Checks if the specified service is currently running or not.
 * @param context/*w  w  w  .  java  2 s  .co  m*/
 * @param service
 * @param maxCheckCount
 * @return
 */
public static final boolean isServiceRunning(Context context, Class<? extends Service> service,
        int maxCheckCount) {
    if (context == null || service == null) {
        return false;
    }

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> list = manager.getRunningServices(maxCheckCount);
    for (RunningServiceInfo info : list) {
        if (service.getCanonicalName().equals(info.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.discovery.darchrow.lang.ClassUtil.java

/**
 *  class info map for LOGGER.//from  www.jav  a  2  s  . co  m
 *
 * @param klass
 *            the clz
 * @return the map for log
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {
    if (Validator.isNullOrEmpty(klass)) {
        return null;
    }

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getName()", klass.getName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern"

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?? voidboolean?byte?char?short?int?long?float  double?
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ??,
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ????,??????
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class????java??false?trueJVM???java??????
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
}

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

public static void scanPlugin(Plugin plugin) {
    if (pluginEvents.containsKey(plugin)) {
        return;/*from   w  ww . ja v  a2s. c  om*/
    }
    BScript.getInstance().debug("Scanning plugin " + plugin.getName());
    if (plugin instanceof JavaPlugin) {
        ClassLoader loader = ReflectionUtil.getFieldValue(JavaPlugin.class, plugin, "classLoader");
        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(new FilterBuilder().exclude(FilterBuilder.prefix("org.bukkit")))
                .setUrls(ClasspathHelper.forClassLoader(loader)));

        Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class);

        BScript.getInstance().info("Found " + classes.size() + " classes extending "
                + Event.class.getCanonicalName() + " in " + plugin.getName());
        for (Class<? extends Event> clazz : classes) {
            if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
                continue;
            }
            BScript.getInstance().debug(clazz.getCanonicalName());

            String className = clazz.getCanonicalName();
            if (className == null) {
                className = clazz.getName();
            }
            BScript.getInstance().debug(className);
            events.put(className, clazz);
            String simpleName = clazz.getSimpleName();
            if (simpleNameEvents.get(simpleName) != null) {
                simpleNameEvents.remove(simpleName);
            } else {
                simpleNameEvents.put(simpleName, clazz);
            }
        }
        if (classes.size() > 0) {
            pluginEvents.put(plugin, classes);
        }
    } else {
        BScript.getInstance().debug("Plugin is not JavaPlugin " + plugin.getName());
    }
}

From source file:clearUp.Collections3.java

/**
  * mapbean//w ww.j  av a 2s  .  c om
  *
  * @param map
  * @param beanClass
  * @return
  */
public static Object map2Bean(Map map, Class<?> beanClass) {
    try {
        Object bean = beanClass.newInstance();
        PropertyUtils.copyProperties(bean, map);
        return bean;
    } catch (Exception e) {
        throw new RuntimeException(beanClass.getCanonicalName() + "!");
    }
}

From source file:com.bradmcevoy.io.FileUtils.java

@SuppressWarnings("unchecked")
public static String readResource(Class cl, String res) throws IOException {
    InputStream in = cl.getResourceAsStream(res);
    if (in == null) {
        throw new IOException(
                "Failed to read resource: " + res + " relative to class: " + cl.getCanonicalName());
    }//from  ww w.  j  a va 2s.  c o  m
    ByteArrayOutputStream out = readIn(in);
    return out.toString();
}