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

@SuppressLint("NewApi")
@SuppressWarnings("all")
private static boolean setProxyKK(WebView webView, String host, int port, String applicationClassName) {
    Context appContext = webView.getContext().getApplicationContext();
    if (null == host) {
        System.clearProperty("http.proxyHost");
        System.clearProperty("http.proxyPort");
        System.clearProperty("https.proxyHost");
        System.clearProperty("https.proxyPort");
    } else {/*w ww  .j  av  a2  s  .  c o m*/
        System.setProperty("http.proxyHost", host);
        System.setProperty("http.proxyPort", port + "");
        System.setProperty("https.proxyHost", host);
        System.setProperty("https.proxyPort", port + "");
    }
    try {
        Class applictionCls = Class.forName(applicationClassName);
        Field loadedApkField = applictionCls.getField("mLoadedApk");
        loadedApkField.setAccessible(true);
        Object loadedApk = loadedApkField.get(appContext);
        Class loadedApkCls = Class.forName("android.app.LoadedApk");
        Field receiversField = loadedApkCls.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        Map receivers = (Map) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((Map) receiverMap).keySet()) {
                Class clazz = rec.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);

                    /*********** optional, may be need in future *************/
                    final String CLASS_NAME = "android.net.ProxyProperties";
                    Class cls = Class.forName(CLASS_NAME);
                    Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class);
                    constructor.setAccessible(true);
                    Object proxyProperties = constructor.newInstance(host, port, null);
                    intent.putExtra("proxy", (Parcelable) proxyProperties);
                    /*********** optional, may be need in future *************/

                    onReceiveMethod.invoke(rec, appContext, intent);
                }
            }
        }
        Log.d(LOG_TAG, "Setting proxy with >= 4.4 API successful!");
        return true;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

/**
 * Helper method used to weed out dynamic Proxy types; types that do
 * not expose concrete method API that we could use to figure out
 * automatic Bean (property) based serialization.
 *//*from   w  w  w  .j a v a 2s  .c o m*/
public static boolean isProxyType(Class<?> type) {
    // Then: well-known proxy (etc) classes
    if (Proxy.isProxyClass(type)) {
        return true;
    }
    String name = type.getName();
    // Hibernate uses proxies heavily as well:
    if (name.startsWith("net.sf.cglib.proxy.") || name.startsWith("org.hibernate.proxy.")) {
        return true;
    }
    // Not one of known proxies, nope:
    return false;
}

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

public static String createTemplateName(Class klass, String ext) {
    return "/" + StringUtils.replace(klass.getName(), ".", "/") + "." + ext;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
private static Map<String, Class> getParentClassFields(Map<String, Class> map, Class clazz) {

    Field[] fields = clazz.getDeclaredFields();

    for (Field field : fields) {

        map.put(clazz.getName() + "." + field.getName(), field.getType());

    }/* w w w.  ja v  a  2 s . c  o m*/

    if (clazz.getSuperclass() == null) {

        return map;

    }

    getParentClassFields(map, clazz.getSuperclass());

    return map;

}

From source file:ClassUtil.java

/**
 * Infer the calling frame, skipping the given classes if so provided.
 * Code was derived from a private method found in the JDK Logger class
 *
 * @param skippedClasses the classes to skip
 * @return the frame found, just before the skipped classes (or just before
 * the caller of this method)//from   w  w  w .j  a  va  2  s.co m
 */
public static StackTraceElement getCallingFrame(Class... skippedClasses) {
    // Get the current stack trace.
    StackTraceElement[] stack = (new Throwable()).getStackTrace();

    // Simple case, no classes to skip, just return the caller of the caller
    if (skippedClasses.length == 0) {
        return stack[2];
    }

    // More complex case, return the caller, just before the skipped classes
    // First, search back to a method in the skipped classes, if any
    int ix;
    searchingForSkipped: for (ix = 0; ix < stack.length; ix++) {
        StackTraceElement frame = stack[ix];
        String cname = frame.getClassName();

        for (Class skipped : skippedClasses) {
            if (cname.equals(skipped.getName())) {
                break searchingForSkipped;
            }
        }
    }

    // Now search for the first frame before the skipped classes
    searchingForNonSkipped: for (; ix < stack.length; ix++) {
        StackTraceElement frame = stack[ix];
        String cname = frame.getClassName();

        for (Class skipped : skippedClasses) {
            if (cname.equals(skipped.getName())) {
                continue searchingForNonSkipped;
            }
        }

        // We've found the relevant frame.
        return frame;
    }

    // We haven't found a suitable frame
    return null;
}

From source file:com.seleritycorp.common.base.logging.LogFactory.java

/**
 * Gets the permanent Log for a given Class
 *
 * <p>Permanent logs are meant to be kept around forever. Use them only for
 * messages that are worth to keep around forever.
 *
 * <p>Messages sent to the returned Log are converted to a single line.
 *
 * @param clazz The clazz to get the {@code Log} instance for.
 * @return The permanent log for {@code clazz}
 * @exception LogConfigurationException if no suitable {@code Log} instance
 *            can be returned.//from   ww w.  j  a  v a2s  . c  o  m
 */
public static Log getPermanentLog(@SuppressWarnings("rawtypes") Class clazz) throws LogConfigurationException {
    return getPermanentLog(clazz.getName());
}

From source file:com.greenline.hrs.admin.util.db.SchemaExport.java

public static String exportMySQL(Class type) {
    if (type == null) {
        return StringUtils.EMPTY;
    }//  w  w w  .  ja  va 2 s. c o m
    String tableName = type.getName().substring(type.getName().lastIndexOf('.') + 1);
    tableName = StringUtil.underscoreName(tableName);
    StringBuilder sb = new StringBuilder();
    sb.append("DROP TABLE IF EXISTS `" + tableName + "`;" + LINUX_LINE_DELIMITER);
    sb.append("CREATE TABLE `");
    sb.append(tableName);
    sb.append("` (" + LINUX_LINE_DELIMITER + LINUX_LINE_DELIMITER);
    sb.append("`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '',");
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            sb.append("`" + StringUtil.underscoreName(field.getName()) + "` "
                    + JdbcColumnUtil.getColumeTypeDesc(field.getType()) + " NOT NULL COMMENT '',"
                    + LINUX_LINE_DELIMITER);
        }
    }
    sb.append("PRIMARY KEY (`id`)" + LINUX_LINE_DELIMITER);
    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
    return sb.toString();
}

From source file:net.eledge.android.toolkit.db.internal.SQLBuilder.java

public static String getTableName(Class<?> clazz) {
    Entity entity = clazz.getAnnotation(Entity.class);
    return StringUtils.defaultIfBlank(entity.name(), clazz.getName().toLowerCase(Locale.ENGLISH));
}

From source file:com.luna.common.utils.ReflectUtils.java

public static Class<?> getOriginalClass(Class<?> clz) {
    Class<?> superclass = clz;

    while (superclass.getName().indexOf("_$$_jvst") != -1) {
        superclass = superclass.getSuperclass();

        if (superclass == null) {
            return superclass;
        }/*from w  ww.  j a v a  2s  .  c  o m*/
    }

    return superclass;
}

From source file:gr.abiss.calipso.domain.i18n.AbstractI18nResourceTranslatable.java

/**
 * Returns the Class name without the package (if any)
 * @param c the class//from  www  .j  a  v a  2 s.  co  m
 * @return the name without the package prefix
 */
protected static String getShortName(Class c) {
    String className = c.getName();
    int firstChar = className.lastIndexOf('.') + 1;
    if (firstChar > 0) {
        className = className.substring(firstChar);
    }
    return className;
}