public static Object getPublicProperty(Object o, String p) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(o, p); if(pd==null) { // field? try { Field f = o.getClass().getField(p); return f.get(o); } catch (NoSuchFieldException e) { throw new IllegalArgumentException("No such property "+p+" on "+o.getClass()); } } else { return PropertyUtils.getProperty(o, p); } }
@Override public int compare(Object o1, Object o2) { try { return ((Comparable) PropertyUtils.getProperty(o1, "sequence")).compareTo(PropertyUtils.getProperty(o2, "sequence")); } catch (Exception e) { LOG.warn("Trying to compare objects that do not have a sequence property, assuming they are the same order"); return 0; } } };
/** Returns a <code>SoftReference</code> to the actual data stored into the DataBuffer */ private static SoftReference<?> getBankReference(DataBuffer db) { try { Object array = PropertyUtils.getProperty(db, "bankData"); return new SoftReference<Object>(array); } catch (Exception e) { throw new UnsupportedOperationException("Unknown data buffer type " + db); } } }
fieldNameBuilder.append(nestedFields[level]); String currentFieldName = fieldNameBuilder.toString(); Object fieldVal = PropertyUtils.getProperty(bean, currentFieldName); if (fieldVal == null) {
private Object getProperty(Object bean, String fieldName) { try { Object property = PropertyUtils.getProperty(bean, fieldName); if (property == null) { // in case the bean is a Map, try again with a simple property, it might be masked by the Map property = PropertyUtils.getSimpleProperty(bean, fieldName); } log.debug("[field access] property {} of bean {}: {}", fieldName, bean.getClass().getTypeName(), property); return property; } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { log.debug("Unable to read property {} from {}", fieldName, bean); return null; } }
@Override public String getStringValueFromGetter(Serializable instance, String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Object value = PropertyUtils.getProperty(instance, propertyName); return formatValue(value); }
public Object get(String propertyName) { BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext(); if (brc != null) { try { return PropertyUtils.getProperty(brc, propertyName); } catch (Exception e) { throw new RuntimeException(e); } } return null; }
@SuppressWarnings("all") protected boolean matchCreatorId(Object result, String userId) { if (null == result) { return true; } if (result instanceof RecordCreationEntity) { return userId.equals(((RecordCreationEntity) result).getCreatorId()); } else if (result instanceof Collection) { Collection<?> collection = ((Collection) result); //删掉不能访问的对象 collection.removeAll(collection.stream().filter((Object o) -> !matchCreatorId(o, userId)).collect(Collectors.toList())); } else { try { return userId.equals(PropertyUtils.getProperty(result, "creatorId")); } catch (Exception ignore) { } } return true; } }
final Object propValue = PropertyUtils.getProperty( object, propertyName ); evaluation = predicate.evaluate(propValue); } catch (final IllegalArgumentException e) {
final Object propValue = PropertyUtils.getProperty( object, propertyName ); evaluation = predicate.evaluate(propValue); } catch (final IllegalArgumentException e) {
public static Object getProperty(Object bean, Object name) { try { if(bean==null && QLExpressRunStrategy.isAvoidNullPointer()){ return null; } 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); } } public static Class<?> getPropertyClass(Object bean, Object name) {
value = PropertyUtils.getProperty(bean, property);
@Override public String getEntityId(TranslatedEntity entityType, Object entity) { Map<String, Object> idMetadata = getIdPropertyMetadata(entityType); String idProperty = (String) idMetadata.get("name"); Type idType = (Type) idMetadata.get("type"); if (!(idType instanceof LongType || idType instanceof StringType)) { throw new UnsupportedOperationException("Only ID types of String and Long are currently supported"); } Object idValue; try { idValue = PropertyUtils.getProperty(entity, idProperty); } catch (Exception e) { throw new RuntimeException("Error reading id property", e); } if (idType instanceof StringType) { return (String) idValue; } else if (idType instanceof LongType) { return getUpdatedEntityId(entityType, (Long) idValue); } throw new IllegalArgumentException(String.format("Could not retrieve value for id property. Object: [%s], " + "ID Property: [%s], ID Type: [%s]", entity, idProperty, idType)); }
/** * Compare two JavaBeans by their shared property. * If {@link #getProperty} is null then the actual objects will be compared. * * @param o1 Object The first bean to get data from to compare against * @param o2 Object The second bean to get data from to compare * @return int negative or positive based on order */ public int compare( final T o1, final T o2 ) { if ( property == null ) { // compare the actual objects return internalCompare( o1, o2 ); } try { final Object value1 = PropertyUtils.getProperty( o1, property ); final Object value2 = PropertyUtils.getProperty( o2, property ); return internalCompare( value1, value2 ); } catch ( final IllegalAccessException iae ) { throw new RuntimeException( "IllegalAccessException: " + iae.toString() ); } catch ( final InvocationTargetException ite ) { throw new RuntimeException( "InvocationTargetException: " + ite.toString() ); } catch ( final NoSuchMethodException nsme ) { throw new RuntimeException( "NoSuchMethodException: " + nsme.toString() ); } }
/** * Compare two JavaBeans by their shared property. * If {@link #getProperty} is null then the actual objects will be compared. * * @param o1 Object The first bean to get data from to compare against * @param o2 Object The second bean to get data from to compare * @return int negative or positive based on order */ public int compare( final T o1, final T o2 ) { if ( property == null ) { // compare the actual objects return internalCompare( o1, o2 ); } try { final Object value1 = PropertyUtils.getProperty( o1, property ); final Object value2 = PropertyUtils.getProperty( o2, property ); return internalCompare( value1, value2 ); } catch ( final IllegalAccessException iae ) { throw new RuntimeException( "IllegalAccessException: " + iae.toString() ); } catch ( final InvocationTargetException ite ) { throw new RuntimeException( "InvocationTargetException: " + ite.toString() ); } catch ( final NoSuchMethodException nsme ) { throw new RuntimeException( "NoSuchMethodException: " + nsme.toString() ); } }
try { @SuppressWarnings("unchecked") Collection<SettingsOwner> tmp = (Collection<SettingsOwner>) PropertyUtils.getProperty(target, model.getPropertyName()); container = tmp; } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
/** * Returns an indexed property from the object we're validating. * * @param bean The bean to extract the indexed values from. * @throws ValidatorException If there's an error looking up the property * or, the property found is not indexed. */ Object[] getIndexedProperty(Object bean) throws ValidatorException { Object indexedProperty = null; try { indexedProperty = PropertyUtils.getProperty(bean, this.getIndexedListProperty()); } catch(IllegalAccessException e) { throw new ValidatorException(e.getMessage()); } catch(InvocationTargetException e) { throw new ValidatorException(e.getMessage()); } catch(NoSuchMethodException e) { throw new ValidatorException(e.getMessage()); } if (indexedProperty instanceof Collection) { return ((Collection<?>) indexedProperty).toArray(); } else if (indexedProperty.getClass().isArray()) { return (Object[]) indexedProperty; } else { throw new ValidatorException(this.getKey() + " is not indexed"); } } /**
/** * Returns the size of an indexed property from the object we're validating. * * @param bean The bean to extract the indexed values from. * @throws ValidatorException If there's an error looking up the property * or, the property found is not indexed. */ private int getIndexedPropertySize(Object bean) throws ValidatorException { Object indexedProperty = null; try { indexedProperty = PropertyUtils.getProperty(bean, this.getIndexedListProperty()); } catch(IllegalAccessException e) { throw new ValidatorException(e.getMessage()); } catch(InvocationTargetException e) { throw new ValidatorException(e.getMessage()); } catch(NoSuchMethodException e) { throw new ValidatorException(e.getMessage()); } if (indexedProperty == null) { return 0; } else if (indexedProperty instanceof Collection) { return ((Collection<?>)indexedProperty).size(); } else if (indexedProperty.getClass().isArray()) { return ((Object[])indexedProperty).length; } else { throw new ValidatorException(this.getKey() + " is not indexed"); } }
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { Object value = null; try { value = PropertyUtils.getProperty( source, propertyName ); if ( null == value ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } } catch ( IllegalAccessException e ) { JobEntryValidatorUtils.addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e ); } catch ( InvocationTargetException e ) { JobEntryValidatorUtils.addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e ); } catch ( NoSuchMethodException e ) { JobEntryValidatorUtils.addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e ); } return false; }
@Override public MetadataProviderResponse extractValue(ExtractValueRequest extractValueRequest, Property property) throws PersistenceException { if (!canHandleExtraction(extractValueRequest, property)) { return MetadataProviderResponse.NOT_HANDLED; } Object displayValue = extractValueRequest.getRequestedValue(); if (displayValue == null) { try { displayValue = PropertyUtils.getProperty(extractValueRequest.getEntity(), property.getName()); ((BasicFieldMetadata)property.getMetadata()).setDerived(true); } catch (Exception e) { //swallow all exceptions because null is fine for the display value } } Object actualValue = extractValueRequest.getRequestedValue(); property.setValue(formatValue(actualValue, extractValueRequest, property)); property.setDisplayValue(formatDisplayValue(displayValue, extractValueRequest, property)); return MetadataProviderResponse.HANDLED_BREAK; }