Debian Codegraph @

net/sf/saxon/functions/AccessorFn.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.functions;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.om.Item;
12 import net.sf.saxon.trans.XPathException;
13 import net.sf.saxon.value.AtomicValue;
14 import net.sf.saxon.value.Int64Value;
15 import net.sf.saxon.value.IntegerValue;
16
17 /**
18 * This class supports the get_X_from_Y functions defined in XPath 2.0
19 */
20
21 public abstract class AccessorFn extends ScalarSystemFunction {
22
23 public enum Component {
24 YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS, TIMEZONE,
25 LOCALNAME, NAMESPACE, PREFIX, MICROSECONDS, NANOSECONDS, WHOLE_SECONDS, YEAR_ALLOWING_ZERO
26 }
27
28 public abstract Component getComponentId();
29
30 /**
31 * For an expression that returns an integer or a sequence of integers, get
32 * a lower and upper bound on the values of the integers that may be returned, from
33 * static analysis. The default implementation returns null, meaning "unknown" or
34 * "not applicable". Other implementations return an array of two IntegerValue objects,
35 * representing the lower and upper bounds respectively. The values
36 * UNBOUNDED_LOWER and UNBOUNDED_UPPER are used by convention to indicate that
37 * the value may be arbitrarily large. The values MAX_STRING_LENGTH and MAX_SEQUENCE_LENGTH
38 * are used to indicate values limited by the size of a string or the size of a sequence.
39 *
40 * @return the lower and upper bounds of integer values in the result, or null to indicate
41 * unknown or not applicable.
42 */
43 //@Override
44 public IntegerValue[] getIntegerBounds() {
45 switch (getComponentId()) {
46 case YEAR:
47 return new IntegerValue[]{Int64Value.makeIntegerValue(-100000), Int64Value.makeIntegerValue(+100000)};
48 case MONTH:
49 return new IntegerValue[]{Int64Value.makeIntegerValue(-11), Int64Value.makeIntegerValue(+11)};
50 case DAY:
51 return new IntegerValue[]{Int64Value.makeIntegerValue(-31), Int64Value.makeIntegerValue(+31)};
52 case HOURS:
53 return new IntegerValue[]{Int64Value.makeIntegerValue(-24), Int64Value.makeIntegerValue(+24)};
54 case MINUTES:
55 return new IntegerValue[]{Int64Value.makeIntegerValue(-59), Int64Value.makeIntegerValue(+59)};
56 case SECONDS:
57 return new IntegerValue[]{Int64Value.makeIntegerValue(-59), Int64Value.makeIntegerValue(+59)};
58 default:
59 return null;
60 }
61 }
62
63 /**
64 * Get the required component
65 * @return the integer code identifying of the required component
66 */
67
68 public int getRequiredComponent() {
69 return getComponentId().ordinal();
70 }
71
72 /**
73 * Evaluate the expression
74 */
75
76 public AtomicValue evaluate(Item item, XPathContext context) throws XPathException {
77 return ((AtomicValue)item).getComponent(getComponentId());
78 }
79
80 public String getCompilerName() {
81 return "AccessorFnCompiler";
82 }
83
84
85 public static class YearFromDateTime extends AccessorFn {
86
87 @Override
88 public Component getComponentId() {
89 return Component.YEAR;
90 }
91 }
92
93 public static class MonthFromDateTime extends AccessorFn {
94
95 @Override
96 public Component getComponentId() {
97 return Component.MONTH;
98 }
99 }
100
101 public static class DayFromDateTime extends AccessorFn {
102
103 @Override
104 public Component getComponentId() {
105 return Component.DAY;
106 }
107 }
108
109 public static class HoursFromDateTime extends AccessorFn {
110
111 @Override
112 public Component getComponentId() {
113 return Component.HOURS;
114 }
115 }
116
117 public static class MinutesFromDateTime extends AccessorFn {
118
119 @Override
120 public Component getComponentId() {
121 return Component.MINUTES;
122 }
123 }
124
125 public static class SecondsFromDateTime extends AccessorFn {
126
127 @Override
128 public Component getComponentId() {
129 return Component.SECONDS;
130 }
131 }
132
133 public static class TimezoneFromDateTime extends AccessorFn {
134
135 @Override
136 public Component getComponentId() {
137 return Component.TIMEZONE;
138 }
139 }
140
141 public static class YearFromDate extends AccessorFn {
142
143 @Override
144 public Component getComponentId() {
145 return Component.YEAR;
146 }
147 }
148
149 public static class MonthFromDate extends AccessorFn {
150
151 @Override
152 public Component getComponentId() {
153 return Component.MONTH;
154 }
155 }
156
157 public static class DayFromDate extends AccessorFn {
158
159 @Override
160 public Component getComponentId() {
161 return Component.DAY;
162 }
163 }
164
165 public static class TimezoneFromDate extends AccessorFn {
166
167 @Override
168 public Component getComponentId() {
169 return Component.TIMEZONE;
170 }
171 }
172
173 public static class HoursFromTime extends AccessorFn {
174
175 @Override
176 public Component getComponentId() {
177 return Component.HOURS;
178 }
179 }
180
181 public static class MinutesFromTime extends AccessorFn {
182
183 @Override
184 public Component getComponentId() {
185 return Component.MINUTES;
186 }
187 }
188
189 public static class SecondsFromTime extends AccessorFn {
190
191 @Override
192 public Component getComponentId() {
193 return Component.SECONDS;
194 }
195 }
196
197 public static class TimezoneFromTime extends AccessorFn {
198
199 @Override
200 public Component getComponentId() {
201 return Component.TIMEZONE;
202 }
203 }
204
205 public static class YearsFromDuration extends AccessorFn {
206
207 @Override
208 public Component getComponentId() {
209 return Component.YEAR;
210 }
211 }
212
213 public static class MonthsFromDuration extends AccessorFn {
214
215 @Override
216 public Component getComponentId() {
217 return Component.MONTH;
218 }
219 }
220
221 public static class DaysFromDuration extends AccessorFn {
222
223 @Override
224 public Component getComponentId() {
225 return Component.DAY;
226 }
227 }
228
229 public static class HoursFromDuration extends AccessorFn {
230
231 @Override
232 public Component getComponentId() {
233 return Component.HOURS;
234 }
235 }
236
237 public static class MinutesFromDuration extends AccessorFn {
238
239 @Override
240 public Component getComponentId() {
241 return Component.MINUTES;
242 }
243 }
244
245
246 public static class SecondsFromDuration extends AccessorFn {
247
248 @Override
249 public Component getComponentId() {
250 return Component.SECONDS;
251 }
252 }
253
254 public static class LocalNameFromQName extends AccessorFn {
255
256 @Override
257 public Component getComponentId() {
258 return Component.LOCALNAME;
259 }
260 }
261
262 public static class PrefixFromQName extends AccessorFn {
263
264 @Override
265 public Component getComponentId() {
266 return Component.PREFIX;
267 }
268 }
269
270 public static class NamespaceUriFromQName extends AccessorFn {
271
272 @Override
273 public Component getComponentId() {
274 return Component.NAMESPACE;
275 }
276 }
277
278 }
279