Search in sources :

Example 1 with Function

use of org.eclipse.wst.xml.xpath2.api.Function in project webtools.sourceediting by eclipse.

the class FnAdjustTimeToTimeZone method adjustTime.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence adjustTime(Collection args, DynamicContext dc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expectedArgs());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSTime time = (XSTime) arg1.first();
    XSDayTimeDuration timezone = null;
    if (arg2.empty()) {
        if (time.timezoned()) {
            XSTime localized = new XSTime(time.calendar(), null);
            return localized;
        } else {
            return arg1;
        }
    }
    XMLGregorianCalendar xmlCalendar = null;
    if (time.tz() != null) {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) time.normalizeCalendar(time.calendar(), time.tz()));
    } else {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int) time.second(), 0);
    }
    timezone = (XSDayTimeDuration) arg2.first();
    if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
        throw DynamicError.invalidTimezone();
    }
    if (time.tz() == null) {
        return new XSTime(time.calendar(), timezone);
    }
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSTime(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 2 with Function

use of org.eclipse.wst.xml.xpath2.api.Function in project webtools.sourceediting by eclipse.

the class FnBaseUri method getBaseUri.

/*
	 * Helper function for base-uri support
	 */
public static ResultSequence getBaseUri(Item att) {
    ResultBuffer rs = new ResultBuffer();
    XSAnyURI baseUri = null;
    if (att instanceof NodeType) {
        NodeType node = (NodeType) att;
        Node domNode = node.node_value();
        String buri = domNode.getBaseURI();
        if (buri != null) {
            baseUri = new XSAnyURI(buri);
        } else {
            baseUri = new XSAnyURI("null");
        }
    }
    if (baseUri != null) {
        rs.add(baseUri);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node)

Example 3 with Function

use of org.eclipse.wst.xml.xpath2.api.Function in project webtools.sourceediting by eclipse.

the class FnDateTime method dateTime.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence dateTime(Collection args, StaticContext sc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    // is an empty sequence
    if (arg1.empty() || arg2.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDate param1 = (XSDate) arg1.first();
    XSTime param2 = (XSTime) arg2.first();
    Calendar cal = Calendar.getInstance();
    cal.set(param1.year(), param1.month() - 1, param1.day());
    cal.set(Calendar.HOUR_OF_DAY, param2.hour());
    cal.set(Calendar.MINUTE, param2.minute());
    cal.set(Calendar.SECOND, (new Double(Math.floor(param2.second())).intValue()));
    cal.set(Calendar.MILLISECOND, 0);
    XSDuration dateTimeZone = param1.tz();
    XSDuration timeTimeZone = param2.tz();
    if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        // it's an error, if the arguments have different timezones
        throw DynamicError.inconsistentTimeZone();
    } else if (dateTimeZone == null && timeTimeZone != null) {
        return new XSDateTime(cal, timeTimeZone);
    } else if (dateTimeZone != null && timeTimeZone == null) {
        return new XSDateTime(cal, dateTimeZone);
    } else if ((dateTimeZone != null && timeTimeZone != null) && dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        return new XSDateTime(cal, dateTimeZone);
    } else {
        return new XSDateTime(cal, null);
    }
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Calendar(java.util.Calendar) Iterator(java.util.Iterator) Collection(java.util.Collection) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 4 with Function

use of org.eclipse.wst.xml.xpath2.api.Function in project webtools.sourceediting by eclipse.

the class Function method getResultSetForArityZero.

protected static ResultSequence getResultSetForArityZero(EvaluationContext ec) throws DynamicError {
    ResultSequence rs = ResultSequenceFactory.create_new();
    Item contextItem = ec.getContextItem();
    if (contextItem != null) {
        // if context item is defined, then that is the default argument
        // to fn:string function
        rs.add(new XSString(contextItem.getStringValue()));
    } else {
        throw DynamicError.contextUndefined();
    }
    return rs;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 5 with Function

use of org.eclipse.wst.xml.xpath2.api.Function in project webtools.sourceediting by eclipse.

the class Function method signature.

/**
 * Apply the name and arity to signature.
 *
 * @param name
 *            QName.
 * @param arity
 *            arity of the function.
 * @return Signature.
 */
public static String signature(QName name, int arity) {
    String n = name.expanded_name();
    if (n == null)
        return null;
    n += "_";
    if (arity < 0)
        n += "x";
    else
        n += arity;
    return n;
}
Also used : XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Aggregations

URL (java.net.URL)3073 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)3073 XSModel (org.apache.xerces.xs.XSModel)3072 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)3072 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)3072 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)3072 Schema (javax.xml.validation.Schema)19 XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)15 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)14 Item (org.eclipse.wst.xml.xpath2.api.Item)13 BigInteger (java.math.BigInteger)12 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)10 Collection (java.util.Collection)8 Iterator (java.util.Iterator)8 ArrayList (java.util.ArrayList)6 Function (org.eclipse.wst.xml.xpath2.api.Function)6 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)4 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)4 Map (java.util.Map)3 Duration (javax.xml.datatype.Duration)3