Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:py.una.pol.karaku.test.util.TestUtils.java

/**
 * Retorna la lista de entidades relacionadas a una base.
 * //www. j a va  2  s  .  c  o m
 * @param base
 *            entidad base
 * @return array con todas las entidades que se pueden acceder desde base.
 */
public static Class<?>[] getReferencedClasses(Class<?> base) {

    LOG.info("Scanning for classes with relations with '{}'", base.getName());
    Set<Class<?>> result = getReferencedClasses(base, new HashSet<Class<?>>(10));
    result.add(base);
    for (Class<?> c : result) {
        LOG.info("Found class {} ", c.getSimpleName());
    }
    LOG.info("Found '{}' classes with relations with '{}'", result.size(), base.getSimpleName());
    return result.toArray(new Class<?>[result.size()]);
}

From source file:at.tuwien.minimee.registry.ToolRegistry.java

private static void addCreateScale(Digester digester, Class c) {
    String name = c.getName();
    name = name.substring(name.lastIndexOf(".") + 1);
    // XML elements should start with a lower case letter
    name = name.substring(0, 1).toLowerCase() + name.substring(1);
    // create a scale entry for this value
    String pattern = "*/property/" + name;
    digester.addObjectCreate(pattern, c);
    digester.addSetProperties(pattern);/*from   ww w.jav a 2s  . co  m*/
    digester.addSetNext(pattern, "setScale");
}

From source file:com.mawujun.utils.bean.BeanUtils.java

private static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws IntrospectionException {
    PropertyDescriptor[] pds = beanPropertyCache.get(clazz.getName());
    if (pds != null) {
        //return pds;
    } else {// w w  w  . j  av  a 2 s . c  o m
        BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
        pds = beanInfo.getPropertyDescriptors();
        beanPropertyCache.put(clazz.getName(), pds);
    }
    return pds;
}

From source file:Main.java

public static String idOfClass(Class<?> clazz) {
    Class<?> theClass = clazz;
    StringBuilder sb = new StringBuilder();
    if (theClass.isArray()) {
        do {//  w  w  w.  j a  va 2s  . c om
            sb.append("Array"); //$NON-NLS-1$
            theClass = theClass.getComponentType();
        } while (theClass.isArray());
    }
    String clazzName = theClass.getName();
    clazzName = clazzName.substring(clazzName.lastIndexOf('.') + 1);
    return clazzName + sb.toString();
}

From source file:ClassUtil.java

/**
 * Returns a new instance of an object using constructor with
 * specified parameter types and arguments.
 *
 * @param clazz object class//from   ww  w  . j  a v  a  2 s  .  c o m
 * @param param constructor parameter types
 * @param args constructor initialization arguments
 *
 * @return a new object instance or null if some error occours (exceptions are logged)
 */
public static Object newInstance(Class clazz, Class param[], Object args[]) {
    if (clazz == null) {
        return null;
    }
    String name = clazz.getName();
    return newInstance(name, param, args);
}

From source file:com.elasticbox.jenkins.k8s.util.TestUtils.java

public static void clearEnv(String... keys) {
    try {// w w  w. j  av a  2  s. c o  m
        Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
        Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
        theEnvironmentField.setAccessible(true);
        Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
        for (String key : keys) {
            env.remove(key);
        }
        Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                .getDeclaredField("theCaseInsensitiveEnvironment");
        theCaseInsensitiveEnvironmentField.setAccessible(true);
        Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
        for (String key : keys) {
            cienv.remove(key);
        }
    } catch (NoSuchFieldException e) {
        try {
            Class[] classes = Collections.class.getDeclaredClasses();
            Map<String, String> env = System.getenv();
            for (Class cl : classes) {
                if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                    Field field = cl.getDeclaredField("m");
                    field.setAccessible(true);
                    Object obj = field.get(env);
                    Map<String, String> map = (Map<String, String>) obj;
                    for (String key : keys) {
                        map.remove(key);
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:com.npower.dm.util.DMUtil.java

/**
 * Format a string buffer containing the Class, Interfaces, CodeSource, and
 * ClassLoader information for the given object clazz.
 * //from w  w  w .j  av a2 s  .  c o m
 * @param clazz
 *          the Class
 * @param results,
 *          the buffer to write the info to
 */
public static void displayClassInfo(Class<?> clazz, StringBuffer results) {
    // Print out some codebase info for the ProbeHome
    ClassLoader cl = clazz.getClassLoader();
    results.append("\n" + clazz.getName() + ".ClassLoader=" + cl);
    ClassLoader parent = cl;
    while (parent != null) {
        results.append("\n.." + parent);
        URL[] urls = getClassLoaderURLs(parent);
        int length = urls != null ? urls.length : 0;
        for (int u = 0; u < length; u++) {
            results.append("\n...." + urls[u]);
        }
        if (parent != null)
            parent = parent.getParent();
    }
    CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource();
    if (clazzCS != null)
        results.append("\n++++CodeSource: " + clazzCS);
    else
        results.append("\n++++Null CodeSource");
    results.append("\nImplemented Interfaces:");
    Class<?>[] ifaces = clazz.getInterfaces();
    for (int i = 0; i < ifaces.length; i++) {
        results.append("\n++" + ifaces[i]);
        ClassLoader loader = ifaces[i].getClassLoader();
        results.append("\n++++ClassLoader: " + loader);
        ProtectionDomain pd = ifaces[i].getProtectionDomain();
        CodeSource cs = pd.getCodeSource();
        if (cs != null)
            results.append("\n++++CodeSource: " + cs);
        else
            results.append("\n++++Null CodeSource");
    }
}

From source file:Main.java

private static <T> T newInstance(Context context, Class clazz, Class[] constructorSig, Object... arguments) {
    try {//from   w w w .j a  v a 2s  . co  m
        Constructor<?> constructor = clazz.getConstructor(constructorSig);
        return (T) constructor.newInstance(arguments);
    } catch (Exception e) {
        Log.w(LOG_TAG, "Cannot instantiate class: " + clazz.getName(), e);
    }
    return null;
}

From source file:ClassUtils.java

/**
 * Return the qualified name of the given class: usually simply
 * the class name, but component type class name + "[]" for arrays.
 * @param clazz the class//from w  ww  .j ava2 s . com
 * @return the qualified name of the class
 */
public static String getQualifiedName(Class clazz) {
    if (clazz.isArray()) {
        return getQualifiedNameForArray(clazz);
    }
    return clazz.getName();
}

From source file:com.github.pjungermann.config.validation.ConfigValidatorTest.java

static void autowireByConstructor(Class... classes) {
    for (Class clazz : classes) {
        applicationContext.registerBeanDefinition(clazz.getName(),
                BeanDefinitionBuilder.rootBeanDefinition(clazz)
                        .setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR).getBeanDefinition());
    }/*from   w w  w  . ja v a2s.com*/
}