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


Java PropertyUtils.getPropertyDescriptors方法代码示例

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


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

示例1: buildClass

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public void buildClass(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String clazz=req.getParameter("clazz");
	List<Field> result=new ArrayList<Field>();
	try{
		Class<?> targetClass=Class.forName(clazz);
		PropertyDescriptor[] propertyDescriptors=PropertyUtils.getPropertyDescriptors(targetClass);
		for(PropertyDescriptor pd:propertyDescriptors){
			String name=pd.getName();
			if("class".equals(name)){
				continue;
			}
			result.add(new Field(name));
		}
		writeObjectToJson(resp, result);
	}catch(Exception ex){
		throw new ReportDesignException(ex);
	}
}
 
开发者ID:youseries,项目名称:ureport,代码行数:19,代码来源:DatasourceServletAction.java

示例2: copyBeanNotNull2Bean

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 对象拷贝 数据对象空值不拷贝到目标对象
 * 
 * @param databean 待拷贝对象
 * @param tobean 目标对象
 * @throws NoSuchMethodException
 */
public static void copyBeanNotNull2Bean(Object databean, Object tobean) throws Exception {
	PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(databean);
	for (int i = 0; i < origDescriptors.length; i++) {
		String name = origDescriptors[i].getName();
		// String type = origDescriptors[i].getPropertyType().toString();
		if ("class".equals(name)) {
			continue; // No point in trying to set an object's class
		}
		if (PropertyUtils.isReadable(databean, name) && PropertyUtils.isWriteable(tobean, name)) {
			try {
				Object value = PropertyUtils.getSimpleProperty(databean, name);
				if (value != null) {
					getInstance().setSimpleProperty(tobean, name, value);
				}
			} catch (java.lang.IllegalArgumentException ie) {
				; // Should not happen
			} catch (Exception e) {
				; // Should not happen
			}

		}
	}
}
 
开发者ID:tzou24,项目名称:abina-common-util,代码行数:31,代码来源:ParamsUtils.java

