[ http://issues.apache.org/jira/browse/BEANUTILS-188?page=all ]

Niall Pemberton updated BEANUTILS-188:
--------------------------------------

    Bugzilla Id:   (was: 33352)
    Component/s: Bean / Property Utils

> [beanutils] add collection modifiers feature to PropertyUtilsBean
> -----------------------------------------------------------------
>
>                 Key: BEANUTILS-188
>                 URL: http://issues.apache.org/jira/browse/BEANUTILS-188
>             Project: Commons BeanUtils
>          Issue Type: Improvement
>          Components: Bean / Property Utils
>         Environment: Operating System: All
> Platform: All
>            Reporter: Marc DeXeT
>            Priority: Minor
>
> There's some java beans who are not lazy ones and who need to modify 
> collection
> type properties. Ongoing propertyUtilsBean only allows to set indexed 
> property,
> but not to add or remove items in collection.
> This is a proposition to add following new features :
> - propertyUtilsBean.(add | remove )CollectionPropertyValue(Object bean, String
> name, Object value)
> Action: (add to | remove from ) bean property name a value.
> In other words, search a method (add | remove)item(parameterType value) where
> parameterType.isAssignable(value.class) to add value to item collection, item
> collection bean property being deduced with a stemmer algo (as in
> betwixt.DefaultPluralStemmer) from method name and declared by
> getProperty(bean,name).getClass();
> Sample : 
> myPropertyUtilsBean.addCollectionPropertyValue(myBean,
> "productMap("food").catalog.products", new Product("acmeDogFood", 12));
> will use Catalog.addProduct(Product p) to add new Product("acmeDogFood", 12) 
> to
> inner collection Catalog.products.
> - PropertyUtilsBean.(add | remove )CollectionPropertyValue(Object bean, String
> property, String itemName, Object value)
> Action: (add to | remove from ) bean property name a value.
> In other words, search a method (add | remove)item(parameterType value) where
> parameterType.isAssignable(value.class) to add value to item collection, item
> collection being deduced with a stemmer algo (as in
> betwixt.DefaultPluralStemmer) from itemName and declared by
> getProperty(bean,name).getClass();
> Sample : 
> myPropertyUtilsBean.addCollectionPropertyValue(myBean,
> "productMap("food").catalog","product", new Product("acmeDogFood", 12));
> will use Catalog.addProduct(Product p) to add new Product("acmeDogFood", 12) 
> to
> inner Catalog.productList.
> If there's no Catalog.addProduct(Product p) method, try to invoke
> Collection.add(Object obj) on Catalog.products.
> I have yet created in PropertyUtilsBean sub class such feature as demonstrator
> and unit tests work (for the meantime).
> Constraints:
> - Object are to apply java beans specification.
> - Collection must have readable method ( to be considered as bean property)
> - adder and remover method have to follow conventions copied from
> org.apache.commons.betwixt.strategy.DefaultPluralStemmer
> Matching select in this order for an given itemName or a deduced from method
> name one:
>    1. get itemName+"s" :("items")
>    2. if ( itemName ends with "y" )
>          1. get itemName+"es" (no sample, my english is too poor !)
>          2. get substitute itemName ending with "ies" ("baby" => "babies")
>    3. get itemName + "List"
>    4. get itemName + "Set"
>    5. get itemName + "Collection
>    6. Browse propertyMap to get a property starting with itemName, as 
> "itemBag".
>       If there's several property matching later, select the longuest property
> name : "itemBagCollection" instead of "itemBag"
>       
> - method selection :
> If two methods match this upper requirements (name (add | remove)Item(ParmType
> value) and parameterType.isAssignable(value.class)) , first method matching is
> selected. Methods are ordered following min "distance" metric :
> - "Distance" metric is the base on 
>             public int getDistance(Class c) {
>                 Class superclass = c.getSuperclass();
>                 int distance = 0;
>                 while ( superclass != null ) {
>                     superclass = superclass.getSuperclass();
>                     distance ++;
>                 }
>                 return distance;
>             }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to