View Javadoc

1   package com.atlassian.plugin.osgi.factory.transform;
2   
3   import com.atlassian.plugin.osgi.hostcomponents.HostComponentRegistration;
4   import com.atlassian.plugin.osgi.hostcomponents.PropertyBuilder;
5   
6   import java.util.List;
7   
8   import org.dom4j.Document;
9   import org.dom4j.Element;
10  
11  /**
12   * Transforms host components into Spring configuration
13   * @since 2.1
14   */
15  public class HostComponentSpringTransformer implements SpringTransformer
16  {
17      public void transform(List<HostComponentRegistration> regs, Document pluginDoc, Document springDoc)
18      {
19          Element root = springDoc.getRootElement();
20          if (regs != null)
21          {
22              for (int x=0; x<regs.size(); x++)
23              {
24                  HostComponentRegistration reg = regs.get(x);
25                  String beanName = reg.getProperties().get(PropertyBuilder.BEAN_NAME);
26                  String id = beanName;
27                  if (id == null)
28                      id = "bean"+x;
29  
30                  id = id.replaceAll("#", "LB");
31                  Element osgiService = root.addElement("osgi:reference");
32                  osgiService.addAttribute("id", id);
33  
34                  // Disabling this for now due to some strange Spring DM bug where it will occasionally generate an invalid
35                  // filter, see http://jira.atlassian.com/browse/CONF-13292
36                  //if (beanName != null)
37                  //    osgiService.addAttribute("filter", "(bean-name="+beanName+")");
38  
39                  Element interfaces = osgiService.addElement("osgi:interfaces");
40                  for (String name : reg.getMainInterfaces())
41                  {
42                      Element e = interfaces.addElement("beans:value");
43                      e.setText(name);
44                  }
45              }
46          }
47      }
48  }