KickJava   Java API By Example, From Geeks To Geeks.

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


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
58 package com.sun.org.apache.xerces.internal.impl.xs.traversers;
59
60 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
61 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
62 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;
63 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;
64 import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl;
65 import com.sun.org.apache.xerces.internal.impl.xs.util.XInt;
66 import com.sun.org.apache.xerces.internal.util.DOMUtil;
67 import org.w3c.dom.Element JavaDoc;
68
69 /**
70  * The wildcard schema component traverser.
71  *
72  * <any
73  * id = ID
74  * maxOccurs = (nonNegativeInteger | unbounded) : 1
75  * minOccurs = nonNegativeInteger : 1
76  * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
77  * processContents = (lax | skip | strict) : strict
78  * {any attributes with non-schema namespace . . .}>
79  * Content: (annotation?)
80  * </any>
81  *
82  * <anyAttribute
83  * id = ID
84  * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
85  * processContents = (lax | skip | strict) : strict
86  * {any attributes with non-schema namespace . . .}>
87  * Content: (annotation?)
88  * </anyAttribute>
89  *
90  * @author Rahul Srivastava, Sun Microsystems Inc.
91  * @author Sandy Gao, IBM
92  *
93  * @version $Id: XSDWildcardTraverser.java,v 1.11 2003/06/23 16:35:22 neilg Exp $
94  */

95 class XSDWildcardTraverser extends XSDAbstractTraverser {
96
97     /**
98      * constructor
99      *
100      * @param handler
101      * @param errorReporter
102      * @param gAttrCheck
103      */

104     XSDWildcardTraverser (XSDHandler handler,
105                           XSAttributeChecker gAttrCheck) {
106         super(handler, gAttrCheck);
107     }
108
109
110     /**
111      * Traverse <any>
112      *
113      * @param elmNode
114      * @param schemaDoc
115      * @param grammar
116      * @return the wildcard node index
117      */

118     XSParticleDecl traverseAny(Element JavaDoc elmNode,
119                                XSDocumentInfo schemaDoc,
120                                SchemaGrammar grammar) {
121
122         // General Attribute Checking for elmNode
123
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
124         XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar);
125
126         // for <any>, need to create a new particle to reflect the min/max values
127
XSParticleDecl particle = null;
128         if (wildcard != null) {
129             int min = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]).intValue();
130             int max = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]).intValue();
131             if (max != 0) {
132                 if (fSchemaHandler.fDeclPool !=null) {
133                     particle = fSchemaHandler.fDeclPool.getParticleDecl();
134                 } else {
135                     particle = new XSParticleDecl();
136                 }
137                 particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
138                 particle.fValue = wildcard;
139                 particle.fMinOccurs = min;
140                 particle.fMaxOccurs = max;
141             }
142         }
143
144         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
145
146         return particle;
147     }
148
149
150     /**
151      * Traverse <anyAttribute>
152      *
153      * @param elmNode
154      * @param schemaDoc
155      * @param grammar
156      * @return the wildcard node index
157      */

158     XSWildcardDecl traverseAnyAttribute(Element JavaDoc elmNode,
159                                         XSDocumentInfo schemaDoc,
160                                         SchemaGrammar grammar) {
161
162         // General Attribute Checking for elmNode
163
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
164         XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar);
165         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
166
167         return wildcard;
168     }
169
170
171     /**
172      *
173      * @param elmNode
174      * @param attrValues
175      * @param schemaDoc
176      * @param grammar
177      * @return the wildcard node index
178      */

179      XSWildcardDecl traverseWildcardDecl(Element JavaDoc elmNode,
180                                          Object JavaDoc[] attrValues,
181                                          XSDocumentInfo schemaDoc,
182                                          SchemaGrammar grammar) {
183
184         //get all attributes
185
XSWildcardDecl wildcard = new XSWildcardDecl();
186         // namespace type
187
XInt namespaceTypeAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_NAMESPACE];
188         wildcard.fType = namespaceTypeAttr.shortValue();
189         // namespace list
190
wildcard.fNamespaceList = (String JavaDoc[])attrValues[XSAttributeChecker.ATTIDX_NAMESPACE_LIST];
191         // process contents
192
XInt processContentsAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_PROCESSCONTENTS];
193         wildcard.fProcessContents = processContentsAttr.shortValue();
194
195         //check content
196
Element JavaDoc child = DOMUtil.getFirstChildElement(elmNode);
197         XSAnnotationImpl annotation = null;
198         if (child != null)
199         {
200             if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
201                 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
202                 child = DOMUtil.getNextSiblingElement(child);
203             }
204
205             if (child != null) {
206                 reportSchemaError("s4s-elt-must-match.1", new Object JavaDoc[]{"wildcard", "(annotation?)", DOMUtil.getLocalName(child)}, elmNode);
207             }
208         }
209         wildcard.fAnnotation = annotation;
210
211         return wildcard;
212
213     } // traverseWildcardDecl
214

215 } // XSDWildcardTraverser
216
Popular Tags