GNU Classpath (0.17) | ||
Frames | No Frames |
1: /* DatatypeFactory.java -- 2: Copyright (C) 2004, 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package javax.xml.datatype; 39: 40: import java.math.BigDecimal; 41: import java.math.BigInteger; 42: import java.util.GregorianCalendar; 43: 44: /** 45: * Factory class to create new datatype objects mapping XML to and from Java 46: * objects. 47: * 48: * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a) 49: * @since 1.3 50: */ 51: public abstract class DatatypeFactory 52: { 53: 54: /** 55: * JAXP 1.3 default property name. 56: */ 57: public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory"; 58: 59: /** 60: * JAXP 1.3 default implementation class name. 61: */ 62: public static final java.lang.String DATATYPEFACTORY_IMPLEMENTATION_CLASS = "gnu.xml.datatype.JAXPDatatypeFactory"; 63: 64: protected DatatypeFactory() 65: { 66: } 67: 68: /** 69: * Returns a new factory instance. 70: */ 71: public static DatatypeFactory newInstance() 72: throws DatatypeConfigurationException 73: { 74: try 75: { 76: Class t = Class.forName(DATATYPEFACTORY_IMPLEMENTATION_CLASS); 77: return (DatatypeFactory) t.newInstance(); 78: } 79: catch (Exception e) 80: { 81: throw new DatatypeConfigurationException (e); 82: } 83: } 84: 85: /** 86: * Returns a new duration from its string representation. 87: * @param lexicalRepresentation the lexical representation of the 88: * duration, as specified in XML Schema 1.0 section 3.2.6.1. 89: */ 90: public abstract Duration newDuration(String lexicalRepresentation); 91: 92: /** 93: * Returns a new duration. 94: * @param durationInMilliseconds the duration in milliseconds 95: */ 96: public abstract Duration newDuration(long durationInMilliSeconds); 97: 98: /** 99: * Returns a new duration by specifying the individual components. 100: * @param isPositive whether the duration is positive 101: * @param years the number of years 102: * @param months the number of months 103: * @param days the number of days 104: * @param hours the number of hours 105: * @param minutes th number of minutes 106: * @param seconds the number of seconds 107: */ 108: public abstract Duration newDuration(boolean isPositive, 109: BigInteger years, 110: BigInteger months, 111: BigInteger days, 112: BigInteger hours, 113: BigInteger minutes, 114: BigDecimal seconds); 115: 116: /** 117: * Returns a new duration by specifying the individual components. 118: * @param isPositive whether the duration is positive 119: * @param years the number of years 120: * @param months the number of months 121: * @param days the number of days 122: * @param hours the number of hours 123: * @param minutes th number of minutes 124: * @param seconds the number of seconds 125: */ 126: public Duration newDuration(boolean isPositive, 127: int years, 128: int months, 129: int days, 130: int hours, 131: int minutes, 132: int seconds) 133: { 134: return newDuration(isPositive, 135: BigInteger.valueOf((long) years), 136: BigInteger.valueOf((long) months), 137: BigInteger.valueOf((long) days), 138: BigInteger.valueOf((long) hours), 139: BigInteger.valueOf((long) minutes), 140: BigDecimal.valueOf((long) seconds)); 141: } 142: 143: /** 144: * Returns a new dayTimeDuration from its string representation. 145: * @param lexicalRepresentation the lexical representation of the 146: * duration, as specified in XML Schema 1.0 section 3.2.6.1. 147: */ 148: public Duration newDurationDayTime(String lexicalRepresentation) 149: { 150: return newDuration(lexicalRepresentation); 151: } 152: 153: /** 154: * Returns a new dayTimeDuration. 155: * @param durationInMilliseconds the duration in milliseconds 156: */ 157: public Duration newDurationDayTime(long durationInMilliseconds) 158: { 159: // TODO xmlSchemaType 160: return newDuration(durationInMilliseconds); 161: } 162: 163: /** 164: * Returns a new dayTimeDuration by specifying the individual components. 165: * @param isPositive whether the duration is positive 166: * @param days the number of days 167: * @param hours the number of hours 168: * @param minutes th number of minutes 169: * @param seconds the number of seconds 170: */ 171: public Duration newDurationDayTime(boolean isPositive, 172: BigInteger days, 173: BigInteger hours, 174: BigInteger minutes, 175: BigDecimal seconds) 176: { 177: return newDuration(isPositive, 178: null, 179: null, 180: days, 181: hours, 182: minutes, 183: seconds); 184: } 185: 186: /** 187: * Returns a new dayTimeDuration by specifying the individual components. 188: * @param isPositive whether the duration is positive 189: * @param days the number of days 190: * @param hours the number of hours 191: * @param minutes th number of minutes 192: * @param seconds the number of seconds 193: */ 194: public Duration newDurationDayTime(boolean isPositive, 195: int days, 196: int hours, 197: int minutes, 198: int seconds) 199: { 200: return newDuration(isPositive, 201: null, 202: null, 203: BigInteger.valueOf((long) days), 204: BigInteger.valueOf((long) hours), 205: BigInteger.valueOf((long) minutes), 206: BigDecimal.valueOf((long) seconds)); 207: } 208: 209: /** 210: * Returns a new yearMonthDuration from its string representation. 211: * @param lexicalRepresentation the lexical representation of the 212: * duration, as specified in XML Schema 1.0 section 3.2.6.1. 213: */ 214: public Duration newDurationYearMonth(String lexicalRepresentation) 215: { 216: return newDuration(lexicalRepresentation); 217: } 218: 219: /** 220: * Returns a new yearMonthDuration. 221: * @param durationInMilliseconds the duration in milliseconds 222: */ 223: public Duration newDurationYearMonth(long durationInMilliseconds) 224: { 225: // TODO xmlSchemaType 226: return newDuration(durationInMilliseconds); 227: } 228: 229: /** 230: * Returns a new yearMonthDuration by specifying the individual components. 231: * @param isPositive whether the duration is positive 232: * @param years the number of years 233: * @param months the number of months 234: * @param days the number of days 235: * @param hours the number of hours 236: * @param minutes th number of minutes 237: * @param seconds the number of seconds 238: */ 239: public Duration newDurationYearMonth(boolean isPositive, 240: BigInteger years, 241: BigInteger months) 242: { 243: return newDuration(isPositive, 244: years, 245: months, 246: null, 247: null, 248: null, 249: null); 250: } 251: 252: /** 253: * Returns a new yearMonthDuration by specifying the individual components. 254: * @param isPositive whether the duration is positive 255: * @param years the number of years 256: * @param months the number of months 257: * @param days the number of days 258: * @param hours the number of hours 259: * @param minutes th number of minutes 260: * @param seconds the number of seconds 261: */ 262: public Duration newDurationYearMonth(boolean isPositive, 263: int years, 264: int months) 265: { 266: return newDuration(isPositive, 267: BigInteger.valueOf((long) years), 268: BigInteger.valueOf((long) months), 269: null, 270: null, 271: null, 272: null); 273: } 274: 275: /** 276: * Returns a new XMLGregorianCalendar with no fields initialized. 277: */ 278: public abstract XMLGregorianCalendar newXMLGregorianCalendar(); 279: 280: /** 281: * Returns a new XMLGregorianCalendar from a string representation. 282: * @param lexicalRepresentation the lexical representation as specified in 283: * XML Schema 1.0 Part 2, section 3.2.[7-14].1. 284: */ 285: public abstract XMLGregorianCalendar newXMLGregorianCalendar(String lexicalRepresentation); 286: 287: /** 288: * Returns a new XMLGregorianCalendar based on the specified Gregorian 289: * calendar. 290: */ 291: public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal); 292: 293: /** 294: * Returns a new XMLGregorianCalendar with the specified components. 295: */ 296: public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year, 297: int month, 298: int day, 299: int hour, 300: int minute, 301: int second, 302: BigDecimal fractionalSecond, 303: int timezone); 304: 305: /** 306: * Returns a new XMLGregorianCalendar with the specified components. 307: */ 308: public XMLGregorianCalendar newXMLGregorianCalendar(int year, 309: int month, 310: int day, 311: int hour, 312: int minute, 313: int second, 314: int millisecond, 315: int timezone) 316: { 317: return newXMLGregorianCalendar(BigInteger.valueOf((long) year), 318: month, 319: day, 320: hour, 321: minute, 322: second, 323: new BigDecimal(((double) millisecond) / 1000.0), 324: timezone); 325: } 326: 327: /** 328: * Returns a new XMLGregorianCalendar with the specified components. 329: */ 330: public XMLGregorianCalendar newXMLGregorianCalendarDate(int year, 331: int month, 332: int day, 333: int timezone) 334: { 335: return newXMLGregorianCalendar(BigInteger.valueOf((long) year), 336: month, 337: day, 338: DatatypeConstants.FIELD_UNDEFINED, 339: DatatypeConstants.FIELD_UNDEFINED, 340: DatatypeConstants.FIELD_UNDEFINED, 341: null, 342: timezone); 343: } 344: 345: /** 346: * Returns a new XMLGregorianCalendar with the specified components. 347: */ 348: public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, 349: int minutes, 350: int seconds, 351: int timezone) 352: { 353: return newXMLGregorianCalendar(null, 354: DatatypeConstants.FIELD_UNDEFINED, 355: DatatypeConstants.FIELD_UNDEFINED, 356: hours, 357: minutes, 358: seconds, 359: null, 360: timezone); 361: } 362: 363: /** 364: * Returns a new XMLGregorianCalendar with the specified components. 365: */ 366: public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, 367: int minutes, 368: int seconds, 369: BigDecimal fractionalSecond, 370: int timezone) 371: { 372: return newXMLGregorianCalendar(null, 373: DatatypeConstants.FIELD_UNDEFINED, 374: DatatypeConstants.FIELD_UNDEFINED, 375: hours, 376: minutes, 377: seconds, 378: fractionalSecond, 379: timezone); 380: } 381: 382: /** 383: * Returns a new XMLGregorianCalendar with the specified components. 384: */ 385: public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, 386: int minutes, 387: int seconds, 388: int milliseconds, 389: int timezone) 390: { 391: return newXMLGregorianCalendar(null, 392: DatatypeConstants.FIELD_UNDEFINED, 393: DatatypeConstants.FIELD_UNDEFINED, 394: hours, 395: minutes, 396: seconds, 397: new BigDecimal(((double) milliseconds) / 1000.0), 398: timezone); 399: } 400: 401: }
GNU Classpath (0.17) |