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:net.servicefixture.converter.ObjectConverter.java

/**
 * Use the jexl expression to get the object from the
 * <code>GlobalContext</code>.
 * //  w  w  w  .ja v  a  2 s. co  m
 * Note: the expression must follow <testTableKey>. <request[i]>|
 * <response>.* pattern.
 * 
 * Throws FixtureException if the destType is not assignable from the object
 * type.
 */
private static Object evaluateJexlToken(String expression, Class<?> destType, boolean checkType) {
    Object result = JexlEvaluator.evaluate(expression, GlobalContext.getGlobalJexlContext());

    if (result != null && checkType) {
        Class<?> resultType = result.getClass();
        if (!destType.isAssignableFrom(resultType) && !(destType.isPrimitive()
                && resultType.getName().equalsIgnoreCase("java.lang." + destType.getName()))) {
            throw new ServiceFixtureException("Expression " + expression + " returns a object("
                    + resultType.getName() + ") that is not " + destType.getName() + " type.");
        }
    }
    return result;
}

From source file:com.manydesigns.portofino.utils.Reflections.java

public static Class<?> getUserClass(Object instance) {
    // Assert.notNull(instance, "Instance must not be null");
    Class clazz = instance.getClass();
    if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && !Object.class.equals(superClass)) {
            return superClass;
        }//from ww w.jav  a2s .  c  o m
    }
    return clazz;

}

From source file:com.netradius.hibernate.support.HibernateUtil.java

/**
 * Initializes hibernate and related resources.
 *
 * @param classes the annotated hibernate bean classes to load
 *///from   w  ww . j av  a2 s.c o  m
public static void init(Class<?>... classes) {
    if (sessionFactory == null) {
        log.debug("Initializing hibernate.");
        Configuration config = new Configuration()
                .setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect")
                .setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver")
                .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:testdb")
                .setProperty("hibernate.connection.username", "sa")
                .setProperty("hibernate.connection.password", "")
                .setProperty("hibernate.connection.pool_size", "1")
                .setProperty("hibernate.connection.autocommit", "false")
                .setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider")
                .setProperty("hibernate.hbm2ddl.auto", "create-drop").setProperty("hibernate.show_sql", "false")
                .setProperty("hibernate.current_session_context_class", "thread");
        for (Class<?> clazz : classes) {
            log.debug("Loading class " + clazz.getName());
            config.addAnnotatedClass(clazz);
        }
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
                .buildServiceRegistry();
        sessionFactory = config.buildSessionFactory(serviceRegistry);
        log.debug("Hibernate initialized.");
    }
}

From source file:com.psiphon3.psiphonlibrary.WebViewProxySettings.java

