List of usage examples for org.apache.commons.beanutils PropertyUtils getPropertyDescriptors
public static PropertyDescriptor[] getPropertyDescriptors(Object bean)
Retrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered.
For more details see PropertyUtilsBean
.
From source file:com.ponysdk.ui.server.list.form.AddCustomColumnDescriptorForm.java
private static boolean hasProperty(final Class<?> clas, final String property) { final String propertyPath = property; boolean isValid = true; Class<?> propertyClass = null; try {/*w w w . j a v a 2 s . c om*/ if (propertyPath != null) { final String[] tokens = propertyPath.split("\\."); final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(clas); for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor.getName().equals(tokens[0])) { propertyClass = propertyDescriptor.getPropertyType(); break; } } if (propertyClass == null) throw new Exception("unknown property#" + tokens[0]); for (int i = 1; i < tokens.length; i++) { final PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(propertyClass); boolean found = false; for (final PropertyDescriptor propertyDescriptor : descriptors) { if (propertyDescriptor.getName().equals(tokens[i])) { propertyClass = propertyDescriptor.getPropertyType(); found = true; } } if (!found) throw new Exception("unknown property#" + tokens[i] + " for class#" + propertyClass); } } } catch (final Exception e) { final String errorMessage = "Error occured when finding property '" + propertyPath + "'"; log.error(errorMessage, e); isValid = false; } return isValid; }
From source file:com.jaspersoft.studio.data.tools.mapping.BeanMappingTool.java
public Control createControl(Composite parent) { control = new Composite(parent, SWT.NONE); control.setLayout(new GridLayout(3, false)); Label label = new Label(control, SWT.NONE); label.setText(Messages.BeanMappingTool_labeltitle); final ClassType classType = new ClassType(control, ""); //$NON-NLS-1$ classType.addListener(new ModifyListener() { public void modifyText(ModifyEvent e) { try { errMsg.setText(""); //$NON-NLS-1$ JasperReportsConfiguration jConfig = dataQueryAdapters.getjConfig(); Class<?> clazz = jConfig.getClassLoader().loadClass(classType.getClassType()); methodsarray = PropertyUtils.getPropertyDescriptors(clazz); String[] strm = new String[methodsarray.length]; for (int i = 0; i < methodsarray.length; i++) { strm[i] = methodsarray[i].getName(); }// w ww . j a v a 2s .co m methods.setItems(strm); } catch (ClassNotFoundException e1) { errMsg.setText(Messages.BeanMappingTool_errormessage + e1.getMessage()); } } }); methods = new org.eclipse.swt.widgets.List(control, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL); methods.setItems(new String[] {}); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 3; methods.setLayoutData(gd); Composite bottomToolbar = new Composite(control, SWT.NONE); GridLayout btGL = new GridLayout(3, false); btGL.marginWidth = 0; btGL.marginHeight = 0; bottomToolbar.setLayout(btGL); bottomToolbar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1)); Button gfbtn = new Button(bottomToolbar, SWT.PUSH); gfbtn.setText(Messages.BeanMappingTool_selectfieldstitle); gfbtn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); gfbtn.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { int[] items = methods.getSelectionIndices(); if (methodsarray != null && items != null) { List<JRDesignField> flist = new ArrayList<JRDesignField>(); for (int i = 0; i < items.length; i++) { JRDesignField f = new JRDesignField(); f.setName(methodsarray[items[i]].getName()); Class<?> propertyType = methodsarray[items[i]].getPropertyType(); if (propertyType != null) f.setValueClassName(getClassName(propertyType)); else f.setValueClass(Object.class); String description = methodsarray[items[i]].getShortDescription(); if (description != null) f.setDescription(description); flist.add(f); } fsetter.addFields(flist); } } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); Button clearBtn = new Button(bottomToolbar, SWT.PUSH); clearBtn.setText(Messages.BeanMappingTool_17); clearBtn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); clearBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @Override public void widgetSelected(SelectionEvent e) { fsetter.clearFields(); } }); errMsg = new Label(bottomToolbar, SWT.RIGHT); errMsg.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); return control; }
From source file:com.expressui.core.dao.query.EntityQuery.java
/** * Lifecycle method called after this bean has been constructed. *//*from w w w . java2 s.co m*/ @PostConstruct public void postConstruct() { descriptors = PropertyUtils.getPropertyDescriptors(this); pageSize = applicationProperties.getDefaultPageSize(); clear(); }
From source file:info.magnolia.content2bean.impl.TypeMappingImpl.java
/** * Cache the already resolved types.//from w w w . j a va2 s. c o m * */ @Override public PropertyTypeDescriptor getPropertyTypeDescriptor(Class<?> beanClass, String propName) { PropertyTypeDescriptor dscr; String key = beanClass.getName() + "." + propName; dscr = propertyTypes.get(key); if (dscr != null) { return dscr; } //TypeMapping defaultMapping = TypeMapping.Factory.getDefaultMapping(); // TODO - is this used - or is the comparison correct ? // if (this != defaultMapping) { // dscr = defaultMapping.getPropertyTypeDescriptor(beanClass, propName); // if (dscr.getType() != null) { // return dscr; // } // } dscr = new PropertyTypeDescriptor(); dscr.setName(propName); PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(beanClass); for (int i = 0; i < descriptors.length; i++) { PropertyDescriptor descriptor = descriptors[i]; if (descriptor.getName().equals(propName)) { Class<?> propertytype = descriptor.getPropertyType(); // may be null for indexed properties if (propertytype != null) { dscr.setType(getTypeDescriptor(propertytype)); } break; } } if (dscr.getType() != null) { if (dscr.isMap() || dscr.isCollection()) { int numberOfParameters = dscr.isMap() ? 2 : 1; Method method = getAddMethod(beanClass, propName, numberOfParameters); if (method != null) { dscr.setAddMethod(method); if (dscr.isMap()) { dscr.setCollectionKeyType(getTypeDescriptor(method.getParameterTypes()[0])); dscr.setCollectionEntryType(getTypeDescriptor(method.getParameterTypes()[1])); } else { dscr.setCollectionEntryType(getTypeDescriptor(method.getParameterTypes()[0])); } } } } // remember me propertyTypes.put(key, dscr); return dscr; }
From source file:net.mojodna.searchable.util.SearchableUtils.java
/** * @param clazz// w ww . ja v a 2 s.c o m * @return Fields. */ public static final Field[] getFields(final Class<? extends Searchable> clazz) { Set<Field> fields = new HashSet<Field>(); for (final PropertyDescriptor d : PropertyUtils.getPropertyDescriptors(clazz)) { if (containsIndexAnnotations(d)) { final Field.Store stored = isStored(d); final Field.Index indexStyle = getIndexStyle(d); final float boost = getBoost(d); for (final String name : getFieldnames(d)) { final Field f = new Field(name, clazz.getName() + "#" + d.getName(), stored, indexStyle); f.setBoost(boost); fields.add(f); } } if (containsSortableAnnotations(d)) { fields.add(new Field(IndexSupport.SORTABLE_PREFIX + d.getName(), clazz.getName(), Field.Store.YES, Field.Index.NO)); } } return fields.toArray(new Field[] {}); }
From source file:com.ettrema.httpclient.calsync.parse.BeanPropertyMapper.java
public String toVCard(Object bean) { VCard card = new VCardImpl(); card.setBegin(new BeginType()); PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null) { Method read = pd.getReadMethod(); Annotation[] annotations = read.getAnnotations(); for (Annotation anno : annotations) { Mapper mapper = mapOfMappers.get(anno.annotationType()); if (mapper != null) { mapper.mapToCard(card, bean, pd); }/*from ww w.j av a2 s .co m*/ } } } FormattedNameFeature fname = card.getFormattedName(); if (fname == null) { NameFeature nameFeature = card.getName(); if (nameFeature != null) { String formattedName = nameFeature.getGivenName() + " " + nameFeature.getFamilyName(); fname = new FormattedNameType(formattedName); card.setFormattedName(fname); } } card.setEnd(new EndType()); VCardWriter writer = new VCardWriter(); writer.setVCard(card); String text = writer.buildVCardString(); return text; }
From source file:at.molindo.notify.model.BeanParams.java
private Iterator<PropertyDescriptor> getDescriptorsIter() { return Arrays.asList(PropertyUtils.getPropertyDescriptors(_bean)).iterator(); }
From source file:com.premiumminds.wicket.crudifier.form.elements.ListControlGroups.java
private Set<String> getPropertiesByOrder(Class<?> modelClass) { Set<String> properties = new LinkedHashSet<String>(); for (String property : entitySettings.getOrderOfFields()) { if (!entitySettings.getHiddenFields().contains(property)) properties.add(property);/*from w w w . j a v a 2s.com*/ } for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(modelClass)) { if (!entitySettings.getHiddenFields().contains(descriptor.getName()) && !properties.contains(descriptor.getName()) && !descriptor.getName().equals("class")) properties.add(descriptor.getName()); } return properties; }
From source file:com.bstek.dorado.idesupport.robot.EntityDataTypeReflectionRobot.java
protected void reflectAndComplete(Element element, Class<?> cls) throws Exception { Context context = Context.getCurrent(); DataTypeManager dataTypeManager = (DataTypeManager) context.getServiceBean("dataTypeManager"); Document document = element.getOwnerDocument(); Map<String, Element> propertyDefElementMap = new HashMap<String, Element>(); for (Element propertyDefElement : DomUtils.getChildrenByTagName(element, DataXmlConstants.PROPERTY_DEF)) { String name = propertyDefElement.getAttribute(XmlConstants.ATTRIBUTE_NAME); propertyDefElementMap.put(name, propertyDefElement); }//from w w w . j ava 2s. c om PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(cls); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if ("class".equals(name)) continue; Element propertyDefElement = propertyDefElementMap.get(name); if (propertyDefElement == null) { String dataTypeName = null; DataType propertyDataType = dataTypeManager.getDataType(propertyDescriptor.getPropertyType()); if (propertyDataType != null) { dataTypeName = propertyDataType.getName(); if (IGNORE_DATATYPES.contains(dataTypeName)) { continue; } } propertyDefElement = document.createElement(DataXmlConstants.PROPERTY_DEF); propertyDefElement.setAttribute(XmlConstants.ATTRIBUTE_NAME, name); createPropertyElement(propertyDefElement, DataXmlConstants.ATTRIBUTE_DATA_TYPE, dataTypeName); element.appendChild(propertyDefElement); } } }
From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java
public static Class<?> getPropertyType(Class<?> type, String propertyName) { String[] propertyTokens = StringUtils.split(propertyName, "."); Class<?> result = type; for (String propertyToken : propertyTokens) { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(result); for (PropertyDescriptor descriptor : descriptors) { if (StringUtils.equalsIgnoreCase(propertyToken, descriptor.getName())) { result = descriptor.getPropertyType(); break; } else { result = null;// w w w.j a v a2 s. c o m } } } return result; }