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