Project

Profile

Help

Feature #4671

XdmValue.makeValue(Object) should use the standard Java-to-XDM conversion rules

Added by Michael Kay about 1 month ago. Updated about 1 month ago.

Status:
New
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2020-08-05
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:

Description

The s9api method XdmValue.makeValue(Object) doesn't make use of the standard conversion rules in JPConverter (it has a more restricted set of conversion rules).

There are other places where the standard conversion rules seem to be unnecessarily augmented or adapted:

  • AbstractTransformerImpl.setParameter() does:
            if (value instanceof Sequence) {
                converted = (Sequence)value;
            } else if (value instanceof String) {
                converted = new UntypedAtomicValue(StringView.of((String) value));
            } else if (required.getPrimaryType() instanceof JavaExternalObjectType) {
                converted = new ObjectValue<>(value);
            } else {
                JPConverter converter = JPConverter.allocate(value.getClass(), null, config);
               
  • XPathExpressionImpl.evaluate() does
if (node instanceof ZeroOrOne) {
            node = ((ZeroOrOne) node).head();
        }
        if (node instanceof TreeInfo) {
            node = ((TreeInfo)node).getRootNode();
        }
        if (node instanceof NodeInfo) {
            if (!((NodeInfo) node).getConfiguration().isCompatible(config)) {
                throw new XPathExpressionException(
                        "Supplied node must be built using the same or a compatible Configuration");
            }
            if (node instanceof TreeInfo && ((TreeInfo) node).isTyped() && !executable.isSchemaAware()) {
                throw new XPathExpressionException(
                        "The expression was compiled to handled untyped data, but the input is typed");
            }
            contextItem = (NodeInfo) node;
        } else if (node instanceof Item) {
            contextItem = (Item) node;
        } else {
            JPConverter converter = JPConverter.allocate(node.getClass(), null, config);
            

History

#1 Updated by Michael Kay about 1 month ago

The problem with XdmValue.makeValue(Object) is that it's a static method with no access to a Configuration, whereas the standard JPConverter requires a Configuration (though it hardly uses it: the main uses seem to be (a) to access the registered external object models, and (b) to cache JavaExternalObjectTypes - which probably serves no useful purpose).

I've removed some of the unnecessary differences in the other paths noted. Some of them, though, are signfiicant, such as the special treatment of string as xs:untypedAtomic in the JAXP setParameter() method.

Please register to edit this issue

Also available in: Atom PDF