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


Java BeanInfo.getPropertyDescriptors方法代码示例

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


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

示例1: transMap2Bean

import java.beans.BeanInfo; //导入方法依赖的package包/类
public static void transMap2Bean(Map<String, Object> map, Object obj) {
	try {
		BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor property : propertyDescriptors) {
			String key = property.getName();
			if (map.containsKey(key)) {
				Object value = map.get(key);
				// 得到property对应的setter方法
				Method setter = property.getWriteMethod();
				setter.invoke(obj, value);
			}
		}
	} catch (Exception e) {
		System.out.println("transMap2Bean Error " + e);
	}
	return;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:19,代码来源:InstanceUtil.java

示例2: createFields

import java.beans.BeanInfo; //导入方法依赖的package包/类
private void createFields ()
{
    try
    {
        final BeanInfo bi = Introspector.getBeanInfo ( this.objectClass );
        for ( final PropertyDescriptor pd : bi.getPropertyDescriptors () )
        {
            if ( pd.getReadMethod () != null )
            {
                createDataItem ( pd );
            }
        }
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to create fields", e );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:SimpleObjectExporter.java

示例3: getProperties

import java.beans.BeanInfo; //导入方法依赖的package包/类
/**
 * 通过方法获取属性
 *
 * @param entityClass
 * @return
 */
public List<EntityField> getProperties(Class<?> entityClass) {
    List<EntityField> entityFields = new ArrayList<EntityField>();
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(entityClass);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }
    PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor desc : descriptors) {
        if (!desc.getName().equals("class")) {
            entityFields.add(new EntityField(null, desc));
        }
    }
    return entityFields;
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:23,代码来源:FieldHelper.java

示例4: RootClassInfo

import java.beans.BeanInfo; //导入方法依赖的package包/类
private RootClassInfo(String className, List<String> warnings) {
    super();
    this.className = className;
    this.warnings = warnings;

    if (className == null) {
        return;
    }
    
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(className);
    String nameWithoutGenerics = fqjt.getFullyQualifiedNameWithoutTypeParameters();
    if (!nameWithoutGenerics.equals(className)) {
        genericMode = true;
    }

    try {
        Class<?> clazz = ObjectFactory.externalClassForName(nameWithoutGenerics);
        BeanInfo bi = Introspector.getBeanInfo(clazz);
        propertyDescriptors = bi.getPropertyDescriptors();
    } catch (Exception e) {
        propertyDescriptors = null;
        warnings.add(getString("Warning.20", className)); //$NON-NLS-1$
    }
}
 
开发者ID:DomKing,项目名称:server-utility,代码行数:25,代码来源:RootClassInfo.java

示例5: buildMap

import java.beans.BeanInfo; //导入方法依赖的package包/类
private Map<String, PropertyDescriptor> buildMap(final Class<?> type) {
    Map<String, PropertyDescriptor> nameMap = propertyNameCache.get(type);
    if (nameMap == null) {
        BeanInfo beanInfo;
        try {
            beanInfo = Introspector.getBeanInfo(type, Object.class);
        } catch (final IntrospectionException e) {
            throw new ObjectAccessException("Cannot get BeanInfo of type " + type.getName(), e);
        }
        nameMap = new LinkedHashMap<String, PropertyDescriptor>();
        final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (final PropertyDescriptor descriptor : propertyDescriptors) {
            nameMap.put(descriptor.getName(), descriptor);
        }
        nameMap = sorter.sort(type, nameMap);
        propertyNameCache.put(type, nameMap);
    }
    return nameMap;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:PropertyDictionary.java

示例6: transBean2Map

import java.beans.BeanInfo; //导入方法依赖的package包/类
public static Map<String, Object> transBean2Map(Object obj) {
    Map<String, Object> map = newHashMap();
    if (obj == null) {
        return map;
    }
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor property : propertyDescriptors) {
            String key = property.getName();
            // 过滤class属性
            if (!key.equals("class")) {
                // 得到property对应的getter方法
                Method getter = property.getReadMethod();
                Object value = getter.invoke(obj);
                map.put(key, value);
            }
        }
    } catch (Exception e) {
        System.out.println("transBean2Map Error " + e);
    }
    return map;
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:24,代码来源:InstanceUtil.java

示例7: transBean2Map

import java.beans.BeanInfo; //导入方法依赖的package包/类
/**
 * Bean --> Map
 * @param obj
 * @return
 */
public static Map<String, Object> transBean2Map(Object obj) {
    if(obj == null){
        return null;
    }
    Map<String, Object> map = new HashMap<>();
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor property : propertyDescriptors) {
            String key = property.getName();
            // 过滤class属性
            if (!"class".equals(key)) {
                // 得到property对应的getter方法
                Method getter = property.getReadMethod();
                Object value = getter.invoke(obj);
                map.put(key, value);
            }
        }
    } catch (Exception e) {
        System.out.println("transBean2Map Error " + e);
    }
    return map;
}
 
