1 55 package org.jboss.axis.types; 56 57 import org.jboss.axis.utils.Messages; 58 59 import java.text.NumberFormat ; 60 61 67 public class MonthDay 68 { 69 int month; 70 int day; 71 String timezone = null; 72 73 77 public MonthDay(int month, int day) 78 throws NumberFormatException 79 { 80 setValue(month, day); 81 } 82 83 87 public MonthDay(int month, int day, String timezone) 88 throws NumberFormatException 89 { 90 setValue(month, day, timezone); 91 } 92 93 96 public MonthDay(String source) throws NumberFormatException 97 { 98 if (source.length() < 6) 99 { 100 throw new NumberFormatException (Messages.getMessage("badMonthDay00")); 101 } 102 103 if (source.charAt(0) != '-' || 104 source.charAt(1) != '-' || 105 source.charAt(4) != '-') 106 { 107 throw new NumberFormatException (Messages.getMessage("badMonthDay00")); 108 } 109 110 setValue(Integer.parseInt(source.substring(2, 4)), 111 Integer.parseInt(source.substring(5, 7)), 112 source.substring(7)); 113 } 114 115 public int getMonth() 116 { 117 return month; 118 } 119 120 public void setMonth(int month) 121 { 122 if (month < 1 || month > 12) 124 { 125 throw new NumberFormatException (Messages.getMessage("badMonthDay00")); 126 } 127 this.month = month; 128 } 129 130 public int getDay() 131 { 132 return day; 133 } 134 135 139 public void setDay(int day) 140 { 141 if (day < 1 || day > 31) 143 { 144 throw new NumberFormatException (Messages.getMessage("badMonthDay00")); 145 } 146 if ((month == 2 && day > 29) || 149 ((month == 9 || month == 4 || month == 6 || month == 11) && day > 30)) 150 { 151 throw new NumberFormatException (Messages.getMessage("badMonthDay00")); 152 } 153 this.day = day; 154 } 155 156 public String getTimezone() 157 { 158 return timezone; 159 } 160 161 public void setTimezone(String timezone) 162 { 163 if (timezone != null && timezone.length() > 0) 165 { 166 if (timezone.charAt(0) == '+' || (timezone.charAt(0) == '-')) 168 { 169 if (timezone.length() != 6 || 170 !Character.isDigit(timezone.charAt(1)) || 171 !Character.isDigit(timezone.charAt(2)) || 172 timezone.charAt(3) != ':' || 173 !Character.isDigit(timezone.charAt(4)) || 174 !Character.isDigit(timezone.charAt(5))) 175 throw new NumberFormatException (Messages.getMessage("badTimezone00")); 176 177 } 178 else if (!timezone.equals("Z")) 179 { 180 throw new NumberFormatException (Messages.getMessage("badTimezone00")); 181 } 182 this.timezone = timezone; 184 } 185 } 186 187 public void setValue(int month, int day, String timezone) 188 throws NumberFormatException 189 { 190 setMonth(month); 191 setDay(day); 192 setTimezone(timezone); 193 } 194 195 public void setValue(int month, int day) throws NumberFormatException 196 { 197 setMonth(month); 198 setDay(day); 199 } 200 201 public String toString() 202 { 203 NumberFormat nf = NumberFormat.getInstance(); 205 nf.setGroupingUsed(false); 206 207 nf.setMinimumIntegerDigits(2); 209 String s = "--" + nf.format(month) + "-" + nf.format(day); 210 211 if (timezone != null) 213 { 214 s = s + timezone; 215 } 216 return s; 217 } 218 219 public boolean equals(Object obj) 220 { 221 if (!(obj instanceof MonthDay)) return false; 222 MonthDay other = (MonthDay)obj; 223 if (obj == null) return false; 224 if (this == obj) return true; 225 226 boolean equals = (this.month == other.month && this.day == other.day); 227 if (timezone != null) 228 { 229 equals = equals && timezone.equals(other.timezone); 230 } 231 return equals; 232 } 233 } 234 | Popular Tags |