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.lioland.harmony.web.dao.ODBClass.java
public void loadObject() { Class cls = this.getClass(); System.out.println("loading object: " + cls); try {//from w ww. jav a 2 s .com String docClass = cls.getSimpleName(); String query = "select * from " + docClass + " where " + getUniqueFieldName() + "='" + PropertyUtils.getProperty(this, getUniqueFieldName()) + "'"; System.out.println("Query: " + query); List<ODocument> docs; try (ODatabaseRecord db = DBFactory.getDb()) { OSchema schema = db.getMetadata().getSchema(); if (!schema.existsClass(docClass)) { System.out.println("::::::::::::::WARNING::::::::::::::::"); System.out.println("Created missing class: " + docClass); schema.createClass(docClass); } docs = db.query(new OSQLSynchQuery<ODocument>(query)); } if (!docs.isEmpty()) { fillObject(docs.get(0), this); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException ex) { Logger.getLogger(ODBClass.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.vangent.hieos.empi.match.RecordBuilder.java
/** * * @param subject// w ww. j a v a 2s.co m * @return * @throws EMPIException */ public Record build(Subject subject) throws EMPIException { EMPIConfig empiConfig = EMPIConfig.getInstance(); Record record = new Record(); record.setId(subject.getInternalId()); // Go through each field (according to configuration). List<FieldConfig> fieldConfigs = empiConfig.getFieldConfigList(); for (FieldConfig fieldConfig : fieldConfigs) { String sourceObjectPath = fieldConfig.getSourceObjectPath(); String fieldName = fieldConfig.getName(); // FIXME: Deal with different types (partially implemented)? if (logger.isTraceEnabled()) { logger.trace("field = " + fieldName); logger.trace(" ... sourceObjectPath = " + sourceObjectPath); } try { Object value; // Access the field value. if (sourceObjectPath.equalsIgnoreCase("subject")) { value = subject; } else { value = PropertyUtils.getProperty(subject, sourceObjectPath); } if (value != null) { if (logger.isTraceEnabled()) { logger.trace(" ... value (before transforms) = " + value.toString()); } // Now run any transforms (in order). List<TransformFunctionConfig> transformFunctionConfigs = fieldConfig .getTransformFunctionConfigs(); for (TransformFunctionConfig transformFunctionConfig : transformFunctionConfigs) { if (logger.isTraceEnabled()) { logger.trace(" ... transformFunction = " + transformFunctionConfig.getName()); } TransformFunction transformFunction = transformFunctionConfig.getTransformFunction(); value = transformFunction.transform(value); } if (value != null) { if (logger.isTraceEnabled()) { logger.trace(" ... value (after transforms) = " + value.toString()); } Field field = new Field(fieldName, value.toString()); record.addField(field); } } } catch (Exception ex) { logger.info("Unable to access '" + sourceObjectPath + "' field: " + ex.getMessage()); } } // Now, get rid of any superseded fields. this.removeSupersededFields(record, fieldConfigs); return record; }
From source file:com.genologics.ri.automation.ProcessTypeLink.java
public void setProcessType(Linkable<ProcessType> processType) { uri = processType == null ? null : processType.getUri(); name = null;// w w w . j a va2 s .co m try { name = (String) PropertyUtils.getProperty(processType, "name"); } catch (Exception e) { // Ignore everything - it's only an attempt. } }
From source file:com.googlecode.jtiger.modules.ecside.table.callback.FilterPredicate.java
/** * Use the filter parameters to filter out the table. *//*ww w . j av a 2s. c o m*/ public boolean evaluate(Object bean) { boolean match = false; try { for (Iterator iter = model.getColumnHandler().getColumns().iterator(); iter.hasNext();) { Column column = (Column) iter.next(); String alias = column.getAlias(); String filterValue = model.getLimit().getFilterSet().getFilterValue(alias); if (StringUtils.isEmpty(filterValue)) { continue; } String property = column.getProperty(); Object value = PropertyUtils.getProperty(bean, property); if (value == null) { continue; } if (column.isDate()) { Locale locale = model.getLocale(); value = ExtremeUtils.formatDate(column.getParse(), column.getFormat(), value, locale); } else if (column.isCurrency()) { Locale locale = model.getLocale(); value = ExtremeUtils.formatNumber(column.getFormat(), value, locale); } if (!ECSideUtils.isSearchMatchCaseIgnore(value.toString(), filterValue)) { match = false; // as soon as fail just short circuit break; } match = true; } } catch (Exception e) { logger.error("FilterPredicate.evaluate() had problems", e); } return match; }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.commons.SearchCurrentExecutionCourses.java
@Override public Collection<ExecutionCourse> getSearchResults(Map<String, String> argsMap, String value, int maxCount) { List<ExecutionCourse> result = new ArrayList<ExecutionCourse>(); String slotName = argsMap.get("slot"); Collection<ExecutionCourse> objects = ExecutionSemester.readActualExecutionSemester() .getAssociatedExecutionCoursesSet(); if (value == null) { result.addAll(objects);//from w ww . jav a 2 s. c om } else { String[] values = StringNormalizer.normalize(value).split("\\p{Space}+"); outter: for (ExecutionCourse object : objects) { try { Object objectValue = PropertyUtils.getProperty(object, slotName); if (objectValue == null) { continue; } String normalizedValue = StringNormalizer.normalize(objectValue.toString()); for (int i = 0; i < values.length; i++) { String part = values[i]; if (!normalizedValue.contains(part)) { continue outter; } } result.add(object); if (result.size() >= maxCount) { break; } } catch (IllegalAccessException e) { throw new DomainException("searchObject.type.notFound", e); } catch (InvocationTargetException e) { throw new DomainException("searchObject.failed.read", e); } catch (NoSuchMethodException e) { throw new DomainException("searchObject.failed.read", e); } } } Collections.sort(result, new BeanComparator(slotName)); return result; }
From source file:com.feilong.commons.core.tools.json.JsonUtilTest.java
/** * Name./*from w ww . j ava 2s . com*/ * * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception * @throws NoSuchMethodException * the no such method exception */ @Test public void name() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { String json = "{name=\"json\",bool:true,int:1,double:2.2,func:function(a){ return a; },array:[1,2]}"; JSONObject jsonObject = JSONObject.fromObject(json); Object bean = JSONObject.toBean(jsonObject); Assert.assertEquals(jsonObject.get("name"), PropertyUtils.getProperty(bean, "name")); Assert.assertEquals(jsonObject.get("bool"), PropertyUtils.getProperty(bean, "bool")); Assert.assertEquals(jsonObject.get("int"), PropertyUtils.getProperty(bean, "int")); Assert.assertEquals(jsonObject.get("double"), PropertyUtils.getProperty(bean, "double")); Assert.assertEquals(jsonObject.get("func"), PropertyUtils.getProperty(bean, "func")); List<?> expected = JSONArray.toList(jsonObject.getJSONArray("array")); Assert.assertEquals(expected, PropertyUtils.getProperty(bean, "array")); }
From source file:com.aosa.main.utils.tools.AOSACopyUtil.java
/** * Description<code>Copy properties of orig to dest Exception the Entity and Collection Type</code> <br> * By mutou at 2011-8-30 ?11:36:11 <br> * Object <br>//ww w.ja va 2 s . c o m * @param dest * @param orig * @param ignores * @return the dest bean * @throws */ @SuppressWarnings("rawtypes") public static Object copyProperties(Object dest, Object orig, String[] ignores) { if (dest == null || orig == null) { return dest; } PropertyDescriptor[] destDesc = PropertyUtils.getPropertyDescriptors(dest); try { for (int i = 0; i < destDesc.length; i++) { if (contains(ignores, destDesc[i].getName())) { continue; } Class destType = destDesc[i].getPropertyType(); Class origType = PropertyUtils.getPropertyType(orig, destDesc[i].getName()); if (destType != null && destType.equals(origType) && !destType.equals(Class.class)) { if (!Collection.class.isAssignableFrom(origType)) { Object value = PropertyUtils.getProperty(orig, destDesc[i].getName()); PropertyUtils.setProperty(dest, destDesc[i].getName(), value); } } } return dest; } catch (Exception ex) { throw new AOSARuntimeException(ex); } }
From source file:corner.orm.tapestry.component.CornerSelectModel.java
/** * @see org.apache.tapestry.dojo.form.IAutocompleteModel#getLabelFor(java.lang.Object) *//*from w ww. j a v a 2 s .co m*/ public String getLabelFor(Object value) { try { if (value instanceof String) { return value.toString(); } else { return PropertyUtils .getProperty(value, TapestryHtmlFormatter.lowerFirstLetter(this.filter.getLabel())) .toString(); } } catch (Exception e) { throw new ApplicationRuntimeException(e); } }
From source file:com.esofthead.mycollab.module.project.ui.components.DateInfoComp.java
public void displayEntryDateTime(ValuedBean bean) { this.removeAllComponents(); this.withMargin(new MarginInfo(false, false, false, true)); Label dateInfoHeader = new Label( FontAwesome.CALENDAR.getHtml() + " " + AppContext.getMessage(ProjectCommonI18nEnum.SUB_INFO_DATES), ContentMode.HTML);//from ww w. j a v a 2 s . c o m dateInfoHeader.setStyleName("info-hdr"); this.addComponent(dateInfoHeader); MVerticalLayout layout = new MVerticalLayout().withMargin(new MarginInfo(false, false, false, true)) .withWidth("100%"); try { Date createdDate = (Date) PropertyUtils.getProperty(bean, "createdtime"); ELabel createdDateLbl = new ELabel(AppContext.getMessage(ProjectCommonI18nEnum.ITEM_CREATED_DATE, DateTimeUtils.getPrettyDateValue(createdDate, AppContext.getUserLocale()))) .withDescription(AppContext.formatDateTime(createdDate)); layout.addComponent(createdDateLbl); Date updatedDate = (Date) PropertyUtils.getProperty(bean, "lastupdatedtime"); ELabel updatedDateLbl = new ELabel(AppContext.getMessage(ProjectCommonI18nEnum.ITEM_UPDATED_DATE, AppContext.formatPrettyTime(updatedDate))) .withDescription(AppContext.formatDateTime(updatedDate)); layout.addComponent(updatedDateLbl); this.addComponent(layout); } catch (Exception e) { LOG.error("Get date is failed {}", BeanUtility.printBeanObj(bean)); } }
From source file:br.com.sicoob.cro.cop.batch.configuration.TaskletInjector.java
/** * Cria o contexto de dados para o tasklet. * * @return um {@link TaskletContext}./*from w ww .j a va2 s.c om*/ */ private TaskletContext createContext() throws Exception { return ConstructorUtils.invokeConstructor(TaskletContext.class, (StepParameters) PropertyUtils.getProperty(this.step, BatchKeys.PARAMETERS.getKey())); }