开发者ID:hykes,项目名称:CodeGen,代码行数:29,代码来源:BuilderUtil.java

示例8: getPropertyDescriptor

import java.beans.BeanInfo; //导入方法依赖的package包/类
private PropertyDescriptor getPropertyDescriptor(Class objClass, String property) throws IntrospectionException
{
	synchronized (m_descriptorMapLock)
	{
		Map<String, PropertyDescriptor> propMap = m_descriptorMap.get(objClass);

		if (propMap == null)
		{
			propMap = new HashMap<>();
			m_descriptorMap.put(objClass, propMap);

			BeanInfo beanInfo = Introspector.getBeanInfo(objClass);
			PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor descriptor : descriptors)
			{
				propMap.put(getUnderscorePropertyName(descriptor.getName()), descriptor);
			}
		}

		return (propMap.get(property));
	}
}
 
开发者ID:quqiangsheng,项目名称:abhot,代码行数:23,代码来源:QueryParser.java

示例9: BeanProperties

import java.beans.BeanInfo; //导入方法依赖的package包/类
public BeanProperties(Class<?> type) throws ELException {
    this.type = type;
    this.properties = new HashMap<String, BeanProperty>();
    try {
        BeanInfo info = Introspector.getBeanInfo(this.type);
        PropertyDescriptor[] pds = info.getPropertyDescriptors();
        for (PropertyDescriptor pd: pds) {
            this.properties.put(pd.getName(), new BeanProperty(type, pd));
        }
        if (System.getSecurityManager() != null) {
            // When running with SecurityManager, some classes may be
            // not accessible, but have accessible interfaces.
            populateFromInterfaces(type);
        }
    } catch (IntrospectionException ie) {
        throw new ELException(ie);
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:19,代码来源:BeanELResolver.java

示例10: paserClass

import java.beans.BeanInfo; //导入方法依赖的package包/类
private static List<Variable> paserClass(String path,Class<?> cls, Collection<Class<?>> parsed) throws Exception{
	List<Variable> variables=new ArrayList<Variable>();
	BeanInfo beanInfo=Introspector.getBeanInfo(cls,Object.class);
	PropertyDescriptor[] pds= beanInfo.getPropertyDescriptors();
	
	if(pds!=null && !parsed.contains(cls)){
		parsed.add(cls);
		for(PropertyDescriptor pd:pds){
			Variable variable=new Variable();
			Class<?> type=pd.getPropertyType();
			Datatype dataType=getDateType(type);
			String propertyName=pd.getName();
			String label=getPropertyAnnotationLabel(cls, propertyName);
			String name=path+pd.getName();
			variable.setName(name);
			variable.setLabel(label==null?name:label);
			variable.setType(dataType);
			variable.setAct(Act.InOut);
			if(Datatype.Object.equals(dataType)){
				variables.addAll(paserClass(path+pd.getName()+".",type, parsed));
			}else{
				variables.add(variable);
			}
		}
	}
	return variables;
}
 
开发者ID:youseries,项目名称:urule,代码行数:28,代码来源:ClassUtils.java

示例11: getValue

import java.beans.BeanInfo; //导入方法依赖的package包/类
@Override
public Object getValue(Object o , Object key)
{
  if (o == null)
    return null;
    
  if (o instanceof Map)
    return ((Map) o).get(key);
  
  if (key == null)
    return null;
    
  String propertyName = key.toString();
  try
  {
    BeanInfo info = Introspector.getBeanInfo(o.getClass());
    PropertyDescriptor[] properties = info.getPropertyDescriptors();
    for (int i = 0; i < properties.length; i++)
    {
      if (propertyName.equals(properties[i].getName()))
      {
        Method m = properties[i].getReadMethod();
        return m.invoke(o);
      }
    }
  }
  catch (Exception e)
  {
    throw new PropertyNotFoundException(e);
  }
  
  throw new PropertyNotFoundException("Couldn't find getter for " + propertyName);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:34,代码来源:MPropertyResolver.java

示例12: getPropertyDescriptors

import java.beans.BeanInfo; //导入方法依赖的package包/类
private static PropertyDescriptor[] getPropertyDescriptors() {
    try {
        BeanInfo info = Introspector.getBeanInfo(Test6660539.class);
        return info.getPropertyDescriptors();
    }
    catch (IntrospectionException exception) {
        throw new Error("unexpected", exception);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:Test6660539.java

示例13: initPropertyDescriptorCache

import java.beans.BeanInfo; //导入方法依赖的package包/类
private static void initPropertyDescriptorCache(Class<?> clazz) throws IntrospectionException {
    String cname = clazz.getName().concat(POINT);
    BeanInfo beanInfo = Introspector.getBeanInfo(clazz, Object.class);
    PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor pd : pds) {
        String name = pd.getName();
        propertyDescriptorCache.put(cname + name, pd);
    }
}
 
开发者ID:lftao,项目名称:jkami,代码行数:10,代码来源:JkBeanUtils.java

示例14: getProperyDescriptor

import java.beans.BeanInfo; //导入方法依赖的package包/类
protected static PropertyDescriptor getProperyDescriptor ( final Class<?> clazz, final String name ) throws Exception
{
    final BeanInfo bi = Introspector.getBeanInfo ( clazz );
    for ( final PropertyDescriptor pd : bi.getPropertyDescriptors () )
    {
        if ( pd.getName ().equals ( name ) )
        {
            return pd;
        }
    }
    return null;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:13,代码来源:BeanMatcher.java

示例15: convertDataType

import java.beans.BeanInfo; //导入方法依赖的package包/类
/** This method will introspect the beanClass & get the getter method for the input propertyName.
 * It will then try & convert the propertyValue to the appropriate datatype.
 * @param beanClass The bean class to be introspected.
 * @param propertyName The Property being searched for.
 * @param propertyValue The value to be converted.
 * @throws IntrospectionException if an exception occurs during introspection.
 * @throws IllegalArgumentException if the property cannot be found on the input class.
 * @throws ClassCastException if the input value can't be mapped to target class
 * @return a converted propertyValue compatible with the getter.
 * @deprecated Use DataTypeMapper.instance() instead.
 */
public static Object convertDataType(Class beanClass, String propertyName, String propertyValue)
throws IntrospectionException, IllegalArgumentException, ClassCastException {
    Object convertedPropertyValue = null;
    if (propertyValue != null) {
        boolean foundProperty = false;
        BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
        if (beanInfo != null) {
            PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    if (StringHelper.equalsIgnoreCaseFirstChar(pd.getName(), propertyName)) {
                        foundProperty = true;
                        if (pd.getPropertyType().isEnum()) {
                            convertedPropertyValue = findEnum(pd.getPropertyType(), propertyValue.toString());
                            if (convertedPropertyValue == null)
                                throw new IllegalArgumentException("Property " + beanClass.getName() + '.' + propertyName + ", cannot be set to the value " + propertyValue + ", since it is not defined in the Enum " + pd.getPropertyType());
                        } else {
                            convertedPropertyValue = DataTypeMapper.instance().map(propertyValue, pd.getPropertyType());
                        }
                        break;
                    }
                }
            }
        }
        if (!foundProperty)
            throw new IllegalArgumentException("Could not find the the property: " + beanClass.getName() + '.' + propertyName);
    }
    return convertedPropertyValue;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:41,代码来源:BeanHelper.java


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