| 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.om.Sequence; |
| 13 |
import net.sf.saxon.om.SequenceIterator; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class MapCreate extends SystemFunction { |
| 25 |
|
| 26 |
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 27 |
|
| 28 |
SequenceIterator<?> iter = arguments[0].iterate(); |
| 29 |
MapItem baseMap = (MapItem) iter.next(); |
| 30 |
if (baseMap == null) { |
| 31 |
return new HashTrieMap(); |
| 32 |
} else { |
| 33 |
if (!(baseMap instanceof HashTrieMap)) { |
| 34 |
baseMap = HashTrieMap.copy(baseMap); |
| 35 |
} |
| 36 |
MapItem next; |
| 37 |
while ((next = (MapItem) iter.next()) != null) { |
| 38 |
for (KeyValuePair pair : next.keyValuePairs()) { |
| 39 |
if (baseMap.get(pair.key) != null) { |
| 40 |
throw new XPathException("Duplicate key value (" + pair.key + ") in map", "XQDY0137"); |
| 41 |
} else { |
| 42 |
baseMap = baseMap.addEntry(pair.key, pair.value); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
return baseMap; |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public String getStreamerName() { |
| 52 |
return "NewMap"; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|