Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 6494 invoked from network); 13 Nov 2008 23:27:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Nov 2008 23:27:40 -0000 Received: (qmail 3210 invoked by uid 500); 13 Nov 2008 23:27:43 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 3132 invoked by uid 500); 13 Nov 2008 23:27:42 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 3081 invoked by uid 99); 13 Nov 2008 23:27:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Nov 2008 15:27:42 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Nov 2008 23:26:30 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 5B4A5234C28E for ; Thu, 13 Nov 2008 15:26:44 -0800 (PST) Message-ID: <1778647928.1226618804372.JavaMail.jira@brutus> Date: Thu, 13 Nov 2008 15:26:44 -0800 (PST) From: "Niall Pemberton (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (BEANUTILS-330) DefaultResolver being able to handle parenthesis "(" and ")" in mapped property key names In-Reply-To: <2111779834.1226504144782.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/BEANUTILS-330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12647460#action_12647460 ] Niall Pemberton commented on BEANUTILS-330: ------------------------------------------- This has been requested before (BEANUTILS-109), but I'm not sure there a straightforward solution that works all the time - for example I don't believe your implementation would cope with a key of "ABC(DEF". > DefaultResolver being able to handle parenthesis "(" and ")" in mapped property key names > ----------------------------------------------------------------------------------------- > > Key: BEANUTILS-330 > URL: https://issues.apache.org/jira/browse/BEANUTILS-330 > Project: Commons BeanUtils > Issue Type: Improvement > Components: Expression Syntax > Environment: java version "1.6.0_03" > Java(TM) SE Runtime Environment (build 1.6.0_03-b05) > Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing) > Reporter: Pierre Post > Fix For: 1.8.0 > > Original Estimate: 2h > Remaining Estimate: 2h > > Unfortunately, the new {{org.apache.commons.beanutils.expression.DefaultResolver}} class is unable to handle mapped property key names that contain parenthesis "(" and ")". Following properties cause an exception when using {{BeanUtils.populate()}}. > {code:title=Bean.properties}job[0].param(anotherParam(key))=value{code} > {code:title=Bean.java}// JavaBean class > public class Bean { > private List job; > public static class Job { > private Map param; > // appropriate public getters and setters here > } > // appropriate public getters and setters here > }{code} > {noformat} > java.lang.IllegalArgumentException: No bean specified > at org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:874) > at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:933) > at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830) > ... > {noformat} > I slightly modified the {{getKey()}} and {{next()}} methods so that they can handle multiple nested mapped delimiters. Now, when using a {{BeanUtilsBean}} instance with a {{PropertyUtilsBean}} and my new resolver, the above properties are accepted without exception: > {code:title=MyResolver.java}public class MyResolver extends DefaultResolver { > // delimiter constants here > public String getKey(String expression) { > if (expression == null || expression.length() == 0) { > return null; > } > for (int i = 0; i < expression.length(); i++) { > char c = expression.charAt(i); > if (c == NESTED || c == INDEXED_START) { > return null; > } else if (c == MAPPED_START) { > int end = getMappedEnd(expression, i); > if (end < 0) { > throw new IllegalArgumentException("Missing End Delimiter"); > } > return expression.substring(i + 1, end); > } > } > return null; > } > > public String next(String expression) { > if (expression == null || expression.length() == 0) { > return null; > } > boolean indexed = false; > int mappedCount = 0; > for (int i = 0; i < expression.length(); i++) { > char c = expression.charAt(i); > if (indexed) { > if (c == INDEXED_END) { > return expression.substring(0, i + 1); > } > } else if (mappedCount > 0) { > if (c == MAPPED_START) { > mappedCount++; > } else if (c == MAPPED_END) { > mappedCount--; > if (mappedCount == 0) { > return expression.substring(0, i + 1); > } > } > } else { > if (c == NESTED) { > return expression.substring(0, i); > } else if (c == MAPPED_START) { > mappedCount++; > } else if (c == INDEXED_START) { > indexed = true; > } > } > } > return expression; > } > > private int getMappedEnd(String expression, int start) { > int count = 0; > for (int i = start; i < expression.length(); i++) { > char c = expression.charAt(i); > if (c == MAPPED_START) { > count++; > } else if (c == MAPPED_END) { > count--; > if (count == 0) { > return i; > } > } > } > return -1; > } > }{code} > If the changes don't affect the other uses of a resolver, I would recommend to adapt {{DefaultResolver}} accordingly as nothing forbids to have "(" and ")" in a key name if I correctly understand. > Best regards, > Pierre -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.