View Javadoc
1   package com.atlassian.plugin.osgi.factory.transform.model;
2   
3   import com.atlassian.plugin.PluginParseException;
4   import org.dom4j.Element;
5   
6   import java.util.LinkedHashSet;
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 static com.google.common.base.Preconditions.checkNotNull;
13  
14  /**
15   * Represents the data in a component-import tag in the plugin descriptor
16   *
17   * @since 2.2.0
18   */
19  public class ComponentImport {
20      private final String key;
21      private final Set<String> interfaces;
22      private final String filter;
23      private final Element source;
24  
25      public ComponentImport(Element element) throws PluginParseException {
26          checkNotNull(element);
27          createPattern().
28                  rule(
29                          test("@key").withError("The key is required"),
30                          test("(@interface and string-length(@interface) > 0) or (interface and string-length(interface[1]) > 0)")
31                                  .withError("The interface must be specified either via the 'interface'" +
32                                          "attribute or child 'interface' elements")).
33                  evaluate(element);
34  
35          this.source = element;
36          this.key = element.attributeValue("key").trim();
37          final String filter = element.attributeValue("filter");
38          this.filter = filter != null ? filter.trim() : null;
39          this.interfaces = new LinkedHashSet<>();
40          if (element.attribute("interface") != null) {
41              interfaces.add(element.attributeValue("interface").trim());
42          } else {
43              List<Element> compInterfaces = element.elements("interface");
44              for (Element inf : compInterfaces) {
45                  interfaces.add(inf.getTextTrim());
46              }
47          }
48      }
49  
50      public String getKey() {
51          return key;
52      }
53  
54      public Set<String> getInterfaces() {
55          return interfaces;
56      }
57  
58      public Element getSource() {
59          return source;
60      }
61  
62      /**
63       * @return The configured ldap filter
64       * @since 2.3.0
65       */
66      public String getFilter() {
67          return filter;
68      }
69  }