Package javax.xml.datatype

Examples of javax.xml.datatype.DatatypeFactory


            Assert.assertEquals(xgcals[i], actual[i]);
        }
    }

    private void performTestNewDuration(StandardTypesServiceClient serviceClient) throws DatatypeConfigurationException {
        DatatypeFactory df = DatatypeFactory.newInstance();
        Duration[] da = new Duration[3];
        da[0] = df.newDuration(1000000000000L);
        da[1] = df.newDurationDayTime(1000000000000L);
        da[2] = df.newDurationYearMonth(true, 1, 3);

        for (int i = 0; i < da.length; ++i) {
            Assert.assertEquals(da[i].negate(), serviceClient.getNewDurationForward(da[i]));
        }
    }
View Full Code Here


        }
    }

    private void performTestNewDurationArray(StandardTypesServiceClient serviceClient)
        throws DatatypeConfigurationException {
        DatatypeFactory df = DatatypeFactory.newInstance();
        Duration[] da = new Duration[3];
        da[0] = df.newDuration(1000000000000L);
        da[1] = df.newDurationDayTime(1000000000000L);
        da[2] = df.newDurationYearMonth(true, 1, 3);

        Duration[] actual = serviceClient.getNewDurationArrayForward(da);
        Assert.assertEquals(da.length, actual.length);
        for (int i = 0; i < da.length; ++i) {
            Assert.assertEquals(da[i].negate(), actual[i]);
View Full Code Here

        if (aNotification.getUserData() != null) {
            jaxb.withUserData(String.valueOf(aNotification.getUserData()));
        }

        try {
            DatatypeFactory df = getDatatypeFactory();
            Date date = new Date(aNotification.getTimeStamp());
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(date);
            jaxb.withDateTime(df.newXMLGregorianCalendar(gc));

            Object bean = wrap ? mObjectFactory.createNotificationEvent(jaxb) : jaxb;

            StringWriter sw = new StringWriter();
View Full Code Here

      gc.add(GregorianCalendar.DAY_OF_MONTH, transferExpirationDays);
     
      transferToken.setExpirationDate(gc.getTime());
 
      try {
        DatatypeFactory df = DatatypeFactory.newInstance();
        // For output
        expirationTime.value = df.newXMLGregorianCalendar(gc);
      }
      catch(DatatypeConfigurationException ce)
      { throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));}
 
      List<String> keyList = keyBag.getKey();
View Full Code Here

      if (userExpiration.getTimeInMillis() < expirationDate.getTimeInMillis())
        expirationDate.setTimeInMillis(userExpiration.getTimeInMillis());
    }

    try {
      DatatypeFactory df = DatatypeFactory.newInstance();
      apiSubscription.setExpiresAfter(df.newXMLGregorianCalendar(expirationDate));
    }
    catch(DatatypeConfigurationException ce) {
      throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
    }
   
View Full Code Here

    try {
      if (date!=null) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(date.getTime());
       
        DatatypeFactory df = DatatypeFactory.newInstance();
        result = df.newXMLGregorianCalendar(gc);
      }
    }
    catch(DatatypeConfigurationException ce) {
      throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
    }
