Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JbossAppXmlWriter |
|
| 11.0;11 |
1 | package org.apache.maven.plugin.ear; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
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 | * An <tt>XmlWriter</tt> based implementation used to generate a | |
31 | * <tt>jboss-app.xml</tt> file | |
32 | * | |
33 | * @author <a href="snicoll@apache.org">Stephane Nicoll</a> | |
34 | * @version $Id: JbossAppXmlWriter.java 746726 2009-02-22 15:15:41Z snicoll $ | |
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 | // If JBoss 4.2 or 5.0, write the JBoss 4.2 and JBoss 5.0-compatible stuff | |
84 | 0 | if ( jbossConfiguration.isJbossFourDotTwo() || jbossConfiguration.isJbossFive() ) |
85 | { | |
86 | // library-directory | |
87 | 0 | if ( jbossConfiguration.getLibraryDirectory() != null ) |
88 | { | |
89 | 0 | writer.startElement( JbossConfiguration.LIBRARY_DIRECTORY ); |
90 | 0 | writer.writeText ( jbossConfiguration.getLibraryDirectory() ); |
91 | 0 | writer.endElement(); |
92 | } | |
93 | } | |
94 | ||
95 | // If JBoss 4.2, write the jboss4.2 specific stuff | |
96 | 0 | if ( jbossConfiguration.isJbossFourDotTwo() ) |
97 | { | |
98 | // module-order (only available in 4.2 and 4.3) | |
99 | 0 | if ( jbossConfiguration.getModuleOrder() != null ) |
100 | { | |
101 | 0 | writer.startElement( JbossConfiguration.MODULE_ORDER ); |
102 | 0 | writer.writeText( jbossConfiguration.getModuleOrder() ); |
103 | 0 | writer.endElement(); |
104 | } | |
105 | } | |
106 | ||
107 | // If JBoss 4, write the jboss4 specific stuff | |
108 | 0 | if ( jbossConfiguration.isJbossFour() || jbossConfiguration.isJbossFourDotTwo() ) |
109 | { | |
110 | 0 | if ( jbossConfiguration.getSecurityDomain() != null ) |
111 | { | |
112 | 0 | writer.startElement( JbossConfiguration.SECURITY_DOMAIN ); |
113 | 0 | writer.writeText( jbossConfiguration.getSecurityDomain() ); |
114 | 0 | writer.endElement(); |
115 | } | |
116 | 0 | if ( jbossConfiguration.getUnauthenticatedPrincipal() != null ) |
117 | { | |
118 | 0 | writer.startElement( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL ); |
119 | 0 | writer.writeText( jbossConfiguration.getUnauthenticatedPrincipal() ); |
120 | 0 | writer.endElement(); |
121 | } | |
122 | } | |
123 | ||
124 | // classloader repository | |
125 | 0 | if ( jbossConfiguration.getLoaderRepository() != null || jbossConfiguration.getLoaderRepositoryConfig() != null) |
126 | { | |
127 | 0 | writer.startElement( JbossConfiguration.LOADER_REPOSITORY ); |
128 | ||
129 | // classloader repository class | |
130 | 0 | if ( jbossConfiguration.getLoaderRepositoryClass() != null) |
131 | { | |
132 | 0 | writer.addAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE, |
133 | jbossConfiguration.getLoaderRepositoryClass() ); | |
134 | } | |
135 | ||
136 | // we don't need to write any text if only the loader repo configuration is changed | |
137 | 0 | if ( jbossConfiguration.getLoaderRepository() != null ) |
138 | { | |
139 | 0 | writer.writeText( jbossConfiguration.getLoaderRepository() ); |
140 | } | |
141 | ||
142 | // classloader configuration | |
143 | 0 | if ( jbossConfiguration.getLoaderRepositoryConfig() != null ) |
144 | { | |
145 | 0 | writer.startElement( JbossConfiguration.LOADER_REPOSITORY_CONFIG ); |
146 | ||
147 | // classloader configuration parser | |
148 | 0 | if ( jbossConfiguration.getConfigParserClass() != null) |
149 | { | |
150 | 0 | writer.addAttribute( JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE, |
151 | jbossConfiguration.getConfigParserClass() ); | |
152 | } | |
153 | 0 | writer.writeText( jbossConfiguration.getLoaderRepositoryConfig() ); |
154 | 0 | writer.endElement(); |
155 | } | |
156 | ||
157 | 0 | writer.endElement(); |
158 | } | |
159 | ||
160 | // jmx name | |
161 | 0 | if ( jbossConfiguration.getJmxName() != null ) |
162 | { | |
163 | 0 | writer.startElement( JbossConfiguration.JMX_NAME ); |
164 | 0 | writer.writeText( jbossConfiguration.getJmxName() ); |
165 | 0 | writer.endElement(); |
166 | } | |
167 | ||
168 | 0 | List dataSources = jbossConfiguration.getDataSources(); |
169 | // Write out data source modules first | |
170 | 0 | if ( dataSources != null ) |
171 | { | |
172 | 0 | final Iterator it = dataSources.iterator(); |
173 | 0 | while ( it.hasNext() ) |
174 | { | |
175 | 0 | String dsPath = (String) it.next(); |
176 | 0 | writer.startElement( MODULE_ELEMENT ); |
177 | 0 | writer.startElement( SERVICE_ELEMENT ); |
178 | 0 | writer.writeText( dsPath ); |
179 | 0 | writer.endElement(); |
180 | 0 | writer.endElement(); |
181 | 0 | } |
182 | } | |
183 | ||
184 | // Write the JBoss specific modules | |
185 | 0 | final Iterator it = earModules.iterator(); |
186 | 0 | while ( it.hasNext() ) |
187 | { | |
188 | 0 | EarModule earModule = (EarModule) it.next(); |
189 | 0 | if ( JbossEarModule.class.isInstance( earModule ) ) |
190 | { | |
191 | 0 | JbossEarModule jbossEarModule = (JbossEarModule) earModule; |
192 | 0 | jbossEarModule.appendJbossModule( writer, jbossConfiguration.getVersion() ); |
193 | } | |
194 | 0 | } |
195 | 0 | writer.endElement(); |
196 | ||
197 | 0 | close( w ); |
198 | 0 | } |
199 | } |