1 package org.apache.maven.plugins.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 class EnvEntry
31 {
32
33 static final String ENV_ENTRY = "env-entry";
34
35 static final String DESCRIPTION = "description";
36
37 static final String ENV_ENTRY_NAME = "env-entry-name";
38
39 static final String ENV_ENTRY_TYPE = "env-entry-type";
40
41 static final String ENV_ENTRY_VALUE = "env-entry-value";
42
43 static final String ENV_LOOKUP_NAME = "lookup-name";
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 private final String lookupName;
54
55 EnvEntry( String description, String name, String type, String value, String lookupName )
56 {
57 if ( StringUtils.isEmpty( name ) )
58 {
59 throw new IllegalArgumentException( ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null." );
60 }
61 else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( value ) )
62 {
63 throw new IllegalArgumentException( ENV_ENTRY_TYPE + " in " + ENV_ENTRY + " element cannot be null if no "
64 + ENV_ENTRY_VALUE + " was specified." );
65
66 }
67
68 this.description = description;
69 this.name = name;
70 this.type = type;
71 this.value = value;
72 this.lookupName = lookupName;
73 }
74
75 public String getDescription()
76 {
77 return description;
78 }
79
80 public String getName()
81 {
82 return name;
83 }
84
85 public String getType()
86 {
87 return type;
88 }
89
90 public String getValue()
91 {
92 return value;
93 }
94
95 public String getLookupName()
96 {
97 return lookupName;
98 }
99
100
101
102
103
104
105 public void appendEnvEntry( XMLWriter writer )
106 {
107 System.out.println( "appendEnvEntry()" );
108 writer.startElement( ENV_ENTRY );
109
110
111 if ( getDescription() != null )
112 {
113 doWriteElement( writer, DESCRIPTION, getDescription() );
114 }
115
116
117 doWriteElement( writer, ENV_ENTRY_NAME, getName() );
118
119
120 if ( getType() != null )
121 {
122 doWriteElement( writer, ENV_ENTRY_TYPE, getType() );
123 }
124
125
126 if ( getValue() != null )
127 {
128 doWriteElement( writer, ENV_ENTRY_VALUE, getValue() );
129 }
130
131
132 if ( getLookupName() != null )
133 {
134 doWriteElement( writer, ENV_LOOKUP_NAME, getLookupName() );
135 }
136
137
138 writer.endElement();
139 }
140
141 private void doWriteElement( XMLWriter writer, String element, String text )
142 {
143 writer.startElement( element );
144 writer.writeText( text );
145 writer.endElement();
146 }
147
148 public String toString()
149 {
150 return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + ", lookup-name="
151 + getLookupName() + "]";
152 }
153
154 }