本文整理汇总了Java中org.apache.commons.beanutils.PropertyUtils.getProperty方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtils.getProperty方法的具体用法?Java PropertyUtils.getProperty怎么用?Java PropertyUtils.getProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.beanutils.PropertyUtils
的用法示例。
在下文中一共展示了PropertyUtils.getProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instanceChildObject
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private void instanceChildObject(Object obj,String propertyName){
int pointIndex=propertyName.indexOf(".");
if(pointIndex==-1){
return;
}
String name=propertyName.substring(0,pointIndex);
propertyName=propertyName.substring(pointIndex+1);
try {
Object instance=PropertyUtils.getProperty(obj, name);
if(instance!=null){
instanceChildObject(instance,propertyName);
return;
}
Object targetEntity=new GeneralEntity(name);
PropertyUtils.setProperty(obj, name, targetEntity);
instanceChildObject(targetEntity,propertyName);
} catch (Exception e) {
throw new RuleException(e);
}
}
示例2: getDynamicFieldByteSize
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
* 获取动态属性长度
*
* @param bean
* @param charset
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
@SuppressWarnings("unchecked")
public int getDynamicFieldByteSize(Object bean, Charset charset)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Object value = PropertyUtils.getProperty(bean, field.getName());
if (null == value) {
return 0;
}
switch (dynamicFieldType) {
// 如果是打包剩余的所有Byte
case allRestByte:
return ((String) value).getBytes(charset).length;
// 如果是文件matedata
case matedata:
return MetadataMapper.toByte((Set<MateData>) value, charset).length;
default:
return getFieldSize(field);
}
}
示例3: getContentTypeFromModel
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private String getContentTypeFromModel(Object model) {
if (model instanceof ContentItem) {
ContentItem contentItem = (ContentItem) model;
return contentItem.getSystem().getType();
}
ContentItemMapping contentItemMapping = model.getClass().getAnnotation(ContentItemMapping.class);
if (contentItemMapping != null) {
return contentItemMapping.value();
}
try {
Object system = PropertyUtils.getProperty(model, "system");
if (system instanceof System) {
return ((System) system).getType();
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
logger.debug("Unable to find System property on model", e);
}
return null;
}
示例4: compare
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public int compare(T o1, T o2) {
Comparable obj1 = null;
Comparable obj2 = null;
try {
obj1 = (Comparable) PropertyUtils.getProperty(o1, this.propertyPath);
obj2 = (Comparable) PropertyUtils.getProperty(o2, this.propertyPath);
} catch (NestedNullException ignored) {
// Ignored, als het property NULL is, dan vergelijken met NULL
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalArgumentException("Could not retrieve property " + this.propertyPath, e);
}
Comparator<Comparable<Object>> objectComparator = null;
if ((obj1 != null && obj2 != null) && obj1 instanceof String) {
obj1 = ((String) obj1).toLowerCase().trim();
obj2 = ((String) obj2).toLowerCase().trim();
if (!StringUtils.isEmpty((String) obj1) && !StringUtils.isEmpty((String) obj2)) {
if (StringUtils.isNumeric((String) obj1) && StringUtils.isNumeric((String) obj2)) {
objectComparator = Comparator.comparingDouble(o -> new Double(String.valueOf(o)));
}
}
}
if (objectComparator == null) {
objectComparator = Comparator.naturalOrder();
}
//noinspection unchecked
return Comparator.nullsLast(objectComparator).compare(obj1, obj2);
}
示例5: getUserSetting
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Produces
@CoreSetting("PRODUCER")
public String getUserSetting(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
if (annotated.isAnnotationPresent(CoreSetting.class)) {
String settingPath = annotated.getAnnotation(CoreSetting.class).value();
Object object = yamlCoreSettings;
String[] split = settingPath.split("\\.");
int c = 0;
while (c < split.length) {
try {
object = PropertyUtils.getProperty(object, split[c]);
c++;
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LogManager.getLogger(getClass()).error("Failed retrieving setting " + settingPath, e);
return null;
}
}
return String.valueOf(object);
}
return null;
}
示例6: getProperty
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public static Object getProperty(Object bean, Object name) {
try {
if(bean.getClass().isArray() && name.equals("length")){
return Array.getLength(bean);
}else if (bean instanceof Class) {
if(name.equals("class")){
return bean;
}else{
Field f = ((Class<?>) bean).getDeclaredField(name.toString());
return f.get(null);
}
}else if(bean instanceof Map ){
return ((Map<?,?>)bean).get(name);
}else {
Object obj = PropertyUtils.getProperty(bean, name.toString());
return obj;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: compare
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
*
* @param o1
* An entry in a map
* @param o2
* Another entry in the map
* @return Comparison result
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public int compare(Object o1, Object o2) {
try {
Object o1Field = PropertyUtils.getProperty(o1, this.attributeName);
Object o2Field = PropertyUtils.getProperty(o2, this.attributeName);
if (o1Field == null) {
return this.direction;
}
if (o2Field == null) {
return -1 * this.direction;
}
if (o1Field instanceof Comparable && o2Field instanceof Comparable) {
return this.direction * ((Comparable) o1Field).compareTo((Comparable) o2Field);
}
} catch (Exception ignore) {
return 0;
}
return 0;
}
示例8: getCurrentTaskInfo
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
* 获取当前节点信息
*
* @param processInstance
* @return
*/
private Task getCurrentTaskInfo(ProcessInstance processInstance) {
Task currentTask = null;
try {
String activitiId = (String) PropertyUtils.getProperty(processInstance, "activityId");
logger.debug("current activity id: {}", activitiId);
currentTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey(activitiId)
.singleResult();
logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));
} catch (Exception e) {
logger.error("can not get property activityId from processInstance: {}", processInstance);
}
return currentTask;
}
示例9: getProperty
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
public Object getProperty(String name) {
if (bean instanceof Map) {
if (bean instanceof MultiValueMap) {
MultiValueMap<String, ?> valueMap = (MultiValueMap<String, ?>) bean;
List<?> values = valueMap.get(name);
if (values == null || values.isEmpty()) {
return null;
} else if (values.size() == 1) {
return values.get(0);
}
return values;
}
return ((Map<String, ?>)bean).get(name);
}
try {
return PropertyUtils.getProperty(bean, name);
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Property '" + name + "' does not exist for object of " +
"type " + bean.getClass().getName() + ".");
}
}
return null;
}
示例10: mapBean
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public void mapBean(Object bean, String beanName, String property, Object value,
Map<String, ConversionOptionBO> conversionOption) throws FlatwormParserException {
try {
ConversionOptionBO option = conversionOption.get("append");
if (option != null && "true".equalsIgnoreCase(option.getValue())) {
Object currentValue = PropertyUtils.getProperty(bean, property);
if (currentValue != null)
value = currentValue.toString() + value;
}
PropertyUtils.setProperty(bean, property, value);
} catch (Exception e) {
log.error("While running set property method for " + beanName + "." + property
+ " with value '" + value + "'", e);
throw new FlatwormParserException("Setting field " + beanName + "." + property);
}
}
示例11: initializeSimpleProperty
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private Object initializeSimpleProperty(Object parentObject, String property, PropertyDescriptor propertyMetaData)
throws Exception
{
Object propertyValue = null;
//A Regular Property
propertyValue = PropertyUtils.getProperty(parentObject, property);
if(propertyValue == null)
{
Object newlyInitialized = propertyMetaData.getPropertyType().newInstance();
PropertyUtils.setProperty(parentObject, property, newlyInitialized);
propertyValue = newlyInitialized;
}
return propertyValue;
}
示例12: decorate
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public void decorate(Object bean, String property, Object strategy) {
try {
Object key = PropertyUtils.getProperty(bean, property);
if(key != null){
SysUser sysUser = null;
if(key instanceof Integer)
sysUser = sysUserAdvanceService.loadByKey((Integer)key);
if(key instanceof String)
sysUser = sysUserAdvanceService.loadByUnique((String)key);
if(sysUser != null)
PropertyUtils.setProperty(bean, (String)strategy, sysUser.getUsername());
}
} catch (NullPointerException | IllegalAccessException | InvocationTargetException
| NoSuchMethodException e) {
log.error(Exceptions.getStackTraceAsString(e));
}
}
示例13: getInsertSql
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public static String getInsertSql(Object entity,Table table, boolean includePk)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
StringBuilder sql = new StringBuilder(),
columnsStr = new StringBuilder(Symbol.L_PARENTHESIS),
valuesStr = new StringBuilder(Symbol.L_PARENTHESIS);
sql.append(" INSERT INTO ").append(Configuration.dialect
.wrapQuote(table.getName()) + Symbol.SPACE);
Collection<Column> columns = table.getColumns().values();
for(Iterator<Column> ite = columns.iterator();ite.hasNext();) {
Column column = ite.next();
if(column.isPrimaryKey() && !includePk)
continue;
columnsStr.append(Symbol.SPACE + Configuration.dialect
.wrapQuote(column.getSqlName()) + (ite.hasNext() ? Symbol.COMMA : Symbol.EMPTY));
Object data = PropertyUtils.getProperty(entity, column.getName());
valuesStr.append(Symbol.SPACE + value2Sql(data) + (ite.hasNext() ? Symbol.COMMA : Symbol.EMPTY));
}
columnsStr.append(Symbol.R_PARENTHESIS);
valuesStr.append(Symbol.R_PARENTHESIS);
return sql.append(columnsStr).append(" VALUES").append(valuesStr).toString();
}
示例14: 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());
}
}
}
示例15: getReference
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private static Object getReference ( final Map<String, Object> map, final String expression )
{
try
{
return PropertyUtils.getProperty ( map, expression );
}
catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException e )
{
throw new RuntimeException ( e );
}
}