1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.ear;
20
21 import org.codehaus.plexus.util.xml.XMLWriter;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class ResourceRef {
46 static final String RESOURCE_REF = "resource-ref";
47
48 static final String RESOURCE_REF_NAME = "res-ref-name";
49
50 static final String RESOURCE_TYPE = "res-type";
51
52 static final String RESOURCE_AUTH = "res-auth";
53
54 static final String LOOKUP_NAME = "lookup-name";
55
56 private String name;
57
58 private String type;
59
60 private String auth;
61
62 private String lookupName;
63
64
65
66
67
68
69
70 public ResourceRef(String name, String type, String auth, String lookupName) {
71 if (name == null || name.isEmpty()) {
72 throw new IllegalArgumentException(
73 RESOURCE_REF_NAME + " in " + RESOURCE_REF_NAME + " element cannot be null.");
74 } else if ((type == null || type.isEmpty()) && (auth == null || auth.isEmpty())) {
75 throw new IllegalArgumentException(RESOURCE_TYPE + " in " + RESOURCE_REF_NAME + " element cannot be null ");
76 }
77
78 this.name = name;
79 this.type = type;
80 this.auth = auth;
81 this.lookupName = lookupName;
82 }
83
84
85
86
87
88
89 public void appendResourceRefEntry(XMLWriter writer) {
90 writer.startElement(RESOURCE_REF);
91
92
93 doWriteElement(writer, RESOURCE_REF_NAME, getName());
94
95
96 if (getType() != null) {
97 doWriteElement(writer, RESOURCE_TYPE, getType());
98 }
99
100
101 if (getAuth() != null) {
102 doWriteElement(writer, RESOURCE_AUTH, getAuth());
103 }
104
105
106 if (getLookupName() != null) {
107 doWriteElement(writer, LOOKUP_NAME, getLookupName());
108 }
109
110
111 writer.endElement();
112 }
113
114 private void doWriteElement(XMLWriter writer, String element, String text) {
115 writer.startElement(element);
116 writer.writeText(text);
117 writer.endElement();
118 }
119
120
121
122
123 public String getName() {
124 return name;
125 }
126
127
128
129
130 public void setName(String name) {
131 this.name = name;
132 }
133
134
135
136
137 public String getType() {
138 return type;
139 }
140
141
142
143
144 public void setType(String type) {
145 this.type = type;
146 }
147
148
149
150
151 public String getAuth() {
152 return auth;
153 }
154
155
156
157
158 public void setAuth(String auth) {
159 this.auth = auth;
160 }
161
162
163
164
165 public String getLookupName() {
166 return lookupName;
167 }
168
169
170
171
172 public void setLookupName(String lookupName) {
173 this.lookupName = lookupName;
174 }
175 }