private static Map<String, ClassProperty> createProperty(Class type) { List<String> fieldNames = Arrays.stream(type.getDeclaredFields()) .map(Field::getName).collect(Collectors.toList()); return Stream.of(propertyUtils.getPropertyDescriptors(type)) .filter(property -> !property.getName().equals("class") && property.getReadMethod() != null && property.getWriteMethod() != null) .map(BeanClassProperty::new) //让字段有序 .sorted(Comparator.comparing(property -> fieldNames.indexOf(property.name))) .collect(Collectors.toMap(ClassProperty::getName, Function.identity(), (k, k2) -> k, LinkedHashMap::new)); }
/** * <p>Retrieve the property descriptors for the specified bean, * introspecting and caching them the first time a particular bean class * is encountered.</p> * * <p><strong>FIXME</strong> - Does not work with DynaBeans.</p> * * @param bean Bean for which property descriptors are requested * @return the property descriptors * * @throws IllegalArgumentException if <code>bean</code> is null */ public PropertyDescriptor[] getPropertyDescriptors(final Object bean) { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } return (getPropertyDescriptors(bean.getClass())); }
/** * <p>Retrieve the property descriptors for the specified bean, * introspecting and caching them the first time a particular bean class * is encountered.</p> * * <p><strong>FIXME</strong> - Does not work with DynaBeans.</p> * * @param bean Bean for which property descriptors are requested * @return the property descriptors * * @throws IllegalArgumentException if <code>bean</code> is null */ public PropertyDescriptor[] getPropertyDescriptors(final Object bean) { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } return (getPropertyDescriptors(bean.getClass())); }
/** * <p>Retrieve the property descriptors for the specified bean, * introspecting and caching them the first time a particular bean class * is encountered.</p> * * <p>For more details see <code>PropertyUtilsBean</code>.</p> * * @param bean Bean for which property descriptors are requested * @return the property descriptors * @throws IllegalArgumentException if <code>bean</code> is null * @see PropertyUtilsBean#getPropertyDescriptors(Object) */ public static PropertyDescriptor[] getPropertyDescriptors(final Object bean) { return PropertyUtilsBean.getInstance().getPropertyDescriptors(bean); }
/** * <p>Retrieve the property descriptors for the specified bean, * introspecting and caching them the first time a particular bean class * is encountered.</p> * * <p>For more details see <code>PropertyUtilsBean</code>.</p> * * @param bean Bean for which property descriptors are requested * @return the property descriptors * @throws IllegalArgumentException if <code>bean</code> is null * @see PropertyUtilsBean#getPropertyDescriptors(Object) */ public static PropertyDescriptor[] getPropertyDescriptors(final Object bean) { return PropertyUtilsBean.getInstance().getPropertyDescriptors(bean); }
/** * <p>Retrieve the property descriptors for the specified class, * introspecting and caching them the first time a particular bean class * is encountered.</p> * * <p>For more details see <code>PropertyUtilsBean</code>.</p> * * @param beanClass Bean class for which property descriptors are requested * @return the property descriptors * @throws IllegalArgumentException if <code>beanClass</code> is null * @see PropertyUtilsBean#getPropertyDescriptors(Class) */ public static PropertyDescriptor[] getPropertyDescriptors(final Class<?> beanClass) { return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass); }
/** * <p>Retrieve the property descriptors for the specified class, * introspecting and caching them the first time a particular bean class * is encountered.</p> * * <p>For more details see <code>PropertyUtilsBean</code>.</p> * * @param beanClass Bean class for which property descriptors are requested * @return the property descriptors * @throws IllegalArgumentException if <code>beanClass</code> is null * @see PropertyUtilsBean#getPropertyDescriptors(Class) */ public static PropertyDescriptor[] getPropertyDescriptors(final Class<?> beanClass) { return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass); }
public static <P> Properties getProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { properties.put(descriptor.getName(), value); } } } } return properties; }
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
.append(bean.getName()).append(" target=(").append(bean.getName()).append(")bean;\n"); PropertyDescriptor[] descriptors = BeanUtilsBean.getInstance().getPropertyUtils().getPropertyDescriptors(bean); boolean hasDict = false; for (PropertyDescriptor descriptor : descriptors) {
public static String getData(List<String> ignored, Object... beans) throws Exception { StringBuilder sb = new StringBuilder(); boolean empty = true; synchronized (beanUtils) { for (Object bean : beans) { if (bean != null) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, ignored)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { if (!empty) { sb.append("&"); } empty = false; sb.append(descriptor.getName()).append("=").append(encodeURI(value)); } } } } } } return sb.toString(); }
public <I> void hear(TypeLiteral<I> type, final TypeEncounter<I> encounter) { PropertyDescriptor propertyDescriptors[] = beanUtilsBean.getPropertyUtils().getPropertyDescriptors(type.getRawType()); final Map<PropertyDescriptor, Key<?>> propertyDependencies = new HashMap<PropertyDescriptor, Key<?>>(propertyDescriptors.length); final Provider<Injector> injectorProvider = encounter.getProvider(Injector.class); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor.getWriteMethod() != null && Modifier.isPublic(propertyDescriptor.getWriteMethod().getModifiers())) { Type propertyType = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0]; propertyDependencies.put(propertyDescriptor, createDependencyKey(propertyDescriptor, propertyType)); } } encounter.register(new MembersInjector<I>() { public void injectMembers(I instance) { for (Map.Entry<PropertyDescriptor, Key<?>> dependency : propertyDependencies.entrySet()) { try { final Injector injector = injectorProvider.get(); Object value = injector.getInstance(getMappedKey(injector, dependency.getValue())); dependency.getKey().getWriteMethod().invoke(instance, value); } catch (ConfigurationException e) { // This is ok, it simply means that we can't fulfill this dependency. // Is there a better way to do this? } catch (InvocationTargetException e) { throw new RuntimeException("Couldn't set property " + dependency.getKey().getDisplayName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("We shouldn't have ever reached this point, we don't try to inject to non-accessible methods.", e); } } } }); }
getPropertyUtilsBean().getPropertyDescriptors(beanClass); if (regulars == null) { regulars = new PropertyDescriptor[0];
getPropertyUtilsBean().getPropertyDescriptors(beanClass); if (regulars == null) { regulars = new PropertyDescriptor[0];
getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { final String name = descriptor.getName();
getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { final String name = descriptor.getName();
getPropertyUtils().getPropertyDescriptors(bean); final Class<?> clazz = bean.getClass(); for (PropertyDescriptor descriptor : descriptors) {
getPropertyUtils().getPropertyDescriptors(bean); final Class<?> clazz = bean.getClass(); for (PropertyDescriptor descriptor : descriptors) {
getPropertyDescriptors(orig); for (PropertyDescriptor origDescriptor : origDescriptors) { final String name = origDescriptor.getName();
.getPropertyDescriptors(entityClass); for (PropertyDescriptor descriptor : descriptors) { Column columnAnn = getAnnotation(entityClass, descriptor, Column.class);