use of org.eclipse.wst.xml.xpath2.api.StaticContext 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);
}
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class FnPrefixFromQName method prefix.
/**
* Prefix-from-QName operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:prefix-from-QName operation.
*/
public static ResultSequence prefix(Collection args, StaticContext sc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get arg
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty())
return ResultBuffer.EMPTY;
QName qname = (QName) arg1.first();
String prefix = qname.prefix();
if (prefix != null) {
if (!XMLConstants.NULL_NS_URI.equals(sc.getNamespaceContext().getNamespaceURI(prefix))) {
return new XSNCName(prefix);
} else {
throw DynamicError.invalidPrefix();
}
}
return ResultBuffer.EMPTY;
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class SeqType method make_atomic.
private AnyAtomicType make_atomic(StaticContext sc, QName qname) {
String ns = qname.namespace();
Map functionLibraries = sc.getFunctionLibraries();
if (!functionLibraries.containsKey(ns))
return null;
FunctionLibrary fl = (FunctionLibrary) functionLibraries.get(ns);
if (!(fl instanceof ConstructorFL))
return null;
ConstructorFL cfl = (ConstructorFL) fl;
return cfl.atomic_type(qname);
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class ElementTest method createElementType.
private AnyType createElementType(Item at, StaticContext sc) {
anyType = new ElementType();
NodeType nodeType = (NodeType) at;
Node node = nodeType.node_value();
Document doc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
doc = (Document) node;
} else {
doc = nodeType.node_value().getOwnerDocument();
}
NodeList nodeList = null;
if (!wild()) {
nodeList = doc.getElementsByTagNameNS(name().namespace(), name().local());
} else {
nodeList = new SingleItemNodeListImpl(node);
}
if (nodeList.getLength() > 0) {
anyType = createElementForXSDType(nodeList, sc);
}
return anyType;
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class AttributeTest method createAttrForXSDType.
private AnyType createAttrForXSDType(Node node, StaticContext sc) {
Attr attr = (Attr) node;
TypeModel typeModel = sc.getTypeModel();
TypeDefinition typedef = typeModel.getType(attr);
if (typedef != null) {
if (typedef.derivedFrom(type().namespace(), type().local(), getDerviationTypes())) {
anyType = new AttrType(attr, sc.getTypeModel());
}
} else {
anyType = new AttrType(attr, sc.getTypeModel());
}
return anyType;
}
Aggregations