KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > traversers > XSDNotationTraverser


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.xs.traversers;
18
19 import org.apache.xerces.impl.xs.SchemaGrammar;
20 import org.apache.xerces.impl.xs.SchemaSymbols;
21 import org.apache.xerces.impl.xs.XSAnnotationImpl;
22 import org.apache.xerces.impl.xs.XSNotationDecl;
23 import org.apache.xerces.util.DOMUtil;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * The notation declaration schema component traverser.
28  *
29  * <notation
30  * id = ID
31  * name = NCName
32  * public = anyURI
33  * system = anyURI
34  * {any attributes with non-schema namespace . . .}>
35  * Content: (annotation?)
36  * </notation>
37  *
38  * @xerces.internal
39  *
40  * @author Rahul Srivastava, Sun Microsystems Inc.
41  * @author Elena Litani, IBM
42  * @version $Id: XSDNotationTraverser.java,v 1.18 2004/12/20 05:43:36 mrglavas Exp $
43  */

44 class XSDNotationTraverser extends XSDAbstractTraverser {
45     
46     XSDNotationTraverser (XSDHandler handler,
47             XSAttributeChecker gAttrCheck) {
48         super(handler, gAttrCheck);
49     }
50     
51     XSNotationDecl traverse(Element JavaDoc elmNode,
52             XSDocumentInfo schemaDoc,
53             SchemaGrammar grammar) {
54         
55         // General Attribute Checking for elmNode
56
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc);
57         //get attributes
58
String JavaDoc nameAttr = (String JavaDoc) attrValues[XSAttributeChecker.ATTIDX_NAME];
59         
60         String JavaDoc publicAttr = (String JavaDoc) attrValues[XSAttributeChecker.ATTIDX_PUBLIC];
61         String JavaDoc systemAttr = (String JavaDoc) attrValues[XSAttributeChecker.ATTIDX_SYSTEM];
62         if (nameAttr == null) {
63             reportSchemaError("s4s-att-must-appear", new Object JavaDoc[]{SchemaSymbols.ELT_NOTATION, SchemaSymbols.ATT_NAME}, elmNode);
64             fAttrChecker.returnAttrArray(attrValues, schemaDoc);
65             return null;
66         }
67         
68         if (systemAttr == null && publicAttr == null)
69             reportSchemaError("PublicSystemOnNotation", null, elmNode);
70         
71         XSNotationDecl notation = new XSNotationDecl();
72         notation.fName = nameAttr;
73         notation.fTargetNamespace = schemaDoc.fTargetNamespace;
74         notation.fPublicId = publicAttr;
75         notation.fSystemId = systemAttr;
76         
77         //check content
78
Element JavaDoc content = DOMUtil.getFirstChildElement(elmNode);
79         XSAnnotationImpl annotation = null;
80         
81         if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
82             annotation = traverseAnnotationDecl(content, attrValues, false, schemaDoc);
83             content = DOMUtil.getNextSiblingElement(content);
84         }
85         else {
86             String JavaDoc text = DOMUtil.getSyntheticAnnotation(elmNode);
87             if (text != null) {
88                 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc);
89             }
90         }
91         notation.fAnnotation = annotation;
92         if (content!=null){
93             Object JavaDoc[] args = new Object JavaDoc [] {SchemaSymbols.ELT_NOTATION, "(annotation?)", DOMUtil.getLocalName(content)};
94             reportSchemaError("s4s-elt-must-match.1", args, content);
95             
96         }
97         grammar.addGlobalNotationDecl(notation);
98         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
99         
100         return notation;
101     }
102 }
103
Popular Tags