| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.ma.map; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.XPathContext; |
| 11 |
import net.sf.saxon.functions.SystemFunction; |
| 12 |
import net.sf.saxon.lib.ConversionRules; |
| 13 |
import net.sf.saxon.om.Sequence; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.type.*; |
| 16 |
import net.sf.saxon.value.AtomicValue; |
| 17 |
import net.sf.saxon.value.BooleanValue; |
| 18 |
import net.sf.saxon.value.UntypedAtomicValue; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class MapUntypedContains extends SystemFunction { |
| 28 |
|
| 29 |
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 30 |
ConversionRules rules = context.getConfiguration().getConversionRules(); |
| 31 |
MapItem map = (MapItem) arguments[0].head(); |
| 32 |
AtomicValue key = (AtomicValue) arguments[1].head(); |
| 33 |
if (key instanceof UntypedAtomicValue) { |
| 34 |
for (PrimitiveUType prim : map.getKeyUType().decompose()) { |
| 35 |
BuiltInAtomicType t = (BuiltInAtomicType)prim.toItemType(); |
| 36 |
StringConverter converter = t.getStringConverter(rules); |
| 37 |
ConversionResult av = converter.convert(key); |
| 38 |
if (av instanceof ValidationFailure) { |
| 39 |
|
| 40 |
if (prim.equals(PrimitiveUType.DECIMAL)) { |
| 41 |
converter = BuiltInAtomicType.DOUBLE.getStringConverter(rules); |
| 42 |
av = converter.convert(key); |
| 43 |
if (av instanceof AtomicValue) { |
| 44 |
if (map.get(av.asAtomic()) != null) { |
| 45 |
return BooleanValue.TRUE; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} else if (map.get(av.asAtomic()) != null) { |
| 50 |
return BooleanValue.TRUE; |
| 51 |
} |
| 52 |
} |
| 53 |
return BooleanValue.FALSE; |
| 54 |
} else if (key.isNaN()) { |
| 55 |
return BooleanValue.FALSE; |
| 56 |
} |
| 57 |
boolean result = map.get(key) != null; |
| 58 |
return BooleanValue.get(result); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|