[ 
https://issues.apache.org/jira/browse/CONFIGURATION-360?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12666696#action_12666696
 ] 

Oliver Heger commented on CONFIGURATION-360:
--------------------------------------------

If I understand you correctly, you would like the beans defined by the 
{{styleDefinition}} elements to be collected into a list and then passed to a 
{{setStyleDefinitions()}} method of the window manager bean, correct?

However, {{XMLBeanDeclaration}} does not support list properties. There is 
currently no simple way to achieve this I am aware of. You could create your 
own bean declaration class derived from {{XMLBeanDeclaration}} and override the 
{{getNestedBeanDeclarations()}} method to deal with multiple occurrences of 
nested elements, but this is certainly not trivial.

As is mentioned in the user guide 
(http://commons.apache.org/configuration/userguide/howto_beans.html, especially 
refer to the paragraph in italics), the mechanisms to define beans provided by 
Commons Configuration are limited. If your requirements are more complex, you 
should think about using a real IoC container.

> java.lang.IllegalArgumentException: Passed in key must select exactly one 
> node:
> -------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-360
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-360
>             Project: Commons Configuration
>          Issue Type: Improvement
>    Affects Versions: 1.5
>            Reporter: kog
>            Priority: Blocker
>
> I am trying to pass a list of values as parameters(Key,Vaue) in a XML file. I 
> am trying to pass the XML file to the XMLBeanDeclaration. It throws an error 
> as noted below. Please note Key is the same but values are different in the 
> list below. 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <config>
>   <gui>
>     <windowManager config-class="examples.windows.DefaultWindowManager"
>       closable="false" resizable="true" defaultWidth="400"
>       defaultHeight="250">
>       <styleDefinition config-class="examples.windows.WindowStyleDefinition"
>         backColor="#ffffff" foreColor="0080ff" iconName="myicon" />
>      <styleDefinition config-class="examples.windows.WindowStyleDefinition"
>         backColor="#00000" foreColor="8888ff" iconName="youricon" />
>     </windowManager>
>   </gui>
> </config>
> I have a test configuration like this:
> private TestConfiguration(String configFile) {
>         try {
>             URL configURL = getClass().getResource("windowconfig.xml");
>             XMLConfiguration config = new XMLConfiguration(configURL);
>             BeanDeclaration decl = new XMLBeanDeclaration(config, 
> "gui.windowManager");
>             WindowManager wm = (WindowManager) BeanHelper.createBean(decl);
>         } catch (Exception exc) {
>             throw new RuntimeException("Initialization failed", exc);
>         }
>     }
> This is the exception I am getting from the above test:
> java.lang.IllegalArgumentException: Passed in key must select exactly one 
> node: styleDefinition 
>                 at 
> org.apache.commons.configuration.HierarchicalConfiguration.configurationAt(HierarchicalConfiguration.java:581)
>                 at 
> org.apache.commons.configuration.HierarchicalConfiguration.configurationAt(HierarchicalConfiguration.java:601)
>                 at 
> org.apache.commons.configuration.beanutils.XMLBeanDeclaration.getNestedBeanDeclarations(XMLBeanDeclaration.java:313)
> The HeirarchialConfiguration.configurationAt method only takes one value but 
> not the list of values during XMLBeanDeclaration. 
> Is there an alternative mechanism to pass a list of values? I would greatly 
> appreciate any help with this.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to