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
13
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
35
36
37
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 }