Coverage Report - org.apache.maven.plugin.ear.JbossAppXmlWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
JbossAppXmlWriter
0%
0/61
0%
0/42
11.5
 
 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 java.io.File;
 23  
 import java.io.Writer;
 24  
 import java.util.List;
 25  
 
 26  
 import org.codehaus.plexus.util.xml.XMLWriter;
 27  
 
 28  
 /**
 29  
  * An <tt>XmlWriter</tt> based implementation used to generate a
 30  
  * <tt>jboss-app.xml</tt> file
 31  
  *
 32  
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
 33  
  * @version $Id: JbossAppXmlWriter.java 1294559 2012-02-28 10:37:58Z snicoll $
 34  
  */
 35  
 final class JbossAppXmlWriter
 36  
     extends AbstractXmlWriter
 37  
 {
 38  
 
 39  
     public static final String DOCTYPE_3_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.3//EN\"\n"
 40  
         + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd\"";
 41  
 
 42  
     public static final String DOCTYPE_4 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.4//EN\"\n"
 43  
         + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd\"";
 44  
 
 45  
     public static final String DOCTYPE_4_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 4.2//EN\"\n"
 46  
         + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd\"";
 47  
 
 48  
     public static final String DOCTYPE_5 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD Java EE Application 5.0//EN\"\n"
 49  
         + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd\"";
 50  
 
 51  
     private static final String JBOSS_APP_ELEMENT = "jboss-app";
 52  
 
 53  
     JbossAppXmlWriter( String encoding )
 54  
     {
 55  0
         super( encoding );
 56  0
     }
 57  
 
 58  
     public void write( File destinationFile, JbossConfiguration jbossConfiguration, List<EarModule> earModules )
 59  
         throws EarPluginException
 60  
     {
 61  0
         final Writer w = initializeWriter( destinationFile );
 62  
 
 63  
         XMLWriter writer;
 64  0
         if ( jbossConfiguration.isJbossThreeDotTwo() )
 65  
         {
 66  0
             writer = initializeXmlWriter( w, DOCTYPE_3_2 );
 67  
         }
 68  0
         else if ( jbossConfiguration.isJbossFour() )
 69  
         {
 70  0
             writer = initializeXmlWriter( w, DOCTYPE_4 );
 71  
         }
 72  0
         else if ( jbossConfiguration.isJbossFourDotTwo() )
 73  
         {
 74  0
             writer = initializeXmlWriter( w, DOCTYPE_4_2 );
 75  
         }
 76  
         else
 77  
         {
 78  0
             writer = initializeXmlWriter( w, DOCTYPE_5 );
 79  
         }
 80  0
         writer.startElement( JBOSS_APP_ELEMENT );
 81  
 
 82  
         // Make sure to write the things in the right order so that the DTD validates
 83  
 
 84  
         // module-order (only available as from 4.2)
 85  0
         if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getModuleOrder() != null )
 86  
         {
 87  0
             writer.startElement( JbossConfiguration.MODULE_ORDER );
 88  0
             writer.writeText( jbossConfiguration.getModuleOrder() );
 89  0
             writer.endElement();
 90  
         }
 91  
 
 92  
         // If JBoss 4, write the jboss4 specific stuff
 93  0
         if ( jbossConfiguration.isJbossFourOrHigher() )
 94  
         {
 95  0
             if ( jbossConfiguration.getSecurityDomain() != null )
 96  
             {
 97  0
                 writer.startElement( JbossConfiguration.SECURITY_DOMAIN );
 98  0
                 writer.writeText( jbossConfiguration.getSecurityDomain() );
 99  0
                 writer.endElement();
 100  
             }
 101  0
             if ( jbossConfiguration.getUnauthenticatedPrincipal() != null )
 102  
             {
 103  0
                 writer.startElement( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL );
 104  0
                 writer.writeText( jbossConfiguration.getUnauthenticatedPrincipal() );
 105  0
                 writer.endElement();
 106  
             }
 107  
         }
 108  
 
 109  
         // classloader repository
 110  0
         if ( jbossConfiguration.getLoaderRepository() != null
 111  
             || jbossConfiguration.getLoaderRepositoryConfig() != null )
 112  
         {
 113  0
             writer.startElement( JbossConfiguration.LOADER_REPOSITORY );
 114  
 
 115  
             // classloader repository class
 116  0
             if ( jbossConfiguration.getLoaderRepositoryClass() != null )
 117  
             {
 118  0
                 writer.addAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE,
 119  
                                      jbossConfiguration.getLoaderRepositoryClass() );
 120  
             }
 121  
 
 122  
             // we don't need to write any text if only the loader repo configuration is changed
 123  0
             if ( jbossConfiguration.getLoaderRepository() != null )
 124  
             {
 125  0
                 writer.writeText( jbossConfiguration.getLoaderRepository() );
 126  
             }
 127  
 
 128  
             // classloader configuration
 129  0
             if ( jbossConfiguration.getLoaderRepositoryConfig() != null )
 130  
             {
 131  0
                 writer.startElement( JbossConfiguration.LOADER_REPOSITORY_CONFIG );
 132  
 
 133  
                 // classloader configuration parser
 134  0
                 if ( jbossConfiguration.getConfigParserClass() != null )
 135  
                 {
 136  0
                     writer.addAttribute( JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE,
 137  
                                          jbossConfiguration.getConfigParserClass() );
 138  
                 }
 139  0
                 writer.writeText( jbossConfiguration.getLoaderRepositoryConfig() );
 140  0
                 writer.endElement();
 141  
             }
 142  
 
 143  0
             writer.endElement();
 144  
         }
 145  
 
 146  
         // jmx name
 147  0
         if ( jbossConfiguration.getJmxName() != null )
 148  
         {
 149  0
             writer.startElement( JbossConfiguration.JMX_NAME );
 150  0
             writer.writeText( jbossConfiguration.getJmxName() );
 151  0
             writer.endElement();
 152  
         }
 153  
 
 154  
         // library-directory (only available as from 4.2)
 155  0
         if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getLibraryDirectory() != null )
 156  
         {
 157  0
             writer.startElement( JbossConfiguration.LIBRARY_DIRECTORY );
 158  0
             writer.writeText( jbossConfiguration.getLibraryDirectory() );
 159  0
             writer.endElement();
 160  
         }
 161  
 
 162  
         // Modules
 163  
 
 164  0
         List<String> dataSources = jbossConfiguration.getDataSources();
 165  
         // Write out data source modules first
 166  0
         if ( dataSources != null )
 167  
         {
 168  0
             for ( String dsPath : dataSources )
 169  
             {
 170  0
                 writer.startElement( MODULE_ELEMENT );
 171  0
                 writer.startElement( SERVICE_ELEMENT );
 172  0
                 writer.writeText( dsPath );
 173  0
                 writer.endElement();
 174  0
                 writer.endElement();
 175  
             }
 176  
         }
 177  
 
 178  
         // Write the JBoss specific modules
 179  0
         for ( EarModule earModule : earModules )
 180  
         {
 181  0
             if ( JbossEarModule.class.isInstance( earModule ) )
 182  
             {
 183  0
                 JbossEarModule jbossEarModule = (JbossEarModule) earModule;
 184  0
                 jbossEarModule.appendJbossModule( writer, jbossConfiguration.getVersion() );
 185  0
             }
 186  
         }
 187  0
         writer.endElement();
 188  
 
 189  0
         close( w );
 190  0
     }
 191  
 }