001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.xs.traversers;
019:
020: import org.apache.xerces.impl.xs.SchemaGrammar;
021: import org.apache.xerces.impl.xs.SchemaSymbols;
022: import org.apache.xerces.impl.xs.XSAnnotationImpl;
023: import org.apache.xerces.impl.xs.XSNotationDecl;
024: import org.apache.xerces.impl.xs.util.XSObjectListImpl;
025: import org.apache.xerces.util.DOMUtil;
026: import org.apache.xerces.xs.XSObjectList;
027: import org.w3c.dom.Element;
028:
029: /**
030: * The notation declaration schema component traverser.
031: *
032: * <notation
033: * id = ID
034: * name = NCName
035: * public = anyURI
036: * system = anyURI
037: * {any attributes with non-schema namespace . . .}>
038: * Content: (annotation?)
039: * </notation>
040: *
041: * @xerces.internal
042: *
043: * @author Rahul Srivastava, Sun Microsystems Inc.
044: * @author Elena Litani, IBM
045: * @version $Id: XSDNotationTraverser.java 446725 2006-09-15 20:40:10Z mrglavas $
046: */
047: class XSDNotationTraverser extends XSDAbstractTraverser {
048:
049: XSDNotationTraverser(XSDHandler handler,
050: XSAttributeChecker gAttrCheck) {
051: super (handler, gAttrCheck);
052: }
053:
054: XSNotationDecl traverse(Element elmNode, XSDocumentInfo schemaDoc,
055: SchemaGrammar grammar) {
056:
057: // General Attribute Checking for elmNode
058: Object[] attrValues = fAttrChecker.checkAttributes(elmNode,
059: true, schemaDoc);
060: //get attributes
061: String nameAttr = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
062:
063: String publicAttr = (String) attrValues[XSAttributeChecker.ATTIDX_PUBLIC];
064: String systemAttr = (String) attrValues[XSAttributeChecker.ATTIDX_SYSTEM];
065: if (nameAttr == null) {
066: reportSchemaError("s4s-att-must-appear",
067: new Object[] { SchemaSymbols.ELT_NOTATION,
068: SchemaSymbols.ATT_NAME }, elmNode);
069: fAttrChecker.returnAttrArray(attrValues, schemaDoc);
070: return null;
071: }
072:
073: if (systemAttr == null && publicAttr == null)
074: reportSchemaError("PublicSystemOnNotation", null, elmNode);
075:
076: XSNotationDecl notation = new XSNotationDecl();
077: notation.fName = nameAttr;
078: notation.fTargetNamespace = schemaDoc.fTargetNamespace;
079: notation.fPublicId = publicAttr;
080: notation.fSystemId = systemAttr;
081:
082: //check content
083: Element content = DOMUtil.getFirstChildElement(elmNode);
084: XSAnnotationImpl annotation = null;
085:
086: if (content != null
087: && DOMUtil.getLocalName(content).equals(
088: SchemaSymbols.ELT_ANNOTATION)) {
089: annotation = traverseAnnotationDecl(content, attrValues,
090: false, schemaDoc);
091: content = DOMUtil.getNextSiblingElement(content);
092: } else {
093: String text = DOMUtil.getSyntheticAnnotation(elmNode);
094: if (text != null) {
095: annotation = traverseSyntheticAnnotation(elmNode, text,
096: attrValues, false, schemaDoc);
097: }
098: }
099: XSObjectList annotations;
100: if (annotation != null) {
101: annotations = new XSObjectListImpl();
102: ((XSObjectListImpl) annotations).add(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,
109: "(annotation?)", DOMUtil.getLocalName(content) };
110: reportSchemaError("s4s-elt-must-match.1", args, content);
111:
112: }
113: grammar.addGlobalNotationDecl(notation);
114: fAttrChecker.returnAttrArray(attrValues, schemaDoc);
115:
116: return notation;
117: }
118: }
|