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:com.dragome.callbackevictor.serverside.utils.ReflectionUtils.java

public static Map<String, Object> discoverMethods(final Class<?> pClazz, final Matcher pMatcher,
        final Indexer pIndexer) {

    log.debug("discovering methods on " + pClazz.getName());

    final Map<String, Object> result = new HashMap<String, Object>();

    Class<?> current = pClazz;
    do {//from www  .ja v a 2  s  . c om
        final Method[] methods = current.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            final String mname = methods[i].getName();
            if (pMatcher.matches(mname)) {
                pIndexer.put(result, mname, methods[i]);

                log.debug("discovered method " + mname + " -> " + methods[i]);
            }
        }
        current = current.getSuperclass();
    } while (current != null);

    return result;
}

From source file:com.puppycrawl.tools.checkstyle.filters.SuppressionCommentFilterTest.java

private static DefaultConfiguration createFilterConfig(Class<?> aClass) {
    return new DefaultConfiguration(aClass.getName());
}

From source file:Main.java

public static String getResourceUrlString(String resourceFileName, Class runningClass) {
    URL url = runningClass.getClassLoader().getResource(resourceFileName);
    if (url == null)
        throw new MissingResourceException("Resource not found: " + resourceFileName, runningClass.getName(),
                resourceFileName);/*from   w  w  w. j  a  v a  2s .c  om*/
    return url.toExternalForm();
}

From source file:Main.java

public static <T> T getConstantValue(final Class aClass, final String constantName) {
    try {//from   w w  w  . j a  va  2s. c om
        return (T) aClass.getDeclaredField(constantName).get(null);
    } catch (NoSuchFieldException e) {
        Log.e("error", "can not find " + constantName + " in " + aClass.getName());
    } catch (IllegalAccessException e) {
        Log.e("error", constantName + " is not accessible");
    } catch (IllegalArgumentException e) {
        Log.e("error", "arguments error when get " + constantName);
    } catch (Exception e) {
        Log.e("error", "can not get constant" + constantName);
    }

    return null;
}

From source file:Main.java

public static <T> T getConstantValue(final Class aClass, final String constantName) {
    try {// w ww  .j  a  v a2  s .com
        return (T) aClass.getDeclaredField(constantName).get(null);
    } catch (NoSuchFieldException e) {
        Log.e("error", "can not find " + constantName + " in " + aClass.getName());
    } catch (IllegalAccessException e) {
        Log.e("error", constantName + " is not accessable");
    } catch (IllegalArgumentException e) {
        Log.e("error", "arguments error when get " + constantName);
    } catch (Exception e) {
        Log.e("error", "can not get constant" + constantName);
    }

    return null;
}

From source file:com.simiacryptus.util.lang.CodeUtil.java

/**
 * Find file file.// w ww .ja v a  2 s.c  om
 *
 * @param clazz the clazz
 * @return the file
 */
@Nullable
public static File findFile(@Nullable final Class<?> clazz) {
    if (null == clazz)
        return null;
    String name = clazz.getName();
    if (null == name)
        return null;
    final String path = name.replaceAll("\\.", "/").replaceAll("\\$.*", "");
    return com.simiacryptus.util.lang.CodeUtil.findFile(path + ".java");
}

From source file:com.redpill_linpro.springframework.beans.factory.config.EtcdPlaceholderConfigurerTests.java

@SuppressWarnings("unchecked")
private static Map<String, String> getModifiableSystemEnvironment() {
    // for os x / linux
    Class<?>[] classes = Collections.class.getDeclaredClasses();
    Map<String, String> env = System.getenv();
    for (Class<?> cl : classes) {
        if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
            try {
                Field field = cl.getDeclaredField("m");
                field.setAccessible(true);
                Object obj = field.get(env);
                if (obj != null
                        && obj.getClass().getName().equals("java.lang.ProcessEnvironment$StringEnvironment")) {
                    return (Map<String, String>) obj;
                }/*from  ww  w  . j a  v  a 2  s.c  o m*/
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }

    // for windows
    Class<?> processEnvironmentClass;
    try {
        processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    try {
        Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                .getDeclaredField("theCaseInsensitiveEnvironment");
        theCaseInsensitiveEnvironmentField.setAccessible(true);
        Object obj = theCaseInsensitiveEnvironmentField.get(null);
        return (Map<String, String>) obj;
    } catch (NoSuchFieldException e) {
        // do nothing
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    try {
        Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
        theEnvironmentField.setAccessible(true);
        Object obj = theEnvironmentField.get(null);
        return (Map<String, String>) obj;
    } catch (NoSuchFieldException e) {
        // do nothing
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    throw new IllegalStateException();
}

From source file:iddb.core.model.dao.DAOFactory.java

@SuppressWarnings("rawtypes")
public static Object forClass(Class claz) {
    if (instance == null) {
        instance = new DAOFactory();
    }//from   w ww . ja va 2  s.c om
    Object dao = instance.getDaoImpl(claz.getName());
    if (dao == null) {
        log.debug("Failed lookup dao for {}", claz.getName());
    }
    return dao;
}

From source file:com.ephesoft.dcma.core.hibernate.EphesoftCriteria.java

/**
 * Creating alias for class.//from   www  .j  a v a 2  s .  co m
 * 
 * @param clazz Class<?> 
 * @return EphesoftCriteria
 */
public static EphesoftCriteria forClass(Class<?> clazz) {
    return new EphesoftCriteria(clazz.getName());
}

From source file:info.novatec.testit.livingdoc.util.ClassUtils.java

private static <T> NoSuchMethodException noSuitableConstructorException(Class<T> klass, Object... args) {
    return new NoSuchMethodException(klass.getName() + ".<init>(" + toString(args) + ")");
}