当前位置: 首页>>代码示例>>Java>>正文


Java BeanUtils.getPropertyDescriptors方法代码示例

本文整理汇总了Java中org.springframework.beans.BeanUtils.getPropertyDescriptors方法的典型用法代码示例。如果您正苦于以下问题:Java BeanUtils.getPropertyDescriptors方法的具体用法?Java BeanUtils.getPropertyDescriptors怎么用?Java BeanUtils.getPropertyDescriptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.BeanUtils的用法示例。


在下文中一共展示了BeanUtils.getPropertyDescriptors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert2Params

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
 * @param obj 要转化的bean
 *            简单的bean
 *            <p>
 *            warne 2016/12/03
 * @return
 */
public List<NameValuePair> convert2Params(Object obj) {
	List<NameValuePair> pairs = new ArrayList();
	if (obj == null) {
		return pairs;
	}

	Class<?> cls = obj.getClass();
	PropertyDescriptor pds[] = BeanUtils.getPropertyDescriptors(cls);
	Arrays.asList(pds).stream().filter(p -> !"class".equalsIgnoreCase(p.getName())).filter(l -> !"java.util.ArrayList".equalsIgnoreCase(l.getName())).forEach(pd -> {
		try {
			Method readMethod = pd.getReadMethod();
			if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) readMethod.setAccessible(true);

			Object value = readMethod.invoke(obj, new Object[0]);
			pairs.add(new BasicNameValuePair(pd.getName(), String.valueOf(value)));
		} catch (Throwable ex) {
			throw new RuntimeException("---bean convert to map happened error---", ex);
		}
	});

	return pairs;
}
 
开发者ID:funtl,项目名称:framework,代码行数:30,代码来源:HttpClientUtil.java

示例2: prepareReq

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private Object prepareReq(Method method) throws InvocationTargetException, IllegalAccessException {
    
    Class<?> reqClass = method.getParameterTypes()[0];
    
    Object t;
    try {
        t = reqClass.newInstance();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    
    PropertyDescriptor[] properties = BeanUtils.getPropertyDescriptors(reqClass);
    for (PropertyDescriptor p : properties) {
        Method writeMethod = p.getWriteMethod();
        if (writeMethod == null || writeMethod.getParameterCount() != 1) {
            continue;
        }
        writeMethod.invoke(t, prepareValue(writeMethod.getParameterTypes()[0], "1"));
    }
    return t;
}
 
开发者ID:nds842,项目名称:sql-first-mapper,代码行数:22,代码来源:AllDaoTest.java

示例3: initialize

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
 * Initialize the mapping metadata for the given class.
 * @param mappedClass the mapped class.
 */
protected void initialize(Class<T> mappedClass) {
	this.mappedClass = mappedClass;
	this.mappedFields = new HashMap<String, PropertyDescriptor>();
	this.mappedProperties = new HashSet<String>();
	PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null) {
			this.mappedFields.put(pd.getName().toLowerCase(), pd);
			String underscoredName = underscoreName(pd.getName());
			if (!pd.getName().toLowerCase().equals(underscoredName)) {
				this.mappedFields.put(underscoredName, pd);
			}
			this.mappedProperties.add(pd.getName());
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:BeanPropertyRowMapper.java

示例4: initJavaBeansCache

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private void initJavaBeansCache() {
    Class<?>[] classes =
            new Class<?>[] { OsgiServiceFactoryBean.class, OsgiServiceProxyFactoryBean.class,
                    OsgiServiceCollectionProxyFactoryBean.class };

    CachedIntrospectionResults.acceptClassLoader(OsgiStringUtils.class.getClassLoader());

    for (Class<?> clazz : classes) {
        BeanUtils.getPropertyDescriptors(clazz);
    }
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:JavaBeansCacheActivator.java

示例5: reflectBean

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private void reflectBean(Class<T> tclazz) {

        tBean = BeanUtils.instantiate(tclazz);

        PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(tclazz);

        for (PropertyDescriptor p : propertyDescriptors) {
            if (p.getWriteMethod() != null) {
                this.fieldsMap.put(p.getName(), p);
            }
        }

        beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(tBean);
    }
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:15,代码来源:HbaseFindBuilder.java

示例6: 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()));
			}
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:42,代码来源:InitialiserServiceImpl.java

示例7: getAttributeInfo

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
 * Iterate through all properties on the MBean class and gives subclasses
 * the chance to vote on the inclusion of both the accessor and mutator.
 * If a particular accessor or mutator is voted for inclusion, the appropriate
 * metadata is assembled and passed to the subclass for descriptor population.
 * @param managedBean the bean instance (might be an AOP proxy)
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the attribute metadata
 * @throws JMException in case of errors
 * @see #populateAttributeDescriptor
 */
@Override
protected ModelMBeanAttributeInfo[] getAttributeInfo(Object managedBean, String beanKey) throws JMException {
	PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean));
	List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>();

	for (PropertyDescriptor prop : props) {
		Method getter = prop.getReadMethod();
		if (getter != null && getter.getDeclaringClass() == Object.class) {
			continue;
		}
		if (getter != null && !includeReadAttribute(getter, beanKey)) {
			getter = null;
		}

		Method setter = prop.getWriteMethod();
		if (setter != null && !includeWriteAttribute(setter, beanKey)) {
			setter = null;
		}

		if (getter != null || setter != null) {
			// If both getter and setter are null, then this does not need exposing.
			String attrName = JmxUtils.getAttributeName(prop, isUseStrictCasing());
			String description = getAttributeDescription(prop, beanKey);
			ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter);

			Descriptor desc = info.getDescriptor();
			if (getter != null) {
				desc.setField(FIELD_GET_METHOD, getter.getName());
			}
			if (setter != null) {
				desc.setField(FIELD_SET_METHOD, setter.getName());
			}

			populateAttributeDescriptor(desc, getter, setter, beanKey);
			info.setDescriptor(desc);
			infos.add(info);
		}
	}

	return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:54,代码来源:AbstractReflectiveMBeanInfoAssembler.java


注:本文中的org.springframework.beans.BeanUtils.getPropertyDescriptors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。