本文整理汇总了Java中org.springframework.beans.BeanUtils.getPropertyDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java BeanUtils.getPropertyDescriptor方法的具体用法?Java BeanUtils.getPropertyDescriptor怎么用?Java BeanUtils.getPropertyDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.BeanUtils
的用法示例。
在下文中一共展示了BeanUtils.getPropertyDescriptor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: predicateOfField
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private Predicate<HealthCheck> predicateOfField(String field, String term) {
PropertyDescriptor propertyDescriptor = BeanUtils.getPropertyDescriptor(HealthCheck.class, field);
if (propertyDescriptor == null) {
// The field is not found, so we just do as if everything matches
// TODO - Maybe we could log that :)
return hc -> true;
} else if (String.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
if (term.contains("*")) {
// We have a regex here
return hc -> invoke(hc, propertyDescriptor.getReadMethod(), String.class).matches(term.replace("*", ".*"));
} else {
return hc -> invoke(hc, propertyDescriptor.getReadMethod(), String.class).contains(term);
}
} else {
if (term.contains("*")) {
return hc -> invoke(hc, propertyDescriptor.getReadMethod(), Object.class).toString().matches(".*" + term.replace("*", ".*") + ".*");
} else {
return hc -> invoke(hc, propertyDescriptor.getReadMethod(), Object.class).toString().contains(term);
}
}
}
示例2: treeSorted
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public QueryResult<T> treeSorted(String keyField, String parentKeyField, Object rootValue) {
try {
List<T> list = getData();
if (list.size() <= 0) {
return this;
}
Class<?> itemClass = list.get(0).getClass();
PropertyDescriptor keyProp = BeanUtils.getPropertyDescriptor(itemClass, keyField);
PropertyDescriptor parentKeyProp = BeanUtils.getPropertyDescriptor(itemClass, parentKeyField);
List<T> newList = new ArrayList<>(list.size());
addTreeNode(newList, list, rootValue, keyProp, parentKeyProp);
setData(newList);
} catch (Exception e) {
throw new RuntimeException(e);
}
return this;
}
示例3: getValue
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private static Object getValue(String propertyName, Object obj) {
if (obj instanceof Map) {
return ((Map) obj).get(propertyName);
} else if (obj instanceof Tuple) {
return ((Tuple) obj).get(propertyName);
} else if (obj != null) {
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(obj.getClass(), propertyName);
try {
return pd.getReadMethod().invoke(obj, new Object[]{});
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
示例4: AbstractProperty
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public AbstractProperty(EntityMetadata metadata, Field field) {
this.metadata = metadata;
String name = field.getName();
Class<?> entityType = metadata.getEntityType();
this.field = field;
descriptor = BeanUtils.getPropertyDescriptor(entityType, name);
if(descriptor == null && name.startsWith("is") && field.getType() == boolean.class){
name = name.substring(2);
descriptor = BeanUtils.getPropertyDescriptor(entityType, name);
}
if(descriptor == null){
throw new RuntimeException("属性[" + name +"]不存在");
}
this.type = field.getType();
}
示例5: getParameter
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
* @param name
* @return dummy
*/
public Object getParameter(String name) {
PropertyDescriptor propertyDescriptor = BeanUtils.getPropertyDescriptor(this.getClass(), name);
if (propertyDescriptor != null) {
Object value = null;
try {
value = propertyDescriptor.getReadMethod().invoke(this, new Object[]{});//调用方法获取方法的返回值
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return value;
}
return null;
}
示例6: execute
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public ActionValue execute(Context context,Object matchedObject,List<Object> allMatchedObjects,Map<String,Object> variableMap) {
Object targetFact=null;
String propertyName=null;
ValueCompute valueCompute=context.getValueCompute();
Object obj=valueCompute.complexValueCompute(value, matchedObject, context,allMatchedObjects,variableMap);
String label=null;
if(type!=null && type.equals(LeftType.NamedReference)){
String refName=referenceName;
targetFact=variableMap.get(refName);
if(targetFact==null){
refName=refName.substring(1,refName.length());
targetFact=variableMap.get(refName);
}
if(targetFact==null){
throw new RuleException("Reference ["+referenceName+"] not define.");
}
propertyName=variableName;
label=referenceName+"."+(variableLabel==null ? variableName : variableLabel);
}else{
String className=context.getVariableCategoryClass(variableCategory);
if(className.equals(HashMap.class.getName())){
targetFact=context.getWorkingMemory().getParameters();
}else{
targetFact=valueCompute.findObject(className, matchedObject, context);
}
if(targetFact==null){
throw new RuleException("Class["+className+"] not found in workingmemory.");
}
if(datatype.equals(Datatype.Enum) && obj!=null && StringUtils.isNotBlank(obj.toString())){
PropertyDescriptor pd=BeanUtils.getPropertyDescriptor(targetFact.getClass(), variableName);
Class<Enum> targetClass=(Class<Enum>)pd.getPropertyType();
obj=Enum.valueOf(targetClass, obj.toString());
}else if(obj!=null){
obj=datatype.convert(obj);
}
propertyName=variableName;
label=variableCategory+"."+(variableLabel==null ? variableName : variableLabel);
}
Utils.setObjectProperty(targetFact, propertyName, obj);
if(debug && Utils.isDebug()){
String msg="###变量赋值:"+label+"="+obj;
context.debugMsg(msg, MsgType.VarAssign, debug);
}
return null;
}
示例7: CacheObject
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public CacheObject(Class<?> clazz)
{
entity = isEntity(clazz);
if( isProperty(clazz) )
{
for( PropertyDescriptor descriptor : BeanUtils.getPropertyDescriptors(clazz) )
{
Method readMethod = descriptor.getReadMethod();
Method writeMethod = descriptor.getWriteMethod();
if( readMethod != null && writeMethod != null )
{
if( readMethod.isAnnotationPresent(Id.class) )
{
id = new MethodProperty(descriptor);
}
Class<?> type = descriptor.getPropertyType();
if( isComplexType(type) )
{
properties.add(new MethodProperty(descriptor));
}
}
}
}
else
{
for( Field field : clazz.getDeclaredFields() )
{
boolean isStatic = Modifier.STATIC == (Modifier.STATIC & field.getModifiers());
if( !isStatic && isComplexType(field.getType()) )
{
properties
.add(new FieldProperty(field, BeanUtils.getPropertyDescriptor(clazz, field.getName())));
}
if( field.isAnnotationPresent(Id.class) )
{
id = new FieldProperty(field, BeanUtils.getPropertyDescriptor(clazz, field.getName()));
}
}
}
}