< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dv/xs/XSSimpleTypeDecl.java

Print this page


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl.dv.xs;
  23 


 218         }
 219         public boolean isIdDeclared (String name) {
 220             return false;
 221         }
 222         public void addId(String name) {
 223         }
 224         public void addIdRef(String name) {
 225         }
 226         public String getSymbol (String symbol) {
 227             return symbol.intern();
 228         }
 229         public String getURI(String prefix) {
 230             return null;
 231         }
 232         public Locale getLocale() {
 233             return Locale.getDefault();
 234         }
 235     };
 236 
 237     protected static TypeValidator[] getGDVs() {
 238         return (TypeValidator[])gDVs.clone();
 239     }
 240     private TypeValidator[] fDVs = gDVs;
 241     protected void setDVs(TypeValidator[] dvs) {
 242         fDVs = dvs;
 243     }
 244 
 245     // this will be true if this is a static XSSimpleTypeDecl
 246     // and hence must remain immutable (i.e., applyFacets
 247     // may not be permitted to have any effect).
 248     private boolean fIsImmutable = false;
 249 
 250     private XSSimpleTypeDecl fItemType;
 251     private XSSimpleTypeDecl[] fMemberTypes;
 252     // The most specific built-in type kind.
 253     private short fBuiltInKind;
 254 
 255     private String fTypeName;
 256     private String fTargetNamespace;
 257     private short fFinalSet = 0;
 258     private XSSimpleTypeDecl fBase;


 417         fractionDigitsAnnotation = fBase.fractionDigitsAnnotation;
 418 
 419         //we also set fundamental facets information in case applyFacets is not called.
 420         calcFundamentalFacets();
 421         fIsImmutable = isImmutable;
 422 
 423         // Inherit from the base type
 424         fBuiltInKind = base.fBuiltInKind;
 425     }
 426 
 427     //Create a new simple type for list.
 428     protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl itemType, boolean isImmutable,
 429             XSObjectList annotations) {
 430         fBase = fAnySimpleType;
 431         fTypeName = name;
 432         fTargetNamespace = uri;
 433         fFinalSet = finalSet;
 434         fAnnotations = annotations;
 435 
 436         fVariety = VARIETY_LIST;
 437         fItemType = (XSSimpleTypeDecl)itemType;
 438         fValidationDV = DV_LIST;
 439         fFacetsDefined = FACET_WHITESPACE;
 440         fFixedFacet = FACET_WHITESPACE;
 441         fWhiteSpace = WS_COLLAPSE;
 442 
 443         //setting fundamental facets
 444         calcFundamentalFacets();
 445         fIsImmutable = isImmutable;
 446 
 447         // Values of this type are lists
 448         fBuiltInKind = XSConstants.LIST_DT;
 449     }
 450 
 451     //Create a new simple type for union.
 452     protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes,
 453             XSObjectList annotations) {
 454         fBase = fAnySimpleType;
 455         fTypeName = name;
 456         fTargetNamespace = uri;
 457         fFinalSet = finalSet;


 527 
 528         // Inherit from the base type
 529         fBuiltInKind = base.fBuiltInKind;
 530 
 531         return this;
 532     }
 533 
 534     //set values for list.
 535     protected XSSimpleTypeDecl setListValues(String name, String uri, short finalSet, XSSimpleTypeDecl itemType,
 536             XSObjectList annotations) {
 537         //decline to do anything if the object is immutable.
 538         if(fIsImmutable) return null;
 539         fBase = fAnySimpleType;
 540         fAnonymous = false;
 541         fTypeName = name;
 542         fTargetNamespace = uri;
 543         fFinalSet = finalSet;
 544         fAnnotations = annotations;
 545 
 546         fVariety = VARIETY_LIST;
 547         fItemType = (XSSimpleTypeDecl)itemType;
 548         fValidationDV = DV_LIST;
 549         fFacetsDefined = FACET_WHITESPACE;
 550         fFixedFacet = FACET_WHITESPACE;
 551         fWhiteSpace = WS_COLLAPSE;
 552 
 553         //setting fundamental facets
 554         calcFundamentalFacets();
 555 
 556         // Values of this type are lists
 557         fBuiltInKind = XSConstants.LIST_DT;
 558 
 559         return this;
 560     }
 561 
 562     //set values for union.
 563     protected XSSimpleTypeDecl setUnionValues(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes,
 564             XSObjectList annotations) {
 565         //decline to do anything if the object is immutable.
 566         if(fIsImmutable) return null;
 567         fBase = fAnySimpleType;


 866                 whiteSpaceAnnotation = facets.whiteSpaceAnnotation;
 867                 fFacetsDefined |= FACET_WHITESPACE;
 868                 if ((fixedFacet & FACET_WHITESPACE) != 0)
 869                     fFixedFacet |= FACET_WHITESPACE;
 870             }
 871         }
 872         // enumeration
 873         if ((presentFacet & FACET_ENUMERATION) != 0) {
 874             if ((allowedFacet & FACET_ENUMERATION) == 0) {
 875                 reportError("cos-applicable-facets", new Object[]{"enumeration", fTypeName});
 876             } else {
 877                 List<String> enumVals = facets.enumeration;
 878                 int size = enumVals.size();
 879                 fEnumeration = new ValidatedInfo[size];
 880                 List<NamespaceContext> enumNSDecls = facets.enumNSDecls;
 881                 ValidationContextImpl ctx = new ValidationContextImpl(context);
 882                 enumerationAnnotations = facets.enumAnnotations;
 883                 fEnumerationSize = 0;
 884                 for (int i = 0; i < size; i++) {
 885                     if (enumNSDecls != null)
 886                         ctx.setNSContext((NamespaceContext)enumNSDecls.get(i));
 887                     try {
 888                         ValidatedInfo info = getActualEnumValue((String)enumVals.get(i), ctx, null);
 889                         // check 4.3.5.c0 must: enumeration values from the value space of base
 890                         fEnumeration[fEnumerationSize++] = info;
 891                     } catch (InvalidDatatypeValueException ide) {
 892                         reportError("enumeration-valid-restriction", new Object[]{enumVals.get(i), this.getBaseType().getName()});
 893                     }
 894                 }
 895                 fFacetsDefined |= FACET_ENUMERATION;
 896                 if ((fixedFacet & FACET_ENUMERATION) != 0)
 897                     fFixedFacet |= FACET_ENUMERATION;
 898             }
 899         }
 900 
 901         // maxInclusive
 902         if ((presentFacet & FACET_MAXINCLUSIVE) != 0) {
 903             if ((allowedFacet & FACET_MAXINCLUSIVE) == 0) {
 904                 reportError("cos-applicable-facets", new Object[]{"maxInclusive", fTypeName});
 905             } else {
 906                 maxInclusiveAnnotation = facets.maxInclusiveAnnotation;
 907                 try {
 908                     fMaxInclusive = fBase.getActualValue(facets.maxInclusive, context, tempInfo, true);


2587     }
2588 
2589     public boolean derivedFrom(String ancestorNS, String ancestorName, short derivation) {
2590         // REVISIT: implement according to derivation
2591 
2592         // ancestor is null, retur false
2593         if (ancestorName == null)
2594             return false;
2595         // ancestor is anyType, return true
2596         if (URI_SCHEMAFORSCHEMA.equals(ancestorNS) &&
2597                 ANY_TYPE.equals(ancestorName)) {
2598             return true;
2599         }
2600 
2601         // recursively get base, and compare it with ancestor
2602         XSTypeDefinition type = this;
2603         while (!(ancestorName.equals(type.getName()) &&
2604                 ((ancestorNS == null && type.getNamespace() == null) ||
2605                         (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) &&   // compare with ancestor
2606                         type != fAnySimpleType) {  // reached anySimpleType
2607             type = (XSTypeDefinition)type.getBaseType();
2608         }
2609 
2610         return type != fAnySimpleType;
2611     }
2612 
2613     /**
2614      * Checks if a type is derived from another by restriction, given the name
2615      * and namespace. See:
2616      * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom
2617      *
2618      * @param ancestorNS
2619      *            The namspace of the ancestor type declaration
2620      * @param ancestorName
2621      *            The name of the ancestor type declaration
2622      * @param derivationMethod
2623      *            The derivation method
2624      *
2625      * @return boolean True if the ancestor type is derived from the reference type by the specifiied derivation method.
2626      */
2627     public boolean isDOMDerivedFrom(String ancestorNS, String ancestorName, int derivationMethod) {


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl.dv.xs;
  23 


 218         }
 219         public boolean isIdDeclared (String name) {
 220             return false;
 221         }
 222         public void addId(String name) {
 223         }
 224         public void addIdRef(String name) {
 225         }
 226         public String getSymbol (String symbol) {
 227             return symbol.intern();
 228         }
 229         public String getURI(String prefix) {
 230             return null;
 231         }
 232         public Locale getLocale() {
 233             return Locale.getDefault();
 234         }
 235     };
 236 
 237     protected static TypeValidator[] getGDVs() {
 238         return gDVs.clone();
 239     }
 240     private TypeValidator[] fDVs = gDVs;
 241     protected void setDVs(TypeValidator[] dvs) {
 242         fDVs = dvs;
 243     }
 244 
 245     // this will be true if this is a static XSSimpleTypeDecl
 246     // and hence must remain immutable (i.e., applyFacets
 247     // may not be permitted to have any effect).
 248     private boolean fIsImmutable = false;
 249 
 250     private XSSimpleTypeDecl fItemType;
 251     private XSSimpleTypeDecl[] fMemberTypes;
 252     // The most specific built-in type kind.
 253     private short fBuiltInKind;
 254 
 255     private String fTypeName;
 256     private String fTargetNamespace;
 257     private short fFinalSet = 0;
 258     private XSSimpleTypeDecl fBase;


 417         fractionDigitsAnnotation = fBase.fractionDigitsAnnotation;
 418 
 419         //we also set fundamental facets information in case applyFacets is not called.
 420         calcFundamentalFacets();
 421         fIsImmutable = isImmutable;
 422 
 423         // Inherit from the base type
 424         fBuiltInKind = base.fBuiltInKind;
 425     }
 426 
 427     //Create a new simple type for list.
 428     protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl itemType, boolean isImmutable,
 429             XSObjectList annotations) {
 430         fBase = fAnySimpleType;
 431         fTypeName = name;
 432         fTargetNamespace = uri;
 433         fFinalSet = finalSet;
 434         fAnnotations = annotations;
 435 
 436         fVariety = VARIETY_LIST;
 437         fItemType = itemType;
 438         fValidationDV = DV_LIST;
 439         fFacetsDefined = FACET_WHITESPACE;
 440         fFixedFacet = FACET_WHITESPACE;
 441         fWhiteSpace = WS_COLLAPSE;
 442 
 443         //setting fundamental facets
 444         calcFundamentalFacets();
 445         fIsImmutable = isImmutable;
 446 
 447         // Values of this type are lists
 448         fBuiltInKind = XSConstants.LIST_DT;
 449     }
 450 
 451     //Create a new simple type for union.
 452     protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes,
 453             XSObjectList annotations) {
 454         fBase = fAnySimpleType;
 455         fTypeName = name;
 456         fTargetNamespace = uri;
 457         fFinalSet = finalSet;


 527 
 528         // Inherit from the base type
 529         fBuiltInKind = base.fBuiltInKind;
 530 
 531         return this;
 532     }
 533 
 534     //set values for list.
 535     protected XSSimpleTypeDecl setListValues(String name, String uri, short finalSet, XSSimpleTypeDecl itemType,
 536             XSObjectList annotations) {
 537         //decline to do anything if the object is immutable.
 538         if(fIsImmutable) return null;
 539         fBase = fAnySimpleType;
 540         fAnonymous = false;
 541         fTypeName = name;
 542         fTargetNamespace = uri;
 543         fFinalSet = finalSet;
 544         fAnnotations = annotations;
 545 
 546         fVariety = VARIETY_LIST;
 547         fItemType = itemType;
 548         fValidationDV = DV_LIST;
 549         fFacetsDefined = FACET_WHITESPACE;
 550         fFixedFacet = FACET_WHITESPACE;
 551         fWhiteSpace = WS_COLLAPSE;
 552 
 553         //setting fundamental facets
 554         calcFundamentalFacets();
 555 
 556         // Values of this type are lists
 557         fBuiltInKind = XSConstants.LIST_DT;
 558 
 559         return this;
 560     }
 561 
 562     //set values for union.
 563     protected XSSimpleTypeDecl setUnionValues(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes,
 564             XSObjectList annotations) {
 565         //decline to do anything if the object is immutable.
 566         if(fIsImmutable) return null;
 567         fBase = fAnySimpleType;


 866                 whiteSpaceAnnotation = facets.whiteSpaceAnnotation;
 867                 fFacetsDefined |= FACET_WHITESPACE;
 868                 if ((fixedFacet & FACET_WHITESPACE) != 0)
 869                     fFixedFacet |= FACET_WHITESPACE;
 870             }
 871         }
 872         // enumeration
 873         if ((presentFacet & FACET_ENUMERATION) != 0) {
 874             if ((allowedFacet & FACET_ENUMERATION) == 0) {
 875                 reportError("cos-applicable-facets", new Object[]{"enumeration", fTypeName});
 876             } else {
 877                 List<String> enumVals = facets.enumeration;
 878                 int size = enumVals.size();
 879                 fEnumeration = new ValidatedInfo[size];
 880                 List<NamespaceContext> enumNSDecls = facets.enumNSDecls;
 881                 ValidationContextImpl ctx = new ValidationContextImpl(context);
 882                 enumerationAnnotations = facets.enumAnnotations;
 883                 fEnumerationSize = 0;
 884                 for (int i = 0; i < size; i++) {
 885                     if (enumNSDecls != null)
 886                         ctx.setNSContext(enumNSDecls.get(i));
 887                     try {
 888                         ValidatedInfo info = getActualEnumValue(enumVals.get(i), ctx, null);
 889                         // check 4.3.5.c0 must: enumeration values from the value space of base
 890                         fEnumeration[fEnumerationSize++] = info;
 891                     } catch (InvalidDatatypeValueException ide) {
 892                         reportError("enumeration-valid-restriction", new Object[]{enumVals.get(i), this.getBaseType().getName()});
 893                     }
 894                 }
 895                 fFacetsDefined |= FACET_ENUMERATION;
 896                 if ((fixedFacet & FACET_ENUMERATION) != 0)
 897                     fFixedFacet |= FACET_ENUMERATION;
 898             }
 899         }
 900 
 901         // maxInclusive
 902         if ((presentFacet & FACET_MAXINCLUSIVE) != 0) {
 903             if ((allowedFacet & FACET_MAXINCLUSIVE) == 0) {
 904                 reportError("cos-applicable-facets", new Object[]{"maxInclusive", fTypeName});
 905             } else {
 906                 maxInclusiveAnnotation = facets.maxInclusiveAnnotation;
 907                 try {
 908                     fMaxInclusive = fBase.getActualValue(facets.maxInclusive, context, tempInfo, true);


2587     }
2588 
2589     public boolean derivedFrom(String ancestorNS, String ancestorName, short derivation) {
2590         // REVISIT: implement according to derivation
2591 
2592         // ancestor is null, retur false
2593         if (ancestorName == null)
2594             return false;
2595         // ancestor is anyType, return true
2596         if (URI_SCHEMAFORSCHEMA.equals(ancestorNS) &&
2597                 ANY_TYPE.equals(ancestorName)) {
2598             return true;
2599         }
2600 
2601         // recursively get base, and compare it with ancestor
2602         XSTypeDefinition type = this;
2603         while (!(ancestorName.equals(type.getName()) &&
2604                 ((ancestorNS == null && type.getNamespace() == null) ||
2605                         (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) &&   // compare with ancestor
2606                         type != fAnySimpleType) {  // reached anySimpleType
2607             type = type.getBaseType();
2608         }
2609 
2610         return type != fAnySimpleType;
2611     }
2612 
2613     /**
2614      * Checks if a type is derived from another by restriction, given the name
2615      * and namespace. See:
2616      * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom
2617      *
2618      * @param ancestorNS
2619      *            The namspace of the ancestor type declaration
2620      * @param ancestorName
2621      *            The name of the ancestor type declaration
2622      * @param derivationMethod
2623      *            The derivation method
2624      *
2625      * @return boolean True if the ancestor type is derived from the reference type by the specifiied derivation method.
2626      */
2627     public boolean isDOMDerivedFrom(String ancestorNS, String ancestorName, int derivationMethod) {


< prev index next >