當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertyUtils.getProperty方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:21,代碼來源:PackageServletHandler.java

示例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);
    }
}
 
開發者ID:whatodo,項目名稱:FastDFS_Client,代碼行數:29,代碼來源:FieldMateData.java

示例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;
}
 
開發者ID:Kentico,項目名稱:delivery-sdk-java,代碼行數:20,代碼來源:ThymeleafTemplateEngine.java

示例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);
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:34,代碼來源:XmlElementPathBeanComparator.java

示例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;
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:27,代碼來源:UserSettingsProducer.java

示例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);
	}
}
 
開發者ID:alibaba,項目名稱:QLExpress,代碼行數:22,代碼來源:ExpressUtil.java

示例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;
}
 
開發者ID:mrfrag,項目名稱:spring-data-mapdb,代碼行數:32,代碼來源:PropertyComparator.java

示例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;
}
 
開發者ID:batizhao,項目名稱:microservice,代碼行數:22,代碼來源:WorkflowTraceService.java

示例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;
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:26,代碼來源:BeanReader.java

示例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);
    }
}
 
開發者ID:ahenson,項目名稱:flatworm,代碼行數:18,代碼來源:PropertyUtilsMappingStrategy.java

示例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;
}
 
開發者ID:ZalemSoftware,項目名稱:OpenMobster,代碼行數:17,代碼來源:TestBeanSyntax.java

示例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));
	}
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:19,代碼來源:SysUserDecorator.java

示例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();
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:26,代碼來源:SqlUtils.java

示例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());
			}
		}
	}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:24,代碼來源:TrpConfig.java

示例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 );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:DefaultExecutableFactory.java


注:本文中的org.apache.commons.beanutils.PropertyUtils.getProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。