List of usage examples for java.beans IndexedPropertyDescriptor getIndexedPropertyType
public synchronized Class<?> getIndexedPropertyType()
From source file:org.pentaho.reporting.engine.classic.core.util.beans.BeanUtility.java
public static Class getPropertyType(final PropertyDescriptor pd) throws BeanException { final Class typeFromDescriptor = pd.getPropertyType(); if (typeFromDescriptor != null) { return typeFromDescriptor; }/*from ww w . j av a 2s.c o m*/ if (pd instanceof IndexedPropertyDescriptor) { final IndexedPropertyDescriptor idx = (IndexedPropertyDescriptor) pd; return idx.getIndexedPropertyType(); } throw new BeanException("Unable to determine the property type."); }
From source file:es.caib.zkib.jxpath.util.ValueUtils.java
/** * Modifies the index'th element of the bean's property represented by * the supplied property descriptor. Converts the value to the required * type if necessary.//from w w w.jav a2 s.c o m * @param bean to edit * @param propertyDescriptor indicating what to set * @param index int * @param value to set */ public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, int index, Object value) { if (propertyDescriptor instanceof IndexedPropertyDescriptor) { try { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor; Method method = ipd.getIndexedWriteMethod(); if (method != null) { method.invoke(bean, new Object[] { new Integer(index), convert(value, ipd.getIndexedPropertyType()) }); return; } } catch (Exception ex) { throw new RuntimeException( "Cannot access property: " + propertyDescriptor.getName() + ", " + ex.getMessage()); } } // We will fall through if there is no indexed read Object collection = getValue(bean, propertyDescriptor); if (isCollection(collection)) { setValue(collection, index, value); } else if (index == 0) { setValue(bean, propertyDescriptor, value); } else { throw new RuntimeException("Not a collection: " + propertyDescriptor.getName()); } }
From source file:org.apache.axis.utils.BeanPropertyDescriptor.java
/** * Set an indexed property value/*from w w w . j a va 2 s . co m*/ * @param obj is the object * @param i the index * @param newValue is the new value */ public void set(Object obj, int i, Object newValue) throws InvocationTargetException, IllegalAccessException { // Set the new value if (isIndexed()) { IndexedPropertyDescriptor id = (IndexedPropertyDescriptor) myPD; growArrayToSize(obj, id.getIndexedPropertyType(), i); id.getIndexedWriteMethod().invoke(obj, new Object[] { new Integer(i), newValue }); } else { // Not calling 'growArrayToSize' to avoid an extra call to the // property's setter. The setter will be called at the end anyway. // growArrayToSize(obj, myPD.getPropertyType().getComponentType(), i); Object array = get(obj); if (array == null || Array.getLength(array) <= i) { Class componentType = getType().getComponentType(); Object newArray = Array.newInstance(componentType, i + 1); // Copy over the old elements if (array != null) { System.arraycopy(array, 0, newArray, 0, Array.getLength(array)); } array = newArray; } Array.set(array, i, newValue); // Fix for non-indempondent array-type propertirs. // Make sure we call the property's setter. set(obj, array); } }
From source file:net.yasion.common.core.bean.wrapper.ExtendedBeanInfo.java
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) { for (PropertyDescriptor pd : this.propertyDescriptors) { final Class<?> candidateType; final String candidateName = pd.getName(); if (pd instanceof IndexedPropertyDescriptor) { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; candidateType = ipd.getIndexedPropertyType(); if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) { return pd; }/* www .j ava 2s . co m*/ } else { candidateType = pd.getPropertyType(); if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) { return pd; } } } return null; }
From source file:org.springframework.beans.ExtendedBeanInfo.java
@Nullable private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) { for (PropertyDescriptor pd : this.propertyDescriptors) { final Class<?> candidateType; final String candidateName = pd.getName(); if (pd instanceof IndexedPropertyDescriptor) { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; candidateType = ipd.getIndexedPropertyType(); if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) { return pd; }//from w w w .ja v a 2s . c o m } else { candidateType = pd.getPropertyType(); if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) { return pd; } } } return null; }
From source file:pt.ist.maidSyncher.domain.SynchableObject.java
public void copyPropertiesTo(Object dest) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, TaskNotVisibleException { Set<PropertyDescriptor> propertyDescriptorsThatChanged = new HashSet<PropertyDescriptor>(); Object orig = this; checkNotNull(dest);// w w w .j a va 2 s . co m PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(orig); for (PropertyDescriptor origDescriptor : origDescriptors) { String name = origDescriptor.getName(); if (PropertyUtils.isReadable(orig, name)) { PropertyDescriptor destDescriptor = PropertyUtils.getPropertyDescriptor(dest, origDescriptor.getName()); if (PropertyUtils.isWriteable(dest, name) || (destDescriptor != null && MiscUtils.getWriteMethodIncludingFlowStyle(destDescriptor, dest.getClass()) != null)) { Object valueDest = PropertyUtils.getSimpleProperty(dest, name); Object valueOrigin = PropertyUtils.getSimpleProperty(orig, name); LOGGER.debug("OrigDescriptor PropertyType: " + origDescriptor.getPropertyType().getName()); // System.out.println("OrigDescriptor PropertyType: " + origDescriptor.getPropertyType().getName()); //let's ignore the properties were the values are our domain packages if (valueOrigin != null && (SynchableObject.class.isAssignableFrom(valueOrigin.getClass()))) { // System.out.println("Skipping"); continue; //let's skip these properties } if (SynchableObject.class.isAssignableFrom(origDescriptor.getPropertyType())) { // System.out.println("Skipping"); continue; } if (origDescriptor instanceof IndexedPropertyDescriptor) { IndexedPropertyDescriptor indexedPropertyDescriptor = (IndexedPropertyDescriptor) origDescriptor; // System.out.println("OrigDescriptor IndexedPropertyDescriptor: " + indexedPropertyDescriptor.getName()); if (SynchableObject.class .isAssignableFrom(indexedPropertyDescriptor.getIndexedPropertyType())) { // System.out.println("Skipping"); continue; } } //let's ignore all of the dates - as they should be filled by //the system if (valueOrigin instanceof LocalTime) continue; if (Objects.equal(valueDest, valueOrigin) == false) propertyDescriptorsThatChanged.add(origDescriptor); try { if (PropertyUtils.isWriteable(dest, name) == false) { //let's use the flow version Class<?> origPropertyType = origDescriptor.getPropertyType(); Method writeMethodIncludingFlowStyle = MiscUtils .getWriteMethodIncludingFlowStyle(destDescriptor, dest.getClass()); if (Arrays.asList(writeMethodIncludingFlowStyle.getParameterTypes()) .contains(origPropertyType)) { writeMethodIncludingFlowStyle.invoke(dest, valueOrigin); } else { continue; } } else { PropertyUtils.setSimpleProperty(dest, name, valueOrigin); } } catch (IllegalArgumentException ex) { throw new Error("setSimpleProperty returned an exception, dest: " + dest.getClass().getName() + " name : " + name + " valueOrig: " + valueOrigin, ex); } LOGGER.trace("Copied property " + name + " from " + orig.getClass().getName() + " object to a " + dest.getClass().getName() + " oid: " + getExternalId()); } // System.out.println("--"); } } }