Coverage Report - org.apache.maven.plugin.ear.EnvEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
EnvEntry
51%
15/29
50%
6/12
2
 
 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.StringUtils;
 23  
 import org.codehaus.plexus.util.xml.XMLWriter;
 24  
 
 25  
 /**
 26  
  * The representation of a env-entry entry within an
 27  
  * application.xml file.
 28  
  *
 29  
  * @author Jim Brownfield based on code by <a href="snicoll@apache.org">Stephane Nicoll</a>
 30  
  * @version $Id: EnvEntry.java 1377219 2012-08-25 05:42:36Z snicoll $
 31  
  */
 32  
 class EnvEntry
 33  
 {
 34  
 
 35  
     static final String ENV_ENTRY = "env-entry";
 36  
 
 37  
     static final String DESCRIPTION = "description";
 38  
 
 39  
     static final String ENV_ENTRY_NAME = "env-entry-name";
 40  
 
 41  
     static final String ENV_ENTRY_TYPE = "env-entry-type";
 42  
 
 43  
     static final String ENV_ENTRY_VALUE = "env-entry-value";
 44  
 
 45  
     private final String description;
 46  
 
 47  
     private final String name;
 48  
 
 49  
     private final String type;
 50  
 
 51  
     private final String value;
 52  
 
 53  
     public EnvEntry( String description, String name, String type, String value )
 54  6
     {
 55  6
         if ( StringUtils.isEmpty( name ) )
 56  
         {
 57  2
             throw new IllegalArgumentException( ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null." );
 58  
         }
 59  4
         else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( value ) )
 60  
         {
 61  2
             throw new IllegalArgumentException(
 62  
                 ENV_ENTRY_TYPE + " in " + ENV_ENTRY + " element cannot be null if no " + ENV_ENTRY_VALUE +
 63  
                     " was specified." );
 64  
 
 65  
         }
 66  
 
 67  2
         this.description = description;
 68  2
         this.name = name;
 69  2
         this.type = type;
 70  2
         this.value = value;
 71  2
     }
 72  
 
 73  
     public String getDescription()
 74  
     {
 75  2
         return description;
 76  
     }
 77  
 
 78  
     public String getName()
 79  
     {
 80  12
         return name;
 81  
     }
 82  
 
 83  
     public String getType()
 84  
     {
 85  12
         return type;
 86  
     }
 87  
 
 88  
     public String getValue()
 89  
     {
 90  12
         return value;
 91  
     }
 92  
 
 93  
     /**
 94  
      * Appends the <tt>XML</tt> representation of this env-entry.
 95  
      *
 96  
      * @param writer the writer to use
 97  
      */
 98  
     public void appendEnvEntry( XMLWriter writer )
 99  
     {
 100  0
         writer.startElement( ENV_ENTRY );
 101  
 
 102  
         // description
 103  0
         if ( getDescription() != null )
 104  
         {
 105  0
             doWriteElement( writer, DESCRIPTION, getDescription() );
 106  
         }
 107  
 
 108  
         // env entry name
 109  0
         doWriteElement( writer, ENV_ENTRY_NAME, getName() );
 110  
 
 111  
         // env entry type
 112  0
         if ( getType() != null )
 113  
         {
 114  0
             doWriteElement( writer, ENV_ENTRY_TYPE, getType() );
 115  
         }
 116  
 
 117  
         // env entry value
 118  0
         if ( getValue() != null )
 119  
         {
 120  0
             doWriteElement( writer, ENV_ENTRY_VALUE, getValue() );
 121  
         }
 122  
 
 123  
         // end of env-entry
 124  0
         writer.endElement();
 125  0
     }
 126  
 
 127  
 
 128  
     private void doWriteElement( XMLWriter writer, String element, String text )
 129  
     {
 130  0
         writer.startElement( element );
 131  0
         writer.writeText( text );
 132  0
         writer.endElement();
 133  0
     }
 134  
 
 135  
     public String toString()
 136  
     {
 137  10
         return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + "]";
 138  
     }
 139  
 
 140  
 
 141  
 }