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.netspective.axiom.TestUtils.java

static public DriverManagerConnectionProvider getConnProvider(Class connProviderId, boolean reCreateDb) {
    return getConnProvider(connProviderId.getName(), reCreateDb);
}

From source file:eu.riscoss.server.DBConnector.java

public static File findLocation(Class<?> cls) {
    String t = cls.getPackage().getName() + ".";
    String clsname = cls.getName().substring(t.length());
    String s = cls.getResource(clsname + ".class").toString();

    s = s.substring(s.indexOf("file:") + 5);
    int p = s.indexOf("!");
    if (p != -1) {
        s = s.substring(0, p);/*from w w  w.j  a va 2s.  c om*/
    }

    return new File(new File(s).getParent());
}

From source file:Main.java

public static String getApplicationPath(Class cls) {
    if (cls == null)
        throw new java.lang.IllegalArgumentException("parameter is not null !");
    ClassLoader loader = cls.getClassLoader();
    String clsName = cls.getName() + ".class";
    Package pack = cls.getPackage();
    System.out.println("package name is : " + (pack == null));
    String path = "";
    if (pack != null) {
        String packName = pack.getName();
        if (packName.startsWith("java.") || packName.startsWith("javax."))
            throw new java.lang.IllegalArgumentException("This is system class");
        clsName = clsName.substring(packName.length() + 1);
        if (packName.indexOf(".") < 0)
            path = packName + "/";
        else {/*from  www.j  a  v  a  2  s  . c  o m*/
            int start = 0, end = 0;
            end = packName.indexOf(".");
            while (end != -1) {
                path = path + packName.substring(start, end) + "/";
                start = end + 1;
                end = packName.indexOf(".", start);
            }
            path = path + packName.substring(start) + "/";
        }
    }
    java.net.URL url = loader.getResource(path + clsName);
    String realPath = url.getPath();
    int pos = realPath.indexOf("file:");
    if (pos > -1)
        realPath = realPath.substring(pos + 5);
    pos = realPath.indexOf(path + clsName);
    realPath = realPath.substring(0, pos - 1);
    if (realPath.endsWith("!"))
        realPath = realPath.substring(0, realPath.lastIndexOf("/"));
    try {
        realPath = java.net.URLDecoder.decode(realPath, "utf-8");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return realPath;
}

From source file:org.agiso.core.lang.util.ClassUtils.java

public static String locate(Class<?> c, ClassLoader cl) /*throws ClassNotFoundException*/ {
    return locate(c.getName(), cl);
}

From source file:ca.travelagency.components.formheader.DaoEntityModel.java

@SuppressWarnings("unchecked")
private static <T> T createNewDaoEntity(Class<?> clazz) {
    try {/*from  w w  w  .j  a v  a  2 s .co m*/
        return (T) clazz.newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Can not create object of class: " + clazz.getName(), e);
    }
}

From source file:TextUtilities.java

/**
 * Translates the specified resource name into the context of the specified
 * class. Basically, this method returns the name of the resource you need to
 * use when loading via a classloader, if via the specified class you would
 * load it simply with <code>Class.getResource(resourceName)</code>.
 *//* w w  w  . ja  v a 2 s .co m*/

public static String translateResource(Class c, String resourceName) {
    String path = c.getName();
    int dotIndex = path.lastIndexOf('.');
    if (dotIndex != -1) {
        path = path.substring(0, dotIndex);
        path = path.replace('.', '/') + '/' + resourceName;
    } else
        return resourceName;

    return path;
}

From source file:com.github.dozermapper.core.loader.api.FieldsMappingOptions.java

public static FieldsMappingOption customConverter(final Class<? extends CustomConverter> type,
        final String parameter) {
    return customConverter(type.getName(), parameter);
}

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.  j  a v a2s  .  com*/
    }
    return false;
}

From source file:com.comstar.mars.env.EnvMapperFactoryBean.java

public static Map<String, Object> getAllMappers(Class mapperClazz) {
    Map<String, Object> result = new HashMap<>();
    String clazzName = mapperClazz.getName();

    for (String env : envMappers.keySet()) {
        Map<String, Object> mappers = envMappers.get(env);
        if (mappers.containsKey(clazzName)) {
            result.put(env, mappers.get(clazzName));
        }//from w  ww  .j a  v a 2 s . c o m
    }

    return result;
}

From source file:com.ejisto.modules.web.util.FieldSerializationUtil.java

private static MockedField translateField(Field field, Object container, String className, String contextPath) {
    Class<?> fieldType = field.getType();
    MockedField out = buildMockedField(className, field.getName(), contextPath, fieldType.getName());
    Object value = safeGet(field, container);
    if (value == null || isBlackListed(fieldType)) {
        out.setFieldValue(null);//from w  w  w  .  jav a2s .  c o  m
        return out;
    }
    int hashCode = System.identityHashCode(value);
    String existingClassMapping = CACHED_IDS.putIfAbsent(hashCode, out.getFieldType());
    if (StringUtils.isNotBlank(existingClassMapping)) {
        out.setLink(String.valueOf(hashCode));
        return out;
    } else if (field.isEnumConstant() || fieldType.isPrimitive()) {
        out.setFieldValue(String.valueOf(value));
    } else {
        out.setExpression(translateValue(value));
    }
    out.setRecordedObjectHashCode(hashCode);
    return out;
}