commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Masker71 (JIRA)" <j...@apache.org>
Subject [jira] Commented: (BEANUTILS-252) getNestedProperty doesn't work with maps properly
Date Mon, 06 Nov 2006 16:34:38 GMT
    [ http://issues.apache.org/jira/browse/BEANUTILS-252?page=comments#action_12447467 ] 
            
Masker71 commented on BEANUTILS-252:
------------------------------------

Hello Niall,

I think you are right, let's probaly leave it as it is. I just choosed wrong tool for my needs.
I wanted to write a simple translator using BeanUtils functionality to extract beans from
the map and get their properties. For example: system has number of beans which has property
'numValue' (as well as some other properties that could be used in formula). Beans are stored
in the map by their names as keys. User is entering the formula (with some formula builder
e.g.): "values(attr1).numValue + value(attr2).numValue", translator is parsing it, separates
"value(attr1).numValue", "+" and "value(attr2).numValue", calculates results and performs
final calculations on them. But after I re-thought what I am going to do I understood that
I am inventing a wheel :) and found out that commons jexl is what can be used instead of BeanUtils
and suits perfectly for such case.

Thank you again

> getNestedProperty doesn't work with maps properly
> -------------------------------------------------
>
>                 Key: BEANUTILS-252
>                 URL: http://issues.apache.org/jira/browse/BEANUTILS-252
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.7.0
>         Environment: Any
>            Reporter: Masker71
>
> Hello,
> Here is an example of PropertyUtils.getProperty use:
> HashMap myMap = new HashMap();
> myMap.put("key","value");
> Request:
> System.out.println(PropertyUtils.getProperty(myMap, "(key)"));
> Result:
> null
> Workaround:
> HashMap myMap = new HashMap();
> myMap.put("(key)","value");
> Request:
> System.out.println(PropertyUtils.getProperty(myMap, "(key)"));
> Result:
> value
> The reason of this behaviour is that in the implementation of PropertyUtilsBean.getNestedProperty
function.
> Currently it doesn't extract 'key' from brackets. variable name is equal to "(key)" when
this method is invoked
> and it is used to extract value from the map:
>         indexOfINDEXED_DELIM = name.indexOf(PropertyUtils.INDEXED_DELIM);
>         indexOfMAPPED_DELIM = name.indexOf(PropertyUtils.MAPPED_DELIM);
>         if (bean instanceof Map) {
>             bean = ((Map) bean).get(name);
>         } else if (indexOfMAPPED_DELIM >= 0) {
>             bean = getMappedProperty(bean, name);
>         } else if (indexOfINDEXED_DELIM >= 0) {
>             bean = getIndexedProperty(bean, name);
>         } else {
>             bean = getSimpleProperty(bean, name);
>         }
>  For the bean methods which returs maps key extraction is performed, why it isn't done
for the Map? Cannot I use any string as a key in the map, why should I use keys enveloped
in brackets? I think what is mentioned to do is that:
>         indexOfINDEXED_DELIM = name.indexOf(PropertyUtils.INDEXED_DELIM);
>         indexOfMAPPED_DELIM = name.indexOf(PropertyUtils.MAPPED_DELIM);
>         indexOfMAPPED_DELIM2 = name.indexOf(PropertyUtils.MAPPED_DELIM2);
>         if (bean instanceof Map) {
>             if (indexOfMAPPED_DELIM >= 0 && indexOfMAPPED_DELIM2>=0)
>                 name = name.substring(indexOfMAPPED_DELIM+1, indexOfMAPPED_DELIM2);
>             bean = ((Map) bean).get(name);
>         } 
> Hope description was clear enough and you will approve it as a bug.
> Thank you

-- 
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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message