List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:com.esofthead.mycollab.validator.constraints.DateComparisionValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { try {//from w w w .ja v a2 s . co m Date firstDate = (Date) PropertyUtils.getProperty(value, firstDateField); Date lastDate = (Date) PropertyUtils.getProperty(value, lastDateField); return (DateTimeUtils.compareByDate(firstDate, lastDate) > 0) ? false : true; } catch (Exception ex) { return true; } }
From source file:com.cyclopsgroup.waterview.utils.BeanPropertyComparator.java
/** * Overwrite or implement method compare() * * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) *//*from w ww . j a v a 2s .c o m*/ public int compare(Object o1, Object o2) { try { Comparable p1 = (Comparable) PropertyUtils.getProperty(o1, propertyName); Comparable p2 = (Comparable) PropertyUtils.getProperty(o2, propertyName); return p1.compareTo(p2); } catch (Exception e) { return 0; } }
From source file:com.esofthead.mycollab.schedule.email.format.EmailLinkFieldFormat.java
@Override public String formatField(MailContext<?> context) { Object wrappedBean = context.getWrappedBean(); Object value;/* www . j a va 2 s . c o m*/ try { value = PropertyUtils.getProperty(wrappedBean, fieldName); return formatEmail((String) value); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { log.error("Error", e); return new Span().write(); } }
From source file:com.pasteur.ci.action.type_gene_cyano.CreerTypeGeneCyanoAction.java
/** * This is the action called from the Struts framework. * * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception/*from w w w .j av a2s . co m*/ * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String design_typ_gene_cyano = (String) PropertyUtils.getProperty(form, "design_typ_gene_cyano"); double conc_typ_gene_cyano = (Double) PropertyUtils.getProperty(form, "conc_typ_gene_cyano"); boolean visible = (Boolean) PropertyUtils.getProperty(form, "visible"); TypeGeneCyano type_gene_cyano = new TypeGeneCyano(); type_gene_cyano.setDesign_typ_gene_cyano(design_typ_gene_cyano); type_gene_cyano.setVisible(visible); TypeGeneCyanoDAOImplement gdaoi = new TypeGeneCyanoDAOImplement(DAOFactory.getInstance()); gdaoi.create(type_gene_cyano); return mapping.findForward(SUCCESS); }
From source file:com.pasteur.ci.action.type_gene_cyano.EnregistreModifTypeGeneCyanoAction.java
/** * This is the action called from the Struts framework. * * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception// w w w. j a v a2 s .c o m * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int idtyp_gene_cyano = (Integer) PropertyUtils.getProperty(form, "idtyp_gene_cyano"); String design_typ_gene_cyano = (String) PropertyUtils.getProperty(form, "design_typ_gene_cyano"); double conc_typ_gene_cyano = (Double) PropertyUtils.getProperty(form, "conc_typ_gene_cyano"); boolean visible = (Boolean) PropertyUtils.getProperty(form, "visible"); TypeGeneCyano gene_cyano = new TypeGeneCyano(); gene_cyano.setIdtyp_gene_cyano(idtyp_gene_cyano); gene_cyano.setDesign_typ_gene_cyano(design_typ_gene_cyano); gene_cyano.setVisible(visible); TypeGeneCyanoDAOImplement gdaoi = new TypeGeneCyanoDAOImplement(DAOFactory.getInstance()); gdaoi.update(gene_cyano); return mapping.findForward(SUCCESS); }
From source file:com.pasteur.ci.action.type_gene_toxicite.GestionModifPageTypeGeneToxiciteAction.java
/** * This is the action called from the Struts framework. * * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception//from ww w .ja v a 2s . co m * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int comId = (Integer) PropertyUtils.getProperty(form, "idtyp_gene_toxicite"); TypeGeneToxicite typ_gene_toxicite = new TypeGeneToxicite(); typ_gene_toxicite.setIdtyp_gene_toxicite(comId); TypeGeneToxiciteDAOImplement cdaoi = new TypeGeneToxiciteDAOImplement(DAOFactory.getInstance()); typ_gene_toxicite = (TypeGeneToxicite) cdaoi.find(typ_gene_toxicite); request.setAttribute("tygeneToxi_trouve", typ_gene_toxicite); return mapping.findForward(SUCCESS); }
From source file:com.pasteur.ci.action.creation.ajaxGenreAlgueAction.java
/** * This is the action called from the Struts framework. * * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception//from w ww. j av a 2s .c o m * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int idfamille = (Integer) PropertyUtils.getProperty(form, "idfamille"); GenreAlgueDAOImplement gadaoi = new GenreAlgueDAOImplement(DAOFactory.getInstance()); ArrayList<GenreAlgue> listgenre = (ArrayList<GenreAlgue>) (Object) gadaoi.find(idfamille); HashMap hm = new HashMap(); for (GenreAlgue ga : listgenre) { String hu = "hu" + ga.getIdgenre_algue(); hm.put(hu, ga.getDesign_genre_algue()); // System.out.println(Integer.toString(ga.getIdgenre_algue())+" --"+ga.getDesign_genre_algue()); } // chaque cl de notre map devient une cl dans l'objet JSON (utilisation de Json-lib) JSONObject json = JSONObject.fromObject(hm); // faon d'envoyer l'objet JSON pour que Prototype puisse le rcuprer response.setHeader("X-JSON", json.toString()); return null; }
From source file:com.glaf.core.util.Tools.java
@SuppressWarnings("unchecked") public static Map<String, Object> getDataMap(Object target) { Map<String, Object> dataMap = new TreeMap<String, Object>(); if (Map.class.isAssignableFrom(target.getClass())) { Map<String, Object> map = (Map<String, Object>) target; Set<Entry<String, Object>> entrySet = map.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { dataMap.put(key.toString(), value); }/*from w ww . jav a2 s . c o m*/ } } else { PropertyDescriptor[] propertyDescriptor = BeanUtils.getPropertyDescriptors(target.getClass()); for (int i = 0; i < propertyDescriptor.length; i++) { PropertyDescriptor descriptor = propertyDescriptor[i]; String propertyName = descriptor.getName(); if (propertyName.equalsIgnoreCase("class")) { continue; } try { Object value = PropertyUtils.getProperty(target, propertyName); dataMap.put(propertyName, value); } catch (Exception ex) { } } } return dataMap; }
From source file:com.vangent.hieos.empi.transform.FuzzyNameSearchTransformFunction.java
/** * * @param obj/*w w w . ja v a 2 s . c o m*/ * @return */ public Object transform(Object obj) { SubjectName subjectName = (SubjectName) obj; // Get search mode. boolean isFuzzySearchMode = subjectName.isFuzzySearchMode(); // Get field name to access from SubjectName. String fieldName = this.getFunctionConfig().getParameter(PARAM_FIELD_NAME); if (logger.isTraceEnabled()) { logger.trace(this.getClass().toString() + " fuzzy search mode = " + isFuzzySearchMode); logger.trace("... field name = " + fieldName); } String fieldValue = null; try { // Get field value. Object fieldValueObj = PropertyUtils.getProperty(subjectName, fieldName); if (fieldValueObj != null && isFuzzySearchMode) { fieldValue = (String) fieldValueObj; // Convert to lower case and add a "%" for LIKE clause. fieldValue = fieldValue.toLowerCase(); fieldValue = fieldValue + "%"; } } catch (Exception ex) { // FIXME? logger.info("Unable to access '" + fieldName + ": " + ex.getMessage()); } return fieldValue; }
From source file:com.panet.imeta.job.entry.validator.NotNullValidator.java
public boolean validate(CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context) { LogWriter log = LogWriter.getInstance(); Object value = null;/*from www . j a v a 2 s . c om*/ 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) { log.logBasic(JobEntryValidatorUtils.class.getSimpleName(), e.getMessage()); JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e); } catch (InvocationTargetException e) { log.logBasic(JobEntryValidatorUtils.class.getSimpleName(), e.getMessage()); JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e); } catch (NoSuchMethodException e) { log.logBasic(JobEntryValidatorUtils.class.getSimpleName(), e.getMessage()); JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e); } return false; }