Refine search
final Pattern p = Pattern.compile("^(cm_msg|[a-z][a-z][a-z]?)([0-9]+)_(\\w+)$"); try { final java.beans.PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(field); for (final java.beans.PropertyDescriptor property : properties) { final String propertyName = property.getName(); final Matcher matcher = p.matcher(propertyName); if (matcher.find()) { final Type type = (Type) PropertyUtils.getProperty(field, propertyName); if (!isEmpty(type)) { final String componentName = matcher.group(3);
Map<String, PropertyDescriptor> descriptors = Arrays.stream(PropertyUtils.getPropertyDescriptors(target)) .filter(d -> d.getReadMethod() != null && d.getReadMethod().isAnnotationPresent(PersistentProperty.class)) .collect(Collectors.toMap(PropertyDescriptor::getName, d -> d)); if (descriptors.containsKey(saved.getKey())) { try { PropertyUtils.setProperty(target, saved.getKey(), saved.getValue()); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { System.err.println("Error setting property " + saved.getKey() + " on a " + target.getClass().getSimpleName());
fieldNameBuilder.append(nestedFields[level]); String currentFieldName = fieldNameBuilder.toString(); Object fieldVal = PropertyUtils.getProperty(bean, currentFieldName); if (fieldVal == null) { PropertyUtils.getPropertyDescriptor(bean, currentFieldName); Object defaultInstance = fieldDescriptor.getPropertyType().newInstance(); PropertyUtils.setNestedProperty(bean, currentFieldName, defaultInstance); PropertyUtils.setNestedProperty(bean, propertyName, value); } catch (Exception e) { throw new MetaException(
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); } }
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; } }
public static void setProperty(Object bean, Object name, Object value) { try { if (bean instanceof Class) { Field f = ((Class<?>) bean).getDeclaredField(name.toString()); f.set(null, value); }else if(bean instanceof Map ){ ((Map<Object,Object>)bean).put(name, value); } else { Class<?> filedClass = PropertyUtils.getPropertyType(bean, name.toString()); PropertyUtils.setProperty(bean, name.toString(),ExpressUtil.castObject(value, filedClass, false)); } } catch (Exception e) { throw new RuntimeException("不能访问" + bean + "的property:" + name,e); } }
private PropertyDescriptor getPropertyDescriptor(String name) { for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(xmlizable)) { if (descriptor.getName().equals(name) && descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { return descriptor; } } return null; }
PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(openmrsObject); for (PropertyDescriptor property : properties) { if (property.getPropertyType() == null) { continue; if (property.getWriteMethod() == null || property.getReadMethod() == null) { continue; Object value = PropertyUtils.getProperty(openmrsObject, property.getName()); if (value == null) { continue; PropertyUtils.setProperty(openmrsObject, property.getName(), value); PropertyUtils.setProperty(openmrsObject, property.getName(), null);
static PropertyDescriptor[] getInterfacePropertyDescriptors(Class<?> interfaceClass) { List<PropertyDescriptor> propDescriptors = new ArrayList<>(); propDescriptors.addAll(Arrays.asList(PropertyUtils.getPropertyDescriptors(interfaceClass))); PropertyDescriptor existingPropDescriptor = findPropDescriptorByName(propDescriptors, superPropDescriptor.getName()); if (existingPropDescriptor == null) { propDescriptors.add(superPropDescriptor); } else { try { if (existingPropDescriptor.getReadMethod() == null) { existingPropDescriptor.setReadMethod(superPropDescriptor.getReadMethod()); if (existingPropDescriptor.getWriteMethod() == null) {
SimpleBeanModelNode node = new SimpleBeanModelNode(root.getClass()); for (PropertyDescriptor d : PropertyUtils.getPropertyDescriptors(root)) { if (d.getReadMethod() == null) { continue; if (d.getReadMethod().isAnnotationPresent(PersistentSequence.class)) { Object val = d.getReadMethod().invoke(root); if (!Collection.class.isAssignableFrom(val.getClass())) { continue;
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; }
private List<PropertyDescriptor> getPropertyDescriptors() { List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>(); for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(xmlizable)) { if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { descriptors.add(descriptor); } } return descriptors; } }
Map<String, DictionaryInfo> sets = new TreeMap<String, DictionaryInfo>( String.CASE_INSENSITIVE_ORDER ); PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors( entityClass ); String name = descriptor.getName(); propertyInfo.setType( descriptor.getPropertyType() );
for (PropertyDescriptor prop : PropertyUtils.getPropertyDescriptors(node.getClass())) { if (prop.getReadMethod() != null && Modifier.isPublic(prop.getReadMethod().getModifiers()) && prop.getReadMethod().getDeclaringClass() == node.getClass()) {
/** * Returns property accessor by class property name. * * @param clazz class from which to get property accessor. * @param prop name of the property. * * @return property accessor. */ public static PojoFieldAccessor getPojoFieldAccessor(Class clazz, String prop) { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz); if (descriptors != null) { for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getName().equals(prop)) { Field field = null; try { field = clazz.getDeclaredField(prop); } catch (Throwable ignore) { } return new PojoFieldAccessor(descriptor, field); } } } try { return new PojoFieldAccessor(clazz.getDeclaredField(prop)); } catch (Throwable e) { throw new IllegalArgumentException("POJO class " + clazz.getName() + " doesn't have '" + prop + "' property"); } }
/** * @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]); }
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); } }
private Object getPropertyValue(ASTCssNode object, PropertyDescriptor descriptor) { try { Object result = PropertyUtils.getProperty(object, descriptor.getName()); return result; } catch (IllegalAccessException e) { throw new BugHappened(e, object); } catch (InvocationTargetException e) { throw new BugHappened(e, object); } catch (NoSuchMethodException e) { throw new BugHappened(e, object); } }
@Override public void exitFieldAccess(FieldAccessExpression expr) { final CodeBlock object = codeSnippet.get(expr.object()); final CodeBlock field = codeSnippet.get(expr.field()); final Object objectRef = blockOrMissing(object, expr.object()); final Expression o = expr.object(); final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(o.getType()); final ImmutableMap<String, PropertyDescriptor> propertyByName = Maps.uniqueIndex(Iterators.forArray(propertyDescriptors), FeatureDescriptor::getName); final String fieldName = field.toString(); final CodeBlock block; if (propertyByName.containsKey(fieldName)) { // we have the property, resolve the read method name for it final PropertyDescriptor descriptor = propertyByName.get(fieldName); final String methodName = descriptor.getReadMethod().getName(); block = CodeBlock.of("$L.$L()", objectRef, methodName); } else if (o instanceof Map) { // there wasn't any property, but the object is a Map, translate into .get() call block = CodeBlock.of("$L.get($S)", objectRef, field); } else { // this is basically an error, because we expected either a property to match or a map lookup. log.warn("Unable to determine field accessor for property {}", field); block = CodeBlock.of("null"); } codeSnippet.put(expr, block); }
@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; } } };