示例3: copyTo

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public void copyTo(T aObject) {

		ModelProperties theProperties = aObject.getProperties();

		try {
			for (PropertyDescriptor theDescriptor : PropertyUtils.getPropertyDescriptors(this)) {
				if (theDescriptor.getReadMethod() != null && theDescriptor.getWriteMethod() != null) {
					Object theValue = PropertyUtils.getProperty(this, theDescriptor.getName());
					if (theValue != null) {
						theProperties.setProperty(theDescriptor.getName(), theValue.toString());
					} else {
						theProperties.setProperty(theDescriptor.getName(), null);
					}
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
 
开发者ID:mirkosertic,项目名称:ERDesignerNG,代码行数:20,代码来源:ModelItemProperties.java

示例4: updateConfigFromBean

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private static void updateConfigFromBean(APropertyChangeSupport bean, String... forceAddThisProperties) {
		List<String> addThoseL = Arrays.asList(forceAddThisProperties);

		logger.debug("updating config from bean: "+bean.getClass().getName()+ ", adding those props: "+CoreUtils.toListString(addThoseL));
		
		for (PropertyDescriptor pd :  PropertyUtils.getPropertyDescriptors(bean)) {
			Object value = null;
			try {
//				logger.debug("property name: "+pd.getName());
				value = PropertyUtils.getProperty(bean, pd.getName());
				String strVal = getValue(value);
				if (config.getProperty(pd.getName())!=null) {
					logger.trace("updating property "+pd.getName()+" to "+strVal);
					config.setProperty(pd.getName(), strVal);
				} else if (addThoseL.contains(pd.getName())) {
					logger.debug("adding new property "+pd.getName()+" to "+strVal);
					config.addProperty(pd.getName(), strVal);
				}
			} catch (Exception e) {
				logger.warn("Could not set property "+pd.getName()+" to "+value+", error: "+e.getMessage());
			}
		}
	}
 
开发者ID:Transkribus,项目名称:TranskribusSwtGui,代码行数:24,代码来源:TrpConfig.java

示例5: generateBeanCode

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public String generateBeanCode(Object bean) {
    if (processedBeans.contains(bean)) {
        return getVariableName(bean);
    }
    processedBeans.add(bean);
    String varName = generateVariableName(bean);
    method.addStatement("$T " + varName + " = new $T()", bean.getClass(), bean.getClass());
    PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(bean.getClass());
    for (PropertyDescriptor propertyDescriptor : properties) {
        try {
            generatePropertySetter(bean, varName, propertyDescriptor);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
    return varName;
}
 
开发者ID:arey,项目名称:javabean-marshaller,代码行数:18,代码来源:JavaBeanMarshaller.java

示例6: copyParentProperties

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void copyParentProperties(final CustomField parent, final CustomField child) {
    final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(parent);
    for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        final String name = propertyDescriptor.getName();
        final boolean isWritable = propertyDescriptor.getWriteMethod() != null;
        final boolean isReadable = propertyDescriptor.getReadMethod() != null;
        if (isReadable && isWritable && !EXCLUDED_PROPERTIES_FOR_DEPENDENT_FIELDS.contains(name)) {
            Object value = PropertyHelper.get(parent, name);
            if (value instanceof Collection) {
                value = new ArrayList<Object>((Collection<Object>) value);
            }
            PropertyHelper.set(child, name, value);
        }
    }
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:17,代码来源:BaseCustomFieldServiceImpl.java

示例7: copyProperties

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * Copies all possible properties from source to dest, ignoring the given properties list. Exceptions are ignored
 */
public static void copyProperties(final Object source, final Object dest, final String... ignored) {
    if (source == null || dest == null) {
        return;
    }
    final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(source);
    for (final PropertyDescriptor sourceDescriptor : propertyDescriptors) {
        try {
            final String name = sourceDescriptor.getName();
            // Check for ignored properties
            if (ArrayUtils.contains(ignored, name)) {
                continue;
            }
            final PropertyDescriptor destProperty = PropertyUtils.getPropertyDescriptor(dest, name);
            if (destProperty.getWriteMethod() == null) {
                // Ignore read-only properties
                continue;
            }
            final Object value = CoercionHelper.coerce(destProperty.getPropertyType(), get(source, name));
            set(dest, name, value);
        } catch (final Exception e) {
            // Ignore this property
        }
    }
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:28,代码来源:PropertyHelper.java

示例8: propertyDescriptorsFor

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * Returns a Map with basic properties for the given entity
 */
public static Map<String, PropertyDescriptor> propertyDescriptorsFor(final Entity entity) {
    final Class<? extends Entity> clazz = getRealClass(entity);
    SortedMap<String, PropertyDescriptor> properties = cachedPropertiesByClass.get(clazz);
    if (properties == null) {
        properties = new TreeMap<String, PropertyDescriptor>();
        final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(clazz);
        for (final PropertyDescriptor descriptor : propertyDescriptors) {
            final String name = descriptor.getName();
            boolean ok = name.equals("id");
            if (!ok) {
                final Method readMethod = descriptor.getReadMethod();
                if (readMethod != null) {
                    final Class<?> declaringClass = readMethod.getDeclaringClass();
                    ok = !declaringClass.equals(Entity.class) && !declaringClass.equals(CustomFieldsContainer.class);
                }
            }
            if (ok) {
                properties.put(name, descriptor);
            }
        }
        properties = Collections.unmodifiableSortedMap(properties);
        cachedPropertiesByClass.put(clazz, properties);
    }
    return properties;
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:29,代码来源:EntityHelper.java

示例9: mergeObjects

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * Deep merge to POJO objects
 *
 * @param target The target POJO
 * @param source The source POJO
 * @param <T>    The POJO type
 * @return The merge result
 */
public static <T> T mergeObjects(T target, T source) {
  // Check that target and source are of the same type
  Preconditions.checkArgument(
      target.getClass().equals(source.getClass()),
      "Type mismatch %s -> %s",
      source.getClass().getSimpleName(),
      target.getClass().getSimpleName()
  );

  PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(target);

  EStream.from(descriptors).forEach(propertyDescriptor -> {

    Object targetValue = PropertyUtils.getProperty(target, propertyDescriptor.getName());
    Object sourceValue = PropertyUtils.getProperty(source, propertyDescriptor.getName());

    if (sourceValue != null) {
      if (targetValue == null) {
        PropertyUtils.setProperty(target, propertyDescriptor.getName(), sourceValue);
      } else {
        if (isJavaType(propertyDescriptor)) {
          if (targetValue != sourceValue) {
            PropertyUtils.setProperty(target, propertyDescriptor.getName(), sourceValue);
          }
        } else {
          mergeObjects(targetValue, sourceValue);
        }
      }
    }
  });

  return target;
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:42,代码来源:ObjectGraphs.java

示例10: initializeObjectGraph

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * Recursively initialize all non-primitive properties of an object
 *
 * @param o The object to initialize
 */
public static void initializeObjectGraph(Object o) {
  PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(o);

  EStream.from(descriptors)
      .filter(propertyDescriptor -> !isJavaType(propertyDescriptor))
      .filter(propertyDescriptor -> PropertyUtils.getProperty(o, propertyDescriptor.getName()) == null)
      .forEach(propertyDescriptor -> {
        Class<?> type = propertyDescriptor.getPropertyType();
        Object subO = type.getDeclaredConstructor().newInstance();
        PropertyUtils.setProperty(o, propertyDescriptor.getName(), subO);
        initializeObjectGraph(subO);
      });
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:19,代码来源:ObjectGraphs.java

示例11: initializeBean

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
protected void initializeBean(Object bean) {
    for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(bean)) {
        Method writeMethod = pd.getWriteMethod();
        if (writeMethod == null) {
            continue;
        }
        injectBean(bean, pd);
        injectValue(bean, pd);
    }
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:11,代码来源:DefaultContainer.java

示例12: getConectorPropertyNames

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public static List /*String*/ getConectorPropertyNames(Conector conector) {
    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(conector);
    List list = new ArrayList(descriptors.length);
    for (int i = 0; i < descriptors.length; i++) {
        PropertyDescriptor descriptor = descriptors[i];
        if (descriptor.getWriteMethod() != null) {
            list.add(descriptor.getName());
        }
    }
    return list;
}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:12,代码来源:ConectorConfigurator.java

示例13: getProperties

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private static Set<String> getProperties(Class<?> clss) {
    final Set<String> result = new TreeSet<>();
    final PropertyDescriptor[] map = PropertyUtils.getPropertyDescriptors(clss);

    for (PropertyDescriptor p : map) {
        if (p.getWriteMethod() != null) {
            result.add(p.getName());
        }
    }

    return result;
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:13,代码来源:ChecksTest.java

示例14: copyPropertiesFromTo

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private void copyPropertiesFromTo(User from, User to) throws Exception {
    for (PropertyDescriptor property : PropertyUtils.getPropertyDescriptors(User.class)) {
        if (NO_UPDATE_PROPERTIES.contains(property.getName())) {
            log.debug("Copying property {}", property.getName());
            Method read = property.getReadMethod();
            Method write = property.getWriteMethod();
            if (read.invoke(from) != null) {
                write.invoke(to, read.invoke(from));
            }
        }
    }
}
 
开发者ID:KTH,项目名称:camel-alma,代码行数:13,代码来源:UserServiceWrapper.java

示例15: getFilters

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 获取筛选
 * 
 * @param params
 *            参数
 * @param type
 *            参数类型
 * @param ignoreProperties
 *            忽略属性
 * @return 筛选
 */
protected List<Filter> getFilters(Map<String, TemplateModel> params, Class<?> type, String... ignoreProperties) throws TemplateModelException {
	List<Filter> filters = new ArrayList<Filter>();
	PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type);
	for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
		String propertyName = propertyDescriptor.getName();
		Class<?> propertyType = propertyDescriptor.getPropertyType();
		if (!ArrayUtils.contains(ignoreProperties, propertyName) && params.containsKey(propertyName)) {
			Object value = FreemarkerUtils.getParameter(propertyName, propertyType, params);
			filters.add(Filter.eq(propertyName, value));
		}
	}
	return filters;
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:25,代码来源:BaseDirective.java


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