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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class ResourceRef
48 {
49 static final String RESOURCE_REF = "resource-ref";
50
51 static final String RESOURCE_REF_NAME = "res-ref-name";
52
53 static final String RESOURCE_TYPE = "res-type";
54
55 static final String RESOURCE_AUTH = "res-auth";
56
57 static final String LOOKUP_NAME = "lookup-name";
58
59 private String name;
60
61 private String type;
62
63 private String auth;
64
65 private String lookupName;
66
67
68
69
70
71
72
73 public ResourceRef( String name, String type, String auth, String lookupName )
74 {
75 if ( StringUtils.isEmpty( name ) )
76 {
77 throw new IllegalArgumentException( RESOURCE_REF_NAME + " in " + RESOURCE_REF_NAME
78 + " element cannot be null." );
79 }
80 else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( auth ) )
81 {
82 throw new IllegalArgumentException( RESOURCE_TYPE + " in " + RESOURCE_REF_NAME
83 + " element cannot be null " );
84 }
85
86 this.name = name;
87 this.type = type;
88 this.auth = auth;
89 this.lookupName = lookupName;
90
91 }
92
93
94
95
96
97
98 public void appendResourceRefEntry( XMLWriter writer )
99 {
100 writer.startElement( RESOURCE_REF );
101
102
103 doWriteElement( writer, RESOURCE_REF_NAME, getName() );
104
105
106 if ( getType() != null )
107 {
108 doWriteElement( writer, RESOURCE_TYPE, getType() );
109 }
110
111
112 if ( getAuth() != null )
113 {
114 doWriteElement( writer, RESOURCE_AUTH, getAuth() );
115 }
116
117
118 if ( getLookupName() != null )
119 {
120 doWriteElement( writer, LOOKUP_NAME, getLookupName() );
121 }
122
123
124 writer.endElement();
125 }
126
127 private void doWriteElement( XMLWriter writer, String element, String text )
128 {
129 writer.startElement( element );
130 writer.writeText( text );
131 writer.endElement();
132 }
133
134
135
136
137 public String getName()
138 {
139 return name;
140 }
141
142
143
144
145 public void setName( String name )
146 {
147 this.name = name;
148 }
149
150
151
152
153 public String getType()
154 {
155 return type;
156 }
157
158
159
160
161 public void setType( String type )
162 {
163 this.type = type;
164 }
165
166
167
168
169 public String getAuth()
170 {
171 return auth;
172 }
173
174
175
176
177 public void setAuth( String auth )
178 {
179 this.auth = auth;
180 }
181
182
183
184
185 public String getLookupName()
186 {
187 return lookupName;
188 }
189
190
191
192
193 public void setLookupName( String lookupName )
194 {
195 this.lookupName = lookupName;
196 }
197
198 }