View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.parsers.collection;
8   
9   import org.mule.config.spring.parsers.assembly.BeanAssembler;
10  import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
11  import org.mule.config.spring.util.SpringXMLUtils;
12  
13  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
14  import org.springframework.beans.factory.xml.ParserContext;
15  import org.w3c.dom.Element;
16  
17  
18  /**
19   * Process an element as a value that is appended to a list in the parent object (the
20   * enclosing XML element).
21   */
22  public class ChildListEntryDefinitionParser extends ChildDefinitionParser
23  {
24  
25      public static final String VALUE = "value";
26      private boolean fromText = true;
27  
28      /**
29       * Takes value from enclosed text
30       *
31       * @param propertyName
32       */
33      public ChildListEntryDefinitionParser(String propertyName)
34      {
35          super(propertyName, ListEntry.class);
36          setIgnoredDefault(true);
37      }
38  
39      /**
40       * Takes value from attribute
41       *
42       * @param propertyName
43       * @param attributeName
44       */
45      public ChildListEntryDefinitionParser(String propertyName, String attributeName)
46      {
47          this(propertyName);
48          addAlias(attributeName, VALUE);
49          removeIgnored(attributeName);
50          fromText = false;
51      }
52  
53      protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
54      {
55          if (fromText)
56          {
57              assembler.extendBean(VALUE, SpringXMLUtils.getTextChild(element), false);
58          }
59          super.postProcess(context, assembler, element);
60      }
61  
62      protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
63      {
64          super.parseChild(element, parserContext, builder);    //To change body of overridden methods use File | Settings | File Templates.
65      }
66  
67      public static class ListEntry
68      {
69  
70          private Object value;
71  
72          public ListEntry()
73          {
74              super();
75          }
76          
77          public ListEntry(Object proxied)
78          {
79              this();
80              value = proxied;
81          }
82  
83          public Object getValue()
84          {
85              return value;
86          }
87  
88          public void setValue(Object value)
89          {
90              this.value = value;
91          }   
92      }
93  
94  }