@TargetApi(Build.VERSION_CODES.KITKAT) // for android.util.ArrayMap methods
@SuppressWarnings("rawtypes")
private static boolean setWebkitProxyLollipop(Context appContext, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port + "");
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port + "");
    try {//  ww w.  j  a v  a 2s  .  c om
        Class applictionClass = Class.forName("android.app.Application");
        Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk");
        mLoadedApkField.setAccessible(true);
        Object mloadedApk = mLoadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers");
        mReceiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = receiver.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        MyLog.d("Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (NoSuchFieldException e) {
        MyLog.d("Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (IllegalAccessException e) {
        MyLog.d("Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (NoSuchMethodException e) {
        MyLog.d("Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (InvocationTargetException e) {
        MyLog.d("Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    }
    return false;
}

From source file:com.fizzed.rocker.compiler.RockerUtil.java

public static String unqualifiedClassName(Class<?> type) {
    String name = type.getName();
    if (name != null && name.lastIndexOf('.') > 0) {
        name = name.substring(name.lastIndexOf('.') + 1); // Map$Entry
        name = name.replace('$', '.'); // Map.Entry
    }//  w  ww .  ja  va  2 s.  co  m
    return name;
}

From source file:ml.shifu.shifu.util.ClassUtils.java

public static Method getFirstMethodWithName(String name, Class<?> clazz) {
    String key = clazz.getName() + "#" + name;
    Method cacheMethod = METHOD_CACHE.get(key);
    if (cacheMethod != null) {
        return cacheMethod;
    }/*from w  ww  . jav a  2  s . c o  m*/
    List<Method> allMethods = ClassUtils.getAllMethods(clazz);
    Method method = null;
    for (Method f : allMethods) {
        if (f.getName().equals(name)) {
            method = f;
            break;
        }
    }
    return method;
}

From source file:Main.java

/**
 * Format a string buffer containing the Class, Interfaces, CodeSource, and
 * ClassLoader information for the given object clazz.
 * //from   w  w w  . j ava 2 s.c  o  m
 * @param clazz
 *          the Class
 * @param results -
 *          the buffer to write the info to
 */
public static void displayClassInfo(Class clazz, StringBuffer results) {
    // Print out some codebase info for the clazz
    ClassLoader cl = clazz.getClassLoader();
    results.append("\n");
    results.append(clazz.getName());
    results.append("(");
    results.append(Integer.toHexString(clazz.hashCode()));
    results.append(").ClassLoader=");
    results.append(cl);
    ClassLoader parent = cl;
    while (parent != null) {
        results.append("\n..");
        results.append(parent);
        URL[] urls = getClassLoaderURLs(parent);
        int length = urls != null ? urls.length : 0;
        for (int u = 0; u < length; u++) {
            results.append("\n....");
            results.append(urls[u]);
        }
        if (parent != null)
            parent = parent.getParent();
    }
    CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource();
    if (clazzCS != null) {
        results.append("\n++++CodeSource: ");
        results.append(clazzCS);
    } else
        results.append("\n++++Null CodeSource");

    results.append("\nImplemented Interfaces:");
    Class[] ifaces = clazz.getInterfaces();
    for (int i = 0; i < ifaces.length; i++) {
        Class iface = ifaces[i];
        results.append("\n++");
        results.append(iface);
        results.append("(");
        results.append(Integer.toHexString(iface.hashCode()));
        results.append(")");
        ClassLoader loader = ifaces[i].getClassLoader();
        results.append("\n++++ClassLoader: ");
        results.append(loader);
        ProtectionDomain pd = ifaces[i].getProtectionDomain();
        CodeSource cs = pd.getCodeSource();
        if (cs != null) {
            results.append("\n++++CodeSource: ");
            results.append(cs);
        } else
            results.append("\n++++Null CodeSource");
    }
}

From source file:com.agileEAP.ireport.utils.Reflections.java

public static Class<?> getUserClass(Object instance) {
    Assert.notNull(instance, "Instance must not be null");
    Class clazz = instance.getClass();
    if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && !Object.class.equals(superClass)) {
            return superClass;
        }/*from  w  ww .ja  v  a 2 s. co m*/
    }
    return clazz;

}

From source file:de.xwic.appkit.webbase.toolkit.util.BundleAccessor.java

/**
 * Returns the description of the given filed and class type.
 * /*from ww w . j  a v  a2  s.  c  o  m*/
 * @param clazz
 * @param langId
 * @param fieldName
 * @return
 */
public static String getBundleStringByType(Class<? extends IEntity> clazz, String langId, String fieldName) {
    Setup setup = ConfigurationManager.getSetup();

    Bundle edBundle = null;
    try {
        EntityDescriptor ed = setup.getEntityDescriptor(clazz.getName());
        edBundle = ed.getDomain().getBundle(langId);
    } catch (ConfigurationException e) {
        log.error(e);
        return "No bundle found for class: " + clazz;
    }
    return fieldName != null ? edBundle.getString(clazz.getName() + "." + fieldName)
            : edBundle.getString(clazz.getName());
}

From source file:org.jdbcluster.dao.Dao.java

/**
 * caches dao configurations//w  w w . ja v  a2s . c  om
 * @param daoClass class of dao object
 * @return map element
 */
private static HashMap<String, String> putCacheMap(Class<?> daoClass) {
    DaoConfig daoConfig = Dao.getDaoConfig();
    if (daoConfig == null)
        throw new ConfigurationException("No Dao configuration present. Call Dao.setDaoConfig first");
    String daoId = daoConfig.getDaoId(daoClass.getName());
    HashMap<String, String> hm = new HashMap<String, String>();
    classToPropsMap.put(daoClass, hm);

    String[] props = daoConfig.getPropertyName(daoId);
    for (String prop : props) {
        String value = daoConfig.getPropertieValue(daoId, prop);
        hm.put(prop, value);
    }
    return hm;
}