2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.validator.tag.IntegerConverterTag
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegerConverterTag
0% 
0% 
1.8
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.validator.tag;
 19  
 
 20  
 import java.util.Locale;
 21  
 import javax.faces.context.FacesContext;
 22  
 import javax.faces.convert.Converter;
 23  
 import javax.faces.el.ValueBinding;
 24  
 import javax.faces.webapp.ConverterTag;
 25  
 import javax.faces.webapp.UIComponentTag;
 26  
 import org.apache.shale.util.ConverterHelper;
 27  
 import org.apache.shale.validator.converter.IntegerConverter;
 28  
 
 29  
 /**
 30  
  * <p>JSP custom action for <code>IntegerConverter</code>.</p>
 31  
  */
 32  0
 public final class IntegerConverterTag extends ConverterTag {
 33  
     
 34  
     
 35  
     // -------------------------------------------------------- Static Variables
 36  
 
 37  
 
 38  
     /**
 39  
      * Serial version UID.
 40  
      */
 41  
     private static final long serialVersionUID = 1L;
 42  
 
 43  
 
 44  
     /**
 45  
      * <p>Helper object for performing conversions.</p>
 46  
      */
 47  0
     private static final ConverterHelper HELPER =
 48  
             new ConverterHelper();
 49  
 
 50  
 
 51  
     // -------------------------------------------------------------- Properties
 52  
 
 53  
 
 54  0
     private String locale = null;
 55  
     public void setLocale(String locale) {
 56  0
         this.locale = locale;
 57  0
     }
 58  
 
 59  
 
 60  0
     private String message = null;
 61  
     public void setMessage(String message) {
 62  0
         this.message = message;
 63  0
     }
 64  
 
 65  
 
 66  0
     private String pattern = null;
 67  
     public void setPattern(String pattern) {
 68  0
         this.pattern = pattern;
 69  0
     }
 70  
 
 71  
 
 72  
     // ------------------------------------------------------------- Tag Methods
 73  
 
 74  
 
 75  
     /**
 76  
      * <p>Release resources allocated for this instance.</p>
 77  
      */
 78  
     public void release() {
 79  
 
 80  0
         locale = null;
 81  0
         message = null;
 82  0
         pattern = null;
 83  
 
 84  0
         super.release();
 85  
 
 86  0
     }
 87  
 
 88  
 
 89  
     // ---------------------------------------------------- ConverterTag Methods
 90  
 
 91  
 
 92  
     /**
 93  
      * <p>Create and return a new <code>Converter</code> instance to be
 94  
      * registered on our corresponding <code>UIComponent</code>.</p>
 95  
      */
 96  
     protected Converter createConverter() {
 97  
 
 98  0
         FacesContext context = FacesContext.getCurrentInstance();
 99  0
         IntegerConverter converter = new IntegerConverter();
 100  
 
 101  0
         if (locale != null) {
 102  0
             Locale value = null;
 103  0
             if (UIComponentTag.isValueReference(locale)) {
 104  0
                 ValueBinding vb = context.getApplication().createValueBinding(locale);
 105  0
                 value = (Locale) vb.getValue(context);
 106  0
             } else {
 107  0
                 value = (Locale) HELPER.asObject(context, Locale.class, locale);
 108  
             }
 109  0
             converter.setLocale(value);
 110  
         }
 111  
 
 112  0
         if (pattern != null) {
 113  0
             String value = null;
 114  0
             if (UIComponentTag.isValueReference(message)) {
 115  0
                 ValueBinding vb = context.getApplication().createValueBinding(pattern);
 116  0
                 value = (String) vb.getValue(context);
 117  0
             } else {
 118  0
                 value = pattern;
 119  
             }
 120  0
             converter.setPattern(value);
 121  
         }
 122  
 
 123  0
         return converter;
 124  
 
 125  
     }
 126  
 
 127  
 
 128  
 }