List of usage examples for java.lang Class getName
public String getName()
From source file:Main.java
public static String getType(Class<?> paramClass) { if (paramClass.isArray()) { return "[" + getDesc(paramClass.getComponentType()); }/*from w w w. ja va 2 s. c o m*/ if (!paramClass.isPrimitive()) { return paramClass.getName().replaceAll("\\.", "/"); } return getPrimitiveLetter(paramClass); }
From source file:ReflectionHelper.java
@SuppressWarnings("unchecked") public static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) { try {//from w w w . j a v a2 s . co m Method m = annotation.getClass().getMethod(parameterName); Object o = m.invoke(annotation); if (o.getClass().getName().equals(type.getName())) { return (T) o; } else { String msg = "Wrong parameter type. Expected: " + type.getName() + " Actual: " + o.getClass().getName(); throw new RuntimeException(msg); } } catch (NoSuchMethodException e) { String msg = "The specified annotation defines no parameter '" + parameterName + "'."; throw new RuntimeException(msg, e); } catch (IllegalAccessException e) { String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName(); throw new RuntimeException(msg, e); } catch (InvocationTargetException e) { String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName(); throw new RuntimeException(msg, e); } }
From source file:Main.java
public static ActivityManager.RunningServiceInfo getServiceInfo(Context context, Class<? extends Service> cls) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo info : manager.getRunningServices(Integer.MAX_VALUE)) { if (cls.getName().equals(info.service.getClassName())) { return info; }/* ww w. ja v a 2 s . co m*/ } return null; }
From source file:com.jkoolcloud.tnt4j.streams.utils.LoggerUtils.java
/** * Detects used logging framework. Now recognizes these logger frameworks: * <ul>// ww w .j ava2 s . c om * <li>LOG4J</li> * <li>JUL - Java util logging</li> * <li>LOGBACK</li> * <li>SLF4J - may be in combination with any from above</li> * </ul> * * @param logger * logger event sink instance * * @return number containing used logging frameworks describing bits */ public static int detectLogger(EventSink logger) { int loggerMask = 0; Class<?> shc = logger.getSinkHandle().getClass(); if (shc.getName().startsWith("org.apache.log4j.")) { // NON-NLS loggerMask |= LOG4J; } else if (shc.getName().startsWith("ch.qos.logback.")) { // NON-NLS loggerMask |= LOGBACK; } else if (shc.getName().startsWith("java.util.logging.")) { // NON-NLS loggerMask |= JUL; } else if (shc.getName().startsWith("org.slf4j.")) { // NON-NLS loggerMask |= SLF4J; if (shc.getName().equals("org.slf4j.impl.Log4jLoggerAdapter")) { // NON-NLS loggerMask |= LOG4J; } else if (shc.getName().equals("org.slf4j.impl.JDK14LoggerAdapter")) { // NON-NLS loggerMask |= JUL; } else { // TODO: anything else? } } return loggerMask; }
From source file:Main.java
public static boolean isServiceRunning(Class<? extends Service> serviceClass) { ActivityManager manager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; }//from www . j a v a 2s . co m } return false; }
From source file:org.frat.common.converter.ConverterService.java
private static <T, F> BeanCopier getBeanCopierInstance(T source, Class<F> targetClass, Converter converter) { String key = source.getClass().getName() + "#" + targetClass.getName(); BeanCopier beanCopier = CACHED_COPIER_MAP.get(key); if (beanCopier == null) { synchronized (CACHED_COPIER_MAP) { beanCopier = CACHED_COPIER_MAP.get(key); if (beanCopier == null) { beanCopier = TypeAwareBeanCopier.instantiate(source.getClass(), targetClass, converter != null); CACHED_COPIER_MAP.put(key, beanCopier); }/* w w w.j ava2 s . c om*/ } } return beanCopier; }
From source file:net.ontopia.utils.ontojsp.TaglibTagFactory.java
public static String getTagName(Class tagclass) { String classname = tagclass.getName(); for (String tagname : classes.keySet()) { if (classes.get(tagname).equals(classname)) return tagname; }//ww w . j a v a 2 s. com return "unresolved tag: " + classname; }
From source file:Main.java
public static boolean hasActivity(Class<?> clz) { if (null != clz) { if (null != activityStack && activityStack.size() > 0) { for (int i = 0; i < activityStack.size(); i++) { if (activityStack.get(i).getClass().getName().contains(clz.getName())) { return true; }//from w ww . j av a 2 s.com } } } 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. *//* w w w . jav a 2 s .c o m*/ public static boolean isProxyType(Class<?> type) { // As per [Issue#57], should NOT disqualify JDK proxy: /* // 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:app.core.Db.java
public static <T extends PersistentObject> List<T> find(Class<T> entityClass, int firstResultIndex, int maxResults) { return (List<T>) createQuery("from " + entityClass.getName()).setFirstResult(firstResultIndex) .setMaxResults(maxResults).list(); }