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 {
55 if ( StringUtils.isEmpty( name ) )
56 {
57 throw new IllegalArgumentException( ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null." );
58 }
59 else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( value ) )
60 {
61 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 this.description = description;
68 this.name = name;
69 this.type = type;
70 this.value = value;
71 }
72
73 public String getDescription()
74 {
75 return description;
76 }
77
78 public String getName()
79 {
80 return name;
81 }
82
83 public String getType()
84 {
85 return type;
86 }
87
88 public String getValue()
89 {
90 return value;
91 }
92
93
94
95
96
97
98 public void appendEnvEntry( XMLWriter writer )
99 {
100 writer.startElement( ENV_ENTRY );
101
102
103 if ( getDescription() != null )
104 {
105 doWriteElement( writer, DESCRIPTION, getDescription() );
106 }
107
108
109 doWriteElement( writer, ENV_ENTRY_NAME, getName() );
110
111
112 if ( getType() != null )
113 {
114 doWriteElement( writer, ENV_ENTRY_TYPE, getType() );
115 }
116
117
118 if ( getValue() != null )
119 {
120 doWriteElement( writer, ENV_ENTRY_VALUE, getValue() );
121 }
122
123
124 writer.endElement();
125 }
126
127
128 private void doWriteElement( XMLWriter writer, String element, String text )
129 {
130 writer.startElement( element );
131 writer.writeText( text );
132 writer.endElement();
133 }
134
135 public String toString()
136 {
137 return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + "]";
138 }
139
140
141 }