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 public class ResourceRef
40 {
41 static final String RESOURCE_REF = "resource-ref";
42
43 static final String RESOURCE_REF_NAME = "res-ref-name";
44
45 static final String RESOURCE_TYPE = "res-type";
46
47 static final String RESOURCE_AUTH = "res-auth";
48
49 private String name;
50
51 private String type;
52
53 private String auth;
54
55
56
57
58
59
60 public ResourceRef( String name, String type, String auth )
61 {
62 if ( StringUtils.isEmpty( name ) )
63 {
64 throw new IllegalArgumentException( RESOURCE_REF_NAME + " in " + RESOURCE_REF_NAME
65 + " element cannot be null." );
66 }
67 else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( auth ) )
68 {
69 throw new IllegalArgumentException( RESOURCE_TYPE + " in " + RESOURCE_REF_NAME
70 + " element cannot be null " );
71 }
72
73 this.name = name;
74 this.type = type;
75 this.auth = auth;
76
77 }
78
79
80
81
82
83
84 public void appendResourceRefEntry( XMLWriter writer )
85 {
86 writer.startElement( RESOURCE_REF );
87
88
89 doWriteElement( writer, RESOURCE_REF_NAME, getName() );
90
91
92 if ( getType() != null )
93 {
94 doWriteElement( writer, RESOURCE_TYPE, getType() );
95 }
96
97
98 if ( getAuth() != null )
99 {
100 doWriteElement( writer, RESOURCE_AUTH, getAuth() );
101 }
102
103
104 writer.endElement();
105 }
106
107 private void doWriteElement( XMLWriter writer, String element, String text )
108 {
109 writer.startElement( element );
110 writer.writeText( text );
111 writer.endElement();
112 }
113
114
115
116
117 public String getName()
118 {
119 return name;
120 }
121
122
123
124
125 public void setName( String name )
126 {
127 this.name = name;
128 }
129
130
131
132
133 public String getType()
134 {
135 return type;
136 }
137
138
139
140
141 public void setType( String type )
142 {
143 this.type = type;
144 }
145
146
147
148
149 public String getAuth()
150 {
151 return auth;
152 }
153
154
155
156
157 public void setAuth( String auth )
158 {
159 this.auth = auth;
160 }
161
162 }