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.codehaus.plexus.util.xml.XMLWriter; |
23 | |
|
24 | |
import java.io.File; |
25 | |
import java.io.Writer; |
26 | |
import java.util.Iterator; |
27 | |
import java.util.List; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
final class JbossAppXmlWriter |
37 | |
extends AbstractXmlWriter |
38 | |
{ |
39 | |
|
40 | |
public static final String DOCTYPE_3_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.3//EN\"\n" + |
41 | |
"\t\"http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd\""; |
42 | |
|
43 | |
public static final String DOCTYPE_4 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.4//EN\"\n" + |
44 | |
"\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd\""; |
45 | |
|
46 | |
public static final String DOCTYPE_4_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.4//EN\"\n" + |
47 | |
"\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd\""; |
48 | |
|
49 | |
public static final String DOCTYPE_5 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD Java EE Application 5.0//EN\"\n" + |
50 | |
"\t\"http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd\""; |
51 | |
|
52 | |
private static final String JBOSS_APP_ELEMENT = "jboss-app"; |
53 | |
|
54 | |
JbossAppXmlWriter( String encoding ) |
55 | |
{ |
56 | 0 | super( encoding ); |
57 | 0 | } |
58 | |
|
59 | |
public void write( File destinationFile, JbossConfiguration jbossConfiguration, List earModules ) |
60 | |
throws EarPluginException |
61 | |
{ |
62 | 0 | final Writer w = initializeWriter( destinationFile ); |
63 | |
|
64 | |
XMLWriter writer; |
65 | 0 | if ( jbossConfiguration.isJbossThreeDotTwo() ) |
66 | |
{ |
67 | 0 | writer = initializeXmlWriter( w, DOCTYPE_3_2 ); |
68 | |
} |
69 | 0 | else if ( jbossConfiguration.isJbossFour() ) |
70 | |
{ |
71 | 0 | writer = initializeXmlWriter( w, DOCTYPE_4 ); |
72 | |
} |
73 | 0 | else if ( jbossConfiguration.isJbossFourDotTwo() ) |
74 | |
{ |
75 | 0 | writer = initializeXmlWriter( w, DOCTYPE_4_2 ); |
76 | |
} |
77 | |
else |
78 | |
{ |
79 | 0 | writer = initializeXmlWriter( w, DOCTYPE_5 ); |
80 | |
} |
81 | 0 | writer.startElement( JBOSS_APP_ELEMENT ); |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | 0 | if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getModuleOrder() != null ) |
87 | |
{ |
88 | 0 | writer.startElement( JbossConfiguration.MODULE_ORDER ); |
89 | 0 | writer.writeText( jbossConfiguration.getModuleOrder() ); |
90 | 0 | writer.endElement(); |
91 | |
} |
92 | |
|
93 | |
|
94 | 0 | if ( jbossConfiguration.isJbossFourOrHigher() ) |
95 | |
{ |
96 | 0 | if ( jbossConfiguration.getSecurityDomain() != null ) |
97 | |
{ |
98 | 0 | writer.startElement( JbossConfiguration.SECURITY_DOMAIN ); |
99 | 0 | writer.writeText( jbossConfiguration.getSecurityDomain() ); |
100 | 0 | writer.endElement(); |
101 | |
} |
102 | 0 | if ( jbossConfiguration.getUnauthenticatedPrincipal() != null ) |
103 | |
{ |
104 | 0 | writer.startElement( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL ); |
105 | 0 | writer.writeText( jbossConfiguration.getUnauthenticatedPrincipal() ); |
106 | 0 | writer.endElement(); |
107 | |
} |
108 | |
} |
109 | |
|
110 | |
|
111 | 0 | if ( jbossConfiguration.getLoaderRepository() != null || |
112 | |
jbossConfiguration.getLoaderRepositoryConfig() != null ) |
113 | |
{ |
114 | 0 | writer.startElement( JbossConfiguration.LOADER_REPOSITORY ); |
115 | |
|
116 | |
|
117 | 0 | if ( jbossConfiguration.getLoaderRepositoryClass() != null ) |
118 | |
{ |
119 | 0 | writer.addAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE, |
120 | |
jbossConfiguration.getLoaderRepositoryClass() ); |
121 | |
} |
122 | |
|
123 | |
|
124 | 0 | if ( jbossConfiguration.getLoaderRepository() != null ) |
125 | |
{ |
126 | 0 | writer.writeText( jbossConfiguration.getLoaderRepository() ); |
127 | |
} |
128 | |
|
129 | |
|
130 | 0 | if ( jbossConfiguration.getLoaderRepositoryConfig() != null ) |
131 | |
{ |
132 | 0 | writer.startElement( JbossConfiguration.LOADER_REPOSITORY_CONFIG ); |
133 | |
|
134 | |
|
135 | 0 | if ( jbossConfiguration.getConfigParserClass() != null ) |
136 | |
{ |
137 | 0 | writer.addAttribute( JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE, |
138 | |
jbossConfiguration.getConfigParserClass() ); |
139 | |
} |
140 | 0 | writer.writeText( jbossConfiguration.getLoaderRepositoryConfig() ); |
141 | 0 | writer.endElement(); |
142 | |
} |
143 | |
|
144 | 0 | writer.endElement(); |
145 | |
} |
146 | |
|
147 | |
|
148 | 0 | if ( jbossConfiguration.getJmxName() != null ) |
149 | |
{ |
150 | 0 | writer.startElement( JbossConfiguration.JMX_NAME ); |
151 | 0 | writer.writeText( jbossConfiguration.getJmxName() ); |
152 | 0 | writer.endElement(); |
153 | |
} |
154 | |
|
155 | |
|
156 | 0 | if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getLibraryDirectory() != null ) |
157 | |
{ |
158 | 0 | writer.startElement( JbossConfiguration.LIBRARY_DIRECTORY ); |
159 | 0 | writer.writeText( jbossConfiguration.getLibraryDirectory() ); |
160 | 0 | writer.endElement(); |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | 0 | List dataSources = jbossConfiguration.getDataSources(); |
166 | |
|
167 | 0 | if ( dataSources != null ) |
168 | |
{ |
169 | 0 | final Iterator it = dataSources.iterator(); |
170 | 0 | while ( it.hasNext() ) |
171 | |
{ |
172 | 0 | String dsPath = (String) it.next(); |
173 | 0 | writer.startElement( MODULE_ELEMENT ); |
174 | 0 | writer.startElement( SERVICE_ELEMENT ); |
175 | 0 | writer.writeText( dsPath ); |
176 | 0 | writer.endElement(); |
177 | 0 | writer.endElement(); |
178 | 0 | } |
179 | |
} |
180 | |
|
181 | |
|
182 | 0 | final Iterator it = earModules.iterator(); |
183 | 0 | while ( it.hasNext() ) |
184 | |
{ |
185 | 0 | EarModule earModule = (EarModule) it.next(); |
186 | 0 | if ( JbossEarModule.class.isInstance( earModule ) ) |
187 | |
{ |
188 | 0 | JbossEarModule jbossEarModule = (JbossEarModule) earModule; |
189 | 0 | jbossEarModule.appendJbossModule( writer, jbossConfiguration.getVersion() ); |
190 | |
} |
191 | 0 | } |
192 | 0 | writer.endElement(); |
193 | |
|
194 | 0 | close( w ); |
195 | 0 | } |
196 | |
} |