1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001-2004 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.XSNotationDecl;
  62. import com.sun.org.apache.xerces.internal.util.DOMUtil;
  63. import org.w3c.dom.Element;
  64. /**
  65. * The notation declaration schema component traverser.
  66. *
  67. * <notation
  68. * id = ID
  69. * name = NCName
  70. * public = anyURI
  71. * system = anyURI
  72. * {any attributes with non-schema namespace . . .}>
  73. * Content: (annotation?)
  74. * </notation>
  75. *
  76. * @author Rahul Srivastava, Sun Microsystems Inc.
  77. * @author Elena Litani, IBM
  78. * @version $Id: XSDNotationTraverser.java,v 1.12 2004/01/22 15:22:53 sandygao Exp $
  79. */
  80. class XSDNotationTraverser extends XSDAbstractTraverser {
  81. XSDNotationTraverser (XSDHandler handler,
  82. XSAttributeChecker gAttrCheck) {
  83. super(handler, gAttrCheck);
  84. }
  85. XSNotationDecl traverse(Element elmNode,
  86. XSDocumentInfo schemaDoc,
  87. SchemaGrammar grammar) {
  88. // General Attribute Checking for elmNode
  89. Object[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc);
  90. //get attributes
  91. String nameAttr = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
  92. String publicAttr = (String) attrValues[XSAttributeChecker.ATTIDX_PUBLIC];
  93. String systemAttr = (String) attrValues[XSAttributeChecker.ATTIDX_SYSTEM];
  94. if (nameAttr == null) {
  95. reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_NOTATION, SchemaSymbols.ATT_NAME}, elmNode);
  96. fAttrChecker.returnAttrArray(attrValues, schemaDoc);
  97. return null;
  98. }
  99. if (systemAttr == null && publicAttr == null)
  100. reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_NOTATION, "system or public"}, elmNode);
  101. XSNotationDecl notation = new XSNotationDecl();
  102. notation.fName = nameAttr;
  103. notation.fTargetNamespace = schemaDoc.fTargetNamespace;
  104. notation.fPublicId = publicAttr;
  105. notation.fSystemId = systemAttr;
  106. //check content
  107. Element content = DOMUtil.getFirstChildElement(elmNode);
  108. XSAnnotationImpl annotation = null;
  109. if (content != null) {
  110. // traverse annotation if any
  111. if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
  112. annotation = traverseAnnotationDecl(content, attrValues, false, schemaDoc);
  113. content = DOMUtil.getNextSiblingElement(content);
  114. }
  115. }
  116. notation.fAnnotation = annotation;
  117. if (content!=null){
  118. Object[] args = new Object [] {SchemaSymbols.ELT_NOTATION, "(annotation?)", DOMUtil.getLocalName(content)};
  119. reportSchemaError("s4s-elt-must-match.1", args, content);
  120. }
  121. grammar.addGlobalNotationDecl(notation);
  122. fAttrChecker.returnAttrArray(attrValues, schemaDoc);
  123. return notation;
  124. }
  125. }