/** * Determine whether one atomic type is a subtype of another (without access to the TypeHierarchy object) * @param one the first atomic type * @param two the second atomic type * @return true if the first atomic type is equal to, or derived by restriction from, the second atomic * type */ public static boolean isSubType(AtomicType one, AtomicType two) { while (true) { if (one.getFingerprint() == two.getFingerprint()) { return true; } SchemaType s = one.getBaseType(); if (s instanceof AtomicType) { one = (AtomicType)s; } else { return false; } } }
/** * Determine whether one atomic type is a subtype of another (without access to the TypeHierarchy object) * @param one the first atomic type * @param two the second atomic type * @return true if the first atomic type is equal to, or derived by restriction from, the second atomic * type */ public static boolean isSubType(AtomicType one, AtomicType two) { while (true) { if (one.getFingerprint() == two.getFingerprint()) { return true; } SchemaType s = one.getBaseType(); if (s instanceof AtomicType) { one = (AtomicType)s; } else { return false; } } }
/** * Get the index associated with a particular key, a particular source document, * and a particular primitive item type * @param doc the document whose index is required * @param keyFingerprint the name of the key definition * @param itemType the primitive item type of the values being indexed * @return either an index (as a HashMap), or the String "under construction", or null */ private synchronized Object getIndex(DocumentInfo doc, int keyFingerprint, AtomicType itemType) { if (docIndexes==null) { // it's transient, so it will be null when reloading a compiled stylesheet docIndexes = new WeakHashMap(10); } WeakReference ref = (WeakReference)docIndexes.get(doc); if (ref==null) return null; HashMap indexList = (HashMap)ref.get(); if (indexList==null) return null; return indexList.get(new Long(((long)keyFingerprint)<<32 | itemType.getFingerprint())); }
/** * Get the index associated with a particular key, a particular source document, * and a particular primitive item type * @param doc the document whose index is required * @param keyFingerprint the name of the key definition * @param itemType the primitive item type of the values being indexed * @return either an index (as a HashMap), or the String "under construction", or null */ private synchronized Object getIndex(DocumentInfo doc, int keyFingerprint, AtomicType itemType) { if (docIndexes==null) { // it's transient, so it will be null when reloading a compiled stylesheet docIndexes = new WeakHashMap(10); } WeakReference ref = (WeakReference)docIndexes.get(doc); if (ref==null) return null; HashMap indexList = (HashMap)ref.get(); if (indexList==null) return null; return indexList.get(new Long(((long)keyFingerprint)<<32 | itemType.getFingerprint())); }
/** * Get the index associated with a particular key, a particular source document, * and a particular primitive item type * @param doc the document whose index is required * @param keyFingerprint the name of the key definition * @param itemType the primitive item type of the values being indexed * @return either an index (as a HashMap), or the String "under construction", or null */ private synchronized Object getIndex(DocumentInfo doc, int keyFingerprint, AtomicType itemType) { if (docIndexes==null) { // it's transient, so it will be null when reloading a compiled stylesheet docIndexes = new WeakHashMap(10); } WeakReference ref = (WeakReference)docIndexes.get(doc); if (ref==null) return null; HashMap indexList = (HashMap)ref.get(); if (indexList==null) return null; return indexList.get(new Long(((long)keyFingerprint)<<32 | itemType.getFingerprint())); }
/** * Create a cast expression * @param source expression giving the value to be converted * @param target the type to which the value is to be converted * @param allowEmpty true if the expression allows an empty sequence as input, producing * an empty sequence as output. If false, an empty sequence is a type error. */ public CastExpression(Expression source, AtomicType target, boolean allowEmpty) { super(source); this.allowEmpty = allowEmpty; targetType = target; targetPrimitiveType = (AtomicType)target.getPrimitiveItemType(); derived = (targetType.getFingerprint() != targetPrimitiveType.getFingerprint()); adoptChildExpression(source); }
/** * Create a cast expression * @param source expression giving the value to be converted * @param target the type to which the value is to be converted * @param allowEmpty true if the expression allows an empty sequence as input, producing * an empty sequence as output. If false, an empty sequence is a type error. */ public CastExpression(Expression source, AtomicType target, boolean allowEmpty) { super(source); this.allowEmpty = allowEmpty; targetType = target; targetPrimitiveType = (AtomicType)target.getPrimitiveItemType(); derived = (targetType.getFingerprint() != targetPrimitiveType.getFingerprint()); adoptChildExpression(source); }
indexList = (HashMap)indexRef.get(); indexList.put(new Long(((long)keyFingerprint)<<32 | itemType.getFingerprint()), index);
private Calculator assignCalculator(AtomicType type0, AtomicType type1, boolean mustResolve) throws XPathException { Calculator calculator = Calculator.getCalculator(type0.getFingerprint(), type1.getFingerprint(), ArithmeticExpression.mapOpCode(operator), mustResolve); if (calculator == null) { XPathException de = new XPathException("Arithmetic operator is not defined for arguments of types (" + type0.getDescription() + ", " + type1.getDescription() + ")"); de.setLocation(getLocation()); de.setErrorCode("XPTY0004"); throw de; } return calculator; }
private Calculator assignCalculator(AtomicType type0, AtomicType type1, boolean mustResolve) throws XPathException { Calculator calculator = Calculator.getCalculator(type0.getFingerprint(), type1.getFingerprint(), ArithmeticExpression.mapOpCode(operator), mustResolve); if (calculator == null) { XPathException de = new XPathException("Arithmetic operator is not defined for arguments of types (" + type0.getDescription() + ", " + type1.getDescription() + ")"); de.setLocation(getLocation()); de.setErrorCode("XPTY0004"); throw de; } return calculator; }
/** * Test whether a system function with a given name and arity is available. This supports * the function-available() function in XSLT. This method may be called either at compile time * or at run time. * @param functionName * @param arity The number of arguments. This is set to -1 in the case of the single-argument * function-available() function; in this case the method should return true if there is some */ public boolean isAvailable(StructuredQName functionName, int arity) { if (arity != 1 && arity != -1) { return false; } String uri = functionName.getNamespaceURI(); String local = functionName.getLocalName(); if (uri.equals(NamespaceConstant.SCHEMA)) { AtomicType type = (AtomicType)Type.getBuiltInItemType(uri, local); return type != null && type.getFingerprint() != StandardNames.XS_NOTATION; } int fingerprint = config.getNamePool().getFingerprint(uri, local); if (fingerprint == -1) { return false; } else { SchemaType st = config.getSchemaType(fingerprint); return (st != null && st.isAtomicType()); } }
/** * Test whether a system function with a given name and arity is available. This supports * the function-available() function in XSLT. This method may be called either at compile time * or at run time. * @param functionName * @param arity The number of arguments. This is set to -1 in the case of the single-argument * function-available() function; in this case the method should return true if there is some */ public boolean isAvailable(StructuredQName functionName, int arity) { if (arity != 1 && arity != -1) { return false; } String uri = functionName.getNamespaceURI(); String local = functionName.getLocalName(); if (uri.equals(NamespaceConstant.SCHEMA)) { AtomicType type = (AtomicType)Type.getBuiltInItemType(uri, local); return type != null && type.getFingerprint() != StandardNames.XS_NOTATION; } int fingerprint = config.getNamePool().getFingerprint(uri, local); if (fingerprint == -1) { return false; } else { SchemaType st = config.getSchemaType(fingerprint); return (st != null && st.isAtomicType()); } }
int key = (source.getPrimitiveType() << 20) | target.getFingerprint(); Converter converter = converterCache.get(key); if (converter == null) {
/** * Get the type annotation of the current attribute or element node, or atomic value. * The result of this method is undefined unless the most recent event was START_ELEMENT, * ATTRIBUTE, or ATOMIC_VALUE. * * @return the type annotation. This code is the fingerprint of a type name, which may be * resolved to a {@link net.sf.saxon.type.SchemaType} by access to the Configuration. */ public int getTypeAnnotation() { if (treeWalker != null) { return treeWalker.getTypeAnnotation(); } else { Item item = base.current(); if (item instanceof NodeInfo) { return ((NodeInfo)item).getTypeAnnotation(); } else { final TypeHierarchy th = pipe.getConfiguration().getTypeHierarchy(); return ((AtomicType)((AtomicValue)item).getItemType(th)).getFingerprint(); } } }
/** * Get the type annotation of the current attribute or element node, or atomic value. * The result of this method is undefined unless the most recent event was START_ELEMENT, * ATTRIBUTE, or ATOMIC_VALUE. * * @return the type annotation. This code is the fingerprint of a type name, which may be * resolved to a {@link net.sf.saxon.type.SchemaType} by access to the Configuration. */ public int getTypeAnnotation() { if (treeWalker != null) { return treeWalker.getTypeAnnotation(); } else { Item item = base.current(); if (item instanceof NodeInfo) { return ((NodeInfo)item).getTypeAnnotation(); } else { final TypeHierarchy th = pipe.getConfiguration().getTypeHierarchy(); return ((AtomicType)((AtomicValue)item).getItemType(th)).getFingerprint(); } } }
if (type.getFingerprint() == getFingerprint()) {
if (targetType.getFingerprint() == StandardNames.XS_QNAME) { return new QNameValue(prefix, uri, local, BuiltInAtomicType.QNAME, true); } else {
/** * Check that a SequenceType used in the definition of an imported variable or function * is available in the importing module * @param importedType the type that is to be checked * @param declaration the containing query or function definition * @throws net.sf.saxon.trans.XPathException if an error is fonnd. */ public void checkImportedType(SequenceType importedType, Declaration declaration) throws XPathException { ItemType type = importedType.getPrimaryType(); if (type instanceof AnyItemType) { return; } if (type.isAtomicType()) { int f = ((AtomicType)type).getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof ContentTypeTest) { SchemaType annotation = ((ContentTypeTest)type).getSchemaType(); int f = annotation.getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof CombinedNodeTest) { NodeTest[] tests = ((CombinedNodeTest)type).getComponentNodeTests(); for (int i=0; i<tests.length; i++) { SequenceType st = SequenceType.makeSequenceType(tests[i], StaticProperty.EXACTLY_ONE); checkImportedType(st, declaration); } } }
/** * Check that a SequenceType used in the definition of an imported variable or function * is available in the importing module * @param importedType the type that is to be checked * @param declaration the containing query or function definition * @throws net.sf.saxon.trans.XPathException if an error is fonnd. */ public void checkImportedType(SequenceType importedType, Declaration declaration) throws XPathException { ItemType type = importedType.getPrimaryType(); if (type instanceof AnyItemType) { return; } if (type.isAtomicType()) { int f = ((AtomicType)type).getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof ContentTypeTest) { SchemaType annotation = ((ContentTypeTest)type).getSchemaType(); int f = annotation.getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof CombinedNodeTest) { NodeTest[] tests = ((CombinedNodeTest)type).getComponentNodeTests(); for (int i=0; i<tests.length; i++) { SequenceType st = SequenceType.makeSequenceType(tests[i], StaticProperty.EXACTLY_ONE); checkImportedType(st, declaration); } } }
throws XPathException { if (targetType.getFingerprint() == StandardNames.XS_QNAME) { return new QNameValue(prefix, uri, local, BuiltInAtomicType.QNAME, null); } else {