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 22package com.sun.org.apache.xerces.internal.impl.xs.traversers; 23 24import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 25import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 26import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 27import com.sun.org.apache.xerces.internal.impl.xs.XSNotationDecl; 28import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 29import com.sun.org.apache.xerces.internal.util.DOMUtil; 30import com.sun.org.apache.xerces.internal.xs.XSObjectList; 31import org.w3c.dom.Element; 32 33/** 34 * The notation declaration schema component traverser. 35 * 36 * <notation 37 * id = ID 38 * name = NCName 39 * public = anyURI 40 * system = anyURI 41 * {any attributes with non-schema namespace . . .}> 42 * Content: (annotation?) 43 * </notation> 44 * 45 * @xerces.internal 46 * 47 * @author Rahul Srivastava, Sun Microsystems Inc. 48 * @author Elena Litani, IBM 49 */ 50class XSDNotationTraverser extends XSDAbstractTraverser { 51 52 XSDNotationTraverser (XSDHandler handler, 53 XSAttributeChecker gAttrCheck) { 54 super(handler, gAttrCheck); 55 } 56 57 XSNotationDecl traverse(Element elmNode, 58 XSDocumentInfo schemaDoc, 59 SchemaGrammar grammar) { 60 61 // General Attribute Checking for elmNode 62 Object[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc); 63 //get attributes 64 String nameAttr = (String) attrValues[XSAttributeChecker.ATTIDX_NAME]; 65 66 String publicAttr = (String) attrValues[XSAttributeChecker.ATTIDX_PUBLIC]; 67 String systemAttr = (String) attrValues[XSAttributeChecker.ATTIDX_SYSTEM]; 68 if (nameAttr == null) { 69 reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_NOTATION, SchemaSymbols.ATT_NAME}, elmNode); 70 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 71 return null; 72 } 73 74 if (systemAttr == null && publicAttr == null) { 75 reportSchemaError("PublicSystemOnNotation", null, elmNode); 76 publicAttr = "missing"; 77 } 78 79 XSNotationDecl notation = new XSNotationDecl(); 80 notation.fName = nameAttr; 81 notation.fTargetNamespace = schemaDoc.fTargetNamespace; 82 notation.fPublicId = publicAttr; 83 notation.fSystemId = systemAttr; 84 85 //check content 86 Element content = DOMUtil.getFirstChildElement(elmNode); 87 XSAnnotationImpl annotation = null; 88 89 if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) { 90 annotation = traverseAnnotationDecl(content, attrValues, false, schemaDoc); 91 content = DOMUtil.getNextSiblingElement(content); 92 } 93 else { 94 String text = DOMUtil.getSyntheticAnnotation(elmNode); 95 if (text != null) { 96 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc); 97 } 98 } 99 XSObjectList annotations; 100 if (annotation != null) { 101 annotations = new XSObjectListImpl(); 102 ((XSObjectListImpl) annotations).addXSObject(annotation); 103 } else { 104 annotations = XSObjectListImpl.EMPTY_LIST; 105 } 106 notation.fAnnotations = annotations; 107 if (content!=null){ 108 Object[] args = new Object [] {SchemaSymbols.ELT_NOTATION, "(annotation?)", DOMUtil.getLocalName(content)}; 109 reportSchemaError("s4s-elt-must-match.1", args, content); 110 111 } 112 if (grammar.getGlobalNotationDecl(notation.fName) == null) { 113 grammar.addGlobalNotationDecl(notation); 114 } 115 116 // also add it to extended map 117 final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc); 118 final XSNotationDecl notation2 = grammar.getGlobalNotationDecl(notation.fName, loc); 119 if (notation2 == null) { 120 grammar.addGlobalNotationDecl(notation, loc); 121 } 122 123 // handle duplicates 124 if (fSchemaHandler.fTolerateDuplicates) { 125 if (notation2 != null) { 126 notation = notation2; 127 } 128 fSchemaHandler.addGlobalNotationDecl(notation); 129 } 130 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 131 132 return notation; 133 } 134} 135