Coverage report

  %line %branch
org.apache.commons.jelly.tags.dynabean.DynaclassTag
84% 
100% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.jelly.tags.dynabean;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 
 20  
 import org.apache.commons.beanutils.BasicDynaClass;
 21  
 import org.apache.commons.beanutils.DynaClass;
 22  
 import org.apache.commons.beanutils.DynaProperty;
 23  
 import org.apache.commons.jelly.JellyTagException;
 24  
 import org.apache.commons.jelly.MissingAttributeException;
 25  
 import org.apache.commons.jelly.TagSupport;
 26  
 import org.apache.commons.jelly.XMLOutput;
 27  
 
 28  
 /**
 29  
  * A tag which creates and defines and creates a DynaClass
 30  
  * The DynaClass object is placed by name in the context,
 31  
  * so that a DynaBean tag can use it by name to instantiate
 32  
  * a DynaBean object
 33  
  *
 34  
  * @author Theo Niemeijer
 35  
  * @version 1.0
 36  
  */
 37  
 public class DynaclassTag extends TagSupport {
 38  
 
 39  9
     private ArrayList propList = new ArrayList();
 40  9
     private DynaProperty[] props = null;
 41  9
     private DynaClass dynaClass = null;
 42  
 
 43  
     private String name;
 44  
     private String var;
 45  
 
 46  9
     public DynaclassTag() {
 47  9
     }
 48  
 
 49  
     // Tag interface
 50  
     //-------------------------------------------------------------------------
 51  
     public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
 52  
 
 53  9
         if (name == null) {
 54  0
             throw new MissingAttributeException("name");
 55  
         }
 56  
 
 57  9
         if (var == null) {
 58  0
             var = name;
 59  
         }
 60  
 
 61  
         // Evaluate the body of the dynaclass definition
 62  9
         invokeBody(output);
 63  
 
 64  
         // Convert the list of properties into array
 65  9
         props =
 66  
             (DynaProperty[]) propList.toArray(
 67  
                 new DynaProperty[propList.size()]);
 68  
 
 69  9
         if (props == null) {
 70  0
             throw new JellyTagException("No properties list");
 71  
         }
 72  
 
 73  9
         if (props.length == 0) {
 74  0
             throw new JellyTagException("No properties");
 75  
         }
 76  
 
 77  
         // Create the dynaclass with name and properties
 78  9
         dynaClass = (DynaClass) new BasicDynaClass(name, null, props);
 79  
 
 80  
         // Place new dynaclass in context
 81  9
         context.setVariable(getVar(), dynaClass);
 82  9
     }
 83  
 
 84  
     // Properties
 85  
     //-------------------------------------------------------------------------
 86  
 
 87  
     /**
 88  
      * Sets the name of the new DynaClass
 89  
      */
 90  
     public void setName(String name) {
 91  9
         this.name = name;
 92  9
     }
 93  
 
 94  
     public String getVar() {
 95  9
         return var;
 96  
     }
 97  
 
 98  
     /**
 99  
      * Sets the name of the variable to export the DynaClass instance
 100  
      */
 101  
     public void setVar(String var) {
 102  9
         this.var = class="keyword">var;
 103  9
     }
 104  
 
 105  
     protected void addDynaProperty(DynaProperty prop) {
 106  21
         propList.add(prop);
 107  21
     }
 108  
 }

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