1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.ear;
20
21 import org.codehaus.plexus.util.xml.XMLWriter;
22
23
24
25
26
27
28 class EnvEntry {
29
30 static final String ENV_ENTRY = "env-entry";
31
32 static final String DESCRIPTION = "description";
33
34 static final String ENV_ENTRY_NAME = "env-entry-name";
35
36 static final String ENV_ENTRY_TYPE = "env-entry-type";
37
38 static final String ENV_ENTRY_VALUE = "env-entry-value";
39
40 static final String ENV_LOOKUP_NAME = "lookup-name";
41
42 private final String description;
43
44 private final String name;
45
46 private final String type;
47
48 private final String value;
49
50 private final String lookupName;
51
52 EnvEntry(String description, String name, String type, String value, String lookupName) {
53 if (name == null || name.isEmpty()) {
54 throw new IllegalArgumentException(ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null.");
55 } else if ((type == null || type.isEmpty()) && (value == null || value.isEmpty())) {
56
57 throw new IllegalArgumentException(ENV_ENTRY_TYPE + " in " + ENV_ENTRY + " element cannot be null if no "
58 + ENV_ENTRY_VALUE + " was specified.");
59 }
60
61 this.description = description;
62 this.name = name;
63 this.type = type;
64 this.value = value;
65 this.lookupName = lookupName;
66 }
67
68 public String getDescription() {
69 return description;
70 }
71
72 public String getName() {
73 return name;
74 }
75
76 public String getType() {
77 return type;
78 }
79
80 public String getValue() {
81 return value;
82 }
83
84 public String getLookupName() {
85 return lookupName;
86 }
87
88
89
90
91
92
93 public void appendEnvEntry(XMLWriter writer) {
94 writer.startElement(ENV_ENTRY);
95
96
97 if (getDescription() != null) {
98 doWriteElement(writer, DESCRIPTION, getDescription());
99 }
100
101
102 doWriteElement(writer, ENV_ENTRY_NAME, getName());
103
104
105 if (getType() != null) {
106 doWriteElement(writer, ENV_ENTRY_TYPE, getType());
107 }
108
109
110 if (getValue() != null) {
111 doWriteElement(writer, ENV_ENTRY_VALUE, getValue());
112 }
113
114
115 if (getLookupName() != null) {
116 doWriteElement(writer, ENV_LOOKUP_NAME, getLookupName());
117 }
118
119
120 writer.endElement();
121 }
122
123 private void doWriteElement(XMLWriter writer, String element, String text) {
124 writer.startElement(element);
125 writer.writeText(text);
126 writer.endElement();
127 }
128
129 public String toString() {
130 return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + ", lookup-name="
131 + getLookupName() + "]";
132 }
133 }