001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.samples.bindings;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021: import java.util.StringTokenizer;
022:
023: /**
024: * DateWrapper is a specific sample test-class to demo the aggregate-binding.
025: * This class must loook quite awkward, but is specially designed to look
026: * similar to the XML structure used in the same sample.
027: *
028: * That is also why all field types here are simply kept to String
029: * This will cause the binding-conversion to be applied.
030: */
031: public class DateWrapper {
032:
033: private Map split = new HashMap();
034:
035: public DateWrapper(String day, String month, String year) {
036: setDay(day);
037: setMonth(month);
038: setYear(year);
039: }
040:
041: public String getCombined() {
042: return "" + getDay() + "/" + getMonth() + "/" + getYear();
043: }
044:
045: public void setCombined(String fullDate) {
046: StringTokenizer st = new StringTokenizer(fullDate, "/");
047: setDay(st.nextToken());
048: setMonth(st.nextToken());
049: setYear(st.nextToken());
050: }
051:
052: public Map getSplit() {
053: return this .split;
054: }
055:
056: /**
057: * @return Returns the day.
058: */
059: public String getDay() {
060: return split.get("day").toString();
061: }
062:
063: /**
064: * @param day The day to set.
065: */
066: public void setDay(String day) {
067: split.put("day", day);
068: }
069:
070: /**
071: * @return Returns the month.
072: */
073: public String getMonth() {
074: return split.get("month").toString();
075: }
076:
077: /**
078: * @param month The month to set.
079: */
080: public void setMonth(String month) {
081: split.put("month", month);
082: }
083:
084: /**
085: * @return Returns the year.
086: */
087: public String getYear() {
088: return split.get("year").toString();
089: }
090:
091: /**
092: * @param year The year to set.
093: */
094: public void setYear(String year) {
095: split.put("year", year);
096: }
097:
098: public String toString() {
099: return "Wrapped Date as combined='" + getCombined()
100: + "' as split=[" + getDay() + ", " + getMonth() + ", "
101: + getYear() + "]";
102: }
103: }
|