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