Coverage Report - javax.faces.convert._ParametrizableFacesMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
_ParametrizableFacesMessage
0%
0/37
0%
0/28
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 javax.faces.convert;
 20  
 
 21  
 import java.text.MessageFormat;
 22  
 import java.util.Locale;
 23  
 
 24  
 import javax.el.ValueExpression;
 25  
 import javax.faces.application.FacesMessage;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.el.ValueBinding;
 28  
 
 29  
 /** 
 30  
  * This class encapsulates a FacesMessage to evaluate the label
 31  
  * expression on render response, where f:loadBundle is available
 32  
  * 
 33  
  * @author Leonardo Uribe (latest modification by $Author: skitching $)
 34  
  * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
 35  
  */
 36  
 class _ParametrizableFacesMessage extends FacesMessage
 37  
 {
 38  
     /**
 39  
      * 
 40  
      */
 41  
     private static final long serialVersionUID = 7792947730961657948L;
 42  
 
 43  
     private final Object _args[];
 44  
     private String _evaluatedDetail;
 45  
     private String _evaluatedSummary;
 46  
     private transient Object _evaluatedArgs[];
 47  
     private Locale _locale;
 48  
 
 49  
     public _ParametrizableFacesMessage(
 50  
             String summary, String detail, Object[] args, Locale locale)
 51  
     {
 52  0
         super(summary, detail);
 53  0
         if(locale == null) throw new NullPointerException("locale");
 54  0
         _locale = locale;
 55  0
         _args = args;
 56  0
     }
 57  
 
 58  
     public _ParametrizableFacesMessage(FacesMessage.Severity severity,
 59  
             String summary, String detail, Object[] args, Locale locale)
 60  
     {
 61  0
         super(severity, summary, detail);
 62  0
         if(locale == null) throw new NullPointerException("locale");
 63  0
         _locale = locale;
 64  0
         _args = args;
 65  0
     }
 66  
 
 67  
     @Override
 68  
     public String getDetail()
 69  
     {
 70  0
         if (_evaluatedArgs == null && _args != null)
 71  
         {
 72  0
             evaluateArgs();
 73  
         }
 74  0
         if (_evaluatedDetail == null)
 75  
         {
 76  0
             MessageFormat format = new MessageFormat(super.getDetail(), _locale);
 77  0
             _evaluatedDetail = format.format(_evaluatedArgs);
 78  
         }
 79  0
         return _evaluatedDetail;
 80  
     }
 81  
 
 82  
     @Override
 83  
     public String getSummary()
 84  
     {
 85  0
         if (_evaluatedArgs == null && _args != null)
 86  
         {
 87  0
             evaluateArgs();
 88  
         }
 89  0
         if (_evaluatedSummary == null)
 90  
         {
 91  0
             MessageFormat format = new MessageFormat(super.getSummary(), _locale);
 92  0
             _evaluatedSummary = format.format(_evaluatedArgs);
 93  
         }
 94  0
         return _evaluatedSummary;
 95  
     }
 96  
 
 97  
     private void evaluateArgs()
 98  
     {
 99  0
         _evaluatedArgs = new Object[_args.length];
 100  0
         FacesContext facesContext = null;
 101  0
         for (int i = 0; i < _args.length; i++)
 102  
         {
 103  0
             if (_args[i] == null)
 104  
             {
 105  0
                 continue;
 106  
             }
 107  0
             else if (_args[i] instanceof ValueBinding)
 108  
             {
 109  0
                 if (facesContext == null)
 110  
                 {
 111  0
                     facesContext = FacesContext.getCurrentInstance();
 112  
                 }
 113  0
                 _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
 114  
             }
 115  0
             else if (_args[i] instanceof ValueExpression)
 116  
             {
 117  0
                 if (facesContext == null)
 118  
                 {
 119  0
                     facesContext = FacesContext.getCurrentInstance();
 120  
                 }
 121  0
                 _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
 122  
             }
 123  
             else 
 124  
             {
 125  0
                 _evaluatedArgs[i] = _args[i];
 126  
             }
 127  
         }
 128  0
     }
 129  
 }