将一个JavaBean对象的所有属性封装在Map中并返回，
注意只能将拥有Getter方法的属性才能取出并封装到Map中

@param bean 需要转换的Bean对象
@return 返回一个Map , 失败返回null
489592
public static <T> Map<String, Object> toMap(T bean) {
        Map<String, Object> map = null;
        try {
            map = PropertyUtils.describe(bean);
            map.remove("class");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return map;
    }
146799
@Override
    public P get(Bean bean) {
        return clazz.cast(metaBean().metaProperty(name()).get(bean));
    }
1372656
public Object getBean(String name) {
		Bean bean = beans.get(name);
		if (null == bean) {
			return null;
		}
		return bean.object;
	}
769452
public static final Set<String> getProperties(Object bean)
    {
        return stream(bean).collect(Collectors.toSet());
    }
38716
public static Object get(final Object bean, final String property) {

        try {
            if (property.indexOf(".") >= 0) {

                final Object subBean = ClassMockUtils.get(bean, property.substring(0, property.indexOf(".")));

                if (subBean == null) {

                    return null;
                }

                final String newProperty = property.substring(property.indexOf(".") + 1);

                return ClassMockUtils.get(subBean, newProperty);
            }

            Method method = null;

            try {
                method = bean.getClass().getMethod(ClassMockUtils.propertyToGetter(property), new Class[] {});
            } catch (final NoSuchMethodException e) {
                method = bean.getClass().getMethod(ClassMockUtils.propertyToGetter(property, true), new Class[] {});
            }

            return method.invoke(bean, new Object[] {});

        } catch (final Exception e) {

            throw new RuntimeException("Can't get property " + property + " in the class " + bean.getClass().getName(), e);
        }
    }
286562
@SuppressWarnings("unchecked")
	public <T> T getInstance(Class<T> beanClass) {
		String[] beanNames = applicationContext.getBeanNamesForType(beanClass);
		if (beanNames.length == 0) {
			return null;
		}
		return (T) applicationContext.getBean(beanNames[0]);
	}
614612
@Override
  public final Method getFor(final Class<?> pClass, final String pFieldName) {
    Map<String, Method> methMap = this.rapiMethodsMap.get(pClass);
    if (methMap == null) {
      // There is no way to get from Map partially initialized bean
      // in this double-checked locking implementation
      // cause putting to the Map fully initialized bean
      synchronized (this.rapiMethodsMap) {
        methMap = this.rapiMethodsMap.get(pClass);
        if (methMap == null) {
          methMap = new HashMap<String, Method>();
          Method[] methods = getUtlReflection().retrieveMethods(pClass);
          for (Method method : methods) {
            if (method.getName().startsWith("get")) {
              String fldNm = method.getName().substring(3, 4).toLowerCase()
                + method.getName().substring(4);
              methMap.put(fldNm, method);
            }
          }
          //assigning fully initialized object:
          this.rapiMethodsMap.put(pClass, methMap);
        }
      }
    }
    return methMap.get(pFieldName);
  }
987092
public static void copyPropertiesToMap(Object bean, String prefix, Map<String, Object> map) {
        Class clazz = bean.getClass();
        Method[] methods = bean.getClass().getMethods();
        for (Method method : methods) {
            // 复制属性
            Class returnc = method.getReturnType();
            if (ReflectUtils.isBeanPropertyReadMethod(method)) {
                String propertyName = ReflectUtils.getPropertyNameFromBeanReadMethod(method);
                try {
                    if (ReflectUtils.getPropertySetterMethod(clazz, propertyName, returnc) == null) {
                        continue; // 还需要有set方法
                    }
                } catch (Exception e) {
                    continue;
                }
                Object val;
                try {
                    val = method.invoke(bean);
                } catch (InvocationTargetException e) {
                    throw new SofaRpcRuntimeException("Can't access copy " + propertyName, e.getCause());
                } catch (IllegalAccessException e) {
                    throw new SofaRpcRuntimeException("Can't access copy " + propertyName, e);
                }
                if (val != null) { // 值不为空，放入缓存
                    map.put(prefix + propertyName, val);
                }
            }
        }
        Field[] fields = bean.getClass().getFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            if (map.containsKey(prefix + fieldName)) {
                continue;
            }
            int m = field.getModifiers();
            if (!Modifier.isStatic(m) && !Modifier.isTransient(m)) {
                Object val = null;
                try {
                    if (field.isAccessible()) {
                        val = field.get(bean);
                    } else {
                        try {
                            field.setAccessible(true);
                            val = field.get(bean);
                        } finally {
                            field.setAccessible(false);
                        }
                    }
                } catch (IllegalAccessException e) {
                    // LOGGER.warn("Can't access field" + fieldName + "when copy value to context", e);
                }
                if (val != null) {
                    map.put(prefix + fieldName, val);
                }
            }
        }
    }
