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.wabacus.util.Logger.java

private static Log getLogObj(Class sourceClass) {
    Log logObj = mLogClasses.get(sourceClass.getName());
    if (logObj == null) {
        logObj = LogFactory.getLog(sourceClass);
        mLogClasses.put(sourceClass.getName(), logObj);
    }//w  ww .ja va2  s .c o m
    return logObj;
}

From source file:com.networknt.utility.Util.java

public static String getFrameworkVersion() {
    // this doesn't work.
    // TODO make it work.
    Class clazz = Util.class;
    URL location = clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class");
    System.out.println("location = " + location);
    //location = jar:file:/Users/stevehu/project/light-example-4j/petstore/target/swagger-light-server-1.0.0.jar!/com/networknt/utility/Util.class
    return location.toString();
}

From source file:Main.java

public static boolean isMyServiceRunning(Context context, Class<?> clz) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (clz.getName().equals(service.service.getClassName())) {
            return true;
        }//from ww  w  . j  av a2  s  .c  o m
    }
    return false;
}

From source file:com.lonepulse.robozombie.util.Is.java

/**
 * <p>Determines if the given type terminates an endpoint lookup along an inheritance hierarchy.</p>
 * /*from  w  ww.  j  a v a 2  s  .c  om*/
 * <p>This evaluation is performed using a basic conditional check which will return {@code true} if 
 * the given type is in the specified packages list. If a package list is not provided, the hierarchy 
 * is deemed to have terminated if the given type is ina a package whose name starts with <b>"android."</b>, 
 * <b>"java."</b>, <b>"javax."</b> or <b>"junit."</b>.</p>
 * 
 * <p>Will be rendered obsolete if a future enhancement allows isolation of packages to scan for 
 * endpoint injection.</p>
 *
 * @param type
 *          the {@link Class} of the type to be checked for hierarchy termination 
 * <br><br>
 * @param packagePrefixes
 *          the packages prefixes to restrict the inheritance hierarchy to; else {@code null} 
 *          or {@code empty} to specify the <b>restriction packages</b> as "android.", "java.", 
 *          "javax." or "junit."
 * <br><br>
 * @return {@code true} if this type represents a termination in the hierarchy 
 * <br><br>
 * @since 1.2.4
 */
public static boolean hierarchyTerminal(Class<?> type, List<String> packagePrefixes) {

    String name = type.getName();

    if (packagePrefixes != null && !packagePrefixes.isEmpty()) {

        for (String packagePrefix : packagePrefixes) {

            if (name.startsWith(packagePrefix)) {

                return false;
            }
        }

        return true;
    }

    return name.startsWith("android.") || name.startsWith("java.") || name.startsWith("javax.")
            || name.startsWith("junit.");
}

From source file:DebugUtilities.java

public static void printClassHierarchy(Class aClass, PrintWriter writer, String prefix) {
    String subPrefix = "-->";

    for (int i = 0;; ++i) {
        writer.println(prefix + " " + subPrefix + " " + aClass.getName());

        aClass = aClass.getSuperclass();

        if (aClass == Object.class)
            break;

        subPrefix = "--" + subPrefix;
    }/* w w  w  . j a  v a 2 s.c o m*/
}

From source file:io.wcm.testing.mock.osgi.OsgiMetadataUtil.java

/**
 * Try to read OSGI-metadata from /OSGI-INF and read all implemented interfaces and service properties
 * @param clazz OSGi service implementation class
 * @return Metadata document or null//from w w w.  j  a  v  a2s  .  c om
 */
public static Document geDocument(Class clazz) {
    String metadataPath = "/OSGI-INF/" + clazz.getName() + ".xml";
    InputStream metadataStream = clazz.getResourceAsStream(metadataPath);
    if (metadataStream == null) {
        return null;
    }
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        return documentBuilder.parse(metadataStream);
    } catch (ParserConfigurationException | SAXException | IOException ex) {
        throw new RuntimeException("Unable to read classpath resource: " + metadataPath, ex);
    } finally {
        try {
            metadataStream.close();
        } catch (IOException ex) {
            // ignore
        }
    }
}

From source file:Main.java

public static void checkAndFixAccess(Member paramMember) {
    AccessibleObject localAccessibleObject = (AccessibleObject) paramMember;
    try {//from   w w w  . j ava 2  s.  c o  m
        localAccessibleObject.setAccessible(true);
        return;
    } catch (SecurityException localSecurityException) {
        while (localAccessibleObject.isAccessible())
            ;
        Class localClass = paramMember.getDeclaringClass();
        throw new IllegalArgumentException("Can not access " + paramMember + " (from class "
                + localClass.getName() + "; failed to set access: " + localSecurityException.getMessage());
    }
}

From source file:Main.java

public static Constructor<?> findConstructorExact(Class<?> clazz, Class<?>... parameterTypes) {
    StringBuilder sb = new StringBuilder(clazz.getName());
    sb.append(getParametersString(parameterTypes));
    sb.append("#exact");
    String fullConstructorName = sb.toString();

    if (constructorCache.containsKey(fullConstructorName)) {
        Constructor<?> constructor = constructorCache.get(fullConstructorName);
        if (constructor == null)
            throw new NoSuchMethodError(fullConstructorName);
        return constructor;
    }/*from   ww w.  ja  v a  2  s .  com*/

    try {
        Constructor<?> constructor = clazz.getDeclaredConstructor(parameterTypes);
        constructor.setAccessible(true);
        constructorCache.put(fullConstructorName, constructor);
        return constructor;
    } catch (NoSuchMethodException e) {
        constructorCache.put(fullConstructorName, null);
        throw new NoSuchMethodError(fullConstructorName);
    }
}

From source file:org.openmrs.calculation.CalculationUtil.java

/**
 * Checks if the specified class name is for a wrapper class for a primitive type
 * /*  w  w w.jav a  2s  .  c  o m*/
 * @param className the class name to check
 * @return true if the class name is for a wrapper class for a primitive type otherwise false
 * @should return true for primitive type wrapper class names
 */
public static boolean isPrimitiveWrapperClassName(String className) {
    final Class<?>[] primitiveWrappers = { Boolean.class, Character.class, Byte.class, Short.class,
            Integer.class, Float.class, Double.class, Long.class };
    if (className != null) {
        for (Class<?> wrapper : primitiveWrappers) {
            if (className.equals(wrapper.getName()))
                return true;
        }
    }
    return false;
}

From source file:PackageUtils.java

public static String getPackageName(Class<?> clazz) {
    String className = clazz.getName();
    if (className.startsWith("[L")) {
        className = className.substring(2);
    }//  ww w  . ja v a2  s . com
    return getPackageName(className);
}