List of usage examples for java.beans PropertyDescriptor getReadMethod
public synchronized Method getReadMethod()
From source file:org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor.java
public Object getDataValue(R rowObj, int columnIndex) { try {// w w w . j av a2 s . co m PropertyDescriptor propertyDesc = getPropertyDescriptor(rowObj, columnIndex); Method readMethod = propertyDesc.getReadMethod(); return readMethod.invoke(rowObj); } catch (Exception e) { log.warn(e); throw new RuntimeException(e); } }
From source file:de.erdesignerng.dialect.ModelItemProperties.java
public void initializeFrom(T aObject) { ModelProperties theProperties = aObject.getProperties(); try {//w w w .j a va2s. c om for (PropertyDescriptor theDescriptor : PropertyUtils.getPropertyDescriptors(this)) { if (theDescriptor.getReadMethod() != null && theDescriptor.getWriteMethod() != null) { String theValue = theProperties.getProperty(theDescriptor.getName()); if (!StringUtils.isEmpty(theValue)) { Class theType = theDescriptor.getPropertyType(); if (theType.isEnum()) { PropertyUtils.setProperty(this, theDescriptor.getName(), Enum.valueOf(theType, theValue)); } if (String.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), theValue); } if (Long.class.equals(theType) || long.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), Long.parseLong(theValue)); } if (Integer.class.equals(theType) || int.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), Integer.parseInt(theValue)); } if (Boolean.class.equals(theType) || boolean.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), Boolean.parseBoolean(theValue)); } } } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.beangle.ems.security.restrict.service.IdentifierDataResolver.java
@SuppressWarnings("unchecked") public <T> List<T> unmarshal(RestrictField field, String text) { if (null == field.getType()) { return (List<T>) CollectUtils.newArrayList(StringUtils.split(text, ",")); } else {//w ww .j a v a 2 s . co m Class<?> clazz = null; try { clazz = Class.forName(field.getType()); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new RuntimeException(e); } EntityType myType = Model.getEntityType(clazz); OqlBuilder<T> builder = OqlBuilder.from(myType.getEntityName(), "restrictField"); String[] ids = StringUtils.split(text, ","); PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(clazz, field.getKeyName()); Class<?> propertyType = pd.getReadMethod().getReturnType(); List<Object> realIds = CollectUtils.newArrayList(ids.length); for (String id : ids) { Object realId = ConvertUtils.convert(id, propertyType); realIds.add(realId); } builder.where("restrictField." + field.getKeyName() + " in (:ids)", realIds).cacheable(); return entityDao.search(builder); } }
From source file:com.expedia.seiso.domain.service.impl.ItemMerger.java
@SneakyThrows private void mergeSimpleProperty(Item src, Item dest, PropertyDescriptor propDesc) { val getter = propDesc.getReadMethod(); val setter = propDesc.getWriteMethod(); if (getter == null || setter == null) { log.trace("Skipping simple property: {}", propDesc.getName()); return;//from w ww . j a va 2 s. c o m } val propValue = getter.invoke(src); setter.invoke(dest, propValue); }
From source file:de.micromata.genome.db.jpa.history.impl.DefaultHistoryPropertyProvider.java
License:asdf
/** * Read property value.//from w w w . j av a 2s. c o m * * @param entity the entity * @param pd the pd * @return the object */ protected Object readPropertyValue(Object entity, PropertyDescriptor pd) { Method method = pd.getReadMethod(); try { Object value = method.invoke(entity); return value; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { GLog.warn(GenomeLogCategory.Jpa, "Hist; Cannot read property: " + ex.getMessage(), new LogExceptionAttribute(ex)); return null; } }
From source file:org.bibsonomy.database.validation.DatabaseModelValidator.java
/** * checks if the string attributes of the model respect the field lengths of * the database//ww w. j a v a2 s.co m * * @param model the model to validate * @param id the id of the model (used for the errormessage) * @param session the session */ public void validateFieldLength(final T model, final String id, final DBSession session) { final Class<? extends Object> clazz = model.getClass(); final FieldLengthErrorMessage fieldLengthError = new FieldLengthErrorMessage(); try { final BeanInfo bi = Introspector.getBeanInfo(clazz); /* * loop through all properties * if there are any performance issues, their cause might be here */ for (final PropertyDescriptor d : bi.getPropertyDescriptors()) { final Method getter = d.getReadMethod(); if (present(getter)) { final Object value = getter.invoke(model, (Object[]) null); /* * check max length */ if (value instanceof String) { final String stringValue = (String) value; final int length = stringValue.length(); final String propertyName = d.getName(); final int maxLength = DatabaseSchemaInformation.getInstance() .getMaxColumnLengthForProperty(clazz, propertyName); if ((maxLength > 0) && (length > maxLength)) { fieldLengthError.addToFields(propertyName, maxLength); } } } } if (fieldLengthError.hasErrors()) { session.addError(id, fieldLengthError); log.warn("Added fieldlengthError"); } } catch (final Exception ex) { log.error("could not introspect object of class 'user'", ex); } }
From source file:com.bradmcevoy.property.BeanPropertySource.java
@Override public List<QName> getAllPropertyNames(Resource r) { BeanPropertyResource anno = getAnnotation(r); if (anno == null) return null; PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(r); List<QName> list = new ArrayList<QName>(); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null) { list.add(new QName(anno.value(), pd.getName())); }//from w ww .j a v a2s. co m } return list; }
From source file:com.avanza.ymer.MongoQueryFactory.java
/** * @param template Template object/*from w w w. j a va 2 s . co m*/ * @return A Spring mongo {@link Query} */ public Query createMongoQueryFromTemplate(Object template) { try { Criteria criteria = null; BasicMongoPersistentEntity<?> pe = mongoMappingContext.getPersistentEntity(template.getClass()); for (PropertyDescriptor pd : getTemplatablePropertyDescriptors(template.getClass())) { Object objectValue = pd.getReadMethod().invoke(template); if (objectValue == null) { continue; // null == accept any value } String fieldName = pe.getPersistentProperty(pd.getName()).getFieldName(); Object mongoValue = mongoConverter.convertToMongoType(objectValue); criteria = addCriteria(criteria, fieldName, mongoValue); } return criteria != null ? new Query(criteria) : new Query(); } catch (Exception e) { throw new CouldNotCreateMongoQueryException(e); } }
From source file:com.orange.mmp.api.ws.jsonrpc.SimpleBeanSerializer.java
@Override public Object marshall(SerializerState state, Object p, Object o) throws MarshallException { JSONObject jsonObj = new JSONObject(); try {//from www .j a v a 2 s. co m BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class); for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod != null) { Object propValue = readMethod.invoke(o); Object json = ser.marshall(state, o, propValue, propertyDescriptor.getName()); jsonObj.put(propertyDescriptor.getName(), json); } } } catch (JSONException jse) { throw new MarshallException("Failed to marshall Bean"); } catch (IllegalAccessException iae) { throw new MarshallException("Failed to analyse Bean"); } catch (InvocationTargetException ite) { throw new MarshallException("Failed to analyse Bean"); } catch (IntrospectionException ie) { throw new MarshallException("Failed to analyse Bean"); } return jsonObj; }
From source file:io.milton.property.BeanPropertySource.java
@Override public List<QName> getAllPropertyNames(Resource r) { BeanPropertyResource anno = getAnnotation(r); if (anno == null) { return null; }/*w w w . java2s. c om*/ PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(r); List<QName> list = new ArrayList<QName>(); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null) { list.add(new QName(anno.value(), pd.getName())); } } return list; }