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  import javax.annotation.Nonnull;
11  
12  /**
13   * Processes an "available" attribute in the plugin namespace.
14   * Also handles registering the {@link com.atlassian.plugin.osgi.hostcomponents.HostComponentProvider} through
15   * the {@link com.atlassian.plugin.spring.SpringHostComponentProviderFactoryBean}.
16   *
17   * In the case of hierarchical contexts we will put the host component provider in the lowest possible context.
18   */
19  public class PluginAvailableBeanDefinitionDecorator implements BeanDefinitionDecorator {
20      /**
21       * Called when the Spring parser encounters an "available" attribute.
22       *
23       * @param source The attribute
24       * @param holder The containing bean definition
25       * @param ctx    The parser context
26       * @return The containing bean definition
27       */
28      @Nonnull
29      public BeanDefinitionHolder decorate(@Nonnull Node source, @Nonnull BeanDefinitionHolder holder,
30                                           @Nonnull ParserContext ctx) {
31          final String isAvailable = ((Attr) source).getValue();
32          if (Boolean.parseBoolean(isAvailable)) {
33              new PluginBeanDefinitionRegistry(ctx.getRegistry()).addBeanName(holder.getBeanName());
34          }
35          return holder;
36      }
37  }