/** * Creates a new instance of the object described by this field. * * @param parent The object for which the field is created * @return A new instance of the field's value * @throws IllegalStateException This field is a simple type and cannot be instantiated */ public Object newInstance(Object parent) throws IllegalStateException { return new Century(); } // -- newInstance
/** * parse a String and convert it into a java.lang.Object * @param str the string to parse * @return the java.lang.Object represented by the string * @throws ParseException a parse exception is thrown if the string to parse * does not follow the rigth format (see the description * of this class) */ public static Object parse(String str) throws ParseException { return parseCentury(str); }
public java.util.Date toDate() throws ParseException { java.util.Date date = null; SimpleDateFormat df = new SimpleDateFormat(YEAR_FORMAT); SimpleTimeZone timeZone = new SimpleTimeZone(0, "UTC"); // Set the time zone if (!isUTC()) { int offset = 0; offset = ((this.getZoneMinute() + this.getZoneHour() * 60) * 60 * 1000); offset = isZoneNegative() ? -offset : offset; timeZone.setRawOffset(offset); timeZone.setID(TimeZone.getAvailableIDs(offset)[0]); } df.setTimeZone(timeZone); date = df.parse(this.toString()); return date; } // toDate()
/** * parse a String and convert it into a Century * @param str the string to parse * @return the Century represented by the string * @throws ParseException a parse exception is thrown if the string to parse * does not follow the rigth format (see the description * of this class) */ public static Century parseCentury(String str) throws ParseException { Century result = new Century(); if (str.startsWith("-")) { result.setNegative(); str =str.substring(1); } if (DEBUG) { System.out.println("In parsing method of Century"); System.out.println("String to parse : "+str); System.out.println("Negative ? "+result.isNegative()); } if (str.length() != 2) { throw new ParseException(str+": Bad XML Schema Century type format (CC)",0); } if (DEBUG) { System.out.println("Processing century: "+str.substring(0,2)); } result.setCentury(Short.parseShort(str)); return result; } //parse
/** * Sets the value of the field associated with this descriptor. * @param target the object in which to set the value * @param value the value of the field */ public void setValue(Object target, Object value) throws java.lang.IllegalStateException { if (! (target instanceof Century) ) { //-- throw exception } Century centuryTarget = (Century) target; if (value == null) { /// do something } //-- update current instance of century with new century try { Century temp = Century.parseCentury(value.toString()) ; centuryTarget.setCentury(temp.getCentury()); } catch (java.text.ParseException ex) { //ignore for now } } //-- setValue
/** * convert this Year to a string The format is defined by W3C XML Schema draft and ISO8601 i.e * (+|-)CC * * @return a string representing this Century */ public String toString() { StringBuilder result = new StringBuilder(String.valueOf(this.getCentury())); if (result.length() == 1) { result.insert(0, 0); } if (isNegative()) { result.insert(0, '-'); } return result.toString(); }// toString
public java.util.Date toDate() throws ParseException { java.util.Date date = null; SimpleDateFormat df = new SimpleDateFormat(YEAR_FORMAT); SimpleTimeZone timeZone = new SimpleTimeZone(0,"UTC"); // Set the time zone if ( !isUTC() ) { int offset = 0; offset = ( (this.getZoneMinute() + this.getZoneHour()*60)*60*1000); offset = isZoneNegative() ? -offset : offset; timeZone.setRawOffset(offset); timeZone.setID(TimeZone.getAvailableIDs(offset)[0]); } df.setTimeZone(timeZone); date = df.parse(this.toString()); return date; } //toDate()
/** * parse a String and convert it into a Century * * @param str the string to parse * @return the Century represented by the string * @throws ParseException a parse exception is thrown if the string to parse does not follow the * rigth format (see the description of this class) */ public static Century parseCentury(String str) throws ParseException { Century result = new Century(); if (str.startsWith("-")) { result.setNegative(); str = str.substring(1); } if (DEBUG) { System.out.println("In parsing method of Century"); System.out.println("String to parse : " + str); System.out.println("Negative ? " + result.isNegative()); } if (str.length() != 2) { throw new ParseException(str + ": Bad XML Schema Century type format (CC)", 0); } if (DEBUG) { System.out.println("Processing century: " + str.substring(0, 2)); } result.setCentury(Short.parseShort(str)); return result; } // parse
/** * Sets the value of the field associated with this descriptor. * * @param target the object in which to set the value * @param value the value of the field */ public void setValue(Object target, Object value) throws java.lang.IllegalStateException { if (!(target instanceof Century)) { // -- throw exception } Century centuryTarget = (Century) target; if (value == null) { /// do something } // -- update current instance of century with new century try { Century temp = Century.parseCentury(value.toString()); centuryTarget.setCentury(temp.getCentury()); } catch (java.text.ParseException ex) { // ignore for now } } // -- setValue
/** * convert this Year to a string * The format is defined by W3C XML Schema draft and ISO8601 * i.e (+|-)CC * @return a string representing this Century */ public String toString() { StringBuffer result = new StringBuffer(); result.append(String.valueOf(this.getCentury())); if (result.length() == 1) { result.insert(0,0); } if (isNegative()) { result.insert(0,"-"); } return result.toString(); }//toString
/** * Creates a new instance of the object described by this field. * * @param parent * The object for which the field is created * @return A new instance of the field's value * @throws IllegalStateException * This field is a simple type and cannot be instantiated */ public Object newInstance(Object parent) throws IllegalStateException { return new Century(); } //-- newInstance
/** * parse a String and convert it into a java.lang.Object * * @param str the string to parse * @return the java.lang.Object represented by the string * @throws ParseException a parse exception is thrown if the string to parse does not follow the * rigth format (see the description of this class) */ public static Object parse(String str) throws ParseException { return parseCentury(str); }