Debian Codegraph @

net/sf/saxon/lib/ConversionRules.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.lib;
9
10 import net.sf.saxon.expr.sort.LRUCache;
11 import net.sf.saxon.om.NotationSet;
12 import net.sf.saxon.om.StandardNames;
13 import net.sf.saxon.type.*;
14 import net.sf.saxon.value.StringToDouble11;
15
16 /**
17 * This class defines a set of rules for converting between different atomic types. It handles the variations
18 * that arise between different versions of the W3C specifications, for example the changes in Name syntax
19 * between XML 1.0 and XML 1.1, the introduction of "+INF" as a permitted xs:double value in XSD 1.1, and so on.
20 * <p>It is possible to nominate a customized <code>ConversionRules</code> object at the level of the
21 * {@link net.sf.saxon.Configuration}, either by instantiating this class and changing the properties, or
22 * by subclassing.</p>
23 *
24 * @see net.sf.saxon.Configuration#setConversionRules(ConversionRules)
25 * @since 9.3
26 */
27
28 public class ConversionRules {
29
30 private StringToDouble stringToDouble = StringToDouble11.getInstance();
31 private NotationSet notationSet; // may be null
32 private URIChecker uriChecker;
33 private boolean allowYearZero = true;
34 private TypeHierarchy typeHierarchy; // may be null
35
36 // These two tables need to be synchronised to make the caching thread-safe
37 private LRUCache<Integer, Converter> converterCache =
38 new LRUCache<>(100, true);
39
40 /**
41 * Default conversion rules. Changed in Saxon 9.9 so these are the XSD 1.1 rules (year zero allowed in dates,
42 * {@code -INF} allowed in {@code xs:double}). Modifying the default conversion rules is inadvisable,
43 * but it could potentially be done in order to retain compatibility with earlier Saxon releases.
44 */
45 public final static ConversionRules DEFAULT = new ConversionRules();
46
47
48 public ConversionRules() {
49 }
50
51 /**
52 * Create a copy of these conversion rules.
53 *
54 * @return a copy of the rules. The cache of converters is NOT copied (because changes to the conversion rules would
55 * invalidate the cache)
56 */
57
58 public ConversionRules copy() {
59 ConversionRules cr = new ConversionRules();
60 copyTo(cr);
61 return cr;
62 }
63
64 /**
65 * Create a copy of these conversion rules.
66 *
67 * @param cr a ConversionRules object which will be updated to hold a copy of the rules.
68 * The cache of converters is NOT copied (because changes to the conversion rules would
69 * invalidate the cache)
70 */
71
72 public void copyTo(ConversionRules cr) {
73 cr.stringToDouble = stringToDouble;
74 cr.notationSet = notationSet;
75 cr.uriChecker = uriChecker;
76 cr.allowYearZero = allowYearZero;
77 cr.typeHierarchy = typeHierarchy;
78 cr.converterCache.clear();
79 }
80
81 public void setTypeHierarchy(TypeHierarchy typeHierarchy) {
82 this.typeHierarchy = typeHierarchy;
83 }
84
85 /**
86 * Set the converter that will be used for converting strings to doubles and floats.
87 *
88 * @param converter the converter to be used. There are two converters in regular use:
89 * they differ only in whether the lexical value "+INF" is recognized as a representation of
90 * positive infinity.
91 */
92
93 public void setStringToDoubleConverter(StringToDouble converter) {
94 this.stringToDouble = converter;
95 }
96
97 /**
98 * Get the converter that will be used for converting strings to doubles and floats.
99 *
100 * @return the converter to be used. There are two converters in regular use:
101 * they differ only in whether the lexical value "+INF" is recognized as a representation of
102 * positive infinity.
103 */
104
105 public StringToDouble getStringToDoubleConverter() {
106 return stringToDouble;
107 }
108
109 /**
110 * Specify the set of notations that are accepted by xs:NOTATION and its subclasses. This is to
111 * support the rule that for a notation to be valid, it must be declared in an xs:notation declaration
112 * in the schema
113 *
114 * @param notations the set of notations that are recognized; or null, to indicate that all notation
115 * names are accepted
116 */
117
118 public void setNotationSet(/*@Nullable*/ NotationSet notations) {
119 this.notationSet = notations;
120 }
121
122 /**
123 * Ask whether a given notation is accepted by xs:NOTATION and its subclasses. This is to
124 * support the rule that for a notation to be valid, it must be declared in an xs:notation declaration
125 * in the schema
126 *
127 * @param uri the namespace URI of the notation
128 * @param local the local part of the name of the notation
129 * @return true if the notation is in the set of recognized notation names
130 */
131
132
133 public boolean isDeclaredNotation(String uri, String local) {
134 //noinspection SimplifiableIfStatement
135 if (notationSet == null) {
136 return true; // in the absence of a known configuration, treat all notations as valid
137 } else {
138 return notationSet.isDeclaredNotation(uri, local);
139 }
140 }
141
142 /**
143 * Set the class to be used for checking URI values. By default, no checking takes place.
144 *
145 * @param checker an object to be used for checking URIs; or null if any string is accepted as an anyURI value
146 */
147
148 public void setURIChecker(URIChecker checker) {
149 this.uriChecker = checker;
150 }
151
152 /**
153 * Ask whether a string is a valid instance of xs:anyURI according to the rules
154 * defined by the current URIChecker
155 *
156 * @param string the string to be checked against the rules for URIs
157 * @return true if the string represents a valid xs:anyURI value
158 */
159
160 public boolean isValidURI(CharSequence string) {
161 return uriChecker == null || uriChecker.isValidURI(string);
162 }
163
164 /**
165 * Say whether year zero is permitted in dates. By default it is not permitted when XSD 1.0 is in use,
166 * but it is permitted when XSD 1.1 is used.
167 *
168 * @param allowed true if year zero is permitted
169 */
170
171 public void setAllowYearZero(boolean allowed) {
172 allowYearZero = allowed;
173 }
174
175 /**
176 * Ask whether year zero is permitted in dates. By default it is not permitted when XSD 1.0 is in use,
177 * but it is permitted when XSD 1.1 is used.
178 *
179 * @return true if year zero is permitted
180 */
181
182 public boolean isAllowYearZero() {
183 return allowYearZero;
184 }
185
186 /**
187 * Get a Converter for a given pair of atomic types. These can be primitive types,
188 * derived types, or user-defined types. The converter implements the casting rules.
189 *
190 * @param source the source type
191 * @param target the target type
192 * @return a Converter if conversion between the two types is possible; or null otherwise
193 */
194
195 /*@Nullable*/
196 public Converter getConverter(AtomicType source, AtomicType target) {
197 // Handle some common cases before looking in the cache
198 if (source == target) {
199 return StringConverter.IdentityConverter.INSTANCE;
200 } else if (source == BuiltInAtomicType.STRING || source == BuiltInAtomicType.UNTYPED_ATOMIC) {
201 return target.getStringConverter(this);
202 } else if (target == BuiltInAtomicType.STRING) {
203 return Converter.ToStringConverter.INSTANCE;
204 } else if (target == BuiltInAtomicType.UNTYPED_ATOMIC) {
205 return Converter.ToUntypedAtomicConverter.INSTANCE;
206 }
207 // For a lookup key, use the primitive type of the source type (always 10 bits) and the
208 // fingerprint of the target type (20 bits)
209 int key = (source.getPrimitiveType() << 20) | target.getFingerprint();
210 Converter converter = converterCache.get(key);
211 if (converter == null) {
212 converter = makeConverter(source, target);
213 if (converter != null) {
214 converterCache.put(key, converter);
215 } else {
216 return null;
217 }
218 }
219 return converter;
220 }
221
222 /**
223 * Create a converter that handles conversion from one primitive type to another.
224 * <p>This method is intended for internal use only. The approved way to get a converter is using the
225 * factory method {@link net.sf.saxon.lib.ConversionRules#getConverter(net.sf.saxon.type.AtomicType, net.sf.saxon.type.AtomicType)}}</p>
226 *
227 * @param sourceType the type of the value to be converted
228 * @param targetType the type of the result of the conversion
229 * @return the converter if one is available; or null if no conversion is possible
230 */
231
232 /*@Nullable*/
233 private Converter makeConverter(AtomicType sourceType, AtomicType targetType) {
234 if (sourceType == targetType) {
235 return StringConverter.IdentityConverter.INSTANCE;
236 }
237
238 int tt = targetType.getFingerprint();
239 int tp = targetType.getPrimitiveType();
240 int st = sourceType.getPrimitiveType();
241
242 if ((st == StandardNames.XS_STRING || st == StandardNames.XS_UNTYPED_ATOMIC) &&
243 (tp == StandardNames.XS_STRING || tp == StandardNames.XS_UNTYPED_ATOMIC)) {
244 return makeStringConverter(targetType);
245 }
246
247 if (!targetType.isPrimitiveType()) {
248 AtomicType primTarget = targetType.getPrimitiveItemType();
249 if (sourceType == primTarget) {
250 return new Converter.DownCastingConverter(targetType, this);
251 } else if (st == StandardNames.XS_STRING || st == StandardNames.XS_UNTYPED_ATOMIC) {
252 return makeStringConverter(targetType);
253 } else {
254 Converter stageOne = makeConverter(sourceType, primTarget);
255 if (stageOne == null) {
256 return null;
257 }
258 Converter stageTwo = new Converter.DownCastingConverter(targetType, this);
259 return new Converter.TwoPhaseConverter(stageOne, stageTwo);
260 }
261 }
262
263
264 if (st == tt) {
265 // we are casting between subtypes of the same primitive type.
266 if (typeHierarchy != null && typeHierarchy.isSubType(sourceType, targetType)) {
267 return new Converter.UpCastingConverter(targetType);
268 }
269 Converter upcast = new Converter.UpCastingConverter(sourceType.getPrimitiveItemType());
270 Converter downcast = new Converter.DownCastingConverter(targetType, this);
271 return new Converter.TwoPhaseConverter(upcast, downcast);
272 }
273
274 switch (tt) {
275 case StandardNames.XS_UNTYPED_ATOMIC:
276 return Converter.ToUntypedAtomicConverter.INSTANCE;
277 case StandardNames.XS_STRING:
278 return Converter.ToStringConverter.INSTANCE;
279 case StandardNames.XS_FLOAT:
280 switch (st) {
281 case StandardNames.XS_UNTYPED_ATOMIC:
282 case StandardNames.XS_STRING:
283 return new StringConverter.StringToFloat(this);
284 case StandardNames.XS_DOUBLE:
285 case StandardNames.XS_DECIMAL:
286 case StandardNames.XS_INTEGER:
287 case StandardNames.XS_NUMERIC:
288 return Converter.NumericToFloat.INSTANCE;
289 case StandardNames.XS_BOOLEAN:
290 return Converter.BooleanToFloat.INSTANCE;
291 default:
292 return null;
293 }
294 case StandardNames.XS_DOUBLE:
295 case StandardNames.XS_NUMERIC:
296 switch (st) {
297 case StandardNames.XS_UNTYPED_ATOMIC:
298 case StandardNames.XS_STRING:
299 return stringToDouble;
300 case StandardNames.XS_FLOAT:
301 case StandardNames.XS_DECIMAL:
302 case StandardNames.XS_INTEGER:
303 case StandardNames.XS_NUMERIC:
304 return Converter.NumericToDouble.INSTANCE;
305 case StandardNames.XS_BOOLEAN:
306 return Converter.BooleanToDouble.INSTANCE;
307 default:
308 return null;
309 }
310 case StandardNames.XS_DECIMAL:
311 switch (st) {
312 case StandardNames.XS_UNTYPED_ATOMIC:
313 case StandardNames.XS_STRING:
314 return StringConverter.StringToDecimal.INSTANCE;
315 case StandardNames.XS_FLOAT:
316 return Converter.FloatToDecimal.INSTANCE;
317 case StandardNames.XS_DOUBLE:
318 return Converter.DoubleToDecimal.INSTANCE;
319 case StandardNames.XS_INTEGER:
320 return Converter.IntegerToDecimal.INSTANCE;
321 case StandardNames.XS_NUMERIC:
322 return Converter.NumericToDecimal.INSTANCE;
323 case StandardNames.XS_BOOLEAN:
324 return Converter.BooleanToDecimal.INSTANCE;
325 default:
326 return null;
327 }
328
329 case StandardNames.XS_INTEGER:
330 switch (st) {
331 case StandardNames.XS_UNTYPED_ATOMIC:
332 case StandardNames.XS_STRING:
333 return StringConverter.StringToInteger.INSTANCE;
334 case StandardNames.XS_FLOAT:
335 return Converter.FloatToInteger.INSTANCE;
336 case StandardNames.XS_DOUBLE:
337 return Converter.DoubleToInteger.INSTANCE;
338 case StandardNames.XS_DECIMAL:
339 return Converter.DecimalToInteger.INSTANCE;
340 case StandardNames.XS_NUMERIC:
341 return Converter.NumericToInteger.INSTANCE;
342 case StandardNames.XS_BOOLEAN:
343 return Converter.BooleanToInteger.INSTANCE;
344 default:
345 return null;
346 }
347 case StandardNames.XS_DURATION:
348 switch (st) {
349 case StandardNames.XS_UNTYPED_ATOMIC:
350 case StandardNames.XS_STRING:
351 return StringConverter.StringToDuration.INSTANCE;
352 case StandardNames.XS_DAY_TIME_DURATION:
353 case StandardNames.XS_YEAR_MONTH_DURATION:
354 return new Converter.UpCastingConverter(BuiltInAtomicType.DURATION);
355 default:
356 return null;
357 }
358 case StandardNames.XS_YEAR_MONTH_DURATION:
359 switch (st) {
360 case StandardNames.XS_UNTYPED_ATOMIC:
361 case StandardNames.XS_STRING:
362 return StringConverter.StringToYearMonthDuration.INSTANCE;
363 case StandardNames.XS_DURATION:
364 case StandardNames.XS_DAY_TIME_DURATION:
365 return Converter.DurationToYearMonthDuration.INSTANCE;
366 default:
367 return null;
368 }
369 case StandardNames.XS_DAY_TIME_DURATION:
370 switch (st) {
371 case StandardNames.XS_UNTYPED_ATOMIC:
372 case StandardNames.XS_STRING:
373 return StringConverter.StringToDayTimeDuration.INSTANCE;
374 case StandardNames.XS_DURATION:
375 case StandardNames.XS_YEAR_MONTH_DURATION:
376 return Converter.DurationToDayTimeDuration.INSTANCE;
377 default:
378 return null;
379 }
380 case StandardNames.XS_DATE_TIME:
381 switch (st) {
382 case StandardNames.XS_UNTYPED_ATOMIC:
383 case StandardNames.XS_STRING:
384 return new StringConverter.StringToDateTime(this);
385 case StandardNames.XS_DATE:
386 return Converter.DateToDateTime.INSTANCE;
387 default:
388 return null;
389 }
390 case StandardNames.XS_TIME:
391 switch (st) {
392 case StandardNames.XS_UNTYPED_ATOMIC:
393 case StandardNames.XS_STRING:
394 return StringConverter.StringToTime.INSTANCE;
395 case StandardNames.XS_DATE_TIME:
396 return Converter.DateTimeToTime.INSTANCE;
397 default:
398 return null;
399 }
400 case StandardNames.XS_DATE:
401 switch (st) {
402 case StandardNames.XS_UNTYPED_ATOMIC:
403 case StandardNames.XS_STRING:
404 return new StringConverter.StringToDate(this);
405 case StandardNames.XS_DATE_TIME:
406 return Converter.DateTimeToDate.INSTANCE;
407 default:
408 return null;
409 }
410 case StandardNames.XS_G_YEAR_MONTH:
411 switch (st) {
412 case StandardNames.XS_UNTYPED_ATOMIC:
413 case StandardNames.XS_STRING:
414 return new StringConverter.StringToGYearMonth(this);
415 case StandardNames.XS_DATE:
416 return Converter.TwoPhaseConverter.makeTwoPhaseConverter(
417 BuiltInAtomicType.DATE, BuiltInAtomicType.DATE_TIME, BuiltInAtomicType.G_YEAR_MONTH, this);
418 case StandardNames.XS_DATE_TIME:
419 return Converter.DateTimeToGYearMonth.INSTANCE;
420 default:
421 return null;
422 }
423 case StandardNames.XS_G_YEAR:
424 switch (st) {
425 case StandardNames.XS_UNTYPED_ATOMIC:
426 case StandardNames.XS_STRING:
427 return new StringConverter.StringToGYear(this);
428 case StandardNames.XS_DATE:
429 return Converter.TwoPhaseConverter.makeTwoPhaseConverter(BuiltInAtomicType.DATE, BuiltInAtomicType.DATE_TIME,
430 BuiltInAtomicType.G_YEAR, this);
431 case StandardNames.XS_DATE_TIME:
432 return Converter.DateTimeToGYear.INSTANCE;
433 default:
434 return null;
435 }
436 case StandardNames.XS_G_MONTH_DAY:
437 switch (st) {
438 case StandardNames.XS_UNTYPED_ATOMIC:
439 case StandardNames.XS_STRING:
440 return StringConverter.StringToGMonthDay.INSTANCE;
441 case StandardNames.XS_DATE:
442 return Converter.TwoPhaseConverter.makeTwoPhaseConverter(BuiltInAtomicType.DATE, BuiltInAtomicType.DATE_TIME,
443 BuiltInAtomicType.G_MONTH_DAY, this);
444 case StandardNames.XS_DATE_TIME:
445 return Converter.DateTimeToGMonthDay.INSTANCE;
446 default:
447 return null;
448 }
449 case StandardNames.XS_G_DAY:
450 switch (st) {
451 case StandardNames.XS_UNTYPED_ATOMIC:
452 case StandardNames.XS_STRING:
453 return StringConverter.StringToGDay.INSTANCE;
454 case StandardNames.XS_DATE:
455 return Converter.TwoPhaseConverter.makeTwoPhaseConverter(BuiltInAtomicType.DATE, BuiltInAtomicType.DATE_TIME,
456 BuiltInAtomicType.G_DAY, this);
457 case StandardNames.XS_DATE_TIME:
458 return Converter.DateTimeToGDay.INSTANCE;
459 default:
460 return null;
461 }
462 case StandardNames.XS_G_MONTH:
463 switch (st) {
464 case StandardNames.XS_UNTYPED_ATOMIC:
465 case StandardNames.XS_STRING:
466 return StringConverter.StringToGMonth.INSTANCE;
467 case StandardNames.XS_DATE:
468 return Converter.TwoPhaseConverter.makeTwoPhaseConverter(BuiltInAtomicType.DATE, BuiltInAtomicType.DATE_TIME,
469 BuiltInAtomicType.G_MONTH, this);
470 case StandardNames.XS_DATE_TIME:
471 return Converter.DateTimeToGMonth.INSTANCE;
472 default:
473 return null;
474 }
475 case StandardNames.XS_BOOLEAN:
476 switch (st) {
477 case StandardNames.XS_UNTYPED_ATOMIC:
478 case StandardNames.XS_STRING:
479 return StringConverter.StringToBoolean.INSTANCE;
480 case StandardNames.XS_FLOAT:
481 case StandardNames.XS_DOUBLE:
482 case StandardNames.XS_DECIMAL:
483 case StandardNames.XS_INTEGER:
484 case StandardNames.XS_NUMERIC:
485 return Converter.NumericToBoolean.INSTANCE;
486 default:
487 return null;
488 }
489 case StandardNames.XS_BASE64_BINARY:
490 switch (st) {
491 case StandardNames.XS_UNTYPED_ATOMIC:
492 case StandardNames.XS_STRING:
493 return StringConverter.StringToBase64Binary.INSTANCE;
494 case StandardNames.XS_HEX_BINARY:
495 return Converter.HexBinaryToBase64Binary.INSTANCE;
496 default:
497 return null;
498 }
499 case StandardNames.XS_HEX_BINARY:
500 switch (st) {
501 case StandardNames.XS_UNTYPED_ATOMIC:
502 case StandardNames.XS_STRING:
503 return StringConverter.StringToHexBinary.INSTANCE;
504 case StandardNames.XS_BASE64_BINARY:
505 return Converter.Base64BinaryToHexBinary.INSTANCE;
506 default:
507 return null;
508 }
509 case StandardNames.XS_ANY_URI:
510 switch (st) {
511 case StandardNames.XS_UNTYPED_ATOMIC:
512 case StandardNames.XS_STRING:
513 return new StringConverter.StringToAnyURI(this);
514 default:
515 return null;
516 }
517 case StandardNames.XS_QNAME:
518 switch (st) {
519 case StandardNames.XS_UNTYPED_ATOMIC:
520 case StandardNames.XS_STRING:
521 return new StringConverter.StringToQName(this);
522 case StandardNames.XS_NOTATION:
523 return Converter.NotationToQName.INSTANCE;
524 default:
525 return null;
526 }
527 case StandardNames.XS_NOTATION:
528 switch (st) {
529 case StandardNames.XS_UNTYPED_ATOMIC:
530 case StandardNames.XS_STRING:
531 return new StringConverter.StringToNotation(this);
532 case StandardNames.XS_QNAME:
533 return Converter.QNameToNotation.INSTANCE;
534 default:
535 return null;
536 }
537
538 case StandardNames.XS_ANY_ATOMIC_TYPE:
539 return StringConverter.IdentityConverter.INSTANCE;
540
541 default:
542 throw new IllegalArgumentException("Unknown primitive type " + tt);
543 }
544 }
545
546 /**
547 * Static factory method to get a StringConverter for a specific target type
548 *
549 * @param targetType the target type of the conversion
550 * @return a StringConverter that can be used to convert strings to the target type, or to
551 * validate strings against the target type
552 */
553
554 /*@NotNull*/
555 private StringConverter makeStringConverter(/*@NotNull*/ final AtomicType targetType) {
556
557 int tt = targetType.getPrimitiveType();
558 if (targetType.isBuiltInType()) {
559 if (tt == StandardNames.XS_STRING) {
560 switch (targetType.getFingerprint()) {
561 case StandardNames.XS_STRING:
562 return StringConverter.StringToString.INSTANCE;
563 case StandardNames.XS_NORMALIZED_STRING:
564 return StringConverter.StringToNormalizedString.INSTANCE;
565 case StandardNames.XS_TOKEN:
566 return StringConverter.StringToToken.INSTANCE;
567 case StandardNames.XS_LANGUAGE:
568 return StringConverter.StringToLanguage.INSTANCE;
569 case StandardNames.XS_NAME:
570 return StringConverter.StringToName.INSTANCE;
571 case StandardNames.XS_NCNAME:
572 return StringConverter.StringToNCName.TO_NCNAME;
573 case StandardNames.XS_ID:
574 return StringConverter.StringToNCName.TO_ID;
575 case StandardNames.XS_IDREF:
576 return StringConverter.StringToNCName.TO_IDREF;
577 case StandardNames.XS_ENTITY:
578 return StringConverter.StringToNCName.TO_ENTITY;
579 case StandardNames.XS_NMTOKEN:
580 return StringConverter.StringToNMTOKEN.INSTANCE;
581 default:
582 throw new AssertionError("Unknown built-in subtype of xs:string");
583
584 }
585 } else if (tt == StandardNames.XS_UNTYPED_ATOMIC) {
586 return StringConverter.StringToUntypedAtomic.INSTANCE;
587 } else if (targetType.isPrimitiveType()) {
588 // converter to built-in types unrelated to xs:string
589 Converter converter = getConverter(BuiltInAtomicType.STRING, targetType);
590 assert converter != null;
591 return (StringConverter) converter;
592 } else if (tt == StandardNames.XS_INTEGER) {
593 return new StringConverter.StringToIntegerSubtype((BuiltInAtomicType) targetType);
594 } else {
595 switch (targetType.getFingerprint()) {
596 case StandardNames.XS_DAY_TIME_DURATION:
597 return StringConverter.StringToDayTimeDuration.INSTANCE;
598 case StandardNames.XS_YEAR_MONTH_DURATION:
599 return StringConverter.StringToYearMonthDuration.INSTANCE;
600 case StandardNames.XS_DATE_TIME_STAMP:
601 StringConverter first = new StringConverter.StringToDateTime(this);
602 Converter.DownCastingConverter second = new Converter.DownCastingConverter(targetType, this);
603 return new StringConverter.StringToNonStringDerivedType(first, second);
604 default:
605 throw new AssertionError("Unknown built in type " + targetType);
606 }
607 }
608 } else {
609 if (tt == StandardNames.XS_STRING) {
610 if (targetType.getBuiltInBaseType() == BuiltInAtomicType.STRING) {
611 // converter to user-defined subtypes of xs:string
612 return new StringConverter.StringToStringSubtype(this, targetType);
613 } else {
614 // converter to user-defined subtypes of built-in subtypes of xs:string
615 return new StringConverter.StringToDerivedStringSubtype(this, targetType);
616 }
617 } else {
618 // converter to user-defined types derived from types other than xs:string
619 StringConverter first = targetType.getPrimitiveItemType().getStringConverter(this);
620 Converter.DownCastingConverter second = new Converter.DownCastingConverter(targetType, this);
621 return new StringConverter.StringToNonStringDerivedType(first, second);
622 }
623 }
624
625 }
626
627 }
628