Coverage Report - org.apache.fulcrum.intake.model.AppData
 
Classes in this File Line Coverage Branch Coverage Complexity
AppData
48%
18/37
43%
7/16
2.375
 
 1  
 package org.apache.fulcrum.intake.model;
 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.Serializable;
 23  
 import java.util.List;
 24  
 
 25  
 import javax.xml.bind.annotation.XmlAccessType;
 26  
 import javax.xml.bind.annotation.XmlAccessorType;
 27  
 import javax.xml.bind.annotation.XmlAttribute;
 28  
 import javax.xml.bind.annotation.XmlElement;
 29  
 import javax.xml.bind.annotation.XmlRootElement;
 30  
 
 31  
 import org.apache.fulcrum.intake.IntakeException;
 32  
 
 33  
 /**
 34  
  * A class for holding application data structures.
 35  
  *
 36  
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
 37  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 38  
  * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
 39  
  * @version $Id: AppData.java 1771953 2016-11-29 20:29:12Z tv $
 40  
  */
 41  
 @XmlRootElement(name="input-data")
 42  
 @XmlAccessorType(XmlAccessType.NONE)
 43  2
 public class AppData implements Serializable
 44  
 {
 45  
     /**
 46  
      * Serial version id
 47  
      */
 48  
     private static final long serialVersionUID = -3953843038383617960L;
 49  
 
 50  
     /** List of groups */
 51  
     private List<Group> groups;
 52  
 
 53  
     /** Package that will be used for all mapTo objects */
 54  2
     private String basePackage = "";
 55  
 
 56  
     /** Prefix string that will be used to qualify &lt;prefix&gt;:&lt;intakegroup&gt; names */
 57  
     private String groupPrefix;
 58  
 
 59  
     /**
 60  
      * Return a collection of input sections (&lt;group&gt;).
 61  
      * The names of the groups returned here are only unique
 62  
      * to this AppData object and not qualified with the groupPrefix.
 63  
      * This method is used in the IntakeService to register all the
 64  
      * groups with and without prefix in the service.
 65  
      *
 66  
      * @return the list of groups
 67  
      */
 68  
     public List<Group> getGroups()
 69  
     {
 70  80
         return groups;
 71  
     }
 72  
 
 73  
     /**
 74  
      * Set the collection of groups
 75  
      *
 76  
      * @param groups the groups to set
 77  
      */
 78  
     @XmlElement(name="group")
 79  
     public void setGroups(List<Group> groups)
 80  
     {
 81  2
         this.groups = groups;
 82  2
     }
 83  
 
 84  
     /**
 85  
      * Get a XmlGroup with the given name. It finds both
 86  
      * qualified and unqualified names in this package.
 87  
      *
 88  
      * @param groupName a <code>String</code> value
 89  
      * @return a <code>Group</code> value
 90  
      * @throws IntakeException indicates that the groupName was null
 91  
      */
 92  
     public Group getGroup(String groupName)
 93  
             throws IntakeException
 94  
     {
 95  25
         if (groupName == null)
 96  
         {
 97  0
             throw new IntakeException(
 98  
                     "Intake AppData.getGroup(groupName) is null");
 99  
         }
 100  
 
 101  25
         String groupPrefix = getGroupPrefix();
 102  
 
 103  25
         for (Group group : groups)
 104  
         {
 105  88
             if (group.getIntakeGroupName().equals(groupName))
 106  
             {
 107  25
                 return group;
 108  
             }
 109  63
             if (groupPrefix != null)
 110  
             {
 111  0
                 StringBuilder qualifiedGroupName = new StringBuilder();
 112  
 
 113  0
                 qualifiedGroupName.append(groupPrefix)
 114  0
                         .append(':')
 115  0
                         .append(group.getIntakeGroupName());
 116  
 
 117  0
                 if (qualifiedGroupName.toString().equals(groupName))
 118  
                 {
 119  0
                     return group;
 120  
                 }
 121  
             }
 122  63
         }
 123  0
         return null;
 124  
     }
 125  
 
 126  
     /**
 127  
      * Get the base package String that will be appended to
 128  
      * any mapToObjects
 129  
      *
 130  
      * @return value of basePackage.
 131  
      */
 132  
     public String getBasePackage()
 133  
     {
 134  3
         return basePackage;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Set the base package String that will be appended to
 139  
      * any mapToObjects
 140  
      *
 141  
      * @param v  Value to assign to basePackage.
 142  
      */
 143  
     @XmlAttribute
 144  
     public void setBasePackage(String v)
 145  
     {
 146  2
         if (v == null)
 147  
         {
 148  0
             this.basePackage = "";
 149  
         }
 150  
         else
 151  
         {
 152  2
             if (v.endsWith("."))
 153  
             {
 154  2
                 this.basePackage = v;
 155  
             }
 156  
             else
 157  
             {
 158  0
                 this.basePackage = v + ".";
 159  
             }
 160  
         }
 161  
 
 162  2
     }
 163  
 
 164  
     /**
 165  
      * Get the prefix String that will be used to qualify
 166  
      * intake groups when using multiple XML files
 167  
      *
 168  
      * @return value of groupPrefix
 169  
      */
 170  
     public String getGroupPrefix()
 171  
     {
 172  65
         return groupPrefix;
 173  
     }
 174  
 
 175  
     /**
 176  
      * Set the prefix String that will be used to qualify
 177  
      * intake groups when using multiple XML files
 178  
      *
 179  
      * @param groupPrefix  Value to assign to basePackage.
 180  
      */
 181  
     @XmlAttribute
 182  
     public void setGroupPrefix(String groupPrefix)
 183  
     {
 184  0
         this.groupPrefix = groupPrefix;
 185  0
     }
 186  
 
 187  
     /**
 188  
      * Creates a string representation of this AppData.
 189  
      * The representation is given in xml format.
 190  
      */
 191  
     @Override
 192  
     public String toString()
 193  
     {
 194  0
         StringBuilder result = new StringBuilder();
 195  
 
 196  0
         result.append("<input-data>\n");
 197  0
         for (Group group : groups)
 198  
         {
 199  0
             result.append(group);
 200  0
         }
 201  0
         result.append("</input-data>");
 202  0
         return result.toString();
 203  
     }
 204  
 }