Coverage report

  %line %branch
org.apache.commons.jelly.tags.jface.preference.FieldEditorTag
0% 
0% 

 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.jface.preference;
 17  
 
 18  
 import java.lang.reflect.Constructor;
 19  
 import java.lang.reflect.InvocationTargetException;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.commons.jelly.JellyTagException;
 23  
 import org.apache.commons.jelly.MissingAttributeException;
 24  
 import org.apache.commons.jelly.XMLOutput;
 25  
 import org.apache.commons.jelly.tags.core.UseBeanTag;
 26  
 import org.eclipse.jface.preference.FieldEditor;
 27  
 import org.eclipse.swt.widgets.Composite;
 28  
 
 29  
 /**
 30  
  * This Tag creates a JFace FieldEditor
 31  
  *
 32  
  * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
 33  
  */
 34  0
 public class FieldEditorTag extends UseBeanTag {
 35  
 
 36  
     public FieldEditorTag(Class arg0) {
 37  0
         super(arg0);
 38  0
     }
 39  
 
 40  
     /*
 41  
      * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
 42  
      */
 43  
     public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
 44  0
         PreferencePageTag tag = (PreferencePageTag) findAncestorWithClass(PreferencePageTag.class);
 45  0
         if (tag == null) {
 46  0
             throw new JellyTagException("This tag must be nested inside a <preferencePage>");
 47  
         }
 48  
 
 49  
         // get new instance of FieldEditor
 50  0
         PreferencePageTag.PreferencePageImpl page = tag.getPreferencePageImpl();
 51  0
         getAttributes().put("parentComposite", page.getFieldEditorParent());
 52  
 
 53  
         // add fieldEditor to PreferencePage
 54  0
         Object fieldEditor = newInstance(getDefaultClass(), getAttributes(), output);
 55  0
         if (fieldEditor instanceof FieldEditor) {
 56  0
             page.addField((FieldEditor) fieldEditor);
 57  
         }
 58  
 
 59  0
     }
 60  
 
 61  
     /*
 62  
      * @see org.apache.commons.jelly.tags.core.UseBeanTag#newInstance(java.lang.Class, java.util.Map, org.apache.commons.jelly.XMLOutput)
 63  
      */
 64  
     protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
 65  
         throws JellyTagException {
 66  
 
 67  0
         if (theClass == null) {
 68  0
             throw new JellyTagException("No Class available to create the FieldEditor");
 69  
         }
 70  
 
 71  0
         String name = (String) attributes.get("name");
 72  0
         if (name == null) {
 73  0
             throw new MissingAttributeException("name");
 74  
         }
 75  
 
 76  0
         String labelText = (String) attributes.get("labelText");
 77  0
         if (labelText == null) {
 78  0
             throw new MissingAttributeException("labelText");
 79  
         }
 80  
 
 81  0
         Composite parentComposite = (Composite) attributes.get("parentComposite");
 82  0
         if (parentComposite == null) {
 83  0
             throw new MissingAttributeException("parentComposite");
 84  
         }
 85  
 
 86  
         // let's try to call a constructor
 87  
         try {
 88  0
             Class[] types = { String.class, String.class, Composite.class };
 89  0
             Constructor constructor = theClass.getConstructor(types);
 90  0
             if (constructor != null) {
 91  0
                 Object[] arguments = { name, labelText, parentComposite };
 92  0
                 return constructor.newInstance(arguments);
 93  
             }
 94  0
             return theClass.newInstance();
 95  
 
 96  
         } catch (NoSuchMethodException e) {
 97  0
             throw new JellyTagException(e);
 98  
         } catch (InstantiationException e) {
 99  0
             throw new JellyTagException(e);
 100  
         } catch (IllegalAccessException e) {
 101  0
             throw new JellyTagException(e);
 102  
         } catch (InvocationTargetException e) {
 103  0
             throw new JellyTagException(e);
 104  
         }
 105  
     }
 106  
 
 107  
 }

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