List of usage examples for org.springframework.util ClassUtils isAssignable
public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType)
From source file:io.dyn.core.handler.Handlers.java
@SuppressWarnings({ "unchecked" })
public static <T> T findFirstArgOfType(Class<? extends T> clazz, Object... args) {
for (Object o : args) {
if (null != o && ClassUtils.isAssignable(clazz, o.getClass())) {
return (T) o;
}/*from w ww.j av a2 s.c o m*/
}
return null;
}
From source file:org.lightadmin.core.persistence.metamodel.PersistentPropertyType.java
public static PersistentPropertyType forPersistentProperty(PersistentProperty persistentProperty) { final Class<?> attrType = persistentProperty.getType(); if (persistentProperty.isAnnotationPresent(Embedded.class) || persistentProperty.isAnnotationPresent(EmbeddedId.class)) { return PersistentPropertyType.EMBEDDED; }//from w ww . j av a 2 s . co m if (persistentProperty.isAssociation()) { if (persistentProperty.isCollectionLike()) { return PersistentPropertyType.ASSOC_MULTI; } return PersistentPropertyType.ASSOC; } if (persistentProperty.isMap()) { return PersistentPropertyType.MAP; } if (ClassUtils.isAssignable(Enum.class, attrType)) { return ENUM; } if (forType(attrType) == STRING && persistentProperty.isAnnotationPresent(FileReference.class)) { return PersistentPropertyType.FILE; } if (isOfDateType(persistentProperty)) { return DATE; } if (isOfTimeType(persistentProperty)) { return TIME; } if (isOfDateTimeType(persistentProperty)) { return DATE_TIME; } return forType(attrType); }
From source file:org.sarons.spring4me.web.widget.bind.support.WidgetConfigMethodArgumentResolver.java
public boolean supportsParameter(MethodParameter parameter) { return ClassUtils.isAssignable(WidgetConfig.class, parameter.getParameterType()); }
From source file:org.lightadmin.core.util.DomainConfigurationUtils.java
public static boolean isSuperClassBasedConfigurationCandidate(Class clazz) { return ClassUtils.isAssignable(AdministrationConfiguration.class, clazz); }
From source file:org.cloudfoundry.caldecott.server.converter.ByteBufferHttpMessageConverter.java
@Override public boolean supports(Class<?> clazz) { return ClassUtils.isAssignable(ByteBuffer.class, clazz); }
From source file:biz.deinum.multitenant.validation.AbstractClassMappingValidator.java
/** * Check all the mappings assigned to this validator. If one of the classes * is assignable to this object return true. * //from w w w . j av a 2 s.c o m * @return <code>true</code> when supported, <code>false</code> otherwise */ @SuppressWarnings("rawtypes") public final boolean supports(final Class clazz) { final Iterator keyIter = this.mappings.keySet().iterator(); boolean supports = false; while (keyIter.hasNext() && !supports) { final Class targetClazz = (Class) keyIter.next(); supports = ClassUtils.isAssignable(targetClazz, clazz); } return supports; }
From source file:org.jdal.beans.SimpleTypeConverter.java
/** * {@inheritDoc}/*from ww w . j av a2 s .c o m*/ */ @SuppressWarnings("unchecked") @Override public <T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParameter methodParam) throws TypeMismatchException { T convertedValue = null; try { convertedValue = super.convertIfNecessary(value, requiredType, methodParam); } catch (TypeMismatchException tme) { // Try Object to String conversion if (ClassUtils.isAssignable(String.class, requiredType)) { if (value != null) { PropertyEditor pe = findCustomEditor(value.getClass(), null); if (pe != null) { pe.setValue(value); return (T) pe.getAsText(); } else { // Object to String return (T) value.toString(); } } else { // null to String return (T) ""; } } else { throw tme; } } return convertedValue; }
From source file:biz.deinum.multitenant.validation.AbstractClassMappingValidator.java
/** * Gets the fieldname from the configured map. * @param target/* www .ja v a2 s . co m*/ * @return */ protected final String getFieldName(final Object target) { String fieldName = null; for (final Entry<Class<?>, String> entry : this.mappings.entrySet()) { if (ClassUtils.isAssignable(entry.getKey(), target.getClass())) { fieldName = entry.getValue(); break; } } if (fieldName == null) { throw new IllegalStateException("Cannot find fieldname for class " + target.getClass().getName() + ". Class is not compatible with declared types. [" + this.mappings + "]"); } return fieldName; }
From source file:io.dyn.core.handler.Handlers.java
@SuppressWarnings({ "unchecked" })
public static void invoke(final Object handler, final Object... args) {
if (handler instanceof io.dyn.core.handler.Handler) {
int argc = args.length;
Object argument = (argc > 0 ? args[0] : null);
Object[] otherArgs = (argc > 1 ? Arrays.copyOfRange(args, 1, args.length - 1) : new Object[0]);
((io.dyn.core.handler.Handler) handler).handle(argument, otherArgs);
return;/*w w w .j av a2 s. co m*/
}
if (Sys.isGroovyPresent()) {
if (handler instanceof groovy.lang.Closure) {
groovy.lang.Closure cl = ((groovy.lang.Closure) handler);
Class[] paramTypes = cl.getParameterTypes();
if (paramTypes.length == 0) {
cl.call();
} else {
Object[] params = new Object[paramTypes.length];
if (null != args && args.length > 0) {
for (int i = 0; i < params.length; i++) {
if (null != args[i] && !ClassUtils.isAssignable(args[i].getClass(), paramTypes[i])) {
params[i] = Sys.DEFAULT_CONVERSION_SERVICE.convert(args[i], paramTypes[i]);
} else {
params[i] = args[i];
}
}
cl.call(params);
} else {
cl.call(args);
}
}
return;
}
}
/*
if (Sys.isScalaPresent()) {
if (handler instanceof scala.Function1) {
((scala.Function1) handler).apply(argument);
return;
}
}
*/
/*
if (Sys.isClojurePresent()) {
if (handler instanceof clojure.lang.IFn) {
((clojure.lang.IFn) handler).invoke(argument);
return;
}
}
*/
if (handler instanceof Runnable) {
((Runnable) handler).run();
}
}
From source file:org.zht.framework.util.ZBeanUtil.java
private static void copy(Object source, Object target, Boolean ignorNull, Class<?> editable, String... ignoreProperties) throws BeansException { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); Class<?> actualEditable = target.getClass(); if (editable != null) { if (!editable.isInstance(target)) { throw new IllegalArgumentException("Target class [" + target.getClass().getName() + "] not assignable to Editable class [" + editable.getName() + "]"); }/*from w ww .j a v a 2 s. co m*/ actualEditable = editable; } PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null); for (PropertyDescriptor targetPd : targetPds) { Method writeMethod = targetPd.getWriteMethod(); if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null) { Method readMethod = sourcePd.getReadMethod(); if (readMethod != null && ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) { try { if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Object value = readMethod.invoke(source); if (ignorNull != null && ignorNull) { if (value != null && (!"[]".equals(value.toString()))) {// ? if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(target, value); } } else { if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(target, value); } } catch (Throwable ex) { throw new FatalBeanException( "Could not copy property '" + targetPd.getName() + "' from source to target", ex); } } } } } }