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.mycollab.db.persistence.service.DefaultService.java
@Override public void removeByCriteria(S criteria, Integer accountId) { boolean isValid = false; try {//from w w w.j ava2s . c o m PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(criteria); for (PropertyDescriptor descriptor : propertyDescriptors) { String propName = descriptor.getName(); if ((descriptor.getPropertyType().getGenericSuperclass() == SearchField.class) && (PropertyUtils.getProperty(criteria, propName) != null)) { isValid = true; break; } } } catch (Exception e) { LOG.debug("Error while validating criteria", e); } if (isValid) { getSearchMapper().removeByCriteria(criteria); } }
From source file:com.hack23.cia.service.data.impl.util.LoadHelper.java
/** * Inits the proxy and collections./*from w w w . ja v a2 s .c o m*/ * * @param obj * the obj * @param properties * the properties * @param dejaVu * the deja vu * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception * @throws NoSuchMethodException * the no such method exception */ private static void initProxyAndCollections(final Object obj, final PropertyDescriptor[] properties, final Set<Object> dejaVu) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { for (final PropertyDescriptor propertyDescriptor : properties) { if (PropertyUtils.getReadMethod(propertyDescriptor) != null) { final Object origProp = PropertyUtils.getProperty(obj, propertyDescriptor.getName()); if (origProp != null) { recursiveInitialize(origProp, dejaVu); } if (origProp instanceof Collection) { for (final Object item : (Collection<?>) origProp) { recursiveInitialize(item, dejaVu); } } } } }
From source file:io.milton.http.annotated.CTagAnnotationHandler.java
public String execute(AnnoCollectionResource col) { Object source = col.getSource(); try {//from w w w . j av a2 s .co m Object rawId = null; ControllerMethod cm = getBestMethod(source.getClass()); if (cm == null) { // look for an annotation on the source itself java.lang.reflect.Method m = annoResourceFactory.findMethodForAnno(source.getClass(), annoClass); if (m != null) { rawId = m.invoke(source); if (log.isDebugEnabled()) { log.debug("Got ctag from source object. ctag=" + rawId); } } else { for (String nameProp : CTAG_PROP_NAMES) { if (PropertyUtils.isReadable(source, nameProp)) { Object oPropVal = PropertyUtils.getProperty(source, nameProp); rawId = oPropVal; if (log.isDebugEnabled()) { log.debug("Got ctag from bean property:" + nameProp + " ctag=" + rawId); } break; } } if (rawId == null) { // last ditch effort, use latest mod date on the collection or any member rawId = deriveCtag(col); if (log.isInfoEnabled()) { log.debug( "Derived ctag from directory members. This is not recommended, you should implement an @CTag method. Ctag=" + rawId); } } } } else { rawId = cm.method.invoke(cm.controller, source); if (log.isDebugEnabled()) { log.debug("Got ctag from annotated method. ctag=" + rawId); } } if (rawId != null) { String s = rawId.toString(); if (s.length() == 0) { log.warn("CTAG value is blank"); } return s; } else { log.warn("CTAG value is null"); return null; } } catch (Exception e) { throw new RuntimeException("Exception executing " + getClass() + " - " + source.getClass(), e); } }
From source file:com.esofthead.mycollab.core.persistence.service.DefaultService.java
@Override public void removeByCriteria(S criteria, int accountId) { boolean isValid = false; try {// w ww . jav a 2 s . co m PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(criteria); for (PropertyDescriptor descriptor : propertyDescriptors) { String propName = descriptor.getName(); if ((descriptor.getPropertyType().getGenericSuperclass() == SearchField.class) && (PropertyUtils.getProperty(criteria, propName) != null)) { isValid = true; break; } } } catch (Exception e) { LOG.debug("Error while validating criteria", e); } if (isValid) { getSearchMapper().removeByCriteria(criteria); } }
From source file:com.pasteur.ci.action.creation.ajaxPointPrelevAction.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 a va 2 s. c o m * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int idpoint_prelevement = (Integer) PropertyUtils.getProperty(form, "idpoint_prelevement"); PointPrelevement pointPrelevement = new PointPrelevement(); PointPrelevementDAOImplement ppdaoi = new PointPrelevementDAOImplement(DAOFactory.getInstance()); pointPrelevement.setIdpoint_prelevement(idpoint_prelevement); pointPrelevement = (PointPrelevement) ppdaoi.find(pointPrelevement); //profondeur int idStationPrel = pointPrelevement.getIdstat(); StatPrelevement stationPrelevement = new StatPrelevement(); StatPrelevementDAOImplement spdaoi = new StatPrelevementDAOImplement(DAOFactory.getInstance()); stationPrelevement.setIdstat(idStationPrel); stationPrelevement = (StatPrelevement) spdaoi.find(stationPrelevement); //designation station prelevement //longitude // latitude int idplan_eau = stationPrelevement.getIdplan_eau(); int idhabitat = stationPrelevement.getIdhabitat(); PlanEau planEau = new PlanEau(); PlanEauDAOImplement pedaoi = new PlanEauDAOImplement(DAOFactory.getInstance()); planEau.setIdplan_eau(idplan_eau); planEau = (PlanEau) pedaoi.find(planEau); int idregion = planEau.getIdregion(); int idquartier = planEau.getIdquartier(); int idcommune = planEau.getIdcommune(); int idtype_plan_eau = planEau.getIdtype_plan_eau(); //superficie //commentaire //matiere fecale //designation Plan eau Region region = new Region(); RegionDAOImplement rdaoi = new RegionDAOImplement(DAOFactory.getInstance()); region.setIdregion(idregion); region = (Region) rdaoi.find(region); //region Quartier quartier = new Quartier(); QuartierDAOImplement qdaoi = new QuartierDAOImplement(DAOFactory.getInstance()); quartier.setIdquartier(idquartier); quartier = (Quartier) qdaoi.find(quartier); //quatier Commune commune = new Commune(); CommuneDAOImplement cdaoi = new CommuneDAOImplement(DAOFactory.getInstance()); commune.setIdcommune(idcommune); commune = (Commune) cdaoi.find(commune); // commune TypePlanEau typePlanEau = new TypePlanEau(); TypePlanEauDAOImplement tpedaoi = new TypePlanEauDAOImplement(DAOFactory.getInstance()); typePlanEau.setIdtype_plan_eau(idtype_plan_eau); typePlanEau = (TypePlanEau) tpedaoi.find(typePlanEau); Habitat habitat = new Habitat(); HabitatDAOImplement hdaoi = new HabitatDAOImplement(DAOFactory.getInstance()); habitat.setIdhabitat(idhabitat); habitat = (Habitat) hdaoi.find(habitat); LigneHabitatDAOImplement lhdaoi = new LigneHabitatDAOImplement(DAOFactory.getInstance()); MateriauxConstructionDAOImplement mcdaoi = new MateriauxConstructionDAOImplement(DAOFactory.getInstance()); LigneHabitat ligneHabitat = new LigneHabitat(); ligneHabitat.setIdhabitat(idhabitat); ArrayList<Object> ligne_mat_const_hab = lhdaoi.findS(ligneHabitat); ArrayList mat_const = new ArrayList(); for (Object lmch : ligne_mat_const_hab) { LigneHabitat _lmch = (LigneHabitat) lmch; MateriauxConstruction mc = new MateriauxConstruction(); mc.setIdmateriaux_construction(_lmch.getIdmateriaux_construction()); mc = (MateriauxConstruction) mcdaoi.find(mc); mat_const.add(mc); } LignePratiqueDAOImplement ligne_pratiqueDAO = new LignePratiqueDAOImplement(DAOFactory.getInstance()); PratiqueDAOImplement pratiqueDAO = new PratiqueDAOImplement(DAOFactory.getInstance()); LignePratique lignePratique = new LignePratique(); lignePratique.setIdplan_eau(idplan_eau); ArrayList<Object> ligne_pratique = ligne_pratiqueDAO.findS(lignePratique); ArrayList pratiquer = new ArrayList(); for (Object lmch : ligne_pratique) { LignePratique _lmch = (LignePratique) lmch; Pratique pt = new Pratique(); pt.setIdpratique(_lmch.getIdpratique()); pt = (Pratique) pratiqueDAO.find(pt); pratiquer.add(pt); } String type_pe = typePlanEau.getDesignation(); Double profondeur = pointPrelevement.getProfondeur(); String design_stprelev = stationPrelevement.getIdstat_prelevement(); Double gps_long = stationPrelevement.getGps_long(); Double gps_lat = stationPrelevement.getGps_lat(); double superficie = planEau.getSuperficie(); String commentaire = planEau.getCommentaire(); boolean matiere_fecale = planEau.getMatiere_fecale(); String designation = planEau.getDesignation(); String quatier_ = quartier.getDesignation(); String region_ = region.getDesignation(); String commune_ = commune.getDesignation(); String habitat_designation = habitat.getDesign_habitat(); int effectif = habitat.getEffectif(); Double distance = habitat.getDist_bord_lagune(); String mat_construction = ArrayToStringMC(mat_const); String pratique = ArrayToStringP(pratiquer); // HashMap hm = new HashMap(); hm.put("profondeur", profondeur); hm.put("design_stprelev", design_stprelev); hm.put("gps_long", gps_long); hm.put("gps_lat", gps_lat); hm.put("superficie", superficie); hm.put("commentaire", commentaire); hm.put("matiere_fecale", matiere_fecale); hm.put("designation", designation); hm.put("quartier_", quatier_); hm.put("region_", region_); hm.put("commune_", commune_); hm.put("habitat_designation", habitat_designation); hm.put("effectif", effectif); hm.put("distance", distance); hm.put("mat_construction", mat_construction); hm.put("pratique", pratique); hm.put("type_pe", type_pe); // 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:net.kamhon.ieagle.util.CollectionUtil.java
/** * This function used to convert particular properties in Object to array. * //from w w w.j a v a 2 s .co m * @param objects * @param propertiesNames * @param isSetNullToEmptyString * @return */ public static Object[][] to2DArray(List<?> objects, String[] propertiesNames, boolean isSetNullToEmptyString) { if (isEmpty(objects)) { return new Object[0][0]; } List<Object[]> result = new ArrayList<Object[]>(); for (Object object : objects) { List<Object> record = new ArrayList<Object>(); for (String propertyName : propertiesNames) { try { Object propValue = PropertyUtils.getProperty(object, propertyName); record.add(propValue == null ? "" : propValue); } catch (NestedNullException ex) { // if nested bean referenced is null record.add(""); } catch (Exception ex) { throw new DataException(ex); } } result.add(record.toArray(new Object[0])); } return result.toArray(new Object[1][1]); }
From source file:com.mycollab.aspect.TraceableCreateAspect.java
static ActivityStreamWithBLOBs constructActivity(Class<?> cls, Traceable traceableAnnotation, Object bean, String username, String action) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { ActivityStreamWithBLOBs activity = new ActivityStreamWithBLOBs(); activity.setModule(ClassInfoMap.getModule(cls)); activity.setType(ClassInfoMap.getType(cls)); activity.setTypeid(String.valueOf(PropertyUtils.getProperty(bean, traceableAnnotation.idField()))); activity.setCreatedtime(new GregorianCalendar().getTime()); activity.setAction(action);/*from w w w . j a v a2 s. c om*/ activity.setSaccountid((Integer) PropertyUtils.getProperty(bean, "saccountid")); activity.setCreateduser(username); Object nameObj = PropertyUtils.getProperty(bean, traceableAnnotation.nameField()); String nameField; if (nameObj instanceof Date) { nameField = DateTimeUtils.formatDate((Date) nameObj, "MM/dd/yyyy", Locale.US); } else { nameField = nameObj.toString(); } activity.setNamefield(nameField); if (!"".equals(traceableAnnotation.extraFieldName())) { Integer extraTypeId = (Integer) PropertyUtils.getProperty(bean, traceableAnnotation.extraFieldName()); activity.setExtratypeid(extraTypeId); } return activity; }
From source file:com.eviware.soapui.model.support.XPathReferenceImpl.java
public XPathReferenceImpl(String label, TestProperty property, Object target, String xpathPropertyName) { this.label = label; this.target = target; this.xpathPropertyName = xpathPropertyName; ModelItem modelItem = property == null ? null : property.getModelItem(); if (modelItem instanceof WsdlTestRequestStep) { operation = ((WsdlTestRequestStep) modelItem).getTestRequest().getOperation(); request = property.getName().equalsIgnoreCase("Request"); } else if (modelItem instanceof WsdlMockResponseTestStep) { operation = ((WsdlMockResponseTestStep) modelItem).getOperation(); request = property.getName().equalsIgnoreCase("Request"); } else if (modelItem instanceof WsdlMockResponse) { operation = ((WsdlMockResponse) modelItem).getMockOperation().getOperation(); request = property.getName().equalsIgnoreCase("Request"); } else if (modelItem instanceof WsdlMockOperation) { operation = ((WsdlMockOperation) modelItem).getOperation(); request = property.getName().equalsIgnoreCase("Request"); }/*from w w w . j av a2 s .c om*/ try { this.xpath = (String) PropertyUtils.getProperty(target, xpathPropertyName); } catch (Exception e) { SoapUI.logError(e); } }
From source file:jp.terasoluna.fw.web.taglib.TagUtil.java
/** * wBean?ABean?/* w ww .j a va2 s . co m*/ * wv?peBl?B * ?v?peBNull??Beanp?B * Bean???AO??B * * @param pageContext y?[WReLXg * @param name Bean * @param property Beanv?peB * @param scopeName BeanXR?[v * @return Bean * @throws JspException vXR?[v???, * wBean??? */ public static Object lookup(PageContext pageContext, String name, String property, String scopeName) throws JspException { //wBean?B Object bean = lookup(pageContext, name, scopeName); //BeanNull??O?B if (bean == null) { throw new JspException(); } //v?peBw???ABeanp?B if (property == null) { return bean; } //Beanwv?peBl?B //OJspExceptionbv?B try { return PropertyUtils.getProperty(bean, property); } catch (IllegalAccessException e) { throw new JspException(e); } catch (IllegalArgumentException e) { throw new JspException(e); } catch (InvocationTargetException e) { throw new JspException(e); } catch (NoSuchMethodException e) { throw new JspException(e); } }
From source file:edu.umn.msi.tropix.common.test.BeanTest.java
public static void testBeanProperties(final Object testBean, final HashMultimap<Class<?>, Object> typeObjects) { try {//w w w .j a va 2 s . c o m @SuppressWarnings("unchecked") final Map<String, ?> propertyMap = PropertyUtils.describe(testBean); for (final String propertyName : propertyMap.keySet()) { if (propertyName.equals("class") || !PropertyUtils.isWriteable(testBean, propertyName)) { continue; } final Class<?> type = PropertyUtils.getPropertyType(testBean, propertyName); Collection<?> objects = null; for (final Class<?> typeQuery : typeObjects.keySet()) { if (typeQuery.isAssignableFrom(type)) { objects = typeObjects.get(typeQuery); } } boolean useEquals = true; if (objects == null) { useEquals = false; try { objects = Lists.<Object>newArrayList(EasyMock.createMock(type)); } catch (final Exception e) { // Cannot instantiate mock of this type continue; } } for (final Object expectedObject : objects) { PropertyUtils.setProperty(testBean, propertyName, expectedObject); final Object object = PropertyUtils.getProperty(testBean, propertyName); if (useEquals) { assert object.equals(expectedObject) : "Expected " + expectedObject + " obtained " + object; } else { assert object == expectedObject : "Expected " + expectedObject + " obtained " + object; } } } } catch (final Exception e) { throw new IllegalStateException(e); } }