View Javadoc

1   /*
2    * $Id: GlobalPropertyDefinitionParser.java 12259 2008-07-09 14:18:28Z dirk.olmes $
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  package org.mule.config.spring.parsers.specific;
11  
12  import org.mule.config.spring.parsers.assembly.BeanAssembler;
13  import org.mule.config.spring.parsers.generic.MuleOrphanDefinitionParser;
14  
15  import org.springframework.beans.factory.xml.ParserContext;
16  import org.springframework.util.SystemPropertyUtils;
17  import org.w3c.dom.Element;
18  
19  public class GlobalPropertyDefinitionParser extends MuleOrphanDefinitionParser
20  {
21      private final String VALUE_ATTR = "value";
22      private final String NAME_ATTR = "name";
23  
24      public GlobalPropertyDefinitionParser()
25      {
26          super(true);
27          addIgnored(NAME_ATTR);
28          addIgnored(VALUE_ATTR);
29      }
30  
31      protected Class getBeanClass(Element element)
32      {
33          return String.class;
34      }
35  
36      protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
37      {
38          String name = element.getAttribute(NAME_ATTR);
39          if(name.indexOf(' ') != -1)
40          {
41              logger.warn("Environment property name should not contain spaces: \"" + name + "\"");
42          }
43  
44          String value = element.getAttribute(VALUE_ATTR);
45          assembler.getBean().addConstructorArgValue(SystemPropertyUtils.resolvePlaceholders(value));
46          super.postProcess(context, assembler, element);
47      }
48  }