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:corner.orm.tapestry.component.DefaultSelectFilter.java
/** * cnlabelField/*w w w . j a va 2 s . c o m*/ * @param value * @return */ public String getCnLabelFor(Object value) { try { if (value instanceof String) { return value.toString(); } else { return PropertyUtils.getProperty(value, TapestryHtmlFormatter.lowerFirstLetter(cnlabelField)) .toString(); } } catch (Exception e) { throw new ApplicationRuntimeException(e); } }
From source file:com.nec.nsgui.action.statis.STDataRender4NasSwitch.java
public String getCellRender(int rowIndex, String colName) throws Exception { PageContext context = getSortTagInfo().getPageContext(); AbstractList exportsList = ((ListSTModel) getTableModel()).getDataList(); NasSwitchSubItemInfoBean exportObj = (NasSwitchSubItemInfoBean) exportsList.get(rowIndex); String isWhichNode = exportObj.getIsWhichNode(); String checked = ""; List subItemList_checked = (List) NSActionUtil.getSessionAttribute( (HttpServletRequest) context.getRequest(), SESSION_STATIS_NASSWITCH_SUBITEMLIST_CHECKED); if (subItemList_checked != null) { for (int i = 0; i < subItemList_checked.size(); i++) { NasSwitchSubItemInfoBean temp = (NasSwitchSubItemInfoBean) subItemList_checked.get(i); if (exportObj.getSubItem().equals(temp.getSubItem())) { checked = "checked"; break; }//ww w . jav a 2s .c om } } if (colName.equals("subItemCheckbox")) { StringBuffer cellStr = new StringBuffer( "<input name=\"subItemCheckbox\" type=\"checkbox\" " + " value=\""); cellStr.append(exportObj.getSequence()); cellStr.append("\" id=\"subItemCheckbox" + rowIndex); cellStr.append("\" " + checked); cellStr.append(" onClick=\"return checkNum("); cellStr.append(");\">"); cellStr.append("<script language=\"javascript\">"); cellStr.append("subItem['" + exportObj.getSequence() + "']='" + exportObj.getInterval() + "';"); cellStr.append("</script>"); if (isWhichNode.equals("both")) { return "<td nowrap align=center rowspan=\"2\">" + cellStr.toString() + "</td>"; } else { return "<td nowrap align=center>" + cellStr.toString() + "</td>"; } } if (colName.equals("subItem")) { String subItem = NSActionUtil .sanitize(NSActionUtil.perl2Page(exportObj.getSubItem(), NSActionConst.ENCODING_EUC_JP)); if (isWhichNode.equals("both")) { return "<td nowrap align=left rowspan=\"2\">" + "<label for=\"subItemCheckbox" + rowIndex + "\">" + subItem + "</label>" + "</td>"; } else { return "<td nowrap align=left>" + "<label for=\"subItemCheckbox" + rowIndex + "\">" + subItem + "</label>" + "</td>"; } } if (colName.equals("node")) { String node_message = ""; String collectionId = (String) NSActionUtil .getSessionAttribute((HttpServletRequest) context.getRequest(), SESSION_COLLECTION_ID); if (collectionId.trim().equals(NSW_NFS_Virtual_Export)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.group"); } if (collectionId.trim().equals(NSW_NFS_Server)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.node"); } if (isWhichNode.equals("both") || isWhichNode.equals("group0")) return "<td nowrap align=left>" + node_message + "0</td>"; if (isWhichNode.equals("both") || isWhichNode.equals("group1")) return "<td nowrap align=left>" + node_message + "1</td>"; } if (colName.equals("access_average") || colName.equals("access_max") || colName.equals("response_average") || colName.equals("response_max") || colName.equals("rover_average") || colName.equals("rover_max")) { NasSwitchMaxAverBean nodeInfo = new NasSwitchMaxAverBean(); if (isWhichNode.equals("both") || isWhichNode.equals("group0")) { nodeInfo = exportObj.getBean4Node0(); } else { nodeInfo = exportObj.getBean4Node1(); } String content = PropertyUtils.getProperty(nodeInfo, colName).toString(); if (content.equals("--")) { return "<td nowrap align=center>" + content + "</td>"; } else { return "<td nowrap align=right>" + content + "</td>"; } } if (colName.equals("stockPeriod")) { String stockPeriod = exportObj.getStockPeriod(); if (!isWhichNode.equals("both") && stockPeriod.trim().equals("--")) { return "<td nowrap align=center>" + stockPeriod + "</td>"; } else if (!isWhichNode.equals("both") && !stockPeriod.trim().equals("--")) { return "<td nowrap align=right>" + stockPeriod + "</td>"; } else if (isWhichNode.equals("both") && stockPeriod.trim().equals("--")) { return "<td nowrap align=center rowspan=\"2\">" + stockPeriod + "</td>"; } else if (isWhichNode.equals("both") && !stockPeriod.trim().equals("--")) { return "<td nowrap align=right rowspan=\"2\">" + stockPeriod + "</td>"; } } if (colName.equals("interval")) { String interval = exportObj.getInterval(); StringBuffer cell = new StringBuffer(); if (!isWhichNode.equals("both") && interval.trim().equals("--")) { return "<td nowrap align=center>" + interval + "</td>"; } else if (!isWhichNode.equals("both") && !interval.trim().equals("--")) { return "<td nowrap align=right>" + Integer.parseInt(interval) / 60 + "</td>"; } else if (isWhichNode.equals("both") && interval.trim().equals("--")) { cell.append("<td nowrap align=center rowspan=\"2\">" + interval + "</td>"); } else if (isWhichNode.equals("both") && !interval.trim().equals("--")) { cell.append("<td nowrap align=right rowspan=\"2\">" + Integer.parseInt(interval) / 60 + "</td>"); } if (isWhichNode.equals("both")) { NasSwitchMaxAverBean node1Info = exportObj.getBean4Node1(); String access_average = node1Info.getAccess_average(); String access_max = node1Info.getAccess_max(); String response_average = node1Info.getResponse_average(); String response_max = node1Info.getResponse_max(); String rover_average = node1Info.getRover_average(); String rover_max = node1Info.getRover_max(); String node_message = ""; String collectionId = (String) NSActionUtil .getSessionAttribute((HttpServletRequest) context.getRequest(), SESSION_COLLECTION_ID); if (collectionId.equals(NSW_NFS_Virtual_Export)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.group"); } if (collectionId.equals(NSW_NFS_Server)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.node"); } cell.append("</tr><tr><td nowrap align=center>"); cell.append(node_message); cell.append("1</td>"); if (access_average.equals("--")) { cell.append("<td nowrap align=center>" + access_average + "</td>"); } else { cell.append("<td nowrap align=right>" + access_average + "</td>"); } if (access_max.equals("--")) { cell.append("<td nowrap align=center>" + access_max + "</td>"); } else { cell.append("<td nowrap align=right>" + access_max + "</td>"); } if (response_average.equals("--")) { cell.append("<td nowrap align=center>" + response_average + "</td>"); } else { cell.append("<td nowrap align=right>" + response_average + "</td>"); } if (response_max.equals("--")) { cell.append("<td nowrap align=center>" + response_max + "</td>"); } else { cell.append("<td nowrap align=right>" + response_max + "</td>"); } if (rover_average.equals("--")) { cell.append("<td nowrap align=center>" + rover_average + "</td>"); } else { cell.append("<td nowrap align=right>" + rover_average + "</td>"); } if (rover_max.equals("--")) { cell.append("<td nowrap align=center>" + rover_max + "</td>"); } else { cell.append("<td nowrap align=right>" + rover_max + "</td>"); } } return cell.toString(); } return ""; }
From source file:net.kamhon.ieagle.swing.table.KTableModel.java
private Object[][] generateDataIn2DArray() { if (CollectionUtil.isEmpty(datas)) { return new Object[0][0]; }//from w w w . java 2 s . co m List<Object[]> result = new ArrayList<Object[]>(); for (Object object : datas) { List<Object> record = new ArrayList<Object>(); for (KTableColumn column : columns) { try { Object propValue = null; if (StringUtils.isNotBlank(column.getColumnName())) propValue = PropertyUtils.getProperty(object, column.getColumnName()); if (column instanceof KTableRowCheckBoxColumn) { record.add(false); } else if (column instanceof KTableCheckBoxColumn) { if (propValue instanceof Boolean) { record.add(propValue); } else { record.add(false); } } else { record.add(propValue == null ? "" : propValue); } } catch (NestedNullException ex) { // if nested bean referenced is null if (column instanceof KTableCheckBoxColumn) { record.add(false); } else { record.add(""); } } catch (Exception ex) { throw new DataException(ex); } } log.debug("record = " + CollectionUtil.toLog(record)); result.add(record.toArray(new Object[0])); } return result.toArray(new Object[0][0]); }
From source file:jp.co.acroquest.endosnipe.report.converter.compressor.SamplingCompressor.java
/** * ??????//from w w w. java 2s .c o m * ??????????????? * * @param samplingList measureTimeField?????????????? * @param startTime ? * @param endTime ? * @param measureTimeField ???? * @param operation ?? * @param clazz ?Class * @return ??? * @throws IllegalAccessException ????????? * @throws InvocationTargetException ?????? * @throws NoSuchMethodException ?????? * @throws NoSuchFieldException * @throws InstantiationException * @throws SecurityException */ public List compressSamplingList(List samplingList, Timestamp startTime, Timestamp endTime, String measureTimeField, List<CompressOperation> operation, Class clazz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, SecurityException, InstantiationException, NoSuchFieldException { // ?1???? // ??????????????????? long samplingTerm = (endTime.getTime() - startTime.getTime()) / this.samplingMax_; if (samplingTerm < this.minLimitSamplingTerm_) { samplingTerm = this.minLimitSamplingTerm_; } long nowStartTime = startTime.getTime(); int sampleIndex = 0; List compressedList = new ArrayList(); while (nowStartTime < endTime.getTime()) { // ????? List samplingGroup = new ArrayList(); for (int cnt = sampleIndex; cnt < samplingList.size(); cnt++) { Object sampleData = samplingList.get(cnt); Date measureTime = (Date) PropertyUtils.getProperty(sampleData, measureTimeField); if (nowStartTime > measureTime.getTime()) { sampleIndex++; continue; } if (nowStartTime + samplingTerm <= measureTime.getTime()) { sampleIndex = cnt; break; } samplingGroup.add(sampleData); } // ?? Object compressedData = createCompressedSample(samplingGroup, nowStartTime, nowStartTime + samplingTerm, measureTimeField, operation, clazz); compressedList.add(compressedData); nowStartTime += samplingTerm; } return compressedList; }
From source file:com.google.code.simplestuff.bean.SimpleBean.java
/** * Compare two bean basing the comparison only on the {@link BusinessField} * annotated fields.//from ww w . j a v a 2 s .c o m * * @param firstBean First bean to compare. * @param secondBean Second bean to compare. * @return The equals result. * @throws IllegalArgumentException If one of the beans compared is not an * instance of a {@link BusinessObject} annotated class. */ public static boolean equals(Object firstBean, Object secondBean) { // null + !null = false // null + null = true if ((firstBean == null) || (secondBean == null)) { if ((firstBean == null) && (secondBean == null)) { return true; } else { return false; } } final BusinessObjectDescriptor firstBusinessObjectInfo = BusinessObjectContext .getBusinessObjectDescriptor(firstBean.getClass()); final BusinessObjectDescriptor secondBusinessObjectInfo = BusinessObjectContext .getBusinessObjectDescriptor(secondBean.getClass()); // We don't need here a not null check since by contract the // getBusinessObjectDescriptor method always returns an abject. // All this conditions are to support the case in which // SimpleBean.equals is used in not Business Object. Than the rules are: // !BO.equals(!BO) = The objects are equals if one of them is assignable // to the other (the or is used for the respect the symmetric rule) // !BO.eqauls(BO) = The equals of the !BO is used. // BO.equals(!BO) = The equals of the !BO is used. if (firstBusinessObjectInfo.getNearestBusinessObjectClass() == null) { if (secondBusinessObjectInfo.getNearestBusinessObjectClass() == null) { return firstBean.getClass().isAssignableFrom(secondBean.getClass()) || secondBean.getClass().isAssignableFrom(firstBean.getClass()); } else { return firstBean.equals(secondBean); } } else if (secondBusinessObjectInfo.getNearestBusinessObjectClass() == null) { return secondBean.equals(firstBean); } // TODO: Revise this code in order to make it more readable... // If one of the two bean has the class with Business relevance then // we need to compare the lowest hierarchical annotated classes of // the two beans. if ((firstBusinessObjectInfo.isClassToBeConsideredInComparison() || secondBusinessObjectInfo.isClassToBeConsideredInComparison()) && (!firstBusinessObjectInfo.getNearestBusinessObjectClass() .equals(secondBusinessObjectInfo.getNearestBusinessObjectClass()))) { // If the comparison fails than we can already return false. return false; } // Then we continue with the annotated fields, first checking // if the two objects contain the same annotated fields. A paranoid // comparison (both sides) is done only if the two objects are not on // the same class in order to handle tricky cases. final boolean performParanoidComparison = false; if (!compareAnnotatedFieldsByName(firstBusinessObjectInfo.getAnnotatedFields(), secondBusinessObjectInfo.getAnnotatedFields(), performParanoidComparison)) { // If the comparison fails than we can already return false. return false; } // Then we continue with the values of the annotated fields. Collection<Field> firstBeanAnnotatedFields = firstBusinessObjectInfo.getAnnotatedFields(); for (Field field : firstBeanAnnotatedFields) { final BusinessField fieldAnnotation = field.getAnnotation(BusinessField.class); // Since the cycle is on the annotated Field we are sure that // fieldAnnotation will always be not null. if (fieldAnnotation.includeInEquals()) { Object firstBeanFieldValue = null; Object secondBeanFieldValue = null; try { firstBeanFieldValue = PropertyUtils.getProperty(firstBean, field.getName()); // Also in this case, since before of the cycle we // compare the annotated fields, we can be sure that the // field exists. secondBeanFieldValue = PropertyUtils.getProperty(secondBean, field.getName()); // If there were problems (like when we compare // different Business Object with different Business // Fields), then we return false. } catch (IllegalAccessException e) { if (log.isDebugEnabled()) { log.debug("IllegalAccessException exception when comparing class " + firstBean.getClass().toString() + " with class" + secondBean.getClass().toString(), e); } return false; } catch (InvocationTargetException e) { if (log.isDebugEnabled()) { log.debug("InvocationTargetException exceptionwhen comparing class " + firstBean.getClass().toString() + " with class" + secondBean.getClass().toString(), e); } return false; } catch (NoSuchMethodException e) { if (log.isDebugEnabled()) { log.debug("NoSuchMethodException exception when comparing class " + firstBean.getClass().toString() + " with class" + secondBean.getClass().toString(), e); } return false; } // Some date implementations give not exact // comparison... if ((ClassUtils.isAssignable(field.getType(), Date.class)) || (ClassUtils.isAssignable(field.getType(), Calendar.class))) { if (firstBeanFieldValue != null) { firstBeanFieldValue = DateUtils.round(firstBeanFieldValue, Calendar.MILLISECOND); } if (secondBeanFieldValue != null) { secondBeanFieldValue = DateUtils.round(secondBeanFieldValue, Calendar.MILLISECOND); } } // We use always EqualsBuilder since we can get also // primitive arrays and they need ot be internally // compared. EqualsBuilder equalsBuilder = new EqualsBuilder(); equalsBuilder.append(firstBeanFieldValue, secondBeanFieldValue); if (!equalsBuilder.isEquals()) { return false; } else { // If we are here the bean are both not null and // equals or both null (then equals)... the cycle // can // continue... continue; } } } // If we finally arrive here, then all the comparison were // successful and the two beans are equals. return true; }
From source file:com.utest.webservice.builders.Builder.java
protected void populateLocators(Ti result, UriBuilder ub) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Map<?, ?> resultProperties = PropertyUtils.describe(result); for (Object property : resultProperties.keySet()) { if (((String) property).endsWith("Locator")) { String resourcePath = null; Integer resourceId = null; String resourceName = ((String) property).substring(0, ((String) property).indexOf("Locator")); if (resultProperties.containsKey(resourceName + "Id")) { resourceId = (Integer) PropertyUtils.getProperty(result, resourceName + "Id"); if (resourceId != null) { resourcePath = getResourcePath(resourceName.toLowerCase()); }/*w w w . j a v a 2 s . c om*/ } // represents a user who performed an operation else if (resourceName.endsWith("By")) { resourceId = (Integer) PropertyUtils.getProperty(result, resourceName); if (resourceId != null) { resourcePath = getResourcePath("user"); } } if (resourcePath != null) { String className = getResourceNamedClass(resourceName.toLowerCase()); String name = ""; if (className != null) { try { Class<?> clazz = Class.forName(className); Object namedEntity = factory.getStaticDataService().getEntity(clazz, resourceId); if (namedEntity != null && namedEntity instanceof Named) { name = ((Named) namedEntity).getName(); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ResourceLocator resourceLocator = new ResourceLocator(resourceId, ub.clone().path(resourcePath).build(resourceId).toString(), name); PropertyUtils.setProperty(result, (String) property, resourceLocator); } } } }
From source file:com.mycollab.mobile.ui.AbstractPreviewItemComp.java
private void toggleFavorite() { try {/*from ww w . ja v a 2s .c om*/ if (isFavorite()) { favoriteBtn.removeStyleName("favorite-btn-selected"); favoriteBtn.addStyleName("favorite-btn"); } else { favoriteBtn.addStyleName("favorite-btn-selected"); favoriteBtn.removeStyleName("favorite-btn"); } FavoriteItem favoriteItem = new FavoriteItem(); favoriteItem.setExtratypeid(CurrentProjectVariables.getProjectId()); favoriteItem.setType(getType()); favoriteItem.setTypeid(PropertyUtils.getProperty(beanItem, "id").toString()); favoriteItem.setSaccountid(MyCollabUI.getAccountId()); favoriteItem.setCreateduser(UserUIContext.getUsername()); FavoriteItemService favoriteItemService = AppContextUtil.getSpringBean(FavoriteItemService.class); favoriteItemService.saveOrDelete(favoriteItem); } catch (Exception e) { LOG.error("Error while set favorite flag to bean", e); } }
From source file:jp.co.opentone.bsol.linkbinder.dao.BaseDao.java
/** * ???./* w ww . j a v a2 s.c om*/ * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ private void escape(Object clone, List<String> fields) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { String escapeChar = (String) PropertyUtils.getProperty(clone, "escapeChar"); String escapeEscapeChar = escapeChar + escapeChar; String escapePercent = escapeChar + PERCENT; String escapeUnderBar = escapeChar + UNDER_BAR; for (String field : fields) { Object object = PropertyUtils.getProperty(clone, field); if (object != null) { String value = String.valueOf(object); // ? value = value.replaceAll(escapeChar, escapeEscapeChar); // %? value = value.replaceAll(PERCENT, escapePercent); // _? value = value.replaceAll(UNDER_BAR, escapeUnderBar); PropertyUtils.setProperty(clone, field, value); } } }
From source file:com.khubla.cbean.CBean.java
/** * get Key for T//from www .jav a2 s.c om */ private CBeanKey getKey(T t) throws CBeanException { try { if (cBeanType.getIdField().getType() == UUID.class) { final UUID keyUUID = (UUID) PropertyUtils.getProperty(t, cBeanType.getIdField().getName()); if (null == keyUUID) { final UUID uuid = UUID.randomUUID(); BeanUtils.setProperty(t, cBeanType.getIdField().getName(), uuid); return new CBeanKey(uuid.toString()); } else { return new CBeanKey(keyUUID); } } else if (cBeanType.getIdField().getType() == String.class) { final String keyString = BeanUtils.getProperty(t, cBeanType.getIdField().getName()); if (null == keyString) { final String uuid = UUID.randomUUID().toString(); BeanUtils.setProperty(t, cBeanType.getIdField().getName(), uuid); return new CBeanKey(uuid.toString()); } else { return new CBeanKey(keyString); } } else { return null; } } catch (final Exception e) { throw new CBeanException(e); } }
From source file:name.martingeisse.common.util.ContextAwareXmlWriter.java
/** * Uses the value of the property with the specified name of the current context as a new context, * pushing the old one on the context stack. Use leaveContext() to return to the old context. * @param propertyName the property name *///from ww w. j a v a2 s . co m public void enterEmbeddedPropertyContext(String propertyName) { try { enterContext(PropertyUtils.getProperty(currentContext, propertyName)); } catch (Exception e) { throw new RuntimeException(e); } }