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:ShowClass.java

/** Return the name of an interface or primitive type, handling arrays. */
public static String typename(Class t) {
    String brackets = "";
    while (t.isArray()) {
        brackets += "[]";
        t = t.getComponentType();/* w w  w  .j a  v  a  2s.  c o  m*/
    }
    String name = t.getName();
    int pos = name.lastIndexOf('.');
    if (pos != -1)
        name = name.substring(pos + 1);
    return name + brackets;
}

From source file:Main.java

public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }//from  w w w  . jav  a  2 s .  co  m
    }
    return false;
}

From source file:Main.java

public static InputStream getWsddStream(Class<?> clientClass) {
    InputStream wsdd = clientClass.getResourceAsStream("client-config.wsdd");
    if (wsdd == null) {
        throw new IllegalStateException(
                "Could not find client-config.wsdd relative to " + clientClass.getName());
    }/*  w w w  .  ja  va 2  s .  c  om*/
    return wsdd;
}

From source file:Main.java

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

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

    try {
        Constructor<?> constructor = findConstructorExact(clazz, parameterTypes);
        constructorCache.put(fullConstructorName, constructor);
        return constructor;
    } catch (NoSuchMethodError ignored) {
    }

    Constructor<?> bestMatch = null;
    Constructor<?>[] constructors = clazz.getDeclaredConstructors();
    for (Constructor<?> constructor : constructors) {
        // compare name and parameters
        //         if (ClassUtils.isAssignable(parameterTypes, constructor.getParameterTypes(), true)) {
        //             // get accessible version of method
        //               if (bestMatch == null || MemberUtils.compareParameterTypes(
        //                     constructor.getParameterTypes(),
        //                  bestMatch.getParameterTypes(),
        //                  parameterTypes) < 0) {
        //                  bestMatch = constructor;
        //               }
        //          }
    }

    if (bestMatch != null) {
        bestMatch.setAccessible(true);
        constructorCache.put(fullConstructorName, bestMatch);
        return bestMatch;
    } else {
        NoSuchMethodError e = new NoSuchMethodError(fullConstructorName);
        constructorCache.put(fullConstructorName, null);
        throw e;
    }
}

From source file:Main.java

/**
 * Check whether my service is running.//from  w w w  .  j  a v a2s.  c  o  m
 * @param context application's context
 * @param serviceClass class of the service to look for
 * @return true if the service is running, false otherwise
 */
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
        if (serviceClass.getName().equals(service.service.getClassName()))
            return true;
    return false;
}

From source file:de.joinout.criztovyl.tools.json.creator.JSONCreators.java

/**
 * Try to load a {@link JSONCreators} for the given class.
 * @param clazz the class/*from ww  w  .  j ava2  s .co m*/
 * @return the {@link JSONCreators} if found or <code>null</code> if not.
 */
public static JSONCreator<?> getCreator(Class<?> clazz) {

    String name = clazz.getName();

    if (name.equals(STRING.getCreatorClass().getName()))
        return STRING;

    else if (name.equals(CALENDAR.getCreatorClass().getName()))
        return CALENDAR;

    else if (name.equals(PATH.getCreatorClass().getName()))
        return PATH;

    else
        return null;
}

From source file:Main.java

public static boolean isServiceRunning(Context context, Class serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(serviceInfo.service.getClassName())) {
            return true;
        }/*  www  .j a v  a2  s .c  o m*/
    }
    return false;
}

From source file:info.magnolia.cms.util.FactoryUtil.java

public static Object getInstance(Class interf) {
    try {//from  w  ww  .  j  a va 2  s .c  o m
        return new DiscoverClass().newInstance(interf, props);
    } catch (Exception e) {
        log.error("can't instantiate an implementation of this class [" + interf.getName() + "]");
    }
    return null;
}

From source file:com.CodeSeance.JSeance2.CodeGenXML.Runtime.java

public static Log CreateLogger(Class classObj) {
    return LogFactory.getLog(classObj.getName().replace("com.CodeSeance.JSeance2.CodeGenXML.", ""));
}

From source file:de.tudarmstadt.ukp.dkpro.bigdata.io.hadoop.Text2CASInputFormat.java

/**
 * Tells Text2CASInputFormat to use a custom implementation of DocumentTextExtractor. <br>
 * By default, i.e. if you do not set a custom DocumentTextExtractor, the input line's value is
 * used as the CAS document text.//w  ww. ja  va2  s . c om
 * 
 * @param conf
 *            Configuration object
 * @param extractorClass
 *            Implementation of DocumentTextExtractor
 */
public static void setDocumentTextExtractorClass(Configuration conf,
        Class<? extends DocumentTextExtractor> extractorClass) {
    conf.set("dkpro.uima.text2casinputformat.documenttextextractor", extractorClass.getName());
}