1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 22 23 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 24 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 25 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 26 import com.sun.org.apache.xerces.internal.impl.xs.XSNotationDecl; 27 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 28 import com.sun.org.apache.xerces.internal.util.DOMUtil; 29 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 30 import org.w3c.dom.Element; 31 32 /** 33 * The notation declaration schema component traverser. 34 * 35 * <notation 36 * id = ID 37 * name = NCName 38 * public = anyURI 39 * system = anyURI 40 * {any attributes with non-schema namespace . . .}> 41 * Content: (annotation?) 42 * </notation> 43 * 44 * @xerces.internal 45 * 46 * @author Rahul Srivastava, Sun Microsystems Inc. 47 * @author Elena Litani, IBM 48 */ 49 class XSDNotationTraverser extends XSDAbstractTraverser { 50 51 XSDNotationTraverser (XSDHandler handler, 52 XSAttributeChecker gAttrCheck) { 53 super(handler, gAttrCheck); 54 } 55 56 XSNotationDecl traverse(Element elmNode, 57 XSDocumentInfo schemaDoc, 58 SchemaGrammar grammar) { 59 60 // General Attribute Checking for elmNode 61 Object[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc); 62 //get attributes 63 String nameAttr = (String) attrValues[XSAttributeChecker.ATTIDX_NAME]; 64 65 String publicAttr = (String) attrValues[XSAttributeChecker.ATTIDX_PUBLIC]; 66 String systemAttr = (String) attrValues[XSAttributeChecker.ATTIDX_SYSTEM]; 67 if (nameAttr == null) { 68 reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_NOTATION, SchemaSymbols.ATT_NAME}, elmNode); 69 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 70 return null; 71 } 72 73 if (systemAttr == null && publicAttr == null) { 74 reportSchemaError("PublicSystemOnNotation", null, elmNode); 75 publicAttr = "missing"; 76 } 77 78 XSNotationDecl notation = new XSNotationDecl(); 79 notation.fName = nameAttr; 80 notation.fTargetNamespace = schemaDoc.fTargetNamespace; 81 notation.fPublicId = publicAttr; 82 notation.fSystemId = systemAttr; 83 84 //check content 85 Element content = DOMUtil.getFirstChildElement(elmNode); 86 XSAnnotationImpl annotation = null; 87 88 if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) { 89 annotation = traverseAnnotationDecl(content, attrValues, false, schemaDoc); 90 content = DOMUtil.getNextSiblingElement(content); 91 } 92 else { 93 String text = DOMUtil.getSyntheticAnnotation(elmNode); 94 if (text != null) { 95 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc); 96 } 97 } 98 XSObjectList annotations; 99 if (annotation != null) { 100 annotations = new XSObjectListImpl(); 101 ((XSObjectListImpl) annotations).addXSObject(annotation); 102 } else { 103 annotations = XSObjectListImpl.EMPTY_LIST; 104 } 105 notation.fAnnotations = annotations; 106 if (content!=null){ 107 Object[] args = new Object [] {SchemaSymbols.ELT_NOTATION, "(annotation?)", DOMUtil.getLocalName(content)}; 108 reportSchemaError("s4s-elt-must-match.1", args, content); 109 110 } 111 if (grammar.getGlobalNotationDecl(notation.fName) == null) { 112 grammar.addGlobalNotationDecl(notation); 113 } 114 115 // also add it to extended map 116 final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc); 117 final XSNotationDecl notation2 = grammar.getGlobalNotationDecl(notation.fName, loc); 118 if (notation2 == null) { 119 grammar.addGlobalNotationDecl(notation, loc); 120 } 121 122 // handle duplicates 123 if (fSchemaHandler.fTolerateDuplicates) { 124 if (notation2 != null) { 125 notation = notation2; 126 } 127 fSchemaHandler.addGlobalNotationDecl(notation); 128 } 129 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 130 131 return notation; 132 } 133 }