static public CollectionHelper createCollectionType(Collection collection, String valuePropertyName, Class valueClass) { CollectionHelper ch = new CollectionHelper(); ch.collectionObject = collection; ch.valueClass = valueClass; ch.valueProperty = new BeanProperty(valuePropertyName, valueClass, null); return ch; }
if (!propertyName.equals(ch.getValueProperty().getName())) { throw new PropertyNotFoundException(propertyName, node.getPath(), obj.getClass(), "Collection can only be configured with a property name of [" + ch.getValueProperty().getName() + "] but [" + propertyName + "] was used instead"); boolean isCollection = (Collection.class.isAssignableFrom(property.getType())); boolean isMap = (Map.class.isAssignableFrom(property.getType())); if (property.getField() != null) { XmlBeanProperty annotation = property.getField().getAnnotation(XmlBeanProperty.class); if (annotation != null) { if (!StringUtil.isEmpty(annotation.value())) { if (ch == null && !this.accessPrivateProperties && property.getAddMethod() == null && property.getSetMethod() == null) { throw new PropertyPermissionException(propertyName, node.getPath(), obj.getClass(), "Not permitted to add or set property [" + propertyName + "]"); if (ch != null || property.canAdd()) { checkForDuplicates = false; if (!property.getType().isAssignableFrom(typeAttrClass)) { throw new PropertyInvalidTypeException(propertyName, node.getPath(), obj.getClass(), "Unable to assign a value of specified type [" + typeAttrString + "] to property [" + propertyName + "] which is a type [" + property.getType().getName() + "]"); if (TypeConverterUtil.isSupported(property.getType())) { value = TypeConverterUtil.convert(nodeText, property.getType()); } catch (ConversionException e) { throw new PropertyConversionException(propertyName, node.getPath(), obj.getClass(), "The value [" + nodeText + "] for property [" + propertyName + "] could not be converted to a(n) " + property.getType().getSimpleName() + ". " + e.getMessage()); if (property.canGet()) { try { value = property.get(obj);
ch.mapObject = map; ch.valueClass = valueClass; ch.valueProperty = new BeanProperty(valuePropertyName, valueClass, null); if (!keyClass.isAssignableFrom(ch.keyProperty.getType())) { throw new XmlBeanClassException("Incompatible class specified for key; class of map key [" + keyClass.getName() + "] and class of object key [" + ch.keyProperty.getType().getName() + "] for property [" + keyPropertyName + "]");
if (property.getField() == null) { throw new PropertyPermissionException(propertyName, node.getPath(), obj.getClass(), "Unable to access field for collection type [" + value.getClass().getName() + "]"); } else { Type type = property.getField().getGenericType(); if (!(type instanceof ParameterizedType)) { throw new PropertyPermissionException(propertyName, node.getPath(), obj.getClass(), "Only collection types with a parameterized type are supported");
beanProperty = new BeanProperty(propertyName, fieldType, f); beanProperty = new BeanProperty(propertyName, m.getReturnType(), null); m.setAccessible(true); beanProperty.getMethod = m; beanProperty = new BeanProperty(propertyName, m.getParameterTypes()[0], null); m.setAccessible(true); beanProperty.setMethod = m; beanProperty = new BeanProperty(propertyName, m.getParameterTypes()[0], null); m.setAccessible(true); beanProperty.addMethod = m; try { Method getMethod = ClassUtil.getMethod(type, getMethodName, beanProperty.getType(), null, caseSensitive); try { Method setMethod = ClassUtil.getMethod(type, setMethodName, null, beanProperty.getType(), caseSensitive); try { Method addMethod = ClassUtil.getMethod(type, addMethodName, null, beanProperty.getType(), caseSensitive);
beanProperty = new BeanProperty(propertyName, fieldType, f); beanProperty = new BeanProperty(propertyName, m.getReturnType(), null); m.setAccessible(true); beanProperty.getMethod = m; beanProperty = new BeanProperty(propertyName, m.getParameterTypes()[0], null); m.setAccessible(true); beanProperty.setMethod = m; beanProperty = new BeanProperty(propertyName, m.getParameterTypes()[0], null); m.setAccessible(true); beanProperty.addMethod = m; try { Method getMethod = ClassUtil.getMethod(type, getMethodName, beanProperty.getType(), null, caseSensitive); try { Method setMethod = ClassUtil.getMethod(type, setMethodName, null, beanProperty.getType(), caseSensitive); try { Method addMethod = ClassUtil.getMethod(type, addMethodName, null, beanProperty.getType(), caseSensitive);