View Javadoc

1   /*
2    * $Id: SingleParentFamilyDefinitionParser.java 10256 2008-01-08 15:20:25Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.delegate;
12  
13  import org.mule.config.spring.parsers.MuleChildDefinitionParser;
14  import org.mule.config.spring.parsers.MuleDefinitionParser;
15  import org.mule.config.spring.parsers.MuleDefinitionParserConfiguration;
16  
17  public class SingleParentFamilyDefinitionParser extends AbstractSingleParentFamilyDefinitionParser
18  {
19  
20      public SingleParentFamilyDefinitionParser(MuleDefinitionParser parent)
21      {
22          // avoid the overriden method here
23          super.addDelegate(parent);
24          parent.setIgnoredDefault(false);
25      }
26  
27      protected MuleDefinitionParserConfiguration addDelegate(MuleDefinitionParser delegate)
28      {
29          throw new UnsupportedOperationException("Delegates must be associated with attribute names");
30      }
31  
32      public SingleParentFamilyDefinitionParser addChildDelegate(String attribute, MuleChildDefinitionParser delegate)
33      {
34          return addChildDelegate(new String[]{attribute}, delegate);
35      }
36  
37      public SingleParentFamilyDefinitionParser addChildDelegate(String[] attributes, MuleChildDefinitionParser delegate)
38      {
39          super.addChildDelegate(delegate);
40          delegate.setIgnoredDefault(true);
41          for (int i = 0; i < attributes.length; i++)
42          {
43              getDelegate(0).addIgnored(attributes[i]);
44              delegate.removeIgnored(attributes[i]);
45          }
46          return this;
47      }
48  
49  }
50