Source for javax.xml.datatype.DatatypeFactory

   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:    */
 235:   public Duration newDurationYearMonth(boolean isPositive,
 236:                                        BigInteger years,
 237:                                        BigInteger months)
 238:   {
 239:     return newDuration(isPositive,
 240:                        years,
 241:                        months,
 242:                        null,
 243:                        null,
 244:                        null,
 245:                        null);
 246:   }
 247: 
 248:   /**
 249:    * Returns a new yearMonthDuration by specifying the individual components.
 250:    * @param isPositive whether the duration is positive
 251:    * @param years the number of years
 252:    * @param months the number of months
 253:    */
 254:   public Duration newDurationYearMonth(boolean isPositive,
 255:                                        int years,
 256:                                        int months)
 257:   {
 258:     return newDuration(isPositive,
 259:                        BigInteger.valueOf((long) years),
 260:                        BigInteger.valueOf((long) months),
 261:                        null,
 262:                        null,
 263:                        null,
 264:                        null);
 265:   }
 266: 
 267:   /**
 268:    * Returns a new XMLGregorianCalendar with no fields initialized.
 269:    */
 270:   public abstract XMLGregorianCalendar newXMLGregorianCalendar();
 271: 
 272:   /**
 273:    * Returns a new XMLGregorianCalendar from a string representation.
 274:    * @param lexicalRepresentation the lexical representation as specified in
 275:    * XML Schema 1.0 Part 2, section 3.2.[7-14].1.
 276:    */
 277:   public abstract XMLGregorianCalendar newXMLGregorianCalendar(String lexicalRepresentation);
 278:   
 279:   /**
 280:    * Returns a new XMLGregorianCalendar based on the specified Gregorian
 281:    * calendar.
 282:    */
 283:   public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal);
 284: 
 285:   /**
 286:    * Returns a new XMLGregorianCalendar with the specified components.
 287:    */
 288:   public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year,
 289:                                                                int month,
 290:                                                                int day,
 291:                                                                int hour,
 292:                                                                int minute,
 293:                                                                int second,
 294:                                                                BigDecimal fractionalSecond,
 295:                                                                int timezone);
 296: 
 297:   /**
 298:    * Returns a new XMLGregorianCalendar with the specified components.
 299:    */
 300:   public XMLGregorianCalendar newXMLGregorianCalendar(int year,
 301:                                                       int month,
 302:                                                       int day,
 303:                                                       int hour,
 304:                                                       int minute,
 305:                                                       int second,
 306:                                                       int millisecond,
 307:                                                       int timezone)
 308:   {
 309:     return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
 310:                                    month,
 311:                                    day,
 312:                                    hour,
 313:                                    minute,
 314:                                    second,
 315:                                    new BigDecimal(((double) millisecond) / 1000.0),
 316:                                    timezone);
 317:   }
 318: 
 319:   /**
 320:    * Returns a new XMLGregorianCalendar with the specified components.
 321:    */
 322:   public XMLGregorianCalendar newXMLGregorianCalendarDate(int year,
 323:                                                           int month,
 324:                                                           int day,
 325:                                                           int timezone)
 326:   {
 327:     return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
 328:                                    month,
 329:                                    day,
 330:                                    DatatypeConstants.FIELD_UNDEFINED,
 331:                                    DatatypeConstants.FIELD_UNDEFINED,
 332:                                    DatatypeConstants.FIELD_UNDEFINED,
 333:                                    null,
 334:                                    timezone);
 335:   }
 336: 
 337:   /**
 338:    * Returns a new XMLGregorianCalendar with the specified components.
 339:    */
 340:   public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
 341:                                                           int minutes,
 342:                                                           int seconds,
 343:                                                           int timezone)
 344:   {
 345:     return newXMLGregorianCalendar(null,
 346:                                    DatatypeConstants.FIELD_UNDEFINED,
 347:                                    DatatypeConstants.FIELD_UNDEFINED,
 348:                                    hours,
 349:                                    minutes,
 350:                                    seconds,
 351:                                    null,
 352:                                    timezone);
 353:   }
 354: 
 355:   /**
 356:    * Returns a new XMLGregorianCalendar with the specified components.
 357:    */
 358:   public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
 359:                                                           int minutes,
 360:                                                           int seconds,
 361:                                                           BigDecimal fractionalSecond,
 362:                                                           int timezone)
 363:   {
 364:     return newXMLGregorianCalendar(null,
 365:                                    DatatypeConstants.FIELD_UNDEFINED,
 366:                                    DatatypeConstants.FIELD_UNDEFINED,
 367:                                    hours,
 368:                                    minutes,
 369:                                    seconds,
 370:                                    fractionalSecond,
 371:                                    timezone);
 372:   }
 373: 
 374:   /**
 375:    * Returns a new XMLGregorianCalendar with the specified components.
 376:    */
 377:   public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
 378:                                                           int minutes,
 379:                                                           int seconds,
 380:                                                           int milliseconds,
 381:                                                           int timezone)
 382:   {
 383:     return newXMLGregorianCalendar(null,
 384:                                    DatatypeConstants.FIELD_UNDEFINED,
 385:                                    DatatypeConstants.FIELD_UNDEFINED,
 386:                                    hours,
 387:                                    minutes,
 388:                                    seconds,
 389:                                    new BigDecimal(((double) milliseconds) / 1000.0),
 390:                                    timezone);
 391:   }
 392:     
 393: }