1 | |
package org.apache.maven.plugin.ear; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.plugin.ear.util.JavaEEVersion; |
23 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
24 | |
|
25 | |
import java.io.Writer; |
26 | |
import java.util.Iterator; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
final class ApplicationXmlWriter |
36 | |
extends AbstractXmlWriter |
37 | |
{ |
38 | |
public static final String DOCTYPE_1_3 = |
39 | |
"application PUBLIC\n" + "\t\"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN\"\n" + |
40 | |
"\t\"http://java.sun.com/dtd/application_1_3.dtd\""; |
41 | |
|
42 | |
private static final String APPLICATION_ELEMENT = "application"; |
43 | |
|
44 | |
|
45 | |
private final JavaEEVersion version; |
46 | |
|
47 | |
private final Boolean generateModuleId; |
48 | |
|
49 | |
ApplicationXmlWriter( JavaEEVersion version, String encoding, Boolean generateModuleId ) |
50 | |
{ |
51 | 0 | super( encoding ); |
52 | 0 | this.version = version; |
53 | 0 | this.generateModuleId = generateModuleId; |
54 | 0 | } |
55 | |
|
56 | |
public void write( ApplicationXmlWriterContext context ) |
57 | |
throws EarPluginException |
58 | |
{ |
59 | 0 | Writer w = initializeWriter( context.getDestinationFile() ); |
60 | |
|
61 | 0 | XMLWriter writer = null; |
62 | 0 | if ( JavaEEVersion.OneDotThree.eq( version ) ) |
63 | |
{ |
64 | 0 | writer = initializeRootElementOneDotThree( w ); |
65 | |
} |
66 | 0 | else if ( JavaEEVersion.OneDotFour.eq( version ) ) |
67 | |
{ |
68 | 0 | writer = initializeRootElementOneDotFour( w ); |
69 | |
} |
70 | 0 | else if ( JavaEEVersion.Five.eq( version ) ) |
71 | |
{ |
72 | 0 | writer = initializeRootElementFive( w ); |
73 | |
} |
74 | 0 | else if ( JavaEEVersion.Six.eq( version ) ) |
75 | |
{ |
76 | 0 | writer = initializeRootElementSix( w ); |
77 | |
} |
78 | |
|
79 | |
|
80 | 0 | if ( version.ge( JavaEEVersion.Six ) ) |
81 | |
{ |
82 | 0 | writeApplicationName( context.getApplicationName(), writer ); |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | 0 | if ( version.eq( JavaEEVersion.OneDotThree ) ) |
88 | |
{ |
89 | 0 | writeDisplayName( context.getDisplayName(), writer ); |
90 | 0 | writeDescription( context.getDescription(), writer ); |
91 | |
} |
92 | |
else |
93 | |
{ |
94 | 0 | writeDescription( context.getDescription(), writer ); |
95 | 0 | writeDisplayName( context.getDisplayName(), writer ); |
96 | |
} |
97 | |
|
98 | |
|
99 | 0 | if ( version.ge( JavaEEVersion.Six ) ) |
100 | |
{ |
101 | 0 | writeInitializeInOrder( context.getInitializeInOrder(), writer ); |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | 0 | final Iterator moduleIt = context.getEarModules().iterator(); |
107 | 0 | while ( moduleIt.hasNext() ) |
108 | |
{ |
109 | 0 | EarModule module = (EarModule) moduleIt.next(); |
110 | 0 | module.appendModule( writer, version.getVersion(), generateModuleId ); |
111 | 0 | } |
112 | |
|
113 | 0 | final Iterator securityRoleIt = context.getSecurityRoles().iterator(); |
114 | 0 | while ( securityRoleIt.hasNext() ) |
115 | |
{ |
116 | 0 | SecurityRole securityRole = (SecurityRole) securityRoleIt.next(); |
117 | 0 | securityRole.appendSecurityRole( writer ); |
118 | 0 | } |
119 | |
|
120 | 0 | if ( version.ge( JavaEEVersion.Five ) ) |
121 | |
{ |
122 | 0 | writeLibraryDirectory( context.getLibraryDirectory(), writer ); |
123 | |
} |
124 | |
|
125 | 0 | writer.endElement(); |
126 | |
|
127 | 0 | close( w ); |
128 | 0 | } |
129 | |
|
130 | |
private void writeApplicationName( String applicationName, XMLWriter writer ) |
131 | |
{ |
132 | 0 | if ( applicationName != null ) |
133 | |
{ |
134 | 0 | writer.startElement( "application-name" ); |
135 | 0 | writer.writeText( applicationName ); |
136 | 0 | writer.endElement(); |
137 | |
} |
138 | 0 | } |
139 | |
|
140 | |
private void writeDescription( String description, XMLWriter writer ) |
141 | |
{ |
142 | 0 | if ( description != null ) |
143 | |
{ |
144 | 0 | writer.startElement( "description" ); |
145 | 0 | writer.writeText( description ); |
146 | 0 | writer.endElement(); |
147 | |
} |
148 | 0 | } |
149 | |
|
150 | |
private void writeDisplayName( String displayName, XMLWriter writer ) |
151 | |
{ |
152 | 0 | if ( displayName != null ) |
153 | |
{ |
154 | 0 | writer.startElement( "display-name" ); |
155 | 0 | writer.writeText( displayName ); |
156 | 0 | writer.endElement(); |
157 | |
} |
158 | 0 | } |
159 | |
|
160 | |
private void writeInitializeInOrder( Boolean initializeInOrder, XMLWriter writer ) |
161 | |
{ |
162 | 0 | if ( initializeInOrder != null ) |
163 | |
{ |
164 | 0 | writer.startElement( "initialize-in-order" ); |
165 | 0 | writer.writeText( initializeInOrder.toString() ); |
166 | 0 | writer.endElement(); |
167 | |
} |
168 | 0 | } |
169 | |
|
170 | |
private void writeLibraryDirectory( String libraryDirectory, XMLWriter writer ) |
171 | |
{ |
172 | 0 | if ( libraryDirectory != null ) |
173 | |
{ |
174 | 0 | writer.startElement( "library-directory" ); |
175 | 0 | writer.writeText( libraryDirectory ); |
176 | 0 | writer.endElement(); |
177 | |
} |
178 | 0 | } |
179 | |
|
180 | |
private XMLWriter initializeRootElementOneDotThree( Writer w ) |
181 | |
{ |
182 | 0 | XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 ); |
183 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
184 | 0 | return writer; |
185 | |
} |
186 | |
|
187 | |
private XMLWriter initializeRootElementOneDotFour( Writer w ) |
188 | |
{ |
189 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
190 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
191 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/j2ee" ); |
192 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
193 | 0 | writer.addAttribute( "xsi:schemaLocation", |
194 | |
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" ); |
195 | 0 | writer.addAttribute( "version", "1.4" ); |
196 | 0 | return writer; |
197 | |
} |
198 | |
|
199 | |
private XMLWriter initializeRootElementFive( Writer w ) |
200 | |
{ |
201 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
202 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
203 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
204 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
205 | 0 | writer.addAttribute( "xsi:schemaLocation", |
206 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" ); |
207 | 0 | writer.addAttribute( "version", "5" ); |
208 | 0 | return writer; |
209 | |
} |
210 | |
|
211 | |
private XMLWriter initializeRootElementSix( Writer w ) |
212 | |
{ |
213 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
214 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
215 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
216 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
217 | 0 | writer.addAttribute( "xsi:schemaLocation", |
218 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" ); |
219 | 0 | writer.addAttribute( "version", "6" ); |
220 | 0 | return writer; |
221 | |
} |
222 | |
|
223 | |
} |