View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  /*
17   * Created on 2005/08/15
18   *
19   * TODO To change the template for this generated file go to
20   * Window - Preferences - Java - Code Style - Code Templates
21   */
22  package org.seasar.tuigwaa.model.core.impl;
23  
24  import java.util.Calendar;
25  
26  import org.seasar.tuigwaa.model.common.TgwAttributeVisitor;
27  import org.seasar.tuigwaa.model.common.TgwElementVisitor;
28  
29  
30  /***
31   * タイプが日付に対応
32   * 
33   * @author nishioka
34   */
35  public class DateAttribute extends AbstractAttribute {
36  
37  	public static final String SUFFIX_BEFORE = "before";
38  
39  	public static final String SUFFIX_AFTER = "after";
40  
41  	public static final String SUFFIX_FIX = "fix";
42  
43  	public static final String[] SUFFIXES = { SUFFIX_FIX, SUFFIX_BEFORE,
44  			SUFFIX_AFTER };
45  
46  	private int startYear; // = Calendar.getInstance().get(Calendar.YEAR);
47  
48  	private int endYear; // = Calendar.getInstance().get(Calendar.YEAR);
49  
50  	private String startSuffix = SUFFIX_FIX;
51  
52  	private String endSuffix = SUFFIX_FIX;
53  
54  	public String getType() {
55  		return TYPE_DATE;
56  	}
57  	
58  	public String getEndSuffix() {
59  		return endSuffix;
60  	}
61  
62  	public void setEndSuffix(String endSuffix) {
63  		this.endSuffix = endSuffix;
64  	}
65  
66  	public int getEndYear() {
67  		return endYear;
68  	}
69  
70  	public void setEndYear(int endYear) {
71  		this.endYear = endYear;
72  	}
73  
74  	public String getStartSuffix() {
75  		return startSuffix;
76  	}
77  
78  	public void setStartSuffix(String startSuffix) {
79  		this.startSuffix = startSuffix;
80  	}
81  
82  	public int getStartYear() {
83  		return startYear;
84  	}
85  
86  	public void setStartYear(int startYear) {
87  		this.startYear = startYear;
88  	}
89  		
90  	private int getCurYear(){
91  		return Calendar.getInstance().get(Calendar.YEAR);
92  	}
93  	
94  	public int getStartValue(){
95  		if(SUFFIX_AFTER.equals(getStartSuffix())){
96  			return getStartYear() + getCurYear();
97  		}else if(SUFFIX_BEFORE.equals(getStartSuffix())){
98  			return getCurYear() - getStartYear();
99  		}else if(SUFFIX_FIX.equals(getStartSuffix())){
100 			if(startYear <= 0 ){
101 				return getCurYear() - 10;
102 			}
103 			return startYear;
104 		}
105 		return getCurYear() - 10;
106 	}
107 	
108 	public int getEndValue(){
109 		if(SUFFIX_AFTER.equals(getEndSuffix())){
110 			return getEndYear() + getCurYear();
111 		}else if(SUFFIX_BEFORE.equals(getEndSuffix())){
112 			return getCurYear() - getEndYear();
113 		}else if(SUFFIX_FIX.equals(getEndSuffix())){
114 			if(endYear <= 0){
115 				return getCurYear() + 10;
116 			}
117 			return endYear;
118 		}
119 		return getCurYear() + 10;
120 	}	
121 		
122 	/* for visitor pattern */
123 	public Object accept(TgwElementVisitor visitor, Object data) {
124 		return visitor.visit(this, data);
125 	}
126 	
127 	public Object accept(TgwAttributeVisitor visitor, Object data) {
128 		return visitor.visit(this, data);
129 	}
130 }