public DayTimeDurationValue(String str) throws XPathException {  if(str.length() < 3) throw new XPathException("Type error: xs:duration should start with [+|-]P"); char ch; StringBuffer buf = new StringBuffer(); int p = 0; int state = 0; String value = null; while(p < str.length()) { ch = str.charAt(p); switch(ch) { case '-': if(state > 0) throw new XPathException("Type error in xs:duration: " + str + ": - is not allowed here"); negative = true; break; case 'P': if(state > 0) throw new XPathException("Type error in xs:duration: " + str + ": P is not allowed here"); state++; break; case 'D': if(state != 1 || value == null) throw new XPathException("Type error in xs:duration: " + str +  ": D is not allowed to occur here"); day = Integer.parseInt(value); value = null; state++; break; case 'T': state = 2; break; case 'H': if(state != 2 || value == null) throw new XPathException("Type error in xs:duration: " + str +  ": H is not allowed to occur here"); hour = Integer.parseInt(value); value = null; state++; break; case 'M': if(state > 3 || value == null) throw new XPathException("Type error in xs:duration: " + str +  ": M is not allowed to occur here"); minute = Integer.parseInt(value); state++; value = null; break; case 'S': if(value == null || state > 5) throw new XPathException("Type error in xs:duration: " + str +  ": S is not allowed to occur here"); if(state == 5) { while (value.length() < 3) value += "0"; if (value.length() > 3) value = value.substring(0, 3); millisecond = Integer.parseInt(value); } else second = Integer.parseInt(value); value = null; state++; break; case '.': if(state > 4) throw new XPathException("Type error in xs:duration: " + str +  ": . is not allowed to occur here"); second = Integer.parseInt(value); value = null; state = 5; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': if(state < 1) throw new XPathException("Type error in xs:duration: " + str + ": numeric value not allowed at this position"); buf.append(ch); p++; while(p < str.length()) { ch = str.charAt(p); if(ch == '1' || ch == '2' || ch == '3' || ch == '4' || ch == '5' || ch == '6' || ch == '7' || ch == '8' || ch == '9' || ch == '0') buf.append(ch); else { value = buf.toString(); buf.setLength(0); p--; break; } p++; } break; default: throw new XPathException("Type error in xs:duration: " + str + ": invalid character: " + ch); } p++; }
public DayTimeDurationValue(DurationValue other) throws XPathException { this.day = other.day; this.hour = other.hour; this.minute = other.minute; this.second = other.second; this.millisecond = other.millisecond;
	public DayTimeDurationValue(String str) throws XPathException {		// format is: [+|-]PnDTnHnMnS		if(str.length() < 3)			throw new XPathException("Type error: xs:duration should start with [+|-]P");		char ch;		StringBuffer buf = new StringBuffer();		int p = 0;		int state = 0;		String value = null;		while(p < str.length()) {			ch = str.charAt(p);			switch(ch) {				case '-':					if(state > 0)						throw new XPathException("Type error in xs:duration: " + str + ": - is not allowed here");					negative = true;					break;				case 'P':					if(state > 0)						throw new XPathException("Type error in xs:duration: " + str + ": P is not allowed here");					state++;					break;				case 'D':					if(state != 1 || value == null)						throw new XPathException("Type error in xs:duration: " + str +  ": D is not allowed to occur here");					day = Integer.parseInt(value);					value = null;					state++;					break;				case 'T':					state = 2;					break;				case 'H':					if(state != 2 || value == null)						throw new XPathException("Type error in xs:duration: " + str +  ": H is not allowed to occur here");					hour = Integer.parseInt(value);					value = null;					state++;					break;				case 'M':					if(state > 3 || value == null)						throw new XPathException("Type error in xs:duration: " + str +  ": M is not allowed to occur here");					minute = Integer.parseInt(value);					state++;					value = null;					break;				case 'S':					if(value == null || state > 5)						throw new XPathException("Type error in xs:duration: " + str +  ": S is not allowed to occur here");					if(state == 5) {						while (value.length() < 3) value += "0";						if (value.length() > 3) value = value.substring(0, 3);						millisecond = Integer.parseInt(value);					} else						second = Integer.parseInt(value);					value = null;					state++;					break;				case '.':					if(state > 4)						throw new XPathException("Type error in xs:duration: " + str +  ": . is not allowed to occur here");					second = Integer.parseInt(value);					value = null;					state = 5;					break;				case '1': case '2': case '3': case '4': case '5': case '6': case '7':				case '8': case '9': case '0':					if(state < 1)						throw new XPathException("Type error in xs:duration: " + str + ": numeric value not allowed at this position");					buf.append(ch);					p++;					while(p < str.length()) {						ch = str.charAt(p);						if(ch == '1' || ch == '2' || ch == '3' || ch == '4' || ch == '5' || ch == '6' || ch == '7' ||								ch == '8' || ch == '9' || ch == '0')							buf.append(ch);						else {							value = buf.toString();							buf.setLength(0);							p--;							break;						}						p++;					}					break;				default:					throw new XPathException("Type error in xs:duration: " + str + ": invalid character: " + ch);			}			p++;		}	}