List of usage examples for java.beans PropertyDescriptor getReadMethod
public synchronized Method getReadMethod()
From source file:com.ettrema.httpclient.calsync.parse.BeanPropertyMapper.java
public void toBean(Object bean, String icalText) { VCardEngine cardEngine = new VCardEngine(); VCard vcard;/* w ww .ja va 2 s .co m*/ try { vcard = cardEngine.parse(icalText); } catch (IOException ex) { throw new RuntimeException(ex); } 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.mapToBean(vcard, bean, pd); } } } } }
From source file:com.iorga.webappwatcher.util.BasicParameterHandler.java
private void initAccessorMethods(final PropertyDescriptor fieldPropertyDescriptor) { this.writeMethod = fieldPropertyDescriptor.getWriteMethod(); this.readMethod = fieldPropertyDescriptor.getReadMethod(); if (this.writeMethod == null) { throw new IllegalStateException("Couldn't find setter for " + ownerClass + "." + fieldName); }/*from w w w . java 2s .co m*/ if (this.readMethod == null) { throw new IllegalStateException("Couldn't find getter for " + ownerClass + "." + fieldName); } }
From source file:eu.planets_project.pp.plato.util.jsf.SelectableItemConverter.java
protected String getItemIdentifier(Object o, String property) { PropertyDescriptor desc; Object result;// www. j a va 2 s .c o m try { desc = new PropertyDescriptor(property, o.getClass()); result = desc.getReadMethod().invoke(o); return result.toString(); } catch (Throwable e) { log.error("Unable to get object identifier!", e); } return null; }
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 w w w.j av a2s . 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:net.cpollet.jixture.hibernate3.helper.Hibernate3MappingDefinitionHolder.java
private boolean isGetterForField(PropertyDescriptor pd, Field field) { return null != pd.getReadMethod() && pd.getName().equals(field.getName()); }
From source file:java2typescript.jackson.module.visitors.TSJsonObjectFormatVisitor.java
private boolean isAccessorMethod(Method method, BeanInfo beanInfo) { for (PropertyDescriptor property : beanInfo.getPropertyDescriptors()) { if (method.equals(property.getReadMethod())) { return true; }//from w ww .j a va 2s .com if (method.equals(property.getWriteMethod())) { return true; } } return false; }
From source file:com.agimatec.validation.util.PropertyAccess.java
public Type getJavaType() { /*if(Map.class.isAssignableFrom(beanClass)) { return beanClass. //from www . j a v a2 s . c om }*/ if (rememberField != null) { // use cached field of previous access return rememberField.getGenericType(); } for (PropertyDescriptor each : PropertyUtils.getPropertyDescriptors(beanClass)) { if (each.getName().equals(propertyName) && each.getReadMethod() != null) { return each.getReadMethod().getGenericReturnType(); } } try { // try public field return beanClass.getField(propertyName).getGenericType(); } catch (NoSuchFieldException ex2) { // search for private/protected field up the hierarchy Class theClass = beanClass; while (theClass != null) { try { return theClass.getDeclaredField(propertyName).getGenericType(); } catch (NoSuchFieldException ex3) { // do nothing } theClass = theClass.getSuperclass(); } } return Object.class; // unknown type: allow any type?? }
From source file:de.mogwai.common.web.fieldinformationresolver.jpa.JPAAnnotationFieldInformationResolver.java
public Boolean getRequiredInformation(Application aApplication, FacesContext aContext, Object aBase, String aProperty) {//from w ww .ja va 2 s. c o m try { PropertyDescriptor theDescriptor = PropertyUtils.getPropertyDescriptor(aBase, aProperty); if (theDescriptor == null) { return null; } Method theReadMethod = theDescriptor.getReadMethod(); if (theReadMethod != null) { Column theColumn = theReadMethod.getAnnotation(Column.class); if (theColumn != null) { return !theColumn.nullable(); } } return null; } catch (Exception e) { LOGGER.error("Error", e); return null; } }
From source file:com.impetus.kundera.metadata.processor.AbstractEntityFieldProcessor.java
/** * Populates @Id accesser methods like, getId and setId of clazz to * metadata.//from w ww . j ava2 s .c o m * * @param metadata * the metadata * @param clazz * the clazz * @param f * the f */ protected final void populateIdAccessorMethods(EntityMetadata metadata, Class<?> clazz, Field f) { try { BeanInfo info = Introspector.getBeanInfo(clazz); for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) { if (descriptor.getName().equals(f.getName())) { metadata.setReadIdentifierMethod(descriptor.getReadMethod()); metadata.setWriteIdentifierMethod(descriptor.getWriteMethod()); return; } } } catch (IntrospectionException e) { throw new RuntimeException(e); } }
From source file:de.mogwai.common.web.fieldinformationresolver.jpa.JPAAnnotationFieldInformationResolver.java
public Integer getMaxLengthInformationProvided(Application aApplication, FacesContext aContext, Object aBase, String aProperty) {//from w ww . j a va 2 s . co m try { PropertyDescriptor theDescriptor = PropertyUtils.getPropertyDescriptor(aBase, aProperty); if (theDescriptor == null) { return null; } Method theReadMethod = theDescriptor.getReadMethod(); if (theReadMethod != null) { Column theColumn = theReadMethod.getAnnotation(Column.class); if (theColumn != null) { return theColumn.length(); } } return null; } catch (Exception e) { LOGGER.error("Error", e); return null; } }