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