1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 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 24 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 25 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 26 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 27 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; 28 import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl; 29 import com.sun.org.apache.xerces.internal.impl.xs.util.XInt; 30 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 31 import com.sun.org.apache.xerces.internal.util.DOMUtil; 32 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 33 import org.w3c.dom.Element; 34 35 /** 36 * The wildcard schema component traverser. 37 * 38 * <any 39 * id = ID 40 * maxOccurs = (nonNegativeInteger | unbounded) : 1 41 * minOccurs = nonNegativeInteger : 1 42 * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any 43 * processContents = (lax | skip | strict) : strict 44 * {any attributes with non-schema namespace . . .}> 45 * Content: (annotation?) 46 * </any> 47 * 48 * <anyAttribute 49 * id = ID 50 * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any 51 * processContents = (lax | skip | strict) : strict 52 * {any attributes with non-schema namespace . . .}> 53 * Content: (annotation?) 54 * </anyAttribute> 55 * 56 * @xerces.internal 57 * 58 * @author Rahul Srivastava, Sun Microsystems Inc. 59 * @author Sandy Gao, IBM 60 * 61 * @version $Id: XSDWildcardTraverser.java,v 1.7 2010-11-01 04:40:02 joehw Exp $ 62 */ 63 class XSDWildcardTraverser extends XSDAbstractTraverser { 64 65 /** 66 * constructor 67 * 68 * @param handler 69 * @param errorReporter 70 * @param gAttrCheck 71 */ 72 XSDWildcardTraverser (XSDHandler handler, 73 XSAttributeChecker gAttrCheck) { 74 super(handler, gAttrCheck); 75 } 76 77 78 /** 79 * Traverse <any> 80 * 81 * @param elmNode 82 * @param schemaDoc 83 * @param grammar 84 * @return the wildcard node index 85 */ 86 XSParticleDecl traverseAny(Element elmNode, 87 XSDocumentInfo schemaDoc, 88 SchemaGrammar grammar) { 89 90 // General Attribute Checking for elmNode 91 Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc); 92 XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar); 93 94 // for <any>, need to create a new particle to reflect the min/max values 95 XSParticleDecl particle = null; 96 if (wildcard != null) { 97 int min = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]).intValue(); 98 int max = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]).intValue(); 99 if (max != 0) { 100 if (fSchemaHandler.fDeclPool !=null) { 101 particle = fSchemaHandler.fDeclPool.getParticleDecl(); 102 } else { 103 particle = new XSParticleDecl(); 104 } 105 particle.fType = XSParticleDecl.PARTICLE_WILDCARD; 106 particle.fValue = wildcard; 107 particle.fMinOccurs = min; 108 particle.fMaxOccurs = max; 109 particle.fAnnotations = wildcard.fAnnotations; 110 } 111 } 112 113 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 114 115 return particle; 116 } 117 118 119 /** 120 * Traverse <anyAttribute> 121 * 122 * @param elmNode 123 * @param schemaDoc 124 * @param grammar 125 * @return the wildcard node index 126 */ 127 XSWildcardDecl traverseAnyAttribute(Element elmNode, 128 XSDocumentInfo schemaDoc, 129 SchemaGrammar grammar) { 130 131 // General Attribute Checking for elmNode 132 Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc); 133 XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar); 134 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 135 136 return wildcard; 137 } 138 139 140 /** 141 * 142 * @param elmNode 143 * @param attrValues 144 * @param schemaDoc 145 * @param grammar 146 * @return the wildcard node index 147 */ 148 XSWildcardDecl traverseWildcardDecl(Element elmNode, 149 Object[] attrValues, 150 XSDocumentInfo schemaDoc, 151 SchemaGrammar grammar) { 152 153 //get all attributes 154 XSWildcardDecl wildcard = new XSWildcardDecl(); 155 // namespace type 156 XInt namespaceTypeAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_NAMESPACE]; 157 wildcard.fType = namespaceTypeAttr.shortValue(); 158 // namespace list 159 wildcard.fNamespaceList = (String[])attrValues[XSAttributeChecker.ATTIDX_NAMESPACE_LIST]; 160 // process contents 161 XInt processContentsAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_PROCESSCONTENTS]; 162 wildcard.fProcessContents = processContentsAttr.shortValue(); 163 164 //check content 165 Element child = DOMUtil.getFirstChildElement(elmNode); 166 XSAnnotationImpl annotation = null; 167 if (child != null) 168 { 169 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 170 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 171 child = DOMUtil.getNextSiblingElement(child); 172 } 173 else { 174 String text = DOMUtil.getSyntheticAnnotation(elmNode); 175 if (text != null) { 176 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc); 177 } 178 } 179 180 if (child != null) { 181 reportSchemaError("s4s-elt-must-match.1", new Object[]{"wildcard", "(annotation?)", DOMUtil.getLocalName(child)}, elmNode); 182 } 183 } 184 else { 185 String text = DOMUtil.getSyntheticAnnotation(elmNode); 186 if (text != null) { 187 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc); 188 } 189 } 190 XSObjectList annotations; 191 if (annotation != null) { 192 annotations = new XSObjectListImpl(); 193 ((XSObjectListImpl) annotations).addXSObject(annotation); 194 } else { 195 annotations = XSObjectListImpl.EMPTY_LIST; 196 } 197 wildcard.fAnnotations = annotations; 198 199 return wildcard; 200 201 } // traverseWildcardDecl 202 203 } // XSDWildcardTraverser