KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > xs > traversers > XSDAttributeGroupTraverser


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 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
59 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
60 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
61 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;
62 import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl;
63 import com.sun.org.apache.xerces.internal.util.DOMUtil;
64 import com.sun.org.apache.xerces.internal.util.XMLSymbols;
65 import com.sun.org.apache.xerces.internal.xni.QName;
66 import org.w3c.dom.Element JavaDoc;
67
68 /**
69  * The attribute group definition schema component traverser.
70  *
71  * <attributeGroup
72  * id = ID
73  * name = NCName
74  * ref = QName
75  * {any attributes with non-schema namespace . . .}>
76  * Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
77  * </attributeGroup>
78  *
79  * @author Rahul Srivastava, Sun Microsystems Inc.
80  * @author Sandy Gao, IBM
81  *
82  * @version $Id: XSDAttributeGroupTraverser.java,v 1.11 2003/06/23 16:35:22 neilg Exp $
83  */

84 class XSDAttributeGroupTraverser extends XSDAbstractTraverser {
85
86     XSDAttributeGroupTraverser (XSDHandler handler,
87                                 XSAttributeChecker gAttrCheck) {
88
89         super(handler, gAttrCheck);
90     }
91
92
93     XSAttributeGroupDecl traverseLocal(Element JavaDoc elmNode,
94                                        XSDocumentInfo schemaDoc,
95                                        SchemaGrammar grammar) {
96
97         // General Attribute Checking for elmNode declared locally
98
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
99
100         // get attribute
101
QName refAttr = (QName) attrValues[XSAttributeChecker.ATTIDX_REF];
102
103         XSAttributeGroupDecl attrGrp = null;
104
105         // ref should be here.
106
if (refAttr == null) {
107             reportSchemaError("s4s-att-must-appear", new Object JavaDoc[]{"attributeGroup (local)", "ref"}, elmNode);
108             fAttrChecker.returnAttrArray(attrValues, schemaDoc);
109             return null;
110         }
111
112         // get global decl
113
attrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTEGROUP_TYPE, refAttr, elmNode);
114
115
116         // no children are allowed here except annotation, which is optional.
117
Element JavaDoc child = DOMUtil.getFirstChildElement(elmNode);
118         if (child != null) {
119             String JavaDoc childName = DOMUtil.getLocalName(child);
120             if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) {
121                 traverseAnnotationDecl(child, attrValues, false, schemaDoc);
122                 child = DOMUtil.getNextSiblingElement(child);
123             }
124
125             if (child != null) {
126                 Object JavaDoc[] args = new Object JavaDoc [] {refAttr.rawname, "(annotation?)", DOMUtil.getLocalName(child)};
127                 reportSchemaError("s4s-elt-must-match.1", args, child);
128             }
129          } // if
130

131         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
132         return attrGrp;
133
134     } // traverseLocal
135

136     XSAttributeGroupDecl traverseGlobal(Element JavaDoc elmNode,
137                                         XSDocumentInfo schemaDoc,
138                                         SchemaGrammar grammar) {
139
140         XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl();
141
142         // General Attribute Checking for elmNode declared globally
143
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc);
144
145         String JavaDoc nameAttr = (String JavaDoc) attrValues[XSAttributeChecker.ATTIDX_NAME];
146
147         // global declaration must have a name
148
if (nameAttr == null) {
149             reportSchemaError("s4s-att-must-appear", new Object JavaDoc[]{"attributeGroup (global)", "name"}, elmNode);
150             nameAttr = "no name";
151         }
152
153         attrGrp.fName = nameAttr;
154         attrGrp.fTargetNamespace = schemaDoc.fTargetNamespace;
155
156         // check the content
157
Element JavaDoc child = DOMUtil.getFirstChildElement(elmNode);
158         XSAnnotationImpl annotation = null;
159
160         if (child!=null) {
161             String JavaDoc childName = DOMUtil.getLocalName(child);
162             if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) {
163               annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
164               child = DOMUtil.getNextSiblingElement(child);
165           }
166         }
167
168         // Traverse the attribute and attribute group elements and fill in the
169
// attributeGroup structure
170

171         Element JavaDoc nextNode = traverseAttrsAndAttrGrps(child, attrGrp, schemaDoc, grammar, null);
172         if (nextNode!=null) {
173             // An invalid element was found...
174
Object JavaDoc[] args = new Object JavaDoc [] {nameAttr, "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))", DOMUtil.getLocalName(nextNode)};
175             reportSchemaError("s4s-elt-must-match.1", args, nextNode);
176         }
177  
178         // Remove prohibited attributes from the set
179
attrGrp.removeProhibitedAttrs();
180         
181         // check for restricted redefine:
182
XSAttributeGroupDecl redefinedAttrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction(
183                 XSDHandler.ATTRIBUTEGROUP_TYPE,
184                 new QName(XMLSymbols.EMPTY_STRING, nameAttr, nameAttr, schemaDoc.fTargetNamespace),
185                 schemaDoc, elmNode);
186         if(redefinedAttrGrp != null) {
187             Object JavaDoc[] errArgs = attrGrp.validRestrictionOf(nameAttr, redefinedAttrGrp);
188             if (errArgs != null) {
189                 reportSchemaError((String JavaDoc)errArgs[errArgs.length-1], errArgs, child);
190                 reportSchemaError("src-redefine.7.2.2", new Object JavaDoc [] {nameAttr, errArgs[errArgs.length-1]}, child);
191             }
192         }
193
194         attrGrp.fAnnotation = annotation;
195
196         // make an entry in global declarations.
197
grammar.addGlobalAttributeGroupDecl(attrGrp);
198
199         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
200         return attrGrp;
201
202     } // traverseGlobal
203

204 } // XSDAttributeGroupTraverser
205
Popular Tags