View Javadoc

1   package com.atlassian.plugin.spring.pluginns;
2   
3   import com.atlassian.plugin.spring.PluginBeanDefinitionRegistry;
4   import org.springframework.beans.factory.config.BeanDefinitionHolder;
5   import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
6   import org.springframework.beans.factory.xml.ParserContext;
7   import org.w3c.dom.Attr;
8   import org.w3c.dom.Node;
9   
10  /**
11   * Processes an "available" attribute in the plugin namespace.
12   * Also handles registering the {@link com.atlassian.plugin.osgi.hostcomponents.HostComponentProvider} through
13   * the {@link com.atlassian.plugin.spring.SpringHostComponentProviderFactoryBean}.
14   *
15   * In the case of hierarchical contexts we will put the host component provider in the lowest possible context.
16   */
17  public class PluginAvailableBeanDefinitionDecorator implements BeanDefinitionDecorator
18  {
19      /**
20       * Called when the Spring parser encounters an "available" attribute.
21       * @param source The attribute
22       * @param holder The containing bean definition
23       * @param ctx The parser context
24       * @return The containing bean definition
25       */
26      public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder holder, ParserContext ctx)
27      {
28          final String isAvailable = ((Attr) source).getValue();
29          if (Boolean.parseBoolean(isAvailable))
30          {
31              new PluginBeanDefinitionRegistry(ctx.getRegistry()).addBeanName(holder.getBeanName());
32          }
33          return holder;
34      }
35  }