696839
@Override
	public void setBean(final Object bean) {
		BeanAndProviderBoundComponentModel model = getOrCreateComponentModel();
		model.setBean(bean);

		if (getBeanProperty() == null) {
			setBeanProperty(".");
		}
		// Remove values in scratch map
		removeBeanFromScratchMap();
	}
1061455
private void populateMap(Object bean) {
        Class<?> klass = bean.getClass();

        // If klass is a System class then set includeSuperClass to false.

        boolean includeSuperClass = klass.getClassLoader() != null;

        Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
        for (final Method method : methods) {
            final int modifiers = method.getModifiers();
            if (Modifier.isPublic(modifiers)
                    && !Modifier.isStatic(modifiers)
                    && method.getParameterTypes().length == 0
                    && !method.isBridge()
                    && method.getReturnType() != Void.TYPE
                    && isValidMethodName(method.getName())) {
                final String key = getKeyNameFromMethod(method);
                if (key != null && !key.isEmpty()) {
                    try {
                        final Object result = method.invoke(bean);
                        if (result != null) {
                            this.map.put(key, wrap(result));
                            // we don't use the result anywhere outside of wrap
                            // if it's a resource we should be sure to close it
                            // after calling toString
                            if (result instanceof Closeable) {
                                try {
                                    ((Closeable) result).close();
                                } catch (IOException ignore) {
                                }
                            }
                        }
                    } catch (IllegalAccessException ignore) {
                    } catch (IllegalArgumentException ignore) {
                    } catch (InvocationTargetException ignore) {
                    }
                }
            }
        }
    }
112647
public <T> T toBean(Class<T> clazz) {
		return BeanUtil.mapToBean(this, clazz, false);
	}
499760
private Object findSpringBean(String beanName) {
		ServletContext servletContext = this.pageContext.getServletContext();

		Enumeration<String> attrNames = servletContext.getAttributeNames();
		while (attrNames.hasMoreElements()){
			String attrName = attrNames.nextElement();
			if (attrName.startsWith("org.springframework")){
				try{
					WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext, attrName);
					Object bean = springContext.getBean(beanName);
					return bean;
				}catch(Exception e){
					// continue if the bean cannot be found.
				}
			}
		}
		return null;
	}
318025
@Override
    @SuppressWarnings("unchecked")
    public P get(Bean bean) {
        if (style().isReadable() == false) {
            throw new UnsupportedOperationException("Property cannot be read: " + name());
        }
        try {
            return (P) getMethod.invoke(bean, (Object[]) null);
        } catch (IllegalArgumentException | IllegalAccessException ex) {
            throw new UnsupportedOperationException("Property cannot be read: " + name(), ex);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() instanceof RuntimeException) {
                throw (RuntimeException) ex.getCause();
            }
            throw new RuntimeException(ex);
        }
    }
835446
@Override
    @SuppressWarnings("unchecked")
    public <T> T get(Contextual<T> contextual) {
        Bean bean = (Bean) contextual;
        // you can store the bean somewhere
        if (somewhere.containsKey(bean.getName())) {
            return (T) somewhere.get(bean.getName());
        } else {
            return null;
        }
    }
179523
public Map describe(Object src) throws BeanMappingException {
        Map result = new HashMap();
        BeanMappingParam param = new BeanMappingParam();
        param.setSrcRef(src);
        param.setTargetRef(result);
        param.setConfig(this.describeConfig);
        param.setProcesses(BeanMappingEnvironment.getBeanMapVps());
        // 执行mapping处理
        BeanMappingExecutor.execute(param);
        return result;
    }
1285780
public void setPropertiesOn(final Bean bean) {
        String[][] properties = getProperties();
        for (int i = 0; i < properties.length; i++) {
            if (properties[i].length < 2) {
                continue;
            }
            for (int j = 0; j < properties[i].length - 1; j++) {
                bean.addProperty(properties[i][0], properties[i][j + 1]);
            }
        }
    }
612184
public Map<String, Object> write(Bean bean) {
        JodaBeanUtils.notNull(bean, "bean");
        return writeBean(bean, bean.getClass());
    }