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