View Javadoc

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