Coverage report

  %line %branch
org.apache.turbine.services.intake.model.FieldFactory$3
0% 
0% 

 1  
 package org.apache.turbine.services.intake.model;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.turbine.services.intake.IntakeException;
 23  
 import org.apache.turbine.services.intake.xmlmodel.XmlField;
 24  
 
 25  
 /**
 26  
  * Creates Field objects.
 27  
  *
 28  
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
 29  
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 30  
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
 31  
  * @version $Id: FieldFactory.java 264148 2005-08-29 14:21:04Z henning $
 32  
  */
 33  
 public abstract class FieldFactory
 34  
 {
 35  
     private static Map fieldCtors = initFieldCtors();
 36  
 
 37  
     private static Map initFieldCtors()
 38  
     {
 39  
         fieldCtors = new HashMap();
 40  
 
 41  
         fieldCtors.put("int", new FieldFactory.FieldCtor()
 42  
         {
 43  
             public Field getInstance(XmlField f, Group g)
 44  
                     throws IntakeException
 45  
             {
 46  
                 return new IntegerField(f, g);
 47  
             }
 48  
         }
 49  
         );
 50  
         fieldCtors.put("boolean", new FieldFactory.FieldCtor()
 51  
         {
 52  
             public Field getInstance(XmlField f, Group g)
 53  
                     throws IntakeException
 54  
             {
 55  
                 return new BooleanField(f, g);
 56  
             }
 57  
         }
 58  
         );
 59  
         fieldCtors.put("String", new FieldFactory.FieldCtor()
 60  
         {
 61  0
             public Field getInstance(XmlField f, Group g)
 62  
                     throws IntakeException
 63  
             {
 64  0
                 return new StringField(f, g);
 65  
             }
 66  
         }
 67  
         );
 68  
         fieldCtors.put("BigDecimal", new FieldFactory.FieldCtor()
 69  
         {
 70  
             public Field getInstance(XmlField f, Group g)
 71  
                     throws IntakeException
 72  
             {
 73  
                 return new BigDecimalField(f, g);
 74  
             }
 75  
         }
 76  
         );
 77  
         fieldCtors.put("NumberKey", new FieldFactory.FieldCtor()
 78  
         {
 79  
             public Field getInstance(XmlField f, Group g)
 80  
                     throws IntakeException
 81  
             {
 82  
                 return new NumberKeyField(f, g);
 83  
             }
 84  
         }
 85  
         );
 86  
         fieldCtors.put("ComboKey", new FieldFactory.FieldCtor()
 87  
         {
 88  
             public Field getInstance(XmlField f, Group g)
 89  
                     throws IntakeException
 90  
             {
 91  
                 return new ComboKeyField(f, g);
 92  
             }
 93  
         }
 94  
         );
 95  
         fieldCtors.put("StringKey", new FieldFactory.FieldCtor()
 96  
         {
 97  
             public Field getInstance(XmlField f, Group g)
 98  
                     throws IntakeException
 99  
             {
 100  
                 return new StringKeyField(f, g);
 101  
             }
 102  
         }
 103  
         );
 104  
         fieldCtors.put("FileItem", new FieldFactory.FieldCtor()
 105  
         {
 106  
             public Field getInstance(XmlField f, Group g)
 107  
                     throws IntakeException
 108  
             {
 109  
                 return new FileItemField(f, g);
 110  
             }
 111  
         }
 112  
         );
 113  
         fieldCtors.put("DateString", new FieldFactory.FieldCtor()
 114  
         {
 115  
             public Field getInstance(XmlField f, Group g)
 116  
                     throws IntakeException
 117  
             {
 118  
                 return new DateStringField(f, g);
 119  
             }
 120  
         }
 121  
         );
 122  
         fieldCtors.put("float", new FieldFactory.FieldCtor()
 123  
         {
 124  
             public Field getInstance(XmlField f, Group g)
 125  
                     throws IntakeException
 126  
             {
 127  
                 return new FloatField(f, g);
 128  
             }
 129  
         }
 130  
         );
 131  
         fieldCtors.put("double", new FieldFactory.FieldCtor()
 132  
         {
 133  
             public Field getInstance(XmlField f, Group g)
 134  
                     throws IntakeException
 135  
             {
 136  
                 return new DoubleField(f, g);
 137  
             }
 138  
         }
 139  
         );
 140  
         fieldCtors.put("short", new FieldFactory.FieldCtor()
 141  
         {
 142  
             public Field getInstance(XmlField f, Group g)
 143  
                     throws IntakeException
 144  
             {
 145  
                 return new ShortField(f, g);
 146  
             }
 147  
         }
 148  
         );
 149  
         fieldCtors.put("long", new FieldFactory.FieldCtor()
 150  
         {
 151  
             public Field getInstance(XmlField f, Group g)
 152  
                     throws IntakeException
 153  
             {
 154  
                 return new LongField(f, g);
 155  
             }
 156  
         }
 157  
         );
 158  
         return fieldCtors;
 159  
     }
 160  
 
 161  
     private static abstract class FieldCtor
 162  
     {
 163  
         public Field getInstance(XmlField f, Group g) throws IntakeException
 164  
         {
 165  
             return null;
 166  
         }
 167  
     }
 168  
 
 169  
     /**
 170  
      * Creates a Field object appropriate for the type specified
 171  
      * in the xml file.
 172  
      *
 173  
      * @param xmlField a <code>XmlField</code> value
 174  
      * @return a <code>Field</code> value
 175  
      * @throws IntakeException indicates that an unknown type was specified for a field.
 176  
      */
 177  
     public static final Field getInstance(XmlField xmlField, Group xmlGroup)
 178  
             throws IntakeException
 179  
     {
 180  
         FieldCtor fieldCtor = null;
 181  
         Field field = null;
 182  
         String type = xmlField.getType();
 183  
 
 184  
         fieldCtor = (FieldCtor) fieldCtors.get(type);
 185  
         if (fieldCtor == null)
 186  
         {
 187  
             throw new IntakeException("An Unsupported type has been specified for " +
 188  
                     xmlField.getName() + " in group " + xmlGroup.getIntakeGroupName() + " type = " + type);
 189  
         }
 190  
         else
 191  
         {
 192  
             field = fieldCtor.getInstance(xmlField, xmlGroup);
 193  
         }
 194  
 
 195  
         return field;
 196  
     }
 197  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.