View Full Code Here

  public static Duration convertStringToDuration(String duration) throws DispositionReportFaultMessage {
    if (duration==null) return null;
    Duration result = null;
    try {
     
      DatatypeFactory df = DatatypeFactory.newInstance();
      result = df.newDuration(duration);
    }
    catch(DatatypeConfigurationException ce) {
      throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
    }
View Full Code Here

                } catch (Exception x) {
                        sub.setBrief(false);
                }

                try {
                        DatatypeFactory df = DatatypeFactory.newInstance();
                        DateFormat dformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");
                        String ds = (String) map.get("expires");
                        if (ds != null && ds.trim().length() != 0 && !ds.equals("\"\"")) {
                                Date parsed = dformat.parse(((String[]) map.get("expires"))[0]);
                                GregorianCalendar gcal = new GregorianCalendar();
                                gcal.setTime(parsed);
                                sub.setExpiresAfter(df.newXMLGregorianCalendar(gcal));
                        }
                } catch (Exception ex) {
                        UddiHub.log.debug("Unexpected parsing expires error " + ex.getMessage());
                }

                try {
                        DatatypeFactory df = DatatypeFactory.newInstance();
                        DateFormat dformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");
                        Date parsed = dformat.parse(((String[]) map.get("expires"))[0]);

                        GregorianCalendar gcal = new GregorianCalendar();
                        gcal.setTime(parsed);
                        sub.setExpiresAfter(df.newXMLGregorianCalendar(gcal));
                } catch (Exception ex) {
                        UddiHub.log.debug("Unexpected parsing expires error " + ex.getMessage());
                }

                try {
                        long durationInMilliSeconds = 0;
                        DatatypeFactory df = DatatypeFactory.newInstance();
                        String interval = ((String[]) map.get("interval"))[0];
                        String[] tokens = interval.split(":");
                        durationInMilliSeconds += Integer.parseInt(tokens[0]) * 60 * 60 * 1000;
                        durationInMilliSeconds += Integer.parseInt(tokens[1]) * 60 * 1000;
                        durationInMilliSeconds += Integer.parseInt(tokens[2]) * 1000;

                        sub.setNotificationInterval(df.newDuration(durationInMilliSeconds));

                } catch (Exception ex) {
                        UddiHub.log.debug("Unexpected parsing interval error " + ex.getMessage());
                }

                try {
                        long durationInMilliSeconds = 0;
                        DatatypeFactory df = DatatypeFactory.newInstance();
                        String interval = (String) map.get("interval");
                        String[] tokens = interval.split(":");
                        durationInMilliSeconds += Integer.parseInt(tokens[0]) * 60 * 60 * 1000;
                        durationInMilliSeconds += Integer.parseInt(tokens[1]) * 60 * 1000;
                        durationInMilliSeconds += Integer.parseInt(tokens[2]) * 1000;

                        sub.setNotificationInterval(df.newDuration(durationInMilliSeconds));

                } catch (Exception ex) {
                        UddiHub.log.debug("Unexpected parsing interval error " + ex.getMessage());
                }

View Full Code Here

*/
public class DatatypeAPIUsage {
   
    public static void main (String [] args) {
        try {
            DatatypeFactory df = DatatypeFactory.newInstance();
            // my work number in milliseconds:
            Duration myPhone = df.newDuration(9054133519l);
            Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0);
            int compareVal = myPhone.compare(myLife);
            switch (compareVal) {
                case DatatypeConstants.LESSER:
                    System.out.println("There are fewer milliseconds in my phone number than my lifespan.");
                    break;
                case DatatypeConstants.EQUAL:
                    System.out.println("The same number of milliseconds are in my phone number and my lifespan.");
                    break;
                case DatatypeConstants.GREATER:
                    System.out.println("There are more milliseconds in my phone number than my lifespan.");
                    break;
                case DatatypeConstants.INDETERMINATE:
                    System.out.println("The comparison could not be carried out.");
            }
           
            // create a yearMonthDuration
            Duration ymDuration = df.newDurationYearMonth("P12Y10M");
            System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType());
           
            // create a dayTimeDuration (really this time)
            Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S");
            System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType());
           
            // try to fool the factory!
            try {
                ymDuration = df.newDurationYearMonth("P12Y10M1D");
            }
            catch(IllegalArgumentException e) {
                System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!");
            }
           
            XMLGregorianCalendar xgc = df.newXMLGregorianCalendar();
            xgc.setYear(1975);
            xgc.setMonth(DatatypeConstants.AUGUST);
            xgc.setDay(11);
            xgc.setHour(6);
            xgc.setMinute(44);
            xgc.setSecond(0);
            xgc.setMillisecond(0);
            xgc.setTimezone(5);
            xgc.add(myPhone);
            System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc);
           
            //adding a duration to XMLGregorianCalendar
            xgc.add(myLife);
            System.out.println("Adding the duration myLife to the above calendar:" + xgc);
           
            // create a new XMLGregorianCalendar using the string format of xgc.
            XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat());
           
            // should be equal-if not what happened!!
            if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) {
                System.out.println("oooops!");
            }
View Full Code Here

    public static List<XMLGregorianCalendar> convertCalendar(List<GregorianCalendar> calendar) {
        if (calendar == null) {
            return null;
        }

        DatatypeFactory df;
        try {
            df = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new CmisRuntimeException("Convert exception: " + e.getMessage(), e);
        }

        List<XMLGregorianCalendar> result = new ArrayList<XMLGregorianCalendar>();
        for (GregorianCalendar cal : calendar) {
            result.add(df.newXMLGregorianCalendar(cal));
        }

        return result;
    }
View Full Code Here

TOP

Related Classes of javax.xml.datatype.DatatypeFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.