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

For more information, please explore the Attic.

View Javadoc

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  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      private static final ConverterHelper HELPER =
48              new ConverterHelper();
49  
50  
51      // -------------------------------------------------------------- Properties
52  
53  
54      private String locale = null;
55      public void setLocale(String locale) {
56          this.locale = locale;
57      }
58  
59  
60      private String message = null;
61      public void setMessage(String message) {
62          this.message = message;
63      }
64  
65  
66      private String pattern = null;
67      public void setPattern(String pattern) {
68          this.pattern = pattern;
69      }
70  
71  
72      // ------------------------------------------------------------- Tag Methods
73  
74  
75      /***
76       * <p>Release resources allocated for this instance.</p>
77       */
78      public void release() {
79  
80          locale = null;
81          message = null;
82          pattern = null;
83  
84          super.release();
85  
86      }
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          FacesContext context = FacesContext.getCurrentInstance();
99          IntegerConverter converter = new IntegerConverter();
100 
101         if (locale != null) {
102             Locale value = null;
103             if (UIComponentTag.isValueReference(locale)) {
104                 ValueBinding vb = context.getApplication().createValueBinding(locale);
105                 value = (Locale) vb.getValue(context);
106             } else {
107                 value = (Locale) HELPER.asObject(context, Locale.class, locale);
108             }
109             converter.setLocale(value);
110         }
111 
112         if (pattern != null) {
113             String value = null;
114             if (UIComponentTag.isValueReference(message)) {
115                 ValueBinding vb = context.getApplication().createValueBinding(pattern);
116                 value = (String) vb.getValue(context);
117             } else {
118                 value = pattern;
119             }
120             converter.setPattern(value);
121         }
122 
123         return converter;
124 
125     }
126 
127 
128 }