Debian Codegraph @

net/sf/saxon/type/ExternalObjectType.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.type;
9
10 import net.sf.saxon.om.StructuredQName;
11 import net.sf.saxon.trans.SaxonErrorCode;
12 import net.sf.saxon.trans.XPathException;
13
14 /**
15 * This class represents the type of an external object returned by
16 * an extension function, or supplied as an external variable/parameter.
17 */
18 public abstract class ExternalObjectType extends AnyExternalObjectType {
19
20 /**
21 * Get the name of this type.
22 *
23 * @return the fully qualified name of the Java or .NET class.
24 */
25
26 public abstract String getName();
27
28 /**
29 * Get the target namespace of this type. For Java this is always {@link net.sf.saxon.lib.NamespaceConstant#JAVA_TYPE}.
30 * For .net it is always {@link net.sf.saxon.lib.NamespaceConstant#DOT_NET_TYPE}
31 *
32 * @return the target namespace of this type definition.
33 */
34
35 public abstract String getTargetNamespace();
36
37 /**
38 * Ask whether this is an external type
39 * @return true (it is)
40 */
41
42 public boolean isExternalType(){
43 return true;
44 }
45
46 /**
47 * Get the name of this type
48 * @return a name whose namespace indicates the space of Java or .net classes, and whose local name
49 * is derived from the fully qualified name of the Java or .net class
50 */
51
52 public abstract StructuredQName getTypeName();
53
54 /**
55 * Ask whether this is a plain type (a type whose instances are always atomic values)
56 * @return false. External object types are not considered to be atomic types
57 */
58
59 public final boolean isPlainType() {
60 return false;
61 }
62
63 /**
64 * Generate Javascript code to test whether an item conforms to this item type
65 *
66 * @return a Javascript instruction or sequence of instructions, which can be used as the body
67 * of a Javascript function, and which returns a boolean indication whether the value of the
68 * variable "item" is an instance of this item type.
69 * @throws XPathException if JS code cannot be generated for this item type, for example because
70 * the test is schema-aware.
71 * @param knownToBe
72 * @param targetVersion
73 */
74
75 public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) throws XPathException {
76 throw new XPathException("Cannot generate JS code for external object tests", SaxonErrorCode.SXJS0001);
77 }
78
79 /**
80 * Generate Javascript code to convert a supplied Javascript value to this item type,
81 * if conversion is possible, or throw an error otherwise.
82 *
83 * @param errorCode the error to be thrown if conversion is not possible
84 * @param targetVersion the version of Saxon-JS
85 * @return a Javascript instruction or sequence of instructions, which can be used as the body
86 * of a Javascript function, and which returns the result of conversion to this type, or throws
87 * an error if conversion is not possible. The variable "val" will hold the supplied Javascript
88 * value.
89 */
90 public String generateJavaScriptItemTypeAcceptor(String errorCode, int targetVersion) throws XPathException {
91 throw new XPathException("Cannot generate JS code for external object tests", SaxonErrorCode.SXJS0001);
92 }
93
94
95
96 }