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 Month 68 { 69 int month; 70 String timezone = null; 71 72 76 public Month(int month) throws NumberFormatException 77 { 78 setValue(month); 79 } 80 81 85 public Month(int month, String timezone) 86 throws NumberFormatException 87 { 88 setValue(month, timezone); 89 } 90 91 94 public Month(String source) throws NumberFormatException 95 { 96 if (source.length() < (6)) 97 { 98 throw new NumberFormatException (Messages.getMessage("badMonth00")); 99 } 100 101 if (source.charAt(0) != '-' || 102 source.charAt(1) != '-' || 103 source.charAt(4) != '-' || 104 source.charAt(5) != '-') 105 { 106 throw new NumberFormatException (Messages.getMessage("badMonth00")); 107 } 108 109 setValue(Integer.parseInt(source.substring(2, 4)), 110 source.substring(6)); 111 } 112 113 public int getMonth() 114 { 115 return month; 116 } 117 118 public void setMonth(int month) 119 { 120 if (month < 1 || month > 12) 122 { 123 throw new NumberFormatException (Messages.getMessage("badMonth00")); 124 } 125 this.month = month; 126 } 127 128 public String getTimezone() 129 { 130 return timezone; 131 } 132 133 public void setTimezone(String timezone) 134 { 135 if (timezone != null && timezone.length() > 0) 137 { 138 if (timezone.charAt(0) == '+' || (timezone.charAt(0) == '-')) 140 { 141 if (timezone.length() != 6 || 142 !Character.isDigit(timezone.charAt(1)) || 143 !Character.isDigit(timezone.charAt(2)) || 144 timezone.charAt(3) != ':' || 145 !Character.isDigit(timezone.charAt(4)) || 146 !Character.isDigit(timezone.charAt(5))) 147 throw new NumberFormatException (Messages.getMessage("badTimezone00")); 148 149 } 150 else if (!timezone.equals("Z")) 151 { 152 throw new NumberFormatException (Messages.getMessage("badTimezone00")); 153 } 154 this.timezone = timezone; 156 } 157 } 158 159 public void setValue(int month, String timezone) throws NumberFormatException 160 { 161 setMonth(month); 162 setTimezone(timezone); 163 } 164 165 public void setValue(int month) throws NumberFormatException 166 { 167 setMonth(month); 168 } 169 170 public String toString() 171 { 172 NumberFormat nf = NumberFormat.getInstance(); 174 nf.setGroupingUsed(false); 175 176 nf.setMinimumIntegerDigits(2); 178 String s = "--" + nf.format(month) + "--"; 179 180 if (timezone != null) 182 { 183 s = s + timezone; 184 } 185 return s; 186 } 187 188 public boolean equals(Object obj) 189 { 190 if (!(obj instanceof Month)) return false; 191 Month other = (Month)obj; 192 if (obj == null) return false; 193 if (this == obj) return true; 194 195 boolean equals = (this.month == other.month); 196 if (timezone != null) 197 { 198 equals = equals && timezone.equals(other.timezone); 199 } 200 return equals; 201 } 202 } 203 | Popular Tags |