public static String getTypeName(ItemType type) { if (type.isAtomicType()) { return type.getAtomizedItemType().getTypeName().getLocalPart(); } return type.toString(); }
/** * Determine the data type of the expression, if this is known statically */ public ItemType getItemType(TypeHierarchy th) { if (calculator == null) { return BuiltInAtomicType.ANY_ATOMIC; // type is not known statically } else { ItemType t1 = operand0.getItemType(th); if (!(t1 instanceof AtomicType)) { t1 = t1.getAtomizedItemType(); } ItemType t2 = operand1.getItemType(th); if (!(t2 instanceof AtomicType)) { t2 = t2.getAtomizedItemType(); } return calculator.getResultType((AtomicType) t1.getPrimitiveItemType(), (AtomicType) t2.getPrimitiveItemType()); } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType the type of the context item */ @Override public UType getStaticUType(UType contextItemType) { return UType.fromTypeCode(requiredItemType.getPrimitiveType()); }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { Expression exp = super.optimize(visitor, contextItemType); if (exp == this) { if (contextItemType.isAtomicType()) { return new ContextItemExpression(); } } return exp; }
/** * Return a string representation of this ItemType suitable for use in stylesheet * export files. This differs from the result of toString() in that it will not contain * any references to anonymous types. Note that it may also use the Saxon extended syntax * for union types and tuple types. The default implementation returns the result of * calling {@code toString()}. * * @return the string representation as an instance of the XPath SequenceType construct */ default String toExportString() { return toString(); }
/** * Get the item type of the atomic values that will be produced when an item * of this type is atomized * * @return the item type of the atomic values that will be produced when an item * of this type is atomized */ @Override public PlainType getAtomizedItemType() { return memberType.getPrimaryType().getAtomizedItemType(); }
/** * Get the return type, given knowledge of the actual arguments * @param args the actual arguments supplied * @return the best available item type that the function will return */ public ItemType getResultItemType(Expression[] args) { if ((details.properties & BuiltInFunctionSet.AS_ARG0) != 0) { return args[0].getItemType(); } else if ((details.properties & BuiltInFunctionSet.AS_PRIM_ARG0) != 0) { return args[0].getItemType().getPrimitiveItemType(); } else { return details.itemType; } }
/** * Get the static type of the context item as a UType * @return the static context item type */ public UType getContextItemUType() { return itemType.getUType(); }
public static OperandUsage typeDeterminedUsage(net.sf.saxon.type.ItemType type) { if (type.isPlainType()) { return OperandUsage.ABSORPTION; } else if (type instanceof NodeTest || type == AnyItemType.getInstance()) { return OperandUsage.NAVIGATION; } else { return OperandUsage.INSPECTION; } }
/** * Determine whether this item type matches a given item. * * @param item the item to be tested against this item type * @return true if the item matches this item type, false if it does not match. */ public boolean matches(XdmItem item) { return underlyingType.matchesItem( (Item)item.getUnderlyingValue(), false, processor.getUnderlyingConfiguration()); }
public boolean matchesItem(Item item) { for (ItemType itemType : getChildren()) if (itemType.matches(item)) return true; return false; }
/** * Evaluate as an Item. */ public Item evaluateItem(XPathContext context) throws XPathException { final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); Item item = getBaseExpression().evaluateItem(context); if (item == null) { return null; } if (requiredItemType.matches(item, th)) { return item; } else if (requiredItemType.getUType().subsumes(UType.STRING) && BuiltInAtomicType.ANY_URI.matches(item, th)) { return item; } else { String message = role.composeErrorMessage(requiredItemType, item, th); String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion dynamicError(message, errorCode, context); } else { typeError(message, errorCode, context); } return null; } }
/** * @return Whether to insert 'validate { }' code into generated xquery expression */ public boolean doValidate(Object requestedType) { ItemType t = unifyTypeFromODE(requestedType); t = simplify(t); if (t == null || t.isAtomicType()) return false; return true; }
/** * The toString() method for an expression attempts to give a representation of the expression * in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. * In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax */ public String toString() { String typeDesc = requiredItemType.toString(); return "(" + getBaseExpression() + ") treat as " + typeDesc; }
/** * Get the item type of the atomic values that will be produced when an item * of this type is atomized * * @return the item type of the atomic values that will be produced when an item * of this type is atomized */ @Override public PlainType getAtomizedItemType() { return memberType.getPrimaryType().getAtomizedItemType(); }
/** * Get the return type, given knowledge of the actual arguments * @param args the actual arguments supplied * @return the best available item type that the function will return */ public ItemType getResultItemType(Expression[] args) { if ((details.properties & BuiltInFunctionSet.AS_ARG0) != 0) { return args[0].getItemType(); } else if ((details.properties & BuiltInFunctionSet.AS_PRIM_ARG0) != 0) { return args[0].getItemType().getPrimitiveItemType(); } else { return details.itemType; } }
/** * Get the static type of the context item as a UType * @return the static context item type */ public UType getContextItemUType() { return itemType.getUType(); }
public static OperandUsage typeDeterminedUsage(net.sf.saxon.type.ItemType type) { if (type.isPlainType()) { return OperandUsage.ABSORPTION; } else if (type instanceof NodeTest || type == AnyItemType.getInstance()) { return OperandUsage.NAVIGATION; } else { return OperandUsage.INSPECTION; } }
/** * Evaluate the expression as a boolean */ public boolean effectiveBooleanValue(XPathContext context) throws XPathException { SequenceIterator iter = operand.iterate(context); int count = 0; while (true) { Item item = iter.next(); if (item == null) break; count++; if (!targetType.matchesItem(item, false, context.getConfiguration())) { return false; } if (count==2 && !Cardinality.allowsMany(targetCardinality)) { return false; } } return !(count == 0 && ((targetCardinality & StaticProperty.ALLOWS_ZERO) == 0)); }
private void checkItem(Item item, Location locationId) throws XPathException { TypeHierarchy th = getConfiguration().getTypeHierarchy(); if (!itemType.matches(item, th)) { throwTypeError(null, item, locationId); } }