1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 2001, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.impl.xs.traversers;
  58. import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
  59. import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
  60. import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;
  61. import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;
  62. import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl;
  63. import com.sun.org.apache.xerces.internal.impl.xs.util.XInt;
  64. import com.sun.org.apache.xerces.internal.util.DOMUtil;
  65. import org.w3c.dom.Element;
  66. /**
  67. * The wildcard schema component traverser.
  68. *
  69. * <any
  70. * id = ID
  71. * maxOccurs = (nonNegativeInteger | unbounded) : 1
  72. * minOccurs = nonNegativeInteger : 1
  73. * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  74. * processContents = (lax | skip | strict) : strict
  75. * {any attributes with non-schema namespace . . .}>
  76. * Content: (annotation?)
  77. * </any>
  78. *
  79. * <anyAttribute
  80. * id = ID
  81. * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  82. * processContents = (lax | skip | strict) : strict
  83. * {any attributes with non-schema namespace . . .}>
  84. * Content: (annotation?)
  85. * </anyAttribute>
  86. *
  87. * @author Rahul Srivastava, Sun Microsystems Inc.
  88. * @author Sandy Gao, IBM
  89. *
  90. * @version $Id: XSDWildcardTraverser.java,v 1.11 2003/06/23 16:35:22 neilg Exp $
  91. */
  92. class XSDWildcardTraverser extends XSDAbstractTraverser {
  93. /**
  94. * constructor
  95. *
  96. * @param handler
  97. * @param errorReporter
  98. * @param gAttrCheck
  99. */
  100. XSDWildcardTraverser (XSDHandler handler,
  101. XSAttributeChecker gAttrCheck) {
  102. super(handler, gAttrCheck);
  103. }
  104. /**
  105. * Traverse <any>
  106. *
  107. * @param elmNode
  108. * @param schemaDoc
  109. * @param grammar
  110. * @return the wildcard node index
  111. */
  112. XSParticleDecl traverseAny(Element elmNode,
  113. XSDocumentInfo schemaDoc,
  114. SchemaGrammar grammar) {
  115. // General Attribute Checking for elmNode
  116. Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
  117. XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar);
  118. // for <any>, need to create a new particle to reflect the min/max values
  119. XSParticleDecl particle = null;
  120. if (wildcard != null) {
  121. int min = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]).intValue();
  122. int max = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]).intValue();
  123. if (max != 0) {
  124. if (fSchemaHandler.fDeclPool !=null) {
  125. particle = fSchemaHandler.fDeclPool.getParticleDecl();
  126. } else {
  127. particle = new XSParticleDecl();
  128. }
  129. particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
  130. particle.fValue = wildcard;
  131. particle.fMinOccurs = min;
  132. particle.fMaxOccurs = max;
  133. }
  134. }
  135. fAttrChecker.returnAttrArray(attrValues, schemaDoc);
  136. return particle;
  137. }
  138. /**
  139. * Traverse <anyAttribute>
  140. *
  141. * @param elmNode
  142. * @param schemaDoc
  143. * @param grammar
  144. * @return the wildcard node index
  145. */
  146. XSWildcardDecl traverseAnyAttribute(Element elmNode,
  147. XSDocumentInfo schemaDoc,
  148. SchemaGrammar grammar) {
  149. // General Attribute Checking for elmNode
  150. Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
  151. XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar);
  152. fAttrChecker.returnAttrArray(attrValues, schemaDoc);
  153. return wildcard;
  154. }
  155. /**
  156. *
  157. * @param elmNode
  158. * @param attrValues
  159. * @param schemaDoc
  160. * @param grammar
  161. * @return the wildcard node index
  162. */
  163. XSWildcardDecl traverseWildcardDecl(Element elmNode,
  164. Object[] attrValues,
  165. XSDocumentInfo schemaDoc,
  166. SchemaGrammar grammar) {
  167. //get all attributes
  168. XSWildcardDecl wildcard = new XSWildcardDecl();
  169. // namespace type
  170. XInt namespaceTypeAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_NAMESPACE];
  171. wildcard.fType = namespaceTypeAttr.shortValue();
  172. // namespace list
  173. wildcard.fNamespaceList = (String[])attrValues[XSAttributeChecker.ATTIDX_NAMESPACE_LIST];
  174. // process contents
  175. XInt processContentsAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_PROCESSCONTENTS];
  176. wildcard.fProcessContents = processContentsAttr.shortValue();
  177. //check content
  178. Element child = DOMUtil.getFirstChildElement(elmNode);
  179. XSAnnotationImpl annotation = null;
  180. if (child != null)
  181. {
  182. if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
  183. annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
  184. child = DOMUtil.getNextSiblingElement(child);
  185. }
  186. if (child != null) {
  187. reportSchemaError("s4s-elt-must-match.1", new Object[]{"wildcard", "(annotation?)", DOMUtil.getLocalName(child)}, elmNode);
  188. }
  189. }
  190. wildcard.fAnnotation = annotation;
  191. return wildcard;
  192. } // traverseWildcardDecl
  193. } // XSDWildcardTraverser