/** * Factory method to construct a SequenceType * * @param itemType the ItemType * @param occurrenceIndicator the permitted number of occurrences of the item in the sequence * @return the constricted SequenceType */ /*@NotNull*/ public static SequenceType makeSequenceType(ItemType itemType, OccurrenceIndicator occurrenceIndicator) { return new SequenceType(itemType, occurrenceIndicator); }
/** * Test whether two SequenceType objects represent the same type * * @param other the other SequenceType object * @return true if the other object is a SequenceType representing the same type * @since 9.5 */ public final boolean equals(Object other) { return other instanceof SequenceType && ((SequenceType) other).getOccurrenceIndicator().equals(getOccurrenceIndicator()) && ((SequenceType) other).getItemType().equals(getItemType()); }
@Override public SequenceType[] getArgumentTypes() { return new SequenceType[] { SequenceType.makeSequenceType(ItemType.ANY_ITEM, OccurrenceIndicator.ONE_OR_MORE)}; }
/** * Obtain an array type, that is a type for XDM arrays with a given member type * * @param memberType the type of the members in the array * @return the required array type */ public ItemType getArrayType(SequenceType memberType) { return new ConstructedItemType(new ArrayItemType(memberType.getUnderlyingSequenceType()), processor); }
/** * Obtain an array type, that is a type for XDM arrays with a given member type * * @param memberType the type of the members in the array * @return the required array type */ public ItemType getArrayType(SequenceType memberType) { return new ConstructedItemType(new ArrayItemType(memberType.getUnderlyingSequenceType()), processor); }
/** * Test whether two SequenceType objects represent the same type * * @param other the other SequenceType object * @return true if the other object is a SequenceType representing the same type * @since 9.5 */ public final boolean equals(Object other) { return other instanceof SequenceType && ((SequenceType) other).getOccurrenceIndicator().equals(getOccurrenceIndicator()) && ((SequenceType) other).getItemType().equals(getItemType()); }
@Override public SequenceType getResultType() { return SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ONE); }
/** * Obtain a map type, that is a type for XDM maps with a given key type and value type * @param keyType the type of the keys in the map * @param valueType the type of the values in the map * @return the required map type */ public ItemType getMapType(ItemType keyType, SequenceType valueType) { if (!(keyType.getUnderlyingItemType() instanceof AtomicType)) { throw new IllegalArgumentException("Map key must be atomic"); } return new ConstructedItemType( new MapType((AtomicType)keyType.getUnderlyingItemType(), valueType.getUnderlyingSequenceType()), processor); }
/** * Factory method to construct a SequenceType * * @param itemType the ItemType * @param occurrenceIndicator the permitted number of occurrences of the item in the sequence * @return the constricted SequenceType */ /*@NotNull*/ public static SequenceType makeSequenceType(ItemType itemType, OccurrenceIndicator occurrenceIndicator) { return new SequenceType(itemType, occurrenceIndicator); }
/** * Get a hash code with semantics corresponding to the equals() method * * @return the hash code * @since 9.5 */ public final int hashCode() { return getItemType().hashCode() ^ (getOccurrenceIndicator().hashCode() << 17); }
private static ExtensionFunction createExistsFunction () { return new Function ( new QName ("file", FILE_NAMESPACE, "exists"), SequenceType.makeSequenceType(ItemType.BOOLEAN, OccurrenceIndicator.ONE), new SequenceType[] { SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ONE)}) { @Override public XdmValue call(XdmValue[] arguments) throws SaxonApiException { String path = arguments[0].itemAt(0).getStringValue(); boolean result = new File(path).exists(); return new XdmAtomicValue(result); } }; }
/** * Obtain a map type, that is a type for XDM maps with a given key type and value type * @param keyType the type of the keys in the map * @param valueType the type of the values in the map * @return the required map type */ public ItemType getMapType(ItemType keyType, SequenceType valueType) { if (!(keyType.getUnderlyingItemType() instanceof AtomicType)) { throw new IllegalArgumentException("Map key must be atomic"); } return new ConstructedItemType( new MapType((AtomicType)keyType.getUnderlyingItemType(), valueType.getUnderlyingSequenceType()), processor); }
/** * Get a hash code with semantics corresponding to the equals() method * * @return the hash code * @since 9.5 */ public final int hashCode() { return getItemType().hashCode() ^ (getOccurrenceIndicator().hashCode() << 17); }
private static ExtensionFunction createIsDirFunction () { return new Function ( new QName ("file", FILE_NAMESPACE, "is-dir"), SequenceType.makeSequenceType(ItemType.BOOLEAN, OccurrenceIndicator.ONE), new SequenceType[] { SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ONE)}) { @Override public XdmValue call(XdmValue[] arguments) throws SaxonApiException { String path = arguments[0].itemAt(0).getStringValue(); boolean result = new File(path).isDirectory(); return new XdmAtomicValue(result); } }; }
/** * Get the type of the result of the function * <p>This method must be implemented in all subtypes.</p> * * @param suppliedArgumentTypes the static types of the supplied arguments to the function. * This is provided so that a more precise result type can be returned in the common * case where the type of the result depends on the types of the arguments. * @return the return type of the function, as defined by its function signature */ @Override public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { net.sf.saxon.s9api.SequenceType declaredResult = function.getResultType(); return net.sf.saxon.value.SequenceType.makeSequenceType( declaredResult.getItemType().getUnderlyingItemType(), declaredResult.getOccurrenceIndicator().getCardinality()); }
private static ExtensionFunction createListFunction () { return new Function ( new QName ("file", FILE_NAMESPACE, "list"), SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ZERO_OR_MORE), new SequenceType[] { SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ONE)}) { @Override public XdmValue call(XdmValue[] arguments) throws SaxonApiException { String dir = arguments[0].itemAt(0).getStringValue(); String [] files = new File(dir).list(); if (files == null) { return XdmEmptySequence.getInstance(); } XdmItem[] items = new XdmItem[files.length]; for (int i = 0; i < files.length; i++) { items[i] = new XdmAtomicValue(files[i]); } return new XdmValue (Arrays.asList(items)); } }; }
/** * Get the type of the result of the function * <p>This method must be implemented in all subtypes.</p> * * @param suppliedArgumentTypes the static types of the supplied arguments to the function. * This is provided so that a more precise result type can be returned in the common * case where the type of the result depends on the types of the arguments. * @return the return type of the function, as defined by its function signature */ @Override public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { net.sf.saxon.s9api.SequenceType declaredResult = function.getResultType(); return net.sf.saxon.value.SequenceType.makeSequenceType( declaredResult.getItemType().getUnderlyingItemType(), declaredResult.getOccurrenceIndicator().getCardinality()); }
/** * Get the required types for the arguments of this function. * <p>This method must be implemented in all subtypes.</p> * * @return the required types of the arguments, as defined by the function signature. Normally * this should be an array of size {@link #getMaximumNumberOfArguments()}; however for functions * that allow a variable number of arguments, the array can be smaller than this, with the last * entry in the array providing the required type for all the remaining arguments. */ /*@NotNull*/ @Override public net.sf.saxon.value.SequenceType[] getArgumentTypes() { net.sf.saxon.s9api.SequenceType[] declaredArgs = function.getArgumentTypes(); net.sf.saxon.value.SequenceType[] types = new net.sf.saxon.value.SequenceType[declaredArgs.length]; for (int i = 0; i < declaredArgs.length; i++) { types[i] = net.sf.saxon.value.SequenceType.makeSequenceType( declaredArgs[i].getItemType().getUnderlyingItemType(), declaredArgs[i].getOccurrenceIndicator().getCardinality()); } return types; }
/** * Get the required types for the arguments of this function. * <p>This method must be implemented in all subtypes.</p> * * @return the required types of the arguments, as defined by the function signature. Normally * this should be an array of size {@link #getMaximumNumberOfArguments()}; however for functions * that allow a variable number of arguments, the array can be smaller than this, with the last * entry in the array providing the required type for all the remaining arguments. */ /*@NotNull*/ @Override public net.sf.saxon.value.SequenceType[] getArgumentTypes() { net.sf.saxon.s9api.SequenceType[] declaredArgs = function.getArgumentTypes(); net.sf.saxon.value.SequenceType[] types = new net.sf.saxon.value.SequenceType[declaredArgs.length]; for (int i = 0; i < declaredArgs.length; i++) { types[i] = net.sf.saxon.value.SequenceType.makeSequenceType( declaredArgs[i].getItemType().getUnderlyingItemType(), declaredArgs[i].getOccurrenceIndicator().getCardinality()); } return types; }