< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDSimpleTypeTraverser.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.xs.traversers;
  23 


 279         // get base type from "base" attribute
 280         XSSimpleType baseValidator = null;
 281         if ((restriction || list) && baseTypeName != null) {
 282             baseValidator = findDTValidator(child, name, baseTypeName, refType, schemaDoc);
 283             // if its the built-in type, return null from here
 284             if (baseValidator == null && fIsBuiltIn) {
 285                 fIsBuiltIn = false;
 286                 return null;
 287             }
 288         }
 289         // get types from "memberTypes" attribute
 290         List<XSObject> dTValidators = null;
 291         XSSimpleType dv = null;
 292         XSObjectList dvs;
 293         if (union && memberTypes != null && memberTypes.size() > 0) {
 294             int size = memberTypes.size();
 295             dTValidators = new ArrayList<>(size);
 296             // for each qname in the list
 297             for (int i = 0; i < size; i++) {
 298                 // get the type decl
 299                 dv = findDTValidator(child, name, (QName)memberTypes.get(i),
 300                         XSConstants.DERIVATION_UNION, schemaDoc);
 301                 if (dv != null) {
 302                     // if it's a union, expand it
 303                     if (dv.getVariety() == XSSimpleType.VARIETY_UNION) {
 304                         dvs = dv.getMemberTypes();
 305                         for (int j = 0; j < dvs.getLength(); j++)
 306                             dTValidators.add(dvs.item(j));
 307                     } else {
 308                         dTValidators.add(dv);
 309                     }
 310                 }
 311             }
 312         }
 313 
 314         // check if there is a child "simpleType"
 315         if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_SIMPLETYPE)) {
 316             if (restriction || list) {
 317                 // it's an error for both "base" and "simpleType" to appear
 318                 if (baseTypeName != null) {
 319                     reportSchemaError(list ? "src-simple-type.3.a" : "src-simple-type.2.a", null, content);


 372                     XSConstants.DERIVATION_UNION);
 373         }
 374         // item type of list types can't have list content
 375         if (list && isListDatatype(baseValidator)) {
 376             reportSchemaError("cos-st-restricts.2.1", new Object[]{name, baseValidator.getName()}, child);
 377             fAttrChecker.returnAttrArray(contentAttrs, schemaDoc);
 378             return errorType(name, schemaDoc.fTargetNamespace,
 379                     XSConstants.DERIVATION_LIST);
 380         }
 381         // create the simple type based on the "base" type
 382         XSSimpleType newDecl = null;
 383         if (restriction) {
 384             newDecl = fSchemaHandler.fDVFactory.createTypeRestriction(name, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator,
 385                     annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 386         }
 387         else if (list) {
 388             newDecl = fSchemaHandler.fDVFactory.createTypeList(name, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator,
 389                     annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 390         }
 391         else if (union) {
 392             XSSimpleType[] memberDecls = (XSSimpleType[]) dTValidators.toArray(new XSSimpleType[dTValidators.size()]);
 393             newDecl = fSchemaHandler.fDVFactory.createTypeUnion(name, schemaDoc.fTargetNamespace, (short)finalProperty, memberDecls,
 394                     annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 395         }
 396         // now traverse facets, if it's derived by restriction
 397         if (restriction && content != null) {
 398             FacetInfo fi = traverseFacets(content, baseValidator, schemaDoc);
 399             content = fi.nodeAfterFacets;
 400 
 401             try {
 402                 fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
 403                 newDecl.applyFacets(fi.facetdata, fi.fPresentFacets, fi.fFixedFacets, fValidationState);
 404             } catch (InvalidDatatypeFacetException ex) {
 405                 reportSchemaError(ex.getKey(), ex.getArgs(), child);
 406                 // Recreate the type, ignoring the facets
 407                 newDecl = fSchemaHandler.fDVFactory.createTypeRestriction(name, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator,
 408                         annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 409             }
 410         }
 411         // no element should appear after this point
 412         if (content != null) {


   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.xs.traversers;
  23 


 279         // get base type from "base" attribute
 280         XSSimpleType baseValidator = null;
 281         if ((restriction || list) && baseTypeName != null) {
 282             baseValidator = findDTValidator(child, name, baseTypeName, refType, schemaDoc);
 283             // if its the built-in type, return null from here
 284             if (baseValidator == null && fIsBuiltIn) {
 285                 fIsBuiltIn = false;
 286                 return null;
 287             }
 288         }
 289         // get types from "memberTypes" attribute
 290         List<XSObject> dTValidators = null;
 291         XSSimpleType dv = null;
 292         XSObjectList dvs;
 293         if (union && memberTypes != null && memberTypes.size() > 0) {
 294             int size = memberTypes.size();
 295             dTValidators = new ArrayList<>(size);
 296             // for each qname in the list
 297             for (int i = 0; i < size; i++) {
 298                 // get the type decl
 299                 dv = findDTValidator(child, name, memberTypes.get(i),
 300                         XSConstants.DERIVATION_UNION, schemaDoc);
 301                 if (dv != null) {
 302                     // if it's a union, expand it
 303                     if (dv.getVariety() == XSSimpleType.VARIETY_UNION) {
 304                         dvs = dv.getMemberTypes();
 305                         for (int j = 0; j < dvs.getLength(); j++)
 306                             dTValidators.add(dvs.item(j));
 307                     } else {
 308                         dTValidators.add(dv);
 309                     }
 310                 }
 311             }
 312         }
 313 
 314         // check if there is a child "simpleType"
 315         if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_SIMPLETYPE)) {
 316             if (restriction || list) {
 317                 // it's an error for both "base" and "simpleType" to appear
 318                 if (baseTypeName != null) {
 319                     reportSchemaError(list ? "src-simple-type.3.a" : "src-simple-type.2.a", null, content);


 372                     XSConstants.DERIVATION_UNION);
 373         }
 374         // item type of list types can't have list content
 375         if (list && isListDatatype(baseValidator)) {
 376             reportSchemaError("cos-st-restricts.2.1", new Object[]{name, baseValidator.getName()}, child);
 377             fAttrChecker.returnAttrArray(contentAttrs, schemaDoc);
 378             return errorType(name, schemaDoc.fTargetNamespace,
 379                     XSConstants.DERIVATION_LIST);
 380         }
 381         // create the simple type based on the "base" type
 382         XSSimpleType newDecl = null;
 383         if (restriction) {
 384             newDecl = fSchemaHandler.fDVFactory.createTypeRestriction(name, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator,
 385                     annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 386         }
 387         else if (list) {
 388             newDecl = fSchemaHandler.fDVFactory.createTypeList(name, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator,
 389                     annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 390         }
 391         else if (union) {
 392             XSSimpleType[] memberDecls = dTValidators.toArray(new XSSimpleType[dTValidators.size()]);
 393             newDecl = fSchemaHandler.fDVFactory.createTypeUnion(name, schemaDoc.fTargetNamespace, (short)finalProperty, memberDecls,
 394                     annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 395         }
 396         // now traverse facets, if it's derived by restriction
 397         if (restriction && content != null) {
 398             FacetInfo fi = traverseFacets(content, baseValidator, schemaDoc);
 399             content = fi.nodeAfterFacets;
 400 
 401             try {
 402                 fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
 403                 newDecl.applyFacets(fi.facetdata, fi.fPresentFacets, fi.fFixedFacets, fValidationState);
 404             } catch (InvalidDatatypeFacetException ex) {
 405                 reportSchemaError(ex.getKey(), ex.getArgs(), child);
 406                 // Recreate the type, ignoring the facets
 407                 newDecl = fSchemaHandler.fDVFactory.createTypeRestriction(name, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator,
 408                         annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
 409             }
 410         }
 411         // no element should appear after this point
 412         if (content != null) {


< prev index next >