1 package com.atlassian.plugin.osgi.factory.transform.model;
2
3 import org.dom4j.Element;
4 import org.apache.commons.lang.Validate;
5
6 import java.util.HashSet;
7 import java.util.List;
8 import java.util.Set;
9
10 import static com.atlassian.plugin.util.validation.ValidationPattern.createPattern;
11 import static com.atlassian.plugin.util.validation.ValidationPattern.test;
12 import com.atlassian.plugin.PluginParseException;
13
14
15
16
17
18
19 public class ComponentImport
20 {
21 private final String key;
22 private final Set<String> interfaces;
23 private final String filter;
24 private final Element source;
25
26 public ComponentImport(Element element) throws PluginParseException
27 {
28 Validate.notNull(element);
29 createPattern().
30 rule(
31 test("@key").withError("The key is required"),
32 test("(@interface and string-length(@interface) > 0) or (interface and string-length(interface[1]) > 0)")
33 .withError("The interface must be specified either via the 'interface'" +
34 "attribute or child 'interface' elements")).
35 evaluate(element);
36
37 this.source = element;
38 this.key = element.attributeValue("key");
39 this.filter = element.attributeValue("filter");
40 this.interfaces = new HashSet<String>();
41 if (element.attribute("interface") != null)
42 {
43 interfaces.add(element.attributeValue("interface"));
44 }
45 else
46 {
47 List<Element> compInterfaces = element.elements("interface");
48 for (Element inf : compInterfaces)
49 {
50 interfaces.add(inf.getTextTrim());
51 }
52 }
53 }
54
55 public String getKey()
56 {
57 return key;
58 }
59
60 public Set<String> getInterfaces()
61 {
62 return interfaces;
63 }
64
65 public Element getSource()
66 {
67 return source;
68 }
69
70
71
72
73
74 public String getFilter()
75 {
76 return filter;
77 }
78 }