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 public class EjbRef
32 {
33 static final String DESCRIPTION = "description";
34
35 static final String EJB_REF = "ejb-ref";
36
37 static final String EJB_NAME = "ejb-ref-name";
38
39 static final String EJB_TYPE = "ejb-ref-type";
40
41 static final String EJB_LOOKUP_NAME = "lookup-name";
42
43 private final String description;
44
45 private String name;
46
47 private String type;
48
49 private String lookupName;
50
51
52
53
54
55
56
57 public EjbRef( String description, String name, String type, String lookupName )
58 {
59 if ( StringUtils.isEmpty( name ) )
60 {
61 throw new IllegalArgumentException( EJB_NAME + " in " + EJB_REF + " element cannot be null." );
62 }
63 else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( lookupName ) )
64 {
65 throw new IllegalArgumentException( EJB_TYPE + " in " + EJB_REF + " element cannot be null if no "
66 + EJB_LOOKUP_NAME + " was specified." );
67
68 }
69
70 this.description = description;
71 this.name = name;
72 this.type = type;
73 this.lookupName = lookupName;
74
75 }
76
77
78
79
80
81
82 public void appendEjbRefEntry( XMLWriter writer )
83 {
84 writer.startElement( EJB_REF );
85
86
87 if ( getDescription() != null )
88 {
89 doWriteElement( writer, DESCRIPTION, getDescription() );
90 }
91
92
93 doWriteElement( writer, EJB_NAME, getName() );
94
95
96 if ( getType() != null )
97 {
98 doWriteElement( writer, EJB_TYPE, getType() );
99 }
100
101
102 if ( getLookupName() != null )
103 {
104 doWriteElement( writer, EJB_LOOKUP_NAME, getLookupName() );
105 }
106
107
108 writer.endElement();
109 }
110
111 private void doWriteElement( XMLWriter writer, String element, String text )
112 {
113 writer.startElement( element );
114 writer.writeText( text );
115 writer.endElement();
116 }
117
118
119
120
121 public String getName()
122 {
123 return name;
124 }
125
126
127
128
129 public void setName( String name )
130 {
131 this.name = name;
132 }
133
134
135
136
137 public String getType()
138 {
139 return type;
140 }
141
142
143
144
145 public void setType( String type )
146 {
147 this.type = type;
148 }
149
150
151
152
153 public String getLookupName()
154 {
155 return lookupName;
156 }
157
158
159
160
161 public void setLookupName( String lookupName )
162 {
163 this.lookupName = lookupName;
164 }
165
166
167
168
169 public String getDescription()
170 {
171 return description;
172 }
173 }