Coverage Report - org.apache.maven.plugin.ear.JbossAppXmlWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
JbossAppXmlWriter
0%
0/66
0%
0/44
10
 
 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 768470 2009-04-25 04:17:51Z 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  
         // Make sure to write the things in the right order so that the DTD validates
 84  
 
 85  
         // module-order (only available as from 4.2)
 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  
         // If JBoss 4, write the jboss4 specific stuff
 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  
         // classloader repository
 111  0
         if ( jbossConfiguration.getLoaderRepository() != null ||
 112  
             jbossConfiguration.getLoaderRepositoryConfig() != null )
 113  
         {
 114  0
             writer.startElement( JbossConfiguration.LOADER_REPOSITORY );
 115  
 
 116  
             // classloader repository class
 117  0
             if ( jbossConfiguration.getLoaderRepositoryClass() != null )
 118  
             {
 119  0
                 writer.addAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE,
 120  
                                      jbossConfiguration.getLoaderRepositoryClass() );
 121  
             }
 122  
 
 123  
             // we don't need to write any text if only the loader repo configuration is changed
 124  0
             if ( jbossConfiguration.getLoaderRepository() != null )
 125  
             {
 126  0
                 writer.writeText( jbossConfiguration.getLoaderRepository() );
 127  
             }
 128  
 
 129  
             // classloader configuration
 130  0
             if ( jbossConfiguration.getLoaderRepositoryConfig() != null )
 131  
             {
 132  0
                 writer.startElement( JbossConfiguration.LOADER_REPOSITORY_CONFIG );
 133  
 
 134  
                 // classloader configuration parser
 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  
         // jmx name
 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  
         // library-directory (only available as from 4.2)
 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  
         // Modules
 164  
 
 165  0
         List dataSources = jbossConfiguration.getDataSources();
 166  
         // Write out data source modules first
 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  
         // Write the JBoss specific modules
 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  
 }