Debian Codegraph @

net/sf/saxon/expr/StaticContext.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.expr;
9
10 import net.sf.saxon.Configuration;
11 import net.sf.saxon.expr.parser.Location;
12 import net.sf.saxon.expr.parser.OptimizerOptions;
13 import net.sf.saxon.expr.parser.RetainedStaticContext;
14 import net.sf.saxon.functions.FunctionLibrary;
15 import net.sf.saxon.om.NamespaceResolver;
16 import net.sf.saxon.om.StructuredQName;
17 import net.sf.saxon.trans.DecimalFormatManager;
18 import net.sf.saxon.trans.KeyManager;
19 import net.sf.saxon.trans.XPathException;
20 import net.sf.saxon.type.ItemType;
21
22 import java.util.Set;
23
24 /**
25 * A StaticContext contains the information needed while an expression or pattern
26 * is being parsed. The information is also sometimes needed at run-time.
27 */
28
29 public interface StaticContext {
30
31 /**
32 * Get the system configuration
33 *
34 * @return the Saxon configuration
35 */
36
37 Configuration getConfiguration();
38
39 /**
40 * Get information about the containing package (unit of compilation)
41 * @return the package data
42 */
43
44 PackageData getPackageData();
45
46 /**
47 * Construct a dynamic context for early evaluation of constant subexpressions.
48 *
49 * @return a newly constructed dynamic context
50 */
51
52 XPathContext makeEarlyEvaluationContext();
53
54 /**
55 * Construct a RetainedStaticContext, which extracts information from this StaticContext
56 * to provide the subset of static context information that is potentially needed
57 * during expression evaluation
58 * @return a RetainedStaticContext object: either a newly created one, or one that is
59 * reused from a previous invocation.
60 */
61
62 RetainedStaticContext makeRetainedStaticContext();
63
64 /**
65 * Get the containing location. This is location information relevant to an expression or query
66 * as a whole. In the case of an XPath expression held in a node of an XML document, it will
67 * provide the location of that node. In the case of a query held in a file, it contains the
68 * location of the file (in its systemId property). The method does NOT provide fine-grained
69 * location information for each contained subexpression. The location that is returned should
70 * be immutable for the duration of parsing of an XPath expression or query.
71 *
72 * @return the containing location
73 */
74
75 Location getContainingLocation();
76
77 /**
78 * Issue a compile-time warning.
79 * @param message The warning message. This should not contain any prefix such as "Warning".
80 * @param locator the location of the construct in question. May be null.
81 */
82
83 void issueWarning(String message, Location locator);
84
85 /**
86 * Get the System ID of the container of the expression. This is the containing
87 * entity (file) and is therefore useful for diagnostics. Use getBaseURI() to get
88 * the base URI, which may be different.
89 *
90 * @return the system ID
91 */
92
93 String getSystemId();
94
95 /**
96 * Get the static base URI, for resolving any relative URI's used
97 * in the expression.
98 * Used by the document(), doc(), resolve-uri(), and base-uri() functions.
99 * May return null if the base URI is not known.
100 *
101 * @return the static base URI, or null if not known
102 */
103
104 String getStaticBaseURI();
105
106 /**
107 * Bind a variable used in this expression to the Binding object in which it is declared
108 *
109 * @param qName The name of the variable
110 * @return an expression representing the variable reference, This will often be
111 * a {@link VariableReference}, suitably initialized to refer to the corresponding variable declaration,
112 * but in general it can be any expression which returns the variable's value when evaluated.
113 * @throws XPathException if the variable cannot be bound (has not been declared)
114 */
115
116 Expression bindVariable(StructuredQName qName) throws XPathException;
117
118 /**
119 * Get the function library containing all the in-scope functions available in this static
120 * context
121 *
122 * @return the function library
123 */
124
125 FunctionLibrary getFunctionLibrary();
126
127 /**
128 * Get the name of the default collation.
129 *
130 * @return the name of the default collation; or the name of the codepoint collation
131 * if no default collation has been defined
132 */
133
134 String getDefaultCollationName();
135
136 /**
137 * Get the default XPath namespace for elements and types
138 *
139 * @return the default namespace, or NamespaceConstant.NULL for the non-namespace
140 */
141
142 String getDefaultElementNamespace();
143
144 /**
145 * Get the default function namespace
146 *
147 * @return the default namespace for function names
148 */
149
150 String getDefaultFunctionNamespace();
151
152 /**
153 * Determine whether backwards compatibility mode is used
154 *
155 * @return true if 1.0 compaibility mode is in force.
156 */
157
158 boolean isInBackwardsCompatibleMode();
159
160 /**
161 * Ask whether a Schema for a given target namespace has been imported. Note that the
162 * in-scope element declarations, attribute declarations and schema types are the types registered
163 * with the (schema-aware) configuration, provided that their namespace URI is registered
164 * in the static context as being an imported schema namespace. (A consequence of this is that
165 * within a Configuration, there can only be one schema for any given namespace, including the
166 * null namespace).
167 *
168 * @param namespace the target namespace in question
169 * @return true if the given namespace has been imported
170 */
171
172 boolean isImportedSchema(String namespace);
173
174 /**
175 * Get the set of imported schemas
176 *
177 * @return a Set, the set of URIs representing the target namespaces of imported schemas,
178 * using the zero-length string to denote the "null" namespace.
179 */
180
181 Set<String> getImportedSchemaNamespaces();
182
183 /**
184 * Get a namespace resolver to resolve the namespaces declared in this static context.
185 *
186 * @return a namespace resolver.
187 */
188
189 NamespaceResolver getNamespaceResolver();
190
191 /**
192 * Get the required type of the context item. If no type has been explicitly declared for the context
193 * item, an instance of AnyItemType (representing the type item()) is returned.
194 *
195 * @return the required type of the context item
196 * @since 9.3
197 */
198
199 ItemType getRequiredContextItemType();
200
201 /**
202 * Get a DecimalFormatManager to resolve the names of decimal formats used in calls
203 * to the format-number() function.
204 *
205 * @return the decimal format manager for this static context, or null if no named decimal
206 * formats are available in this environment.
207 * @since 9.2
208 */
209
210 DecimalFormatManager getDecimalFormatManager();
211
212 /**
213 * Get the XPath language level supported, as an integer (being the actual version
214 * number times ten). In Saxon 9.9 the possible values are 20 (XPath 2.0), 30 (XPath 3.0),
215 * 31 (XPath 3.1), and 305 (XPath 3.0 plus the extensions defined in XSLT 3.0).
216 *
217 * @return the XPath language level; the return value will be either 20, 30, 305, or 31
218 * @since 9.7
219 */
220
221 int getXPathVersion();
222
223 /**
224 * Get the KeyManager, containing definitions of keys available for use.
225 *
226 * @return the KeyManager. This is used to resolve key names, both explicit calls
227 * on key() used in XSLT, and system-generated calls on key() which may
228 * also appear in XQuery and XPath
229 */
230
231 KeyManager getKeyManager();
232
233 /**
234 * Get type alias. This is a Saxon extension. A type alias is a QName which can
235 * be used as a shorthand for an itemtype, using the syntax ~typename anywhere that
236 * an item type is permitted.
237 * @param typeName the name of the type alias
238 * @return the corresponding item type, if the name is recognised; otherwise null.
239 */
240
241 ItemType resolveTypeAlias(StructuredQName typeName);
242
243 /**
244 * Get the optimization options in use. By default these are taken from the
245 * {@link Configuration}
246 * @return the optimization options in use
247 */
248
249 default OptimizerOptions getOptimizerOptions() {
250 return getConfiguration().getOptimizerOptions();
251 }
252
253 }
254