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); } }
public static Class<?> getPropertyClass(Object bean, Object name) { try { if(bean.getClass().isArray() && name.equals("length")){ return int.class; }else if (bean instanceof Class) { if(name.equals("class")){ return Class.class; }else{ Field f = ((Class<?>) bean).getDeclaredField(name.toString()); return f.getType(); } }else if(bean instanceof Map ){ Object o = ((Map<?,?>)bean).get(name); if(o == null){ return null; }else{ return o.getClass(); } }else { return PropertyUtils.getPropertyDescriptor(bean, name.toString()).getPropertyType(); } } catch (Exception e) { throw new RuntimeException(e); } } public static void setProperty(Object bean, Object name, Object value) {
PropertyUtils.getPropertyDescriptor(bean, currentFieldName);
PropertyUtils.getPropertyDescriptor(top, actualName); if (desc == null) { throw new NoSuchMethodException
PropertyUtils.getPropertyDescriptor(top, propName); if (desc == null) { throw new NoSuchMethodException
PropertyUtils.getPropertyDescriptor(top, property); if (desc == null) { throw new NoSuchMethodException
PropertyUtils.getPropertyDescriptor(this, key); if (descriptor == null) { final String message = String.format(Locale.ROOT, "Property '%s' in module %s "
+ propertyName)); final PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(instance, propertyName); result = descriptor.getPropertyType();
public PropertyDescriptor getPropertyDescriptor(Object r, String name) { try { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(r, name); return pd; } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { throw new RuntimeException(ex); } catch (NoSuchMethodException ex) { return null; } } }
public static String property(Class<?> clz, String name) { try { PropertyUtils.getPropertyDescriptor(clz, name); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } return name; } }
public SchemaFactoryImpl() { try { defaultField = PropertyUtils.getPropertyDescriptor(this, "defaultField").getReadMethod() .getAnnotation(io.github.ibuildthecloud.gdapi.annotation.Field.class); defaultType = this.getClass().getAnnotation(io.github.ibuildthecloud.gdapi.annotation.Type.class); } catch (Exception e) { throw new IllegalStateException(e); } }
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); } }
protected boolean hasProperty(Object key) { try { return PropertyUtils.getPropertyDescriptor(this.getWrappedContent(), (String) key) != null; } catch (Exception e) { return false; } }
private void writeValue(String property, Object value) { try { if (PropertyUtils.getPropertyDescriptor(model, property) != null) { BeanUtils.setProperty(model, property, value); } } catch (Exception e) { logger.warn("Error modifying object '{}': cannot set value '{}' to property '{}'", model, value, property); logger.warn("Caused by:", e); } }
public static PropertyDescriptor getPropertyDescriptor(Object bean, String name) { try { return org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(bean, name); }catch(Exception e) { handleException(e); return null; } }
protected void setProperty(Object obj, String prop, Record record, Field<?> field) { try { PropertyDescriptor desc = PropertyUtils.getPropertyDescriptor(obj, prop); if (desc != null && desc.getWriteMethod() != null) { Object value = record.getValue(field, desc.getWriteMethod().getParameterTypes()[0]); PropertyUtils.setProperty(obj, prop, value); } } catch (IllegalAccessException e) { throw new IllegalArgumentException("Failed to set property [" + prop + "] on [" + obj + "]", e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("Failed to set property [" + prop + "] on [" + obj + "]", e); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Failed to set property [" + prop + "] on [" + obj + "]", e); } }
public Map<String, byte[]> writeValue(TaggedLogAPIEntity entity, EntityDefinition ed) throws Exception { Map<String, byte[]> qualifierValues = new HashMap<String, byte[]>(); // iterate all modified qualifiers for (String fieldName : entity.modifiedQualifiers()) { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(entity, fieldName); Object obj = pd.getReadMethod().invoke(entity); Qualifier q = ed.getDisplayNameMap().get(fieldName); EntitySerDeser<Object> ser = q.getSerDeser(); byte[] value = ser.serialize(obj); qualifierValues.put(q.getQualifierName(), value); } return qualifierValues; } }
/** * @verifies throw IllegalArgumentException when instance class is null * @see ConversionUtil#getTypeVariableClass(Class, java.lang.reflect.TypeVariable) */ @Test(expected = IllegalArgumentException.class) public void getTypeVariableClass_shouldThrowIllegalArgumentExceptionWhenInstanceClassIsNull() throws Exception { GrandchildGenericType_Int i = new GrandchildGenericType_Int(); Method setter = PropertyUtils.getPropertyDescriptor(i, "value").getWriteMethod(); Type type = ConversionUtil.getTypeVariableClass(null, (TypeVariable<?>) setter.getGenericParameterTypes()[0]); }
/** * @verifies return null when actual type cannot be found * @see ConversionUtil#getTypeVariableClass(Class, java.lang.reflect.TypeVariable) */ @Test public void getTypeVariableClass_shouldReturnNullWhenActualTypeCannotBeFound() throws Exception { GrandchildGenericType_Int i = new GrandchildGenericType_Int(); Method setter = PropertyUtils.getPropertyDescriptor(i, "value").getWriteMethod(); Type type = ConversionUtil.getTypeVariableClass(Temp.class, (TypeVariable<?>) setter.getGenericParameterTypes()[0]); Assert.assertNull(type); }
/** * @verifies resolve TypeVariables to actual type * @see ConversionUtil#convert(Object, java.lang.reflect.Type) */ @Test public void convert_shouldResolveTypeVariablesToActualType() throws Exception { ChildGenericType_Int i = new ChildGenericType_Int(); Method setter = PropertyUtils.getPropertyDescriptor(i, "value").getWriteMethod(); Object result = ConversionUtil.convert("25", setter.getGenericParameterTypes()[0], i); Assert.assertNotNull(result); Assert.assertEquals(25, result); }