1 package com.atlassian.plugin.servlet.descriptors;
2
3 import com.atlassian.plugin.Plugin;
4 import com.atlassian.plugin.servlet.PluginBuilder;
5
6 public class ServletContextParamDescriptorBuilder {
7 private Plugin plugin = new PluginBuilder().build();
8 private String key = "test.servlet.context.param";
9 private String paramName;
10 private String paramValue;
11
12 public ServletContextParamDescriptorBuilder with(Plugin plugin) {
13 this.plugin = plugin;
14 return this;
15 }
16
17 public ServletContextParamDescriptorBuilder withKey(String key) {
18 this.key = key;
19 return this;
20 }
21
22 public ServletContextParamDescriptorBuilder withParam(String name, String value) {
23 paramName = name;
24 paramValue = value;
25 return this;
26 }
27
28 public ServletContextParamModuleDescriptor build() {
29 ModuleDescriptor d = new ModuleDescriptor(plugin, key, paramName, paramValue);
30 plugin.addModuleDescriptor(d);
31 return d;
32 }
33
34 private static final class ModuleDescriptor extends ServletContextParamModuleDescriptor {
35 final String key;
36 final String name;
37 final String value;
38
39 public ModuleDescriptor(
40 Plugin plugin,
41 String key,
42 String name,
43 String value) {
44 this.plugin = plugin;
45 this.key = key;
46 this.name = name;
47 this.value = value;
48 }
49
50 @Override
51 public Plugin getPlugin() {
52 return plugin;
53 }
54
55 @Override
56 public String getCompleteKey() {
57 return getPluginKey() + ":" + key;
58 }
59
60 @Override
61 public String getKey() {
62 return key;
63 }
64
65 @Override
66 public String getParamName() {
67 return name;
68 }
69
70 @Override
71 public String getParamValue() {
72 return value;
73 }
74 }
75 }