Coverage Report - org.apache.myfaces.taglib.core.ConverterImplTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ConverterImplTag
0%
0/40
0%
0/20
0
 
 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
 33  
  * associates it with the nearest parent UIComponent.
 34  
  * 
 35  
  * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
 36  
  * @version $Revision: 810211 $ $Date: 2009-09-01 15:16:03 -0500 (Tue, 01 Sep 2009) $
 37  
  *
 38  
  */
 39  
 @JSFJspTag(
 40  
         name="f:converter",
 41  
         bodyContent="empty")
 42  
 public class ConverterImplTag extends ConverterELTag
 43  
 {
 44  
 
 45  
     private static final long serialVersionUID = -4506829108081L;
 46  
     private ValueExpression _converterId;
 47  
     private ValueExpression _binding;
 48  0
     private String _converterIdString = null;
 49  
 
 50  
     public ConverterImplTag()
 51  
     {
 52  0
         super();
 53  0
     }
 54  
 
 55  
     /**
 56  
      * The converter's registered ID.
 57  
      */
 58  
     @JSFJspAttribute(
 59  
             rtexprvalue=true,
 60  
             className="java.lang.String")
 61  
     public void setConverterId(ValueExpression converterId)
 62  
     {
 63  0
         _converterId = converterId;
 64  0
     }
 65  
 
 66  
     /**
 67  
      * A ValueExpression that evaluates to a Converter.
 68  
      */
 69  
     @JSFJspAttribute(
 70  
             rtexprvalue=true,
 71  
             className="javax.faces.convert.Converter")
 72  
     public void setBinding(ValueExpression binding)
 73  
     {
 74  0
         _binding = binding;
 75  0
     }
 76  
 
 77  
     /**
 78  
      * Use this method to specify the converterId programmatically.
 79  
      *
 80  
      * @param converterIdString
 81  
      */
 82  
     public void setConverterIdString(String converterIdString)
 83  
     {
 84  0
         _converterIdString = converterIdString;
 85  0
     }
 86  
 
 87  
     public void release()
 88  
     {
 89  0
         super.release();
 90  0
         _converterId = null;
 91  0
         _binding = null;
 92  0
         _converterIdString = null;
 93  0
     }
 94  
 
 95  
     protected Converter createConverter() throws JspException
 96  
     {
 97  0
         if (_converterId != null && _converterId.isLiteralText())
 98  
         {
 99  0
             return this.createClassicConverter();
 100  
         }
 101  0
         if (_converterIdString != null){
 102  0
             return this.createClassicConverter();
 103  
         }
 104  
         
 105  0
         return new DelegateConverter(_converterId, _binding,
 106  
                 _converterIdString);
 107  
     }
 108  
 
 109  
     protected Converter createClassicConverter() throws JspException
 110  
     {
 111  0
         Converter converter = null;
 112  
 
 113  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 114  0
         ELContext elContext = facesContext.getELContext();
 115  
 
 116  
         // try to create the converter from the binding expression first, and then from
 117  
         // the converterId
 118  0
         if (_binding != null)
 119  
         {
 120  
             try
 121  
             {
 122  0
                 converter = (Converter) _binding.getValue(elContext);
 123  
 
 124  0
                 if (converter != null)
 125  
                 {
 126  0
                     return converter;
 127  
                 }
 128  
             }
 129  0
             catch (Exception e)
 130  
             {
 131  0
                 throw new JspException(
 132  
                         "Exception creating converter using binding", e);
 133  0
             }
 134  
         }
 135  
 
 136  0
         if ((_converterId != null) || (_converterIdString != null))
 137  
         {
 138  
             try
 139  
             {
 140  0
                 if (null != _converterIdString)
 141  
                 {
 142  0
                     converter = facesContext.getApplication().createConverter(
 143  
                             _converterIdString);
 144  
                 }
 145  
                 else
 146  
                 {
 147  0
                     String converterId = (String) _converterId
 148  
                             .getValue(elContext);
 149  0
                     converter = facesContext.getApplication().createConverter(
 150  
                             converterId);
 151  
                 }
 152  
 
 153  
                 // with binding no converter was created, set its value with the converter
 154  
                 // created using the converterId
 155  0
                 if (converter != null && _binding != null)
 156  
                 {
 157  0
                     _binding.setValue(elContext, converter);
 158  
                 }
 159  
             }
 160  0
             catch (Exception e)
 161  
             {
 162  0
                 throw new JspException(
 163  
                         "Exception creating converter with converterId: "
 164  
                                 + _converterId, e);
 165  0
             }
 166  
         }
 167  
 
 168  0
         return converter;
 169  
     }
 170  
 }