public boolean isFilter() { if (_beanClazz != null) { return ReflectionUtils.is(_beanClazz, Filter.class); } return false; }
public static boolean isAnnotationPresent(final AnnotatedElement element, final Class<? extends Annotation> annotationClass) { return getAnnotation(element, annotationClass) != null; } }
public boolean isRenderer() { if (_beanClazz != null) { return ReflectionUtils.isAnnotationPresent(_beanClazz, RendererBean.class) && ReflectionUtils.is(_beanClazz, Renderer.class); } return false; }
@Override public Object fromString(final Class<?> type, final String str) { if (ReflectionUtils.isString(type)) { return str; if (ReflectionUtils.isBoolean(type)) { return Boolean.valueOf(str); if (ReflectionUtils.isCharacter(type)) { return Character.valueOf(str.charAt(0)); if (ReflectionUtils.isInteger(type)) { return Integer.valueOf(str); if (ReflectionUtils.isLong(type)) { return Long.valueOf(str); if (ReflectionUtils.isByte(type)) { return Byte.valueOf(str); if (ReflectionUtils.isShort(type)) { return Short.valueOf(str); if (ReflectionUtils.isDouble(type)) { return Double.valueOf(str); if (ReflectionUtils.isFloat(type)) { return Float.valueOf(str); if (ReflectionUtils.is(type, Class.class)) {
if (isByte(thisClass) && isByte(ofThatType)) { return true; if (isCharacter(thisClass) && isCharacter(ofThatType)) { return true; if (isBoolean(thisClass) && isBoolean(ofThatType)) { return true; if (isShort(thisClass) && isShort(ofThatType)) { return true; if (isInteger(thisClass) && isInteger(ofThatType)) { return true; if (isLong(thisClass) && isLong(ofThatType)) { return true; if (isFloat(thisClass) && isFloat(ofThatType)) { return true; if (isDouble(thisClass) && isDouble(ofThatType)) { return true;
if (ReflectionUtils.isInteger(type)) { return Integer.parseInt(text); if (ReflectionUtils.isDouble(type)) { return Double.parseDouble(text); if (ReflectionUtils.isLong(type)) { return Long.parseLong(text); if (ReflectionUtils.isByte(type)) { return Byte.parseByte(text); if (ReflectionUtils.isFloat(type)) { return Float.parseFloat(text); if (ReflectionUtils.isShort(type)) { return Short.parseShort(text); if (ReflectionUtils.is(type, Percentage.class)) { return Percentage.parsePercentage(text); if (ReflectionUtils.isNumber(type)) {
private Object toOperand(final Object value) { final Class<?> dataType = inputColumn.getDataType(); if (ReflectionUtils.isBoolean(dataType)) { return ConvertToBooleanTransformer.transformValue(value, ConvertToBooleanTransformer.DEFAULT_TRUE_TOKENS, ConvertToBooleanTransformer.DEFAULT_FALSE_TOKENS); } else if (ReflectionUtils.isDate(dataType)) { return ConvertToDateTransformer.getInternalInstance().transformValue(value); } else if (ReflectionUtils.isNumber(dataType)) { return ConvertToNumberTransformer.transformValue(value); } else if (ReflectionUtils.isString(dataType)) { return ConvertToStringTransformer.transformValue(value); } else { return value; } }
if (propertyDescriptor.isInputColumn()) { widgetClass = MultipleInputColumnsPropertyWidget.class; } else if (ReflectionUtils.isString(type)) { widgetClass = MultipleStringPropertyWidget.class; } else if (type == Dictionary.class) { } else if (type == char.class) { widgetClass = MultipleCharPropertyWidget.class; } else if (ReflectionUtils.isNumber(type)) { widgetClass = MultipleNumberPropertyWidget.class; } else { } else if (ReflectionUtils.isCharacter(type)) { widgetClass = SingleCharacterPropertyWidget.class; } else if (ReflectionUtils.isString(type)) { widgetClass = SingleStringPropertyWidget.class; } else if (ReflectionUtils.isBoolean(type)) { widgetClass = SingleBooleanPropertyWidget.class; } else if (ReflectionUtils.isNumber(type)) { widgetClass = SingleNumberPropertyWidget.class; } else if (ReflectionUtils.isDate(type)) { widgetClass = SingleDatePropertyWidget.class; } else if (type == Dictionary.class) { } else if (type.isEnum()) { widgetClass = SingleEnumPropertyWidget.class; } else if (ReflectionUtils.is(type, Resource.class)) { widgetClass = SingleResourcePropertyWidget.class; } else if (type == File.class) {
private Number convertToNumber(final String stringValue) { if (StringUtils.isNullOrEmpty(stringValue)) { return null; } final Class<?> type = getPropertyDescriptor().getBaseType(); try { final Number number = _numberFormat.parse(stringValue); if (type != Number.class) { if (ReflectionUtils.isInteger(type)) { return Integer.valueOf(number.intValue()); } else if (ReflectionUtils.isLong(type)) { return Long.valueOf(number.longValue()); } else if (ReflectionUtils.isDouble(type)) { return Double.valueOf(number.doubleValue()); } else if (ReflectionUtils.isShort(type)) { return Short.valueOf(number.shortValue()); } else if (ReflectionUtils.isByte(type)) { return Byte.valueOf(number.byteValue()); } else if (ReflectionUtils.isFloat(type)) { return Float.valueOf(number.floatValue()); } } return number; } catch (final ParseException e) { throw new IllegalStateException("Cannot parse to number: " + stringValue); } }
if (ReflectionUtils.is(type, List.class)) { return _arrayConverter.fromString(type, serializedForm); if (ReflectionUtils.is(type, Map.class)) { return _mapStringToStringConverter.fromString(type, serializedForm); final Convertable convertable = ReflectionUtils.getAnnotation(type, Convertable.class); if (convertable != null) { try { final Class<? extends Converter<?>> converterClass = convertable.value(); @SuppressWarnings("unchecked") final Converter<Object> converter = (Converter<Object>) ReflectionUtils.newInstance(converterClass); return converter.fromString(type, serializedForm); } catch (final Exception e) {
public UserDatabaseDriver loadDriver() throws IllegalStateException { if (!_loaded) { final ClassLoader driverClassLoader = ClassLoaderUtils.createClassLoader(_files); final Class<?> loadedClass; try { loadedClass = Class.forName(_driverClassName, true, driverClassLoader); } catch (final Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IllegalStateException("Could not load driver class", e); } logger.info("Loaded class: {}", loadedClass.getName()); if (ReflectionUtils.is(loadedClass, Driver.class)) { _driverInstance = (Driver) ReflectionUtils.newInstance(loadedClass); _registeredDriver = new DriverWrapper(_driverInstance); try { DriverManager.registerDriver(_registeredDriver); } catch (final SQLException e) { throw new IllegalStateException("Could not register driver", e); } } else { throw new IllegalStateException("Class is not a Driver class: " + _driverClassName); } _loaded = true; } return this; }
protected AnnotationBasedRendererBeanDescriptor(final Class<R> rendererClass) throws DescriptorException { super(rendererClass, true); final RendererBean rendererBeanAnnotation = ReflectionUtils.getAnnotation(rendererClass, RendererBean.class); if (rendererBeanAnnotation == null) { throw new DescriptorException(rendererClass + " doesn't implement the RendererBean annotation"); } _renderingFormat = rendererBeanAnnotation.value(); if (_renderingFormat == null || _renderingFormat.isInterface() || Modifier .isAbstract(_renderingFormat.getModifiers())) { throw new DescriptorException("Rendering format (" + _renderingFormat + ") is not a non-abstract class"); } _formatOutputType = ReflectionUtils.getTypeParameter(_renderingFormat, RenderingFormat.class, 0); logger.debug("Found format output type: {}", _formatOutputType); if (_formatOutputType == null) { throw new DescriptorException("Could not determine output type of rendering format: " + _renderingFormat); } @SuppressWarnings("unchecked") final Class<? extends Renderable> rendererInputType = (Class<? extends Renderable>) ReflectionUtils.getTypeParameter(rendererClass, Renderer.class, 0); _rendererInputType = rendererInputType; logger.debug("Found renderer input type: {}", _rendererInputType); _rendererOutputType = ReflectionUtils.getTypeParameter(rendererClass, Renderer.class, 1); logger.debug("Found renderer output type: {}", _rendererOutputType); if (_rendererOutputType == null) { throw new DescriptorException("Could not determine output type of renderer: " + rendererClass); } if (!ReflectionUtils.is(_rendererOutputType, _formatOutputType)) { throw new DescriptorException("The renderer output type (" + _rendererOutputType + ") is not a valid instance or sub-class of format output type (" + _formatOutputType + ")"); } }
@SuppressWarnings("unchecked") private static <I extends Renderable, O> Renderer<I, O> instantiate(final RendererBeanDescriptor<?> descriptor) { final Class<? extends Renderer<?, ?>> componentClass = descriptor.getComponentClass(); final Renderer<?, ?> renderer = ReflectionUtils.newInstance(componentClass); return (Renderer<I, O>) renderer; }
public static int getHierarchyDistance(final Class<?> subtype, final Class<?> supertype) throws IllegalArgumentException { assert subtype != null; assert supertype != null; if (!ReflectionUtils.is(subtype, supertype)) { throw new IllegalArgumentException( "Not a valid subtype of " + supertype.getName() + ": " + subtype.getName()); } if (supertype.isInterface()) { return getInterfaceHierarchyDistance(subtype, supertype); } else { return getClassHierarchyDistance(subtype, supertype); } }
@SuppressWarnings("unchecked") @Override public <T extends JobContext> JobEngine<? extends T> getJobEngine(Class<T> jobContext) { final Collection<JobEngine<?>> jobEngines = getJobEngines(); for (JobEngine<?> jobEngine : jobEngines) { final Class<?> jobEngineTypeParameter = ReflectionUtils.getTypeParameter(jobEngine.getClass(), JobEngine.class, 0); if (ReflectionUtils.is(jobContext, jobEngineTypeParameter)) { return (JobEngine<? extends T>) jobEngine; } } return null; }