Package net.sf.saxon.value

Examples of net.sf.saxon.value.DateTimeValue


  }
 
  public static AtomicValue convertToAtomicValue(Object value) throws TransformerException {
    if (value instanceof java.util.Date) { //special handling for time types
          java.util.Date d = (java.util.Date)value;
          DateTimeValue tdv = DateTimeValue.fromJavaDate(d);
          if (value instanceof Date) {
            value = new DateValue(tdv.getYear(), tdv.getMonth(), tdv.getDay(), tdv.getTimezoneInMinutes());
          } else if (value instanceof Time) {
            value = new TimeValue(tdv.getHour(), tdv.getMinute(), tdv.getSecond(), tdv.getMicrosecond(), tdv.getTimezoneInMinutes());
          } else if (value instanceof Timestamp) {
            Timestamp ts = (Timestamp)value;
            value = tdv.add(DayTimeDurationValue.fromMicroseconds(ts.getNanos() / 1000));
          }
          return (AtomicValue)value;
        }
    JPConverter converter = JPConverter.allocate(value.getClass(), null);
    return (AtomicValue)converter.convert(value, null);
View Full Code Here


                    break;
                case GYEAR_CODE:
                    valueStr = FunctionMethods.format((BigInteger)value, GYEAR_FORMAT);
                    break;
                case GYEARMONTH_CODE:
        DateTimeValue dtv;
        try {
          dtv = ((DateTimeValue)XMLSystemFunctions.convertToAtomicValue(value));
        } catch (TransformerException e) {
          throw new TransformationException(e, e.getMessage());
        }
                  valueStr = new GYearMonthValue(dtv.getYear(), dtv.getMonth(), dtv.getTimezoneInMinutes()).getStringValue();
                    break;
                default:
                    valueStr = defaultTranslation(value);
                    break;
            }
View Full Code Here

    private Object getSimpleContent(Node simpleNode, QName type) {
        String text = simpleNode.getTextContent();
        try {
        Object jobj = XSTypes.toJavaObject(type,text);
            // Saxon wants its own dateTime type and doesn't like Calendar or Date
            if (jobj instanceof Calendar) return new DateTimeValue((Calendar) jobj, true);
            else return jobj;
        } catch (Exception e) { }
        // Elegant way failed, trying brute force
      try {
        return Integer.valueOf(text);
View Full Code Here

        controller.setURIResolver(env.getURIResolver());
        controller.setErrorListener(env.getErrorListener());
        controller.addTraceListener(env.getTraceListener());
        controller.setTraceFunctionDestination(env.getTraceFunctionDestination());
        controller.setSchemaValidationMode(env.getSchemaValidationMode());
        DateTimeValue currentDateTime = env.getCurrentDateTime();
        if (currentDateTime != null) {
            try {
                controller.setCurrentDateTime(currentDateTime);
            } catch (XPathException e) {
                throw new AssertionError(e);    // the value should already have been checked
View Full Code Here

    /**
    * Evaluate in a general context
    */

    public Item evaluateItem(XPathContext context) throws XPathException {
        final DateTimeValue dt = DateTimeValue.getCurrentDateTime(context);
        final TypeHierarchy th = context.getConfiguration().getTypeHierarchy();
        final int targetType = getItemType(th).getPrimitiveType();
        switch (targetType) {
            case StandardNames.XS_DATE_TIME:
                return dt;
            case StandardNames.XS_DATE:
                return dt.convert(BuiltInAtomicType.DATE, true, context).asAtomic();
            case StandardNames.XS_TIME:
                return dt.convert(BuiltInAtomicType.TIME, true, context).asAtomic();
            case StandardNames.XS_DAY_TIME_DURATION:
            case StandardNames.XS_DURATION:
                return dt.getComponent(Component.TIMEZONE);
            default:
                throw new IllegalArgumentException("Wrong target type for current date/time");
        }
    }
View Full Code Here

     *      for repeated calls within the same transformation
     */

    public DateTimeValue getCurrentDateTime() {
        if (currentDateTime==null) {
            currentDateTime = new DateTimeValue(new GregorianCalendar(), true);
        }
        return currentDateTime;
    }
View Full Code Here

    /**
    * Evaluate in a general context
    */

    public Item evaluateItem(XPathContext context) throws XPathException {
        DateTimeValue dt = new DateTimeValue(context);
        int targetType = getItemType().getPrimitiveType();
        switch (targetType) {
            case Type.DATE_TIME:
                return dt;
            case Type.DATE:
                return (DateValue)dt.convert(Type.DATE, context);
            case Type.TIME:
                return (TimeValue)dt.convert(Type.TIME, context);
            case Type.DAY_TIME_DURATION:
            case Type.DURATION:
                return dt.getComponent(Component.TIMEZONE);
            default:
                throw new IllegalArgumentException("Wrong target type for current date/time");
        }
    }
View Full Code Here

        int nargs = argument.length;
        SecondsDurationValue tz = null;
        if (nargs==1) {
            // use the implicit timezone
            tz = (SecondsDurationValue)new DateTimeValue(c).getComponent(Component.TIMEZONE);
            return in.setTimezone(tz);
        } else {
            AtomicValue av2 = (AtomicValue)argument[1].evaluateItem(c);
            if (av2==null) {
                return in.removeTimezone();
View Full Code Here

     *      for repeated calls within the same transformation
     */

    public DateTimeValue getCurrentDateTime() {
        if (currentDateTime==null) {
            currentDateTime = new DateTimeValue(new GregorianCalendar(), true);
        }
        return currentDateTime;
    }
View Full Code Here

        }

        controller.setURIResolver(env.getURIResolver());
        controller.setErrorListener(env.getErrorListener());
        controller.addTraceListener(env.getTraceListener());
        DateTimeValue currentDateTime = env.getCurrentDateTime();
        if (currentDateTime != null) {
            try {
                controller.setCurrentDateTime(currentDateTime);
            } catch (XPathException e) {
                throw new AssertionError(e);    // the value should already have been checked
View Full Code Here

TOP

Related Classes of net.sf.saxon.value.DateTimeValue

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.