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 | 6 | { |
55 | 6 | if ( StringUtils.isEmpty( name ) ) |
56 | |
{ |
57 | 2 | throw new IllegalArgumentException( ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null." ); |
58 | |
} |
59 | 4 | else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( value ) ) |
60 | |
{ |
61 | 2 | 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 | 2 | this.description = description; |
68 | 2 | this.name = name; |
69 | 2 | this.type = type; |
70 | 2 | this.value = value; |
71 | 2 | } |
72 | |
|
73 | |
public String getDescription() |
74 | |
{ |
75 | 2 | return description; |
76 | |
} |
77 | |
|
78 | |
public String getName() |
79 | |
{ |
80 | 12 | return name; |
81 | |
} |
82 | |
|
83 | |
public String getType() |
84 | |
{ |
85 | 12 | return type; |
86 | |
} |
87 | |
|
88 | |
public String getValue() |
89 | |
{ |
90 | 12 | 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 | 10 | return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + "]"; |
138 | |
} |
139 | |
|
140 | |
|
141 | |
} |