List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:adalid.core.XS1.java
static Field getField(boolean log, String role, String name, Class<?> type, Class<?> top, Class<?>... validTypes) { String string;// www.ja v a 2s. co m if (StringUtils.isBlank(role)) { string = "field role is missing or invalid"; if (log) { logFieldErrorMessage(role, name, type, null, string); } return null; } if (StringUtils.isBlank(name)) { string = "field name is missing or invalid"; if (log) { logFieldErrorMessage(role, name, type, null, string); } return null; } if (type == null) { string = "class is missing or invalid"; if (log) { logFieldErrorMessage(role, name, type, null, string); } return null; } Field field = getField(name, type, top); if (field == null) { string = "field " + name + " not in class"; if (log) { logFieldErrorMessage(role, name, type, field, string); } return null; } int modifiers = field.getModifiers(); if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)) { string = "field " + name + " has static and/or final modifier"; if (log) { logFieldErrorMessage(role, name, type, field, string); } return null; } int length = validTypes == null ? 0 : validTypes.length; if (length < 1) { return field; } Class<?> ft = getTrueType(field.getType()); String[] strings = new String[length]; int i = 0; for (Class<?> vt : validTypes) { if (vt.isAssignableFrom(ft)) { return field; } strings[i++] = vt.getSimpleName(); } string = "type of " + name + " is not " + StringUtils.join(strings, " or "); if (log) { logFieldErrorMessage(role, name, type, field, string); } return null; }
From source file:com.exxonmobile.ace.hybris.storefront.servlets.util.FilterSpringUtil.java
/** * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is. *//*from ww w. ja v a2 s .co m*/ public static <T> T getSpringBean(final ServletContext servletContext, final String beanName, final Class<T> beanClass) { T ret = null; final WebApplicationContext appContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); if (StringUtils.isNotBlank(beanName)) { try { ret = (T) appContext.getBean(beanName); } catch (final NoSuchBeanDefinitionException ex) { LOG.warn("No bean found with the specified name. Trying to resolve bean using type..."); } } if (ret == null) { if (beanClass == null) { LOG.warn("No bean could be resolved. Reason: No type specified."); } else { final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass); if (beansOfType != null && !beansOfType.isEmpty()) { if (beansOfType.size() > 1) { LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName() + ". Returning the first one found."); } ret = beansOfType.values().iterator().next(); } } } return ret; }
From source file:com.acc.filter.FilterSpringUtil.java
/** * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is. *///from www . j a v a 2 s .co m public static <T> T getSpringBean(final ServletContext servletContext, final String beanName, final Class<T> beanClass) { T ret = null; final WebApplicationContext appContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); if (StringUtils.isNotBlank(beanName)) { try { ret = (T) appContext.getBean(beanName); } catch (final NoSuchBeanDefinitionException nsbde) { LOG.warn("No bean found with the specified name. Trying to resolve bean using type..."); } } if (ret == null) { if (beanClass == null) { LOG.warn("No bean could be resolved. Reason: No type specified."); } else { final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass); if (beansOfType != null && !beansOfType.isEmpty()) { if (beansOfType.size() > 1) { LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName() + ". Returning the first one found."); } ret = beansOfType.values().iterator().next(); } } } return ret; }
From source file:com.github.dactiv.common.utils.ReflectionUtils.java
/** * ??, Class?. , Object.class.??/*from ww w .ja va 2 s . c o m*/ * * <pre> * * public UserDao extends HibernateDao<User,Long> * </pre> * * @param targetClass * ???Class * @param index * ????? * * @return class */ public static Class getSuperClassGenricType(final Class targetClass, final int index) { Assert.notNull(targetClass, "targetClass?"); Type genType = targetClass.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(targetClass.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { logger.warn("Index: " + index + ", Size of " + targetClass.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(targetClass.getSimpleName() + " not set the actual Class targetClassn superclass generic parameter"); return Object.class; } return (Class) params[index]; }
From source file:jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet.java
private static String prettyName(Class<?> clazz) { StringBuilder postfix = new StringBuilder(); if (Proxy.isProxyClass(clazz)) { return "<em>Proxy Implementation (detailed information unavailable)</em>"; }/*from ww w.j av a 2s . co m*/ if (clazz.isArray()) { clazz = clazz.getComponentType(); appendGenericsInfo(clazz, postfix); postfix.append("[]"); } else { appendGenericsInfo(clazz, postfix); } String n = clazz.getName(); String sn = clazz.getSimpleName(); return "<span class=\"info\">" + sn + postfix + "<span>" + n + postfix + "</span></span>"; }
From source file:com.aliyun.odps.utils.StringUtils.java
/** * Print a log message for starting up and shutting down * * @param clazz/*from w w w. j a v a 2 s . c o m*/ * the class of the server * @param args * arguments * @param LOG * the target log object */ public static void startupShutdownMessage(Class<?> clazz, String[] args, final org.apache.commons.logging.Log LOG) { final String hostname = getHostname(); final String classname = clazz.getSimpleName(); LOG.info(toStartupShutdownString("STARTUP_MSG: ", new String[] { "Starting " + classname, " host = " + hostname, " args = " + Arrays.asList(args) })); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[] { "Shutting down " + classname + " at " + hostname })); } }); }
From source file:strat.mining.stratum.proxy.configuration.ConfigurationManager.java
/** * Return the version of the program//w w w. j a v a 2 s. co m * * @return */ public static String getVersion() { if (version == null) { version = "Dev"; Class<Launcher> clazz = Launcher.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); if (classPath.startsWith("jar")) { // Class not from JAR String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; try { Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Attributes attr = manifest.getMainAttributes(); version = attr.getValue("Implementation-Version"); } catch (IOException e) { // Do nothing, just return Unknown as version version = "Unknown"; } } } return version; }
From source file:com.amazonaws.hal.client.ConversionUtil.java
private static Object convertFromNull(Type type) { if (!(type instanceof Class)) { return null; }/*from w ww.j av a 2s. com*/ Class<?> clazz = (Class) type; if (!clazz.isPrimitive()) { return null; } if (int.class.isAssignableFrom(clazz)) { return 0; } else if (long.class.isAssignableFrom(clazz)) { return 0L; } else if (short.class.isAssignableFrom(clazz)) { return 0; } else if (double.class.isAssignableFrom(clazz)) { return 0.0; } else if (float.class.isAssignableFrom(clazz)) { return 0.0F; } else if (boolean.class.isAssignableFrom(clazz)) { return Boolean.FALSE; } else if (char.class.isAssignableFrom(clazz)) { return 0; } else if (byte.class.isAssignableFrom(clazz)) { return 0; } else { throw new RuntimeException("Unexpected primitive type: " + clazz.getSimpleName()); } }
From source file:com.espertech.esper.filter.FilterSpecCompiler.java
private static void throwConversionError(Class fromType, Class toType, String propertyName) throws ExprValidationException { String text = "Implicit conversion from datatype '" + fromType.getSimpleName() + "' to '" + toType.getSimpleName() + "' for property '" + propertyName + "' is not allowed (strict filter type coercion)"; throw new ExprValidationException(text); }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Object convertToObject(Class<?> clazz, Object obj, MessageSourceAccessor messageSourceAccessor) { try {/*w ww .jav a2 s . com*/ return convertTo(clazz, obj); } catch (RuntimeException e) { if (clazz.isEnum()) { Object o; try { // Method[] methods = clazz.getMethods(); Method fromValueMethod = clazz.getMethod("fromValue", String.class); final String oStr = String.valueOf(obj); o = fromValueMethod.invoke(null, oStr); return o; } catch (Exception e1) { } } if (messageSourceAccessor != null) { String message = messageSourceAccessor.getMessage(s_message, new Object[] { obj.getClass().getSimpleName(), clazz.getSimpleName() }); throw new ValidationException(message); } else { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } } }