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.XSParticleDecl;
024: import org.apache.xerces.impl.xs.XSWildcardDecl;
025: import org.apache.xerces.impl.xs.util.XInt;
026: import org.apache.xerces.impl.xs.util.XSObjectListImpl;
027: import org.apache.xerces.util.DOMUtil;
028: import org.apache.xerces.xs.XSObjectList;
029: import org.w3c.dom.Element;
030:
031: /**
032: * The wildcard schema component traverser.
033: *
034: * <any
035: * id = ID
036: * maxOccurs = (nonNegativeInteger | unbounded) : 1
037: * minOccurs = nonNegativeInteger : 1
038: * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
039: * processContents = (lax | skip | strict) : strict
040: * {any attributes with non-schema namespace . . .}>
041: * Content: (annotation?)
042: * </any>
043: *
044: * <anyAttribute
045: * id = ID
046: * namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
047: * processContents = (lax | skip | strict) : strict
048: * {any attributes with non-schema namespace . . .}>
049: * Content: (annotation?)
050: * </anyAttribute>
051: *
052: * @xerces.internal
053: *
054: * @author Rahul Srivastava, Sun Microsystems Inc.
055: * @author Sandy Gao, IBM
056: *
057: * @version $Id: XSDWildcardTraverser.java 449424 2006-09-24 16:22:30Z mrglavas $
058: */
059: class XSDWildcardTraverser extends XSDAbstractTraverser {
060:
061: /**
062: * constructor
063: *
064: * @param handler
065: * @param errorReporter
066: * @param gAttrCheck
067: */
068: XSDWildcardTraverser(XSDHandler handler,
069: XSAttributeChecker gAttrCheck) {
070: super (handler, gAttrCheck);
071: }
072:
073: /**
074: * Traverse <any>
075: *
076: * @param elmNode
077: * @param schemaDoc
078: * @param grammar
079: * @return the wildcard node index
080: */
081: XSParticleDecl traverseAny(Element elmNode,
082: XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
083:
084: // General Attribute Checking for elmNode
085: Object[] attrValues = fAttrChecker.checkAttributes(elmNode,
086: false, schemaDoc);
087: XSWildcardDecl wildcard = traverseWildcardDecl(elmNode,
088: attrValues, schemaDoc, grammar);
089:
090: // for <any>, need to create a new particle to reflect the min/max values
091: XSParticleDecl particle = null;
092: if (wildcard != null) {
093: int min = ((XInt) attrValues[XSAttributeChecker.ATTIDX_MINOCCURS])
094: .intValue();
095: int max = ((XInt) attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS])
096: .intValue();
097: if (max != 0) {
098: if (fSchemaHandler.fDeclPool != null) {
099: particle = fSchemaHandler.fDeclPool
100: .getParticleDecl();
101: } else {
102: particle = new XSParticleDecl();
103: }
104: particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
105: particle.fValue = wildcard;
106: particle.fMinOccurs = min;
107: particle.fMaxOccurs = max;
108: particle.fAnnotations = wildcard.fAnnotations;
109: }
110: }
111:
112: fAttrChecker.returnAttrArray(attrValues, schemaDoc);
113:
114: return particle;
115: }
116:
117: /**
118: * Traverse <anyAttribute>
119: *
120: * @param elmNode
121: * @param schemaDoc
122: * @param grammar
123: * @return the wildcard node index
124: */
125: XSWildcardDecl traverseAnyAttribute(Element elmNode,
126: XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
127:
128: // General Attribute Checking for elmNode
129: Object[] attrValues = fAttrChecker.checkAttributes(elmNode,
130: false, schemaDoc);
131: XSWildcardDecl wildcard = traverseWildcardDecl(elmNode,
132: attrValues, schemaDoc, grammar);
133: fAttrChecker.returnAttrArray(attrValues, schemaDoc);
134:
135: return wildcard;
136: }
137:
138: /**
139: *
140: * @param elmNode
141: * @param attrValues
142: * @param schemaDoc
143: * @param grammar
144: * @return the wildcard node index
145: */
146: XSWildcardDecl traverseWildcardDecl(Element elmNode,
147: Object[] attrValues, XSDocumentInfo schemaDoc,
148: SchemaGrammar grammar) {
149:
150: //get all attributes
151: XSWildcardDecl wildcard = new XSWildcardDecl();
152: // namespace type
153: XInt namespaceTypeAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_NAMESPACE];
154: wildcard.fType = namespaceTypeAttr.shortValue();
155: // namespace list
156: wildcard.fNamespaceList = (String[]) attrValues[XSAttributeChecker.ATTIDX_NAMESPACE_LIST];
157: // process contents
158: XInt processContentsAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_PROCESSCONTENTS];
159: wildcard.fProcessContents = processContentsAttr.shortValue();
160:
161: //check content
162: Element child = DOMUtil.getFirstChildElement(elmNode);
163: XSAnnotationImpl annotation = null;
164: if (child != null) {
165: if (DOMUtil.getLocalName(child).equals(
166: SchemaSymbols.ELT_ANNOTATION)) {
167: annotation = traverseAnnotationDecl(child, attrValues,
168: false, schemaDoc);
169: child = DOMUtil.getNextSiblingElement(child);
170: } else {
171: String text = DOMUtil.getSyntheticAnnotation(elmNode);
172: if (text != null) {
173: annotation = traverseSyntheticAnnotation(elmNode,
174: text, attrValues, false, schemaDoc);
175: }
176: }
177:
178: if (child != null) {
179: reportSchemaError("s4s-elt-must-match.1", new Object[] {
180: "wildcard", "(annotation?)",
181: DOMUtil.getLocalName(child) }, elmNode);
182: }
183: } else {
184: String text = DOMUtil.getSyntheticAnnotation(elmNode);
185: if (text != null) {
186: annotation = traverseSyntheticAnnotation(elmNode, text,
187: attrValues, false, schemaDoc);
188: }
189: }
190: XSObjectList annotations;
191: if (annotation != null) {
192: annotations = new XSObjectListImpl();
193: ((XSObjectListImpl) annotations).add(annotation);
194: } else {
195: annotations = XSObjectListImpl.EMPTY_LIST;
196: }
197: wildcard.fAnnotations = annotations;
198:
199: return wildcard;
200:
201: } // traverseWildcardDecl
202:
203: } // XSDWildcardTraverser
|