List of usage examples for org.apache.commons.collections FastHashMap get
public Object get(Object key)
From source file:eu.qualityontime.commons.QPropertyUtilsBean.java
/** * <p>/*from www . j av a 2s. c om*/ * Retrieve the property descriptor for the specified property of the * specified bean, or return <code>null</code> if there is no such * descriptor. This method resolves indexed and nested property references * in the same manner as other methods in this class, except that if the * last (or only) name element is indexed, the descriptor for the last * resolved property itself is returned. * </p> * * <p> * <strong>FIXME</strong> - Does not work with DynaBeans. * </p> * * <p> * Note that for Java 8 and above, this method no longer return * IndexedPropertyDescriptor for {@link List}-typed properties, only for * properties typed as native array. (BEANUTILS-492). * * @param bean * Bean for which a property descriptor is requested * @param name * Possibly indexed and/or nested name of the property for which * a property descriptor is requested * @return the property descriptor * * @throws IllegalAccessException * if the caller does not have access to the property accessor * method * @throws IllegalArgumentException * if <code>bean</code> or <code>name</code> is null * @throws IllegalArgumentException * if a nested reference to a property returns null * @throws InvocationTargetException * if the property accessor method throws an exception * @throws NoSuchMethodException * if an accessor method for this propety cannot be found */ public PropertyDescriptor getPropertyDescriptor(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'"); } // Resolve nested references while (resolver.hasNested(name)) { final String next = resolver.next(name); final Object nestedBean = getProperty(bean, next); if (nestedBean == null) { throw new NestedNullException( "Null property value for '" + next + "' on bean class '" + bean.getClass() + "'"); } bean = nestedBean; name = resolver.remove(name); } // Remove any subscript from the final name value name = resolver.getProperty(name); // Look up and return this property from our cache // creating and adding it to the cache if not found. if (name == null) { return null; } final BeanIntrospectionData data = getIntrospectionData(bean.getClass()); PropertyDescriptor result = data.getDescriptor(name); if (result != null) { return result; } FastHashMap mappedDescriptors = getMappedPropertyDescriptors(bean); if (mappedDescriptors == null) { mappedDescriptors = new FastHashMap(); mappedDescriptors.setFast(true); mappedDescriptorsCache.put(bean.getClass(), mappedDescriptors); } result = (PropertyDescriptor) mappedDescriptors.get(name); if (result == null) { // not found, try to create it try { result = new MappedPropertyDescriptor(name, bean.getClass()); } catch (final IntrospectionException ie) { /* * Swallow IntrospectionException TODO: Why? */ } if (result != null) { mappedDescriptors.put(name, result); } } return result; }
From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoPropertyUtilsBean.java
/** * <p>// ww w. jav a 2 s .c om * Retrieve the property descriptor for the specified property of the specified bean, or return <code>null</code> if there is * no such descriptor. This method resolves indexed and nested property references in the same manner as other methods in this * class, except that if the last (or only) name element is indexed, the descriptor for the last resolved property itself is * returned. * </p> * * <p> * <strong>FIXME </strong>- Does not work with DynaBeans. * </p> * * @param bean Bean for which a property descriptor is requested * @param name Possibly indexed and/or nested name of the property for which a property descriptor is requested * * @exception IllegalAccessException if the caller does not have access to the property accessor method * @exception IllegalArgumentException if <code>bean</code> or <code>name</code> is null * @exception IllegalArgumentException if a nested reference to a property returns null * @exception InvocationTargetException if the property accessor method throws an exception * @exception NoSuchMethodException if an accessor method for this propety cannot be found */ public PropertyDescriptor getPropertyDescriptor(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { if (LOG.isDebugEnabled()) LOG.debug("No bean specified, name = " + name); return null; } if (name == null) { throw new IllegalArgumentException("No name specified"); } try { // Resolve nested references Object propBean = null; while (true) { int delim = findNextNestedIndex(name); //int delim = name.indexOf(PropertyUtils.NESTED_DELIM); if (delim < 0) { break; } String next = name.substring(0, delim); int indexOfINDEXED_DELIM = next.indexOf(PropertyUtils.INDEXED_DELIM); int indexOfMAPPED_DELIM = next.indexOf(PropertyUtils.MAPPED_DELIM); if (indexOfMAPPED_DELIM >= 0 && (indexOfINDEXED_DELIM < 0 || indexOfMAPPED_DELIM < indexOfINDEXED_DELIM)) { propBean = getMappedProperty(bean, next); } else { if (indexOfINDEXED_DELIM >= 0) { propBean = getIndexedProperty(bean, next); } else { propBean = getSimpleProperty(bean, next); } } if (ObjectUtils.isNull(propBean)) { Class propertyType = getPropertyType(bean, next); if (propertyType != null) { Object newInstance = ObjectUtils.createNewObjectFromClass(propertyType); setSimpleProperty(bean, next, newInstance); propBean = getSimpleProperty(bean, next); } } bean = propBean; name = name.substring(delim + 1); } // Remove any subscript from the final name value int left = name.indexOf(PropertyUtils.INDEXED_DELIM); if (left >= 0) { name = name.substring(0, left); } left = name.indexOf(PropertyUtils.MAPPED_DELIM); if (left >= 0) { name = name.substring(0, left); } // Look up and return this property from our cache // creating and adding it to the cache if not found. if ((bean == null) || (name == null)) { return (null); } PropertyDescriptor descriptors[] = getPropertyDescriptors(bean); if (descriptors != null) { for (int i = 0; i < descriptors.length; i++) { if (name.equals(descriptors[i].getName())) return (descriptors[i]); } } PropertyDescriptor result = null; FastHashMap mappedDescriptors = getMappedPropertyDescriptors(bean); if (mappedDescriptors == null) { mappedDescriptors = new FastHashMap(); mappedDescriptors.setFast(true); } result = (PropertyDescriptor) mappedDescriptors.get(name); if (result == null) { // not found, try to create it try { result = new MappedPropertyDescriptor(name, bean.getClass()); } catch (IntrospectionException ie) { } if (result != null) { mappedDescriptors.put(name, result); } } return result; } catch (RuntimeException ex) { LOG.error("Unable to get property descriptor for " + bean.getClass().getName() + " . " + name + "\n" + ex.getClass().getName() + ": " + ex.getMessage()); throw ex; } }