1 package com.atlassian.plugin.osgi.factory.transform;
2
3 import com.atlassian.plugin.osgi.hostcomponents.HostComponentRegistration;
4 import com.atlassian.plugin.osgi.external.ListableModuleDescriptorFactory;
5 import com.atlassian.plugin.ModuleDescriptorFactory;
6
7 import java.util.List;
8
9 import org.dom4j.Document;
10 import org.dom4j.Element;
11
12
13
14
15
16 public class ModuleTypeSpringTransformer implements SpringTransformer
17 {
18 public void transform(List<HostComponentRegistration> regs, Document pluginDoc, Document springDoc)
19 {
20 Element root = springDoc.getRootElement();
21 List<Element> elements = pluginDoc.getRootElement().elements("module-type");
22 for (Element e : elements)
23 {
24 Element bean = root.addElement("beans:bean");
25 bean.addAttribute("id", getBeanId(e));
26 bean.addAttribute("class", "com.atlassian.plugin.osgi.external.SingleModuleDescriptorFactory");
27
28 Element arg = bean.addElement("beans:constructor-arg");
29 arg.addAttribute("index", "0");
30 Element value = arg.addElement("beans:value");
31 value.setText(e.attributeValue("key"));
32 Element arg2 = bean.addElement("beans:constructor-arg");
33 arg2.addAttribute("index", "1");
34 Element value2 = arg2.addElement("beans:value");
35 value2.setText(e.attributeValue("class"));
36
37 Element osgiService = root.addElement("osgi:service");
38 osgiService.addAttribute("id", getBeanId(e) +"_osgiService");
39 osgiService.addAttribute("ref", getBeanId(e));
40 osgiService.addAttribute("auto-export", "interfaces");
41 }
42 }
43
44 private String getBeanId(Element e)
45 {
46 return "moduleType-"+e.attributeValue("key");
47 }
48 }