1 package com.atlassian.plugin.osgi.factory.transform;
2
3 import org.dom4j.Document;
4 import org.dom4j.Element;
5
6 import java.util.List;
7 import java.util.ArrayList;
8
9 import com.atlassian.plugin.osgi.hostcomponents.HostComponentRegistration;
10
11
12
13
14
15 public class ComponentImportSpringTransformer implements SpringTransformer
16 {
17 public void transform(List<HostComponentRegistration> regs, Document pluginDoc, Document springDoc)
18 {
19 Element root = springDoc.getRootElement();
20 List<Element> elements = pluginDoc.getRootElement().elements("component-import");
21 for (Element component : elements)
22 {
23 Element osgiReference = root.addElement("osgi:reference");
24 osgiReference.addAttribute("id", component.attributeValue("key"));
25 String infName = component.attributeValue("interface");
26 if (infName != null)
27 osgiReference.addAttribute("interface", infName);
28
29
30 List<Element> compInterfaces = component.elements("interface");
31 if (compInterfaces.size() > 0)
32 {
33 List<String> interfaceNames = new ArrayList<String>();
34 for (Element inf : compInterfaces)
35 interfaceNames.add(inf.getTextTrim());
36
37 Element interfaces = osgiReference.addElement("osgi:interfaces");
38 for (String name : interfaceNames)
39 {
40 Element e = interfaces.addElement("beans:value");
41 e.setText(name);
42 }
43 }
44 }
45 }
46 }