public XdmItem apply(String s) { return new XdmAtomicValue(s); }}))); formatter.setParameter(new QName("report-dir"),
/** * Get a hashcode that reflects the rules for equality matching * @return a suitable hashcode */ @Override public int hashCode() { return getUnderlyingValue().asMapKey().hashCode(); } }
private static ItemType getItemType(XdmItem item, Processor process)throws SaxonApiException{ return new ItemTypeFactory(process).getAtomicType(((XdmAtomicValue) item).getPrimitiveTypeName()); }
public boolean hasFocus(Collection<File> tests) { for (File test : tests) { if (test.exists()) { try { XdmNode node = new XdmNode( processor.getUnderlyingConfiguration().buildDocument(new StreamSource(test))); if (((XdmAtomicValue)xpathCompiler.evaluateSingle("exists(//scenario[@focus])", node)).getBooleanValue()) return true; } catch (SaxonApiException e) { } catch (XPathException e) { } } } return false; }
((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getDecimalValue().intValue())); } else if (ItemType.BOOLEAN == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getBooleanValue())); } else if (ItemType.DOUBLE == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getDoubleValue())); } else if (ItemType.FLOAT == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getDecimalValue().floatValue())); } else if (ItemType.LONG == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getLongValue())); } else if (ItemType.SHORT == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getDecimalValue().shortValue())); } else if (ItemType.BYTE == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getDecimalValue().byteValue())); } else if (ItemType.STRING == itemType) { ((OMElement) destination).setText(String.valueOf(((XdmAtomicValue) xdmItem).getValue()));
/** * Static factory method to construct an XDM map by converting each entry * in a supplied Java map. The keys in the Java map must be convertible * to XDM atomic values using the {@link XdmAtomicValue#makeAtomicValue(Object)} * method. The associated values must be convertible to XDM sequences * using the {@link XdmValue#makeValue(Object)} method. * @param input the supplied map * @return the resulting XdmMap * @throws IllegalArgumentException if any value in the input map cannot be converted * to a corresponding XDM value. */ public static XdmMap makeMap(Map input) throws IllegalArgumentException { HashTrieMap result = new HashTrieMap(); for (Object entry : input.entrySet()) { Object key = ((Map.Entry)entry).getKey(); Object value = ((Map.Entry)entry).getValue(); XdmAtomicValue xKey = XdmAtomicValue.makeAtomicValue(key); XdmValue xValue = XdmValue.makeValue(value); result.initialPut(xKey.getUnderlyingValue(), xValue.getUnderlyingValue()); } return new XdmMap(result); }
protected XdmAtomicValue(AtomicValue value, boolean flag) { setValue(value); }
/** * Get the result of converting the atomic value to a string. This has the same * effect as the XPath string() function. */ public String toString() { return getStringValue(); }
XdmNode node = new XdmNode( processor.getUnderlyingConfiguration().buildDocument(new StreamSource(test))); if (((XdmAtomicValue)xpathCompiler.evaluateSingle("exists(//scenario[@focus])", node)).getBooleanValue()) focusTests.add(testName); } catch (SaxonApiException e) {
/** * Static factory method to construct an XDM map by converting each entry * in a supplied Java map. The keys in the Java map must be convertible * to XDM atomic values using the {@link XdmAtomicValue#makeAtomicValue(Object)} * method. The associated values must be convertible to XDM sequences * using the {@link XdmValue#makeValue(Object)} method. * @param input the supplied map * @return the resulting XdmMap * @throws IllegalArgumentException if any value in the input map cannot be converted * to a corresponding XDM value. */ public static XdmMap makeMap(Map input) throws IllegalArgumentException { HashTrieMap result = new HashTrieMap(); for (Object entry : input.entrySet()) { Object key = ((Map.Entry)entry).getKey(); Object value = ((Map.Entry)entry).getValue(); XdmAtomicValue xKey = XdmAtomicValue.makeAtomicValue(key); XdmValue xValue = XdmValue.makeValue(value); result.initialPut(xKey.getUnderlyingValue(), xValue.getUnderlyingValue()); } return new XdmMap(result); }
protected XdmAtomicValue(AtomicValue value, boolean flag) { setValue(value); }
/** * Get the result of converting the atomic value to a string. This has the same * effect as the XPath string() function. */ public String toString() { return getStringValue(); }
QName langParam = new QName("lang"); xsltTransformer.setParameter(langParam, new XdmAtomicValue("default"));
/** * Obtain a predicate that tests whether an atomic value compares equal to a supplied atomic value of * a comparable type * * @param value the atomic value to be compared with * @return a Predicate which returns true when applied to a value that is equal to the supplied * value under the "is-same-key" comparison rules. (These are the rules used to compare key values * in an XDM map. The rules are chosen to be context-free, error-free, and transitive.) */ public static Predicate<XdmAtomicValue> eq(XdmAtomicValue value) { AtomicMatchKey k2 = value.getUnderlyingValue().asMapKey(); return item -> item.getUnderlyingValue().asMapKey().equals(k2); }
public boolean shouldRun() throws SaxonApiException { String testExpr = ((When) step).getTest(); XdmNode doc = null; NamespaceBinding nsbinding = new NamespaceBinding(runtime, step.getNode()); Hashtable<QName,RuntimeValue> globals = parent.getInScopeOptions(); ReadablePipe reader = inputs.get("#xpath-context").firstElement(); doc = reader.read(); if (reader.moreDocuments() || inputs.get("#xpath-context").size() > 1) { throw XProcException.dynamicError(5); } // Surround testExpr with "boolean()" to force the EBV. Vector<XdmItem> results = evaluateXPath(doc, nsbinding.getNamespaceBindings(), "boolean(" + testExpr + ")", globals); if (results.size() != 1) { throw new XProcException("Attempt to compute EBV in p:when did not return a singleton!?"); } XdmAtomicValue value = (XdmAtomicValue) results.get(0); return value.getBooleanValue(); }
/** * Construct an atomic value given its lexical representation and the name of the required * built-in atomic type. * <p>This method cannot be used to construct values that are namespace-sensitive (QNames and Notations)</p> * @param lexicalForm the value in the lexical space of the target data type. More strictly, the input * value before the actions of the whitespace facet for the target data type are applied. * @param type the required atomic type. This must either be one of the built-in * atomic types defined in XML Schema, or a user-defined type whose definition appears * in a schema that is known to the Processor. * @throws SaxonApiException if the type is unknown, or is not atomic, or is namespace-sensitive; * or if the value supplied in <tt>lexicalForm</tt> is not in the lexical space of the specified atomic * type. */ public XdmAtomicValue(String lexicalForm, ItemType type) throws SaxonApiException { net.sf.saxon.type.ItemType it = type.getUnderlyingItemType(); if (!it.isAtomicType()) { throw new SaxonApiException("Requested type is not atomic"); } Configuration config = type.getProcessor().getUnderlyingConfiguration(); ConversionResult result = new StringValue(lexicalForm).convert( (AtomicType)it, true, config.getConversionContext()); try { setValue(result.asAtomic()); } catch (ValidationException e) { throw new SaxonApiException(e); } }
/** * Get the result of converting the atomic value to a string. This has the same * effect as the XPath string() function. */ public String toString() { return getStringValue(); }
while (iter.hasNext()) { XdmItem next = iter.next(); QName type = next.isAtomicValue() ? ((XdmAtomicValue) next).getPrimitiveTypeName() : null;
private XdmValue getXdmValue(Object value) { if (value instanceof XdmValue) { return (XdmValue) value; } if (value instanceof String) { return new XdmAtomicValue ((String) value); } if (value instanceof Integer) { return new XdmAtomicValue ((Integer) value); } throw new LuxException ("No automatic conversion supplied for " + value.getClass().getName()); }
/** * Get a hashcode that reflects the rules for equality matching * @return a suitable hashcode */ @Override public int hashCode() { return getUnderlyingValue().asMapKey().hashCode(); } }