KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > api > filter > FilterTypeHint


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.databinding.datagrid.api.filter;
19
20 import org.apache.beehive.netui.util.Bundle;
21
22 /**
23  * <p>
24  * The FilterTypeHint is used by a {@link Filter} object in order to provide metadata about the type of
25  * the data in a data set represented by a filter expression. When used on a {@link Filter}, infrastructure
26  * used to build or perform querying using {@link Filter} instances can use type hints in order to build
27  * or perform filtering correctly. For example, when using {@link Filter} instances with SQL, a type
28  * hint can be used to know when to quote a value inside of a <i>WHERE</i> clause.
29  * </p>
30  */

31 public class FilterTypeHint
32     implements java.io.Serializable JavaDoc {
33
34     /**
35      * String value for a date type hint.
36      */

37     private static final String JavaDoc STR_DATE = "DATE";
38
39     /**
40      * String value for a string type hint.
41      */

42     private static final String JavaDoc STR_STRING = "STRING";
43
44     /**
45      * String value for a numeric type hint.
46      */

47     private static final String JavaDoc STR_NUMERIC = "NUMERIC";
48
49     /**
50      * Filter type hint representing a date type.
51      */

52     public static final FilterTypeHint DATE = new FilterTypeHint(STR_DATE);
53
54     /**
55      * Filter type hint representing a string type.
56      */

57     public static final FilterTypeHint STRING = new FilterTypeHint(STR_STRING);
58
59     /**
60      * Filter type hint representing a numeric type.
61      */

62     public static final FilterTypeHint NUMERIC = new FilterTypeHint(STR_NUMERIC);
63
64     private String JavaDoc _hint = null;
65
66     /**
67      * Private constructor.
68      *
69      * @param hint
70      */

71     private FilterTypeHint(String JavaDoc hint) {
72         _hint = hint;
73     }
74
75     /**
76      * Get the type hint string.
77      * @return the type hint string
78      */

79     public String JavaDoc getHint() {
80         return _hint;
81     }
82
83     /**
84      * Get the default filter type hint. This is {@link #STRING}.
85      * @return the default type hint
86      */

87     public static FilterTypeHint getDefault() {
88         return STRING;
89     }
90
91     /**
92      * Given a String, lookup a FilterTypeHint for the String. Valid
93      * @param hint the String to use when looking up a filter type hint
94      * @return the type hint
95      * @throws IllegalArgumentException if the given <code>hint</code> doesn't match a know type hint
96      */

97     public static FilterTypeHint getTypeHint(String JavaDoc hint) {
98         /* todo: this is static; consider providing on a concrete / overridable object */
99         if(STRING.getHint().equals(hint))
100             return STRING;
101         else if(NUMERIC.getHint().equals(hint))
102             return NUMERIC;
103         else if(DATE.getHint().equals(hint))
104             return DATE;
105         else throw new IllegalArgumentException JavaDoc(Bundle.getErrorString("FilterTypeHint_UnknownHintString",
106                                                                       new Object JavaDoc[] {hint}));
107     }
108 }
109
Popular Tags