1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
47
48 private int endYear;
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
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 }