1 package com.atlassian.plugin.web.descriptors;
2
3 import com.atlassian.plugin.util.Assertions;
4 import com.atlassian.plugin.web.NoOpContextProvider;
5 import org.dom4j.Element;
6
7 import com.atlassian.plugin.Plugin;
8 import com.atlassian.plugin.PluginParseException;
9 import com.atlassian.plugin.loaders.LoaderUtils;
10 import com.atlassian.plugin.web.ContextProvider;
11 import com.atlassian.plugin.web.WebFragmentHelper;
12 import com.atlassian.plugin.web.conditions.ConditionLoadingException;
13
14
15
16
17
18
19
20
21
22
23
24 class ContextProviderElementParser
25 {
26 private final WebFragmentHelper webFragmentHelper;
27
28 public ContextProviderElementParser(final WebFragmentHelper webFragmentHelper)
29 {
30 this.webFragmentHelper = webFragmentHelper;
31 }
32
33
34
35
36
37
38
39
40
41 public ContextProvider makeContextProvider(final Plugin plugin, final Element element) throws PluginParseException
42 {
43 Assertions.notNull("plugin == null", plugin);
44 try
45 {
46 final Element contextProviderElement = element.element("context-provider");
47 if (contextProviderElement == null)
48 {
49 return new NoOpContextProvider();
50 }
51 else
52 {
53 final ContextProvider context = webFragmentHelper.loadContextProvider(contextProviderElement.attributeValue("class"), plugin);
54 context.init(LoaderUtils.getParams(contextProviderElement));
55 return context;
56 }
57 }
58 catch (final ClassCastException e)
59 {
60 throw new PluginParseException("Configured context-provider class does not implement the ContextProvider interface", e);
61 }
62 catch (final ConditionLoadingException cle)
63 {
64 throw new PluginParseException("Unable to load the module's display conditions: " + cle.getMessage(), cle);
65 }
66 }
67 }