Coverage Report - org.apache.myfaces.taglib.core.ConverterTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ConverterTag
0%
0/35
0%
0/14
2.667
 
 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  
 /**
 29  
  * Implementation of ConverterELTag
 30  
  *
 31  
  * @author Bruno Aranda (latest modification by $Author: skitching $)
 32  
  * @version $Revision: 684465 $ $Date: 2008-08-10 06:38:21 -0500 (Sun, 10 Aug 2008) $
 33  
  */
 34  
 public class ConverterTag extends ConverterELTag
 35  
 {
 36  
 
 37  
     private static final long serialVersionUID = -4506829108081L;
 38  
     private ValueExpression _converterId;
 39  
     private ValueExpression _binding;
 40  0
     private String _converterIdString = null;
 41  
 
 42  
     public ConverterTag()
 43  
     {
 44  0
         super();
 45  0
     }
 46  
 
 47  
     public void setConverterId(ValueExpression converterId)
 48  
     {
 49  0
         _converterId = converterId;
 50  0
     }
 51  
 
 52  
     public void setBinding(ValueExpression binding)
 53  
     {
 54  0
         _binding = binding;
 55  0
     }
 56  
 
 57  
     /**
 58  
      * Use this method to specify the converterId programmatically.
 59  
      *
 60  
      * @param converterIdString
 61  
      */
 62  
     public void setConverterIdString(String converterIdString)
 63  
     {
 64  0
         _converterIdString = converterIdString;
 65  0
     }
 66  
 
 67  
     public void release()
 68  
     {
 69  0
         super.release();
 70  0
         _converterId = null;
 71  0
         _binding = null;
 72  0
         _converterIdString = null;
 73  0
     }
 74  
 
 75  
     protected Converter createConverter()
 76  
             throws JspException
 77  
     {
 78  0
         Converter converter = null;
 79  
 
 80  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 81  0
         ELContext elContext = facesContext.getELContext();
 82  
 
 83  
         // try to create the converter from the binding expression first, and then from
 84  
         // the converterId
 85  0
         if (_binding != null)
 86  
         {
 87  
             try
 88  
             {
 89  0
                 converter = (Converter) _binding.getValue(elContext);
 90  
 
 91  0
                 if (converter != null)
 92  
                 {
 93  0
                     return converter;
 94  
                 }
 95  
             }
 96  0
             catch (Exception e)
 97  
             {
 98  0
                 throw new JspException("Exception creating converter using binding", e);
 99  0
             }
 100  
         }
 101  
 
 102  0
         if ((_converterId != null) || (_converterIdString != null))
 103  
         {
 104  
             try
 105  
             {
 106  0
                 if (null != _converterIdString)
 107  
                 {
 108  0
                     converter = facesContext.getApplication().createConverter(_converterIdString);
 109  
                 } else 
 110  
                 {
 111  0
                     String converterId = (String) _converterId.getValue(elContext);
 112  0
                     converter = facesContext.getApplication().createConverter(converterId);
 113  
                 }
 114  
 
 115  
                 // with binding no converter was created, set its value with the converter
 116  
                 // created using the converterId
 117  0
                 if (converter != null && _binding != null)
 118  
                 {
 119  0
                     _binding.setValue(elContext, converter);
 120  
                 }
 121  
             }
 122  0
             catch (Exception e)
 123  
             {
 124  0
                 throw new JspException("Exception creating converter with converterId: " + _converterId, e);
 125  0
             }
 126  
         }
 127  
 
 128  0
         return converter;
 129  
     }
 130  
 
 131  
 }