本文整理汇总了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;
}
示例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 );
}
}
示例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;
}
示例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$
}
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}