本文整理汇总了Java中org.apache.commons.lang.ClassUtils.isAssignable方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.isAssignable方法的具体用法?Java ClassUtils.isAssignable怎么用?Java ClassUtils.isAssignable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.ClassUtils
的用法示例。
在下文中一共展示了ClassUtils.isAssignable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MCRCommand
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public MCRCommand(Method cmd) {
className = cmd.getDeclaringClass().getName();
methodName = cmd.getName();
parameterTypes = cmd.getParameterTypes();
org.mycore.frontend.cli.annotation.MCRCommand cmdAnnotation = cmd
.getAnnotation(org.mycore.frontend.cli.annotation.MCRCommand.class);
help = cmdAnnotation.help();
messageFormat = new MessageFormat(cmdAnnotation.syntax(), Locale.ROOT);
setMethod(cmd);
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> paramtype = parameterTypes[i];
if (ClassUtils.isAssignable(paramtype, Integer.class, true)
|| ClassUtils.isAssignable(paramtype, Long.class, true)) {
messageFormat.setFormat(i, NumberFormat.getIntegerInstance(Locale.ROOT));
} else if (!String.class.isAssignableFrom(paramtype)) {
unsupportedArgException(className + "." + methodName, paramtype.getName());
}
}
int pos = cmdAnnotation.syntax().indexOf("{");
suffix = pos == -1 ? cmdAnnotation.syntax() : cmdAnnotation.syntax().substring(0, pos);
}
示例2: populateBean
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private <T> T populateBean(final T resultBean, List<Object> processedColumns, BeanCells cells) {
for (int i = 0; i < processedColumns.size(); i++) {
final Object fieldValue = processedColumns.get(i);
BeanCell cell = cells.getCell(i);
if (cell == null || cell.getType() == null) {
continue;
}
// ClassUtils handles boxed types
if (fieldValue != null && ClassUtils.isAssignable(fieldValue.getClass(), cell.getType(), true)) {
cell.setValue(resultBean, fieldValue);
} else {
Class<?> fieldValueClass = fieldValue == null ? Object.class : fieldValue.getClass();
TypeConverter<Object, Object> converter
= (TypeConverter<Object, Object>) typeConverterRegistry.getConverter(fieldValueClass, cell.getType());
if (converter == null) {
throw new SuperCsvException(Form.at("No converter registered from type {} to type {}. Add one or fix your CellProcessor-annotations to return the field's type",
fieldValueClass.getName(), cell.getType().getName()));
}
cell.setValue(resultBean, converter.convert(fieldValue));
}
}
return resultBean;
}
示例3: getSortType
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private String getSortType(Class<?> dataTypeClass) {
String sortType = UifConstants.TableToolsValues.STRING;
if (ClassUtils.isAssignable(dataTypeClass, KualiPercent.class)) {
sortType = UifConstants.TableToolsValues.PERCENT;
} else if (ClassUtils.isAssignable(dataTypeClass, KualiInteger.class) || ClassUtils.isAssignable(dataTypeClass,
KualiDecimal.class)) {
sortType = UifConstants.TableToolsValues.CURRENCY;
} else if (ClassUtils.isAssignable(dataTypeClass, Timestamp.class)) {
sortType = "date";
} else if (ClassUtils.isAssignable(dataTypeClass, java.sql.Date.class) || ClassUtils.isAssignable(dataTypeClass,
java.util.Date.class)) {
sortType = UifConstants.TableToolsValues.DATE;
} else if (ClassUtils.isAssignable(dataTypeClass, Number.class)) {
sortType = UifConstants.TableToolsValues.NUMERIC;
}
return sortType;
}
示例4: call
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* Handle {@link Call}-annotated methods.
* @param pjp The wrapped method
* @return The result of the service call as configured by {@link Call}.
* @throws Throwable No exception/error is handled in aspect.
*/
@Around("@annotation(org.talend.daikon.annotation.Call)")
public Object call(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
final Call callAnnotation = AnnotationUtils.getAnnotation(m, Call.class);
if (callAnnotation != null) {
final Object[] args = pjp.getArgs();
if (!callAnnotation.using().equals(DefaultHystrixCommand.class)) {
if (!ClassUtils.isAssignable(callAnnotation.service(), DefaultService.class) || StringUtils.isEmpty(callAnnotation.operation())) {
LOGGER.warn("Method '{}' use custom invocation but also sets service and operation name", m.getName());
}
return handleCustomExecution(callAnnotation, args);
} else {
return handleServiceForward(callAnnotation, args);
}
}
return pjp.proceed();
}
示例5: addContainerProperty
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
@Override
public boolean addContainerProperty(Object propertyId, final Class<?> type, Object defaultValue) throws UnsupportedOperationException {
if (propertyId != null && type != null && ClassUtils.isAssignable(propertyId.getClass(), String.class)) {
String pid = (String) propertyId;
if(extraPropertyIds.contains(pid)) {
return false;
} else {
extraPropertyIds.add(pid);
extraTypes.put(pid, type);
fireContainerPropertySetChange();
return true;
}
} else {
return false;
}
}
示例6: getType
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
@Override
public Class<?> getType(Object propertyId) {
if (extraPropertyIds != null && ! extraPropertyIds.isEmpty()) {
if (propertyId != null && ClassUtils.isAssignable(propertyId.getClass(), String.class)) {
return extraTypes.get((String) propertyId);
}
}
Class<?> type = super.getType(propertyId);
if (type != null) return type;
logger.warn("Could not find type for [" + propertyId + "].");
return Object.class;
}
示例7: convertInput
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
@Override
protected void convertInput()
{
final Date date = datePanel.getConvertedInput();
if (date != null) {
isNull = false;
getDateHolder().setDate(date);
final Integer hours = hourOfDayDropDownChoice.getConvertedInput();
final Integer minutes = minuteDropDownChoice.getConvertedInput();
if (hours != null) {
dateHolder.setHourOfDay(hours);
}
if (minutes != null) {
dateHolder.setMinute(minutes);
}
if (ClassUtils.isAssignable(getType(), Timestamp.class) == true) {
setConvertedInput(dateHolder.getTimestamp());
} else {
setConvertedInput(dateHolder.getDate());
}
} else if (settings.required == false) {
isNull = true;
setConvertedInput(null);
}
}
示例8: getMaxLength
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* The field length (if defined by Hibernate). The entity is the target class of the PropertyModel and the field name is the expression of
* the given PropertyModel.
* @param model If not from type PropertyModel then null is returned.
* @return
*/
public static Integer getMaxLength(final IModel<String> model)
{
Integer length = null;
if (ClassUtils.isAssignable(model.getClass(), PropertyModel.class)) {
final PropertyModel< ? > propertyModel = (PropertyModel< ? >) model;
final Object entity = BeanHelper.getFieldValue(propertyModel, ChainingModel.class, "target");
if (entity == null) {
log.warn("Oups, can't get private field 'target' of PropertyModel!.");
} else {
final Field field = propertyModel.getPropertyField();
if (field != null) {
length = HibernateUtils.getPropertyLength(entity.getClass().getName(), field.getName());
} else {
log.info("Can't get field '" + propertyModel.getPropertyExpression() + "'.");
}
}
}
return length;
}
示例9: copyValues
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* Copies all values from the given src object excluding the values created and lastUpdate. Do not overwrite created and lastUpdate from
* the original database object.
* @param src
* @param dest
* @param ignoreFields Does not copy these properties (by field name).
* @return true, if any modifications are detected, otherwise false;
*/
@SuppressWarnings("unchecked")
public static ModificationStatus copyValues(final BaseDO src, final BaseDO dest, final String... ignoreFields)
{
if (ClassUtils.isAssignable(src.getClass(), dest.getClass()) == false) {
throw new RuntimeException("Try to copyValues from different BaseDO classes: this from type "
+ dest.getClass().getName()
+ " and src from type"
+ src.getClass().getName()
+ "!");
}
if (src.getId() != null && (ignoreFields == null || ArrayUtils.contains(ignoreFields, "id") == false)) {
dest.setId(src.getId());
}
return copyDeclaredFields(src.getClass(), src, dest, ignoreFields);
}
示例10: login
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* Logs the user in, if not already logged-in. If an user is already logged in then nothing is done. Therefore you must log-out an user
* before any new login.
* @param username
* @param password not encrypted.
*/
public void login(final String username, final String password, final boolean checkDefaultPage)
{
// start and render the test page
tester.startPage(LoginPage.class);
if (ClassUtils.isAssignable(tester.getLastRenderedPage().getClass(), WicketUtils.getDefaultPage()) == true) {
// Already logged-in.
return;
}
// assert rendered page class
tester.assertRenderedPage(LoginPage.class);
final FormTester form = tester.newFormTester("body:form");
form.setValue(findComponentByLabel(form, "username"), username);
form.setValue(findComponentByLabel(form, "password"), password);
form.submit(KEY_LOGINPAGE_BUTTON_LOGIN);
if (checkDefaultPage == true) {
tester.assertRenderedPage(WicketUtils.getDefaultPage());
}
}
示例11: shouldKeep
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private static boolean shouldKeep(Class type, Object extension, @Nullable Project project) {
boolean keep = (ClassUtils.isAssignable(extension.getClass(), type)
|| (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class)));
if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) {
keep = ((CheckProject) extension).shouldExecuteOnProject(project);
}
return keep;
}
示例12: getObjectTransformationCost
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* Gets the number of steps required needed to turn the source class into
* the destination class. This represents the number of steps in the object
* hierarchy graph.
* @param srcClass The source class
* @param destClass The destination class
* @return The cost of transforming an object
*/
private static float getObjectTransformationCost(Class srcClass, Class destClass) {
if (destClass.isPrimitive()) {
return getPrimitivePromotionCost(srcClass, destClass);
}
float cost = 0.0f;
while (srcClass != null && !destClass.equals(srcClass)) {
if (destClass.isInterface() && ClassUtils.isAssignable(srcClass, destClass)) {
// slight penalty for interface match.
// we still want an exact match to override an interface match,
// but
// an interface match should override anything where we have to
// get a superclass.
cost += 0.25f;
break;
}
cost++;
srcClass = srcClass.getSuperclass();
}
/*
* If the destination class is null, we've travelled all the way up to
* an Object match. We'll penalize this by adding 1.5 to the cost.
*/
if (srcClass == null) {
cost += 1.5f;
}
return cost;
}
示例13: getMatchingAccessibleMethod
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* <p>Find an accessible method that matches the given name and has compatible parameters.
* Compatible parameters mean that every method parameter is assignable from
* the given parameters.
* In other words, it finds a method with the given name
* that will take the parameters given.<p>
*
* <p>This method is used by
* {@link
* #invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
*
* <p>This method can match primitive parameter by passing in wrapper classes.
* For example, a <code>Boolean</code> will match a primitive <code>boolean</code>
* parameter.
*
* @param cls find method in this class
* @param methodName find method with this name
* @param parameterTypes find method with most compatible parameters
* @return The accessible method
*/
public static Method getMatchingAccessibleMethod(Class cls,
String methodName, Class[] parameterTypes) {
try {
Method method = cls.getMethod(methodName, parameterTypes);
MemberUtils.setAccessibleWorkaround(method);
return method;
} catch (NoSuchMethodException e) { /* SWALLOW */
}
// search through all methods
Method bestMatch = null;
Method[] methods = cls.getMethods();
for (int i = 0, size = methods.length; i < size; i++) {
if (methods[i].getName().equals(methodName)) {
// compare parameters
if (ClassUtils.isAssignable(parameterTypes, methods[i]
.getParameterTypes(), true)) {
// get accessible version of method
Method accessibleMethod = getAccessibleMethod(methods[i]);
if (accessibleMethod != null) {
if (bestMatch == null
|| MemberUtils.compareParameterTypes(
accessibleMethod.getParameterTypes(),
bestMatch.getParameterTypes(),
parameterTypes) < 0) {
bestMatch = accessibleMethod;
}
}
}
}
}
if (bestMatch != null) {
MemberUtils.setAccessibleWorkaround(bestMatch);
}
return bestMatch;
}
示例14: getConstructorArgument
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* Checks the type of the constructor argument matches the expected type and returns it.
* Handles {@link Link}s and {@link Provider}s by checking the parameter type is a
* {@link Link} or {@link Provider} or that its type is compatible with the linked / provided object.
*/
private static Object getConstructorArgument(FunctionModelConfig functionModelConfig,
Class<?> objectType,
List<Parameter> path,
Parameter parameter,
ArgumentConverter argumentConverter) {
FunctionArguments args = functionModelConfig.getFunctionArguments(objectType);
Object arg = args.getArgument(parameter.getName());
if (arg == null || arg instanceof Provider || arg instanceof FunctionModelConfig) {
return arg;
// this takes into account boxing of primitives which Class.isAssignableFrom() doesn't
} else if (ClassUtils.isAssignable(arg.getClass(), parameter.getType(), true)) {
return arg;
} else if (arg instanceof Link) {
if (ClassUtils.isAssignable(((Link<?>) arg).getTargetType(), parameter.getType(), true)) {
return arg;
} else {
throw new IncompatibleTypeException(path, "Link argument (" + arg + ") doesn't resolve to the " +
"required type for " + parameter.getFullName());
}
} else if (arg instanceof String && argumentConverter.isConvertible(parameter.getParameterType())) {
try {
return argumentConverter.convertFromString(parameter.getParameterType(), (String) arg);
} catch (Exception e) {
throw new ArgumentConversionException((String) arg, path, "Unable to convert value '" + arg + "' to type " +
parameter.getParameterType().getName(), e);
}
} else {
throw new IncompatibleTypeException(path, "Argument (" + arg + ": " + arg.getClass().getSimpleName() + ") isn't of the " +
"required type for " + parameter.getFullName());
}
}
示例15: convertString
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
* Will convert a String into the specified property type. Integer, Long, Boolean, and String supported.
* @param targetType
* @param value
* @return convertedValue
*/
public static Object convertString(Class targetType, String value) {
Validate.notNull(targetType, "Null targetType not allowed.");
if (value == null) {
return value;
}
if (ClassUtils.isAssignable(targetType, String.class)) {
return value;
}
if (ClassUtils.isAssignable(targetType, Integer.class)) {
return Integer.valueOf(value);
}
if (ClassUtils.isAssignable(targetType, int.class)) {
return Integer.valueOf(value);
}
if (ClassUtils.isAssignable(targetType, Long.class)) {
return Long.valueOf(value);
}
if (ClassUtils.isAssignable(targetType, long.class)) {
return Long.valueOf(value);
}
Boolean bValue = BooleanUtils.toBooleanObject(value);
if (bValue != null) {
return bValue;
}
throw new MonetaException("Property type not supported")
.addContextValue("targetType", targetType.getName());
}