KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > samples > bindings > DateWrapper


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.forms.samples.bindings;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.StringTokenizer JavaDoc;
21
22 /**
23  * DateWrapper is a specific sample test-class to demo the aggregate-binding.
24  * This class must loook quite awkward, but is specially designed to look
25  * similar to the XML structure used in the same sample.
26  *
27  * That is also why all field types here are simply kept to String
28  * This will cause the binding-conversion to be applied.
29  */

30 public class DateWrapper {
31
32     private Map JavaDoc split = new HashMap JavaDoc();
33     
34     public DateWrapper(String JavaDoc day, String JavaDoc month, String JavaDoc year) {
35         setDay(day);
36         setMonth(month);
37         setYear(year);
38     }
39     
40     public String JavaDoc getCombined() {
41         return "" + getDay() +"/" + getMonth() + "/" + getYear();
42     }
43
44
45     public void setCombined(String JavaDoc fullDate) {
46         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(fullDate, "/");
47         setDay(st.nextToken());
48         setMonth(st.nextToken());
49         setYear(st.nextToken());
50     }
51
52     public Map JavaDoc getSplit() {
53         return this.split;
54     }
55
56     /**
57      * @return Returns the day.
58      */

59     public String JavaDoc getDay() {
60         return split.get("day").toString();
61     }
62     /**
63      * @param day The day to set.
64      */

65     public void setDay(String JavaDoc day) {
66         split.put("day", day);
67     }
68     /**
69      * @return Returns the month.
70      */

71     public String JavaDoc getMonth() {
72         return split.get("month").toString();
73     }
74     /**
75      * @param month The month to set.
76      */

77     public void setMonth(String JavaDoc month) {
78         split.put("month", month);
79     }
80     /**
81      * @return Returns the year.
82      */

83     public String JavaDoc getYear() {
84         return split.get("year").toString();
85     }
86     /**
87      * @param year The year to set.
88      */

89     public void setYear(String JavaDoc year) {
90         split.put("year", year);
91     }
92
93     public String JavaDoc toString() {
94         return "Wrapped Date as combined='" + getCombined() + "' as split=["
95                 + getDay() + ", " + getMonth() + ", " + getYear() + "]";
96     }
97 }
98
Popular Tags