KickJava   Java API By Example, From Geeks To Geeks.

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


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.XSParticleDecl;
23 import org.apache.xerces.impl.xs.XSWildcardDecl;
24 import org.apache.xerces.impl.xs.util.XInt;
25 import org.apache.xerces.util.DOMUtil;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * The wildcard schema component traverser.
30  *
31  * <any
32  * id = ID
33  * maxOccurs = (nonNegativeInteger | unbounded) : 1
34  * minOccurs = nonNegativeInteger : 1
35  * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
36  * processContents = (lax | skip | strict) : strict
37  * {any attributes with non-schema namespace . . .}>
38  * Content: (annotation?)
39  * </any>
40  *
41  * <anyAttribute
42  * id = ID
43  * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
44  * processContents = (lax | skip | strict) : strict
45  * {any attributes with non-schema namespace . . .}>
46  * Content: (annotation?)
47  * </anyAttribute>
48  *
49  * @xerces.internal
50  *
51  * @author Rahul Srivastava, Sun Microsystems Inc.
52  * @author Sandy Gao, IBM
53  *
54  * @version $Id: XSDWildcardTraverser.java,v 1.15 2004/12/20 05:43:36 mrglavas Exp $
55  */

56 class XSDWildcardTraverser extends XSDAbstractTraverser {
57     
58     /**
59      * constructor
60      *
61      * @param handler
62      * @param errorReporter
63      * @param gAttrCheck
64      */

65     XSDWildcardTraverser (XSDHandler handler,
66             XSAttributeChecker gAttrCheck) {
67         super(handler, gAttrCheck);
68     }
69     
70     
71     /**
72      * Traverse <any>
73      *
74      * @param elmNode
75      * @param schemaDoc
76      * @param grammar
77      * @return the wildcard node index
78      */

79     XSParticleDecl traverseAny(Element JavaDoc elmNode,
80             XSDocumentInfo schemaDoc,
81             SchemaGrammar grammar) {
82         
83         // General Attribute Checking for elmNode
84
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
85         XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar);
86         
87         // for <any>, need to create a new particle to reflect the min/max values
88
XSParticleDecl particle = null;
89         if (wildcard != null) {
90             int min = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]).intValue();
91             int max = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]).intValue();
92             if (max != 0) {
93                 if (fSchemaHandler.fDeclPool !=null) {
94                     particle = fSchemaHandler.fDeclPool.getParticleDecl();
95                 } else {
96                     particle = new XSParticleDecl();
97                 }
98                 particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
99                 particle.fValue = wildcard;
100                 particle.fMinOccurs = min;
101                 particle.fMaxOccurs = max;
102             }
103         }
104         
105         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
106         
107         return particle;
108     }
109     
110     
111     /**
112      * Traverse <anyAttribute>
113      *
114      * @param elmNode
115      * @param schemaDoc
116      * @param grammar
117      * @return the wildcard node index
118      */

119     XSWildcardDecl traverseAnyAttribute(Element JavaDoc elmNode,
120             XSDocumentInfo schemaDoc,
121             SchemaGrammar grammar) {
122         
123         // General Attribute Checking for elmNode
124
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
125         XSWildcardDecl wildcard = traverseWildcardDecl(elmNode, attrValues, schemaDoc, grammar);
126         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
127         
128         return wildcard;
129     }
130     
131     
132     /**
133      *
134      * @param elmNode
135      * @param attrValues
136      * @param schemaDoc
137      * @param grammar
138      * @return the wildcard node index
139      */

140     XSWildcardDecl traverseWildcardDecl(Element JavaDoc elmNode,
141             Object JavaDoc[] attrValues,
142             XSDocumentInfo schemaDoc,
143             SchemaGrammar grammar) {
144         
145         //get all attributes
146
XSWildcardDecl wildcard = new XSWildcardDecl();
147         // namespace type
148
XInt namespaceTypeAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_NAMESPACE];
149         wildcard.fType = namespaceTypeAttr.shortValue();
150         // namespace list
151
wildcard.fNamespaceList = (String JavaDoc[])attrValues[XSAttributeChecker.ATTIDX_NAMESPACE_LIST];
152         // process contents
153
XInt processContentsAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_PROCESSCONTENTS];
154         wildcard.fProcessContents = processContentsAttr.shortValue();
155         
156         //check content
157
Element JavaDoc child = DOMUtil.getFirstChildElement(elmNode);
158         XSAnnotationImpl annotation = null;
159         if (child != null)
160         {
161             if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
162                 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
163                 child = DOMUtil.getNextSiblingElement(child);
164             }
165             else {
166                 String JavaDoc text = DOMUtil.getSyntheticAnnotation(elmNode);
167                 if (text != null) {
168                     annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc);
169                 }
170             }
171             
172             if (child != null) {
173                 reportSchemaError("s4s-elt-must-match.1", new Object JavaDoc[]{"wildcard", "(annotation?)", DOMUtil.getLocalName(child)}, elmNode);
174             }
175         }
176         else {
177             String JavaDoc text = DOMUtil.getSyntheticAnnotation(elmNode);
178             if (text != null) {
179                 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc);
180             }
181         }
182         wildcard.fAnnotation = annotation;
183         
184         return wildcard;
185         
186     } // traverseWildcardDecl
187

188 } // XSDWildcardTraverser
189
Popular Tags