List of usage examples for java.beans PropertyDescriptor getName
public String getName()
From source file:org.gageot.excel.beans.BeanSetterImpl.java
/** * Set the value of a property on the current bean. * //w w w.j ava2 s . c o m * @param bean bean instance to populate * @param propertyName the name of the property (case insensitive) * @param propertyValue the value of the property */ @Override public void setProperty(Object bean, String propertyName, Object propertyValue) throws BeansException { BeanWrapper wrapper = getWrapper(bean); PropertyDescriptor[] propertyDescriptors = wrapper.getPropertyDescriptors(); // Find a bean property by its name ignoring case. // this way, we can accept any type of case in the spreadsheet file // for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor.getName().equalsIgnoreCase(propertyName)) { wrapper.setPropertyValue(propertyDescriptor.getName(), propertyValue.toString()); break; } } }
From source file:org.zkybase.cmdb.test.AbstractBeanTestCase.java
@Test public void accessors() throws Exception { PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(beanClass); for (PropertyDescriptor prop : props) { String propName = prop.getName(); if ("class".equals(propName)) { continue; }// w ww . j a va2s .com log.debug("Testing property accessors: {}.{}", beanClass, prop.getName()); Method readMethod = prop.getReadMethod(); Method writeMethod = prop.getWriteMethod(); assertNull(readMethod.invoke(bean)); Object dummyValue = getDummyValue(prop.getPropertyType()); writeMethod.invoke(bean, dummyValue); assertSame(dummyValue, readMethod.invoke(bean)); } }
From source file:cat.albirar.framework.sets.impl.ModelDescriptor.java
/** * Resolve properties of the model.//from www. ja v a 2 s.c o m */ private void resolveProperties() { PropertyDescriptor[] pd; pd = BeanUtils.getPropertyDescriptors(model); for (PropertyDescriptor prop : pd) { properties.put(prop.getName(), prop); } }
From source file:com.senacor.core.manager.BaseManagerImpl.java
public List<T> find(final T t) { Session session = getSession();//from w ww .j ava 2 s . c om Criteria criteria = session.createCriteria(boClass); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(boClass); BeanWrapper beanWrapper = new BeanWrapperImpl(t); for (PropertyDescriptor descriptor : descriptors) { if (!descriptor.getName().equals("class") && !descriptor.getName().equals("id")) { Object value = beanWrapper.getPropertyValue(descriptor.getName()); if (value != null) { criteria.add(Restrictions.eq(descriptor.getName(), value)); } } } criteria.addOrder(Order.asc("id")); return criteria.list(); }
From source file:com.swingtech.commons.util.ClassUtil.java
public static List getPropertyDescriptorsFromClass(final Class pClass, final String filterRegEx) { BeanInfo vBeanInfo = null;/* ww w .j a v a2 s . co m*/ PropertyDescriptor[] vPropDescList = null; PropertyDescriptor vPropDesc = null; String vPropName = null; final Vector vPropertyNameList = new Vector(); try { vBeanInfo = Introspector.getBeanInfo(pClass); } catch (final IntrospectionException e) { logger.warn("Utility.getPropertyNamesFromClass. Error trying to use Introspector", e); return null; } vPropDescList = vBeanInfo.getPropertyDescriptors(); for (int i = 0; i < vPropDescList.length; i++) { vPropDesc = vPropDescList[i]; vPropName = vPropDesc.getName(); if (Utility.isNullOrEmpty(filterRegEx) || vPropName.matches(filterRegEx)) { vPropertyNameList.add(vPropDesc); } } if (vPropertyNameList.isEmpty()) { return null; } return vPropertyNameList; }
From source file:com.swingtech.commons.util.ClassUtil.java
/** * @param pClass/*w w w. java 2 s. c om*/ * @param filterRegEx * @return */ public static List getPropertyNamesFromClass(final Class pClass, final String filterRegEx) { BeanInfo vBeanInfo = null; PropertyDescriptor vPropDescList[] = null; PropertyDescriptor vPropDesc = null; String vPropName = null; final Vector vPropertyNameList = new Vector(); try { vBeanInfo = Introspector.getBeanInfo(pClass); } catch (final IntrospectionException e) { logger.warn("Utility.getPropertyNamesFromClass. Error trying to use Introspector", e); return null; } vPropDescList = vBeanInfo.getPropertyDescriptors(); for (int i = 0; i < vPropDescList.length; i++) { vPropDesc = vPropDescList[i]; vPropName = vPropDesc.getName(); if (Utility.isNullOrEmpty(filterRegEx) || vPropName.matches(filterRegEx)) { vPropertyNameList.add(vPropName); } } if (vPropertyNameList.isEmpty()) { return null; } return vPropertyNameList; }
From source file:com.unboundid.scim2.common.utils.SchemaUtils.java
/** * This method will determine if this attribute can have multieple * values, and set that in the builder.// w w w. j a va 2s. c o m * * @param attributeBuilder builder for a scim attribute. * @param propertyDescriptor property descriptor for the field to build * the attribute for. * @param schemaProperty the schema property annotation for the field * to build an attribute for. * @return this. */ private static AttributeDefinition.Builder addMultiValued(final AttributeDefinition.Builder attributeBuilder, final PropertyDescriptor propertyDescriptor, final Attribute schemaProperty) { Class<?> multiValuedClass = schemaProperty.multiValueClass(); boolean multiValued = !multiValuedClass.equals(NullType.class); boolean collectionOrArray = isCollectionOrArray(propertyDescriptor.getPropertyType()); // if the multiValuedClass attribute is present in the annotation, // make sure this is a collection or array. if (multiValued && !collectionOrArray) { throw new RuntimeException("Property named " + propertyDescriptor.getName() + " is annotated with a multiValuedClass, " + "but is not a Collection or an array"); } if (!multiValued && collectionOrArray) { throw new RuntimeException("Property named " + propertyDescriptor.getName() + " is not annotated with a multiValuedClass, " + "but is a Collection or an array"); } attributeBuilder.setMultiValued(multiValued); return attributeBuilder; }
From source file:org.jdal.dao.BeanFilter.java
/** * {@inheritDoc}/*from w ww.j ava2 s . com*/ */ public void clear() { PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(getClass()); for (PropertyDescriptor pd : pds) { if (!ignoredProperties.contains(pd.getName())) { try { pd.getWriteMethod().invoke(this, (Object) null); } catch (Exception e) { log.error("Error nullifing property: [" + pd.getName() + "]", e); } } } }
From source file:org.jdal.dao.BeanFilter.java
/** * {@inheritDoc}/*from w w w. j a v a2s .c o m*/ */ public Map<String, Object> getParameterMap() { PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(getClass()); Map<String, Object> map = new HashMap<String, Object>(); for (PropertyDescriptor pd : pds) { if (!ignoredProperties.contains(pd.getName())) try { map.put(pd.getName(), pd.getReadMethod().invoke(this, (Object[]) null)); } catch (Exception e) { log.error(e); } } return map; }
From source file:org.jdal.vaadin.data.BeanWrapperItem.java
public BeanWrapperItem(Object bean, List<String> properties) { this.beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean); if (properties == null) { for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(bean.getClass())) this.properties.add(pd.getName()); } else {/* w w w . ja va 2 s .c om*/ this.properties = properties; } }