1 /* |
1 /* |
2 * reserved comment block |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT REMOVE OR ALTER! |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
50 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; |
50 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; |
51 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; |
51 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; |
52 import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList; |
52 import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList; |
53 import java.math.BigInteger; |
53 import java.math.BigInteger; |
54 import java.util.AbstractList; |
54 import java.util.AbstractList; |
|
55 import java.util.ArrayList; |
|
56 import java.util.List; |
55 import java.util.Locale; |
57 import java.util.Locale; |
56 import java.util.StringTokenizer; |
58 import java.util.StringTokenizer; |
57 import java.util.Vector; |
|
58 import org.w3c.dom.TypeInfo; |
59 import org.w3c.dom.TypeInfo; |
59 |
60 |
60 /** |
61 /** |
61 * @xerces.internal |
62 * @xerces.internal |
62 * |
63 * |
266 private int fLength = -1; |
267 private int fLength = -1; |
267 private int fMinLength = -1; |
268 private int fMinLength = -1; |
268 private int fMaxLength = -1; |
269 private int fMaxLength = -1; |
269 private int fTotalDigits = -1; |
270 private int fTotalDigits = -1; |
270 private int fFractionDigits = -1; |
271 private int fFractionDigits = -1; |
271 private Vector fPattern; |
272 private List<RegularExpression> fPattern; |
272 private Vector fPatternStr; |
273 private List<String> fPatternStr; |
273 private ValidatedInfo[] fEnumeration; |
274 private ValidatedInfo[] fEnumeration; |
274 private int fEnumerationSize; |
275 private int fEnumerationSize; |
275 private ShortList fEnumerationTypeList; |
276 private ShortList fEnumerationTypeList; |
276 private ObjectList fEnumerationItemTypeList; |
277 private ObjectList fEnumerationItemTypeList; |
277 private StringList fLexicalPattern; |
278 private StringList fLexicalPattern; |
843 regex = new RegularExpression(facets.pattern, "X", context.getLocale()); |
844 regex = new RegularExpression(facets.pattern, "X", context.getLocale()); |
844 } catch (Exception e) { |
845 } catch (Exception e) { |
845 reportError("InvalidRegex", new Object[]{facets.pattern, e.getLocalizedMessage()}); |
846 reportError("InvalidRegex", new Object[]{facets.pattern, e.getLocalizedMessage()}); |
846 } |
847 } |
847 if (regex != null) { |
848 if (regex != null) { |
848 fPattern = new Vector(); |
849 fPattern = new ArrayList<>(); |
849 fPattern.addElement(regex); |
850 fPattern.add(regex); |
850 fPatternStr = new Vector(); |
851 fPatternStr = new ArrayList<>(); |
851 fPatternStr.addElement(facets.pattern); |
852 fPatternStr.add(facets.pattern); |
852 fFacetsDefined |= FACET_PATTERN; |
853 fFacetsDefined |= FACET_PATTERN; |
853 if ((fixedFacet & FACET_PATTERN) != 0) |
854 if ((fixedFacet & FACET_PATTERN) != 0) |
854 fFixedFacet |= FACET_PATTERN; |
855 fFixedFacet |= FACET_PATTERN; |
855 } |
856 } |
856 } |
857 } |
871 // enumeration |
872 // enumeration |
872 if ((presentFacet & FACET_ENUMERATION) != 0) { |
873 if ((presentFacet & FACET_ENUMERATION) != 0) { |
873 if ((allowedFacet & FACET_ENUMERATION) == 0) { |
874 if ((allowedFacet & FACET_ENUMERATION) == 0) { |
874 reportError("cos-applicable-facets", new Object[]{"enumeration", fTypeName}); |
875 reportError("cos-applicable-facets", new Object[]{"enumeration", fTypeName}); |
875 } else { |
876 } else { |
876 Vector enumVals = facets.enumeration; |
877 List<String> enumVals = facets.enumeration; |
877 int size = enumVals.size(); |
878 int size = enumVals.size(); |
878 fEnumeration = new ValidatedInfo[size]; |
879 fEnumeration = new ValidatedInfo[size]; |
879 Vector enumNSDecls = facets.enumNSDecls; |
880 List<NamespaceContext> enumNSDecls = facets.enumNSDecls; |
880 ValidationContextImpl ctx = new ValidationContextImpl(context); |
881 ValidationContextImpl ctx = new ValidationContextImpl(context); |
881 enumerationAnnotations = facets.enumAnnotations; |
882 enumerationAnnotations = facets.enumAnnotations; |
882 fEnumerationSize = 0; |
883 fEnumerationSize = 0; |
883 for (int i = 0; i < size; i++) { |
884 for (int i = 0; i < size; i++) { |
884 if (enumNSDecls != null) |
885 if (enumNSDecls != null) |
885 ctx.setNSContext((NamespaceContext)enumNSDecls.elementAt(i)); |
886 ctx.setNSContext((NamespaceContext)enumNSDecls.get(i)); |
886 try { |
887 try { |
887 ValidatedInfo info = getActualEnumValue((String)enumVals.elementAt(i), ctx, null); |
888 ValidatedInfo info = getActualEnumValue((String)enumVals.get(i), ctx, null); |
888 // check 4.3.5.c0 must: enumeration values from the value space of base |
889 // check 4.3.5.c0 must: enumeration values from the value space of base |
889 fEnumeration[fEnumerationSize++] = info; |
890 fEnumeration[fEnumerationSize++] = info; |
890 } catch (InvalidDatatypeValueException ide) { |
891 } catch (InvalidDatatypeValueException ide) { |
891 reportError("enumeration-valid-restriction", new Object[]{enumVals.elementAt(i), this.getBaseType().getName()}); |
892 reportError("enumeration-valid-restriction", new Object[]{enumVals.get(i), this.getBaseType().getName()}); |
892 } |
893 } |
893 } |
894 } |
894 fFacetsDefined |= FACET_ENUMERATION; |
895 fFacetsDefined |= FACET_ENUMERATION; |
895 if ((fixedFacet & FACET_ENUMERATION) != 0) |
896 if ((fixedFacet & FACET_ENUMERATION) != 0) |
896 fFixedFacet |= FACET_ENUMERATION; |
897 fFixedFacet |= FACET_ENUMERATION; |
1449 fPatternStr = fBase.fPatternStr; |
1450 fPatternStr = fBase.fPatternStr; |
1450 patternAnnotations = fBase.patternAnnotations; |
1451 patternAnnotations = fBase.patternAnnotations; |
1451 } |
1452 } |
1452 else { |
1453 else { |
1453 for (int i = fBase.fPattern.size()-1; i >= 0; --i) { |
1454 for (int i = fBase.fPattern.size()-1; i >= 0; --i) { |
1454 fPattern.addElement(fBase.fPattern.elementAt(i)); |
1455 fPattern.add(fBase.fPattern.get(i)); |
1455 fPatternStr.addElement(fBase.fPatternStr.elementAt(i)); |
1456 fPatternStr.add(fBase.fPatternStr.get(i)); |
1456 } |
1457 } |
1457 if (fBase.patternAnnotations != null) { |
1458 if (fBase.patternAnnotations != null) { |
1458 if (patternAnnotations != null) { |
1459 if (patternAnnotations != null) { |
1459 for (int i = fBase.patternAnnotations.getLength()-1; i >= 0; --i) { |
1460 for (int i = fBase.patternAnnotations.getLength()-1; i >= 0; --i) { |
1460 patternAnnotations.addXSObject(fBase.patternAnnotations.item(i)); |
1461 patternAnnotations.addXSObject(fBase.patternAnnotations.item(i)); |
1828 nvalue = content.toString(); |
1829 nvalue = content.toString(); |
1829 } |
1830 } |
1830 if ( (fFacetsDefined & FACET_PATTERN ) != 0 ) { |
1831 if ( (fFacetsDefined & FACET_PATTERN ) != 0 ) { |
1831 RegularExpression regex; |
1832 RegularExpression regex; |
1832 for (int idx = fPattern.size()-1; idx >= 0; idx--) { |
1833 for (int idx = fPattern.size()-1; idx >= 0; idx--) { |
1833 regex = (RegularExpression)fPattern.elementAt(idx); |
1834 regex = fPattern.get(idx); |
1834 if (!regex.matches(nvalue)){ |
1835 if (!regex.matches(nvalue)){ |
1835 throw new InvalidDatatypeValueException("cvc-pattern-valid", |
1836 throw new InvalidDatatypeValueException("cvc-pattern-valid", |
1836 new Object[]{content, |
1837 new Object[]{content, |
1837 fPatternStr.elementAt(idx), |
1838 fPatternStr.get(idx), |
1838 |
1839 |
1839 fTypeName}); |
1840 fTypeName}); |
1840 } |
1841 } |
1841 } |
1842 } |
1842 } |
1843 } |
3437 public short getType() { |
3438 public short getType() { |
3438 return XSConstants.MULTIVALUE_FACET; |
3439 return XSConstants.MULTIVALUE_FACET; |
3439 } |
3440 } |
3440 } |
3441 } |
3441 |
3442 |
3442 private static abstract class AbstractObjectList extends AbstractList implements ObjectList { |
3443 private static abstract class AbstractObjectList extends AbstractList<Object> implements ObjectList { |
3443 public Object get(int index) { |
3444 public Object get(int index) { |
3444 if (index >= 0 && index < getLength()) { |
3445 if (index >= 0 && index < getLength()) { |
3445 return item(index); |
3446 return item(index); |
3446 } |
3447 } |
3447 throw new IndexOutOfBoundsException("Index: " + index); |
3448 throw new IndexOutOfBoundsException("Index: " + index); |