Coverage Report - org.apache.myfaces.taglib.core.ConverterImplTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ConverterImplTag
0%
0/40
0%
0/20
3.429
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  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,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.taglib.core;
 20  
 
 21  
 import javax.el.ELContext;
 22  
 import javax.el.ValueExpression;
 23  
 import javax.faces.context.FacesContext;
 24  
 import javax.faces.convert.Converter;
 25  
 import javax.faces.webapp.ConverterELTag;
 26  
 import javax.servlet.jsp.JspException;
 27  
 
 28  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspAttribute;
 29  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag;
 30  
 
 31  
 /**
 32  
  * This tag creates an instance of the specified Converter, and associates it with the nearest parent UIComponent.
 33  
  * 
 34  
  * @author Leonardo Uribe (latest modification by $Author$)
 35  
  * @version $Revision$ $Date$
 36  
  * 
 37  
  */
 38  
 @JSFJspTag(name = "f:converter", bodyContent = "empty")
 39  
 public class ConverterImplTag extends ConverterELTag
 40  
 {
 41  
 
 42  
     private static final long serialVersionUID = -4506829108081L;
 43  
     private ValueExpression _converterId;
 44  
     private ValueExpression _binding;
 45  0
     private String _converterIdString = null;
 46  
 
 47  
     public ConverterImplTag()
 48  
     {
 49  0
         super();
 50  0
     }
 51  
 
 52  
     /**
 53  
      * The converter's registered ID.
 54  
      */
 55  
     @JSFJspAttribute(className="javax.el.ValueExpression",
 56  
             deferredValueType="java.lang.String")
 57  
     public void setConverterId(ValueExpression converterId)
 58  
     {
 59  0
         _converterId = converterId;
 60  0
     }
 61  
 
 62  
     /**
 63  
      * A ValueExpression that evaluates to a Converter.
 64  
      */
 65  
     @JSFJspAttribute(className="javax.el.ValueExpression",
 66  
             deferredValueType="javax.faces.convert.Converter")
 67  
     public void setBinding(ValueExpression binding)
 68  
     {
 69  0
         _binding = binding;
 70  0
     }
 71  
 
 72  
     /**
 73  
      * Use this method to specify the converterId programmatically.
 74  
      * 
 75  
      * @param converterIdString
 76  
      */
 77  
     public void setConverterIdString(String converterIdString)
 78  
     {
 79  0
         _converterIdString = converterIdString;
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public void release()
 84  
     {
 85  0
         super.release();
 86  0
         _converterId = null;
 87  0
         _binding = null;
 88  0
         _converterIdString = null;
 89  0
     }
 90  
 
 91  
     @Override
 92  
     protected Converter createConverter() throws JspException
 93  
     {
 94  0
         if (_converterId != null && _converterId.isLiteralText())
 95  
         {
 96  0
             return this.createClassicConverter();
 97  
         }
 98  0
         if (_converterIdString != null)
 99  
         {
 100  0
             return this.createClassicConverter();
 101  
         }
 102  
 
 103  0
         return new DelegateConverter(_converterId, _binding, _converterIdString);
 104  
     }
 105  
 
 106  
     protected Converter createClassicConverter() throws JspException
 107  
     {
 108  0
         Converter converter = null;
 109  
 
 110  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 111  0
         ELContext elContext = facesContext.getELContext();
 112  
 
 113  
         // try to create the converter from the binding expression first, and then from
 114  
         // the converterId
 115  0
         if (_binding != null)
 116  
         {
 117  
             try
 118  
             {
 119  0
                 converter = (Converter)_binding.getValue(elContext);
 120  
 
 121  0
                 if (converter != null)
 122  
                 {
 123  0
                     return converter;
 124  
                 }
 125  
             }
 126  0
             catch (Exception e)
 127  
             {
 128  0
                 throw new JspException("Exception creating converter using binding", e);
 129  0
             }
 130  
         }
 131  
 
 132  0
         if ((_converterId != null) || (_converterIdString != null))
 133  
         {
 134  
             try
 135  
             {
 136  0
                 if (null != _converterIdString)
 137  
                 {
 138  0
                     converter = facesContext.getApplication().createConverter(_converterIdString);
 139  
                 }
 140  
                 else
 141  
                 {
 142  0
                     String converterId = (String)_converterId.getValue(elContext);
 143  0
                     converter = facesContext.getApplication().createConverter(converterId);
 144  
                 }
 145  
 
 146  
                 // with binding no converter was created, set its value with the converter
 147  
                 // created using the converterId
 148  0
                 if (converter != null && _binding != null)
 149  
                 {
 150  0
                     _binding.setValue(elContext, converter);
 151  
                 }
 152  
             }
 153  0
             catch (Exception e)
 154  
             {
 155  0
                 throw new JspException("Exception creating converter with converterId: " + _converterId, e);
 156  0
             }
 157  
         }
 158  
 
 159  0
         return converter;
 160  
     }
 161  
 }