286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/Apackage com.sun.org.apache.xerces.internal.impl.xs.traversers;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;
286N/Aimport com.sun.org.apache.xerces.internal.util.DOMUtil;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLSymbols;
286N/Aimport com.sun.org.apache.xerces.internal.xni.QName;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSObjectList;
286N/Aimport org.w3c.dom.Element;
286N/A
286N/A/**
286N/A * The attribute group definition schema component traverser.
286N/A *
286N/A * <attributeGroup
286N/A * id = ID
286N/A * name = NCName
286N/A * ref = QName
286N/A * {any attributes with non-schema namespace . . .}>
286N/A * Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
286N/A * </attributeGroup>
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Rahul Srivastava, Sun Microsystems Inc.
286N/A * @author Sandy Gao, IBM
286N/A *
286N/A * @version $Id: XSDAttributeGroupTraverser.java,v 1.7 2010-11-01 04:40:02 joehw Exp $
286N/A */
286N/Aclass XSDAttributeGroupTraverser extends XSDAbstractTraverser {
286N/A
286N/A XSDAttributeGroupTraverser (XSDHandler handler,
286N/A XSAttributeChecker gAttrCheck) {
286N/A
286N/A super(handler, gAttrCheck);
286N/A }
286N/A
286N/A
286N/A XSAttributeGroupDecl traverseLocal(Element elmNode,
286N/A XSDocumentInfo schemaDoc,
286N/A SchemaGrammar grammar) {
286N/A
286N/A // General Attribute Checking for elmNode declared locally
286N/A Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
286N/A
286N/A // get attribute
286N/A QName refAttr = (QName) attrValues[XSAttributeChecker.ATTIDX_REF];
286N/A
286N/A XSAttributeGroupDecl attrGrp = null;
286N/A
286N/A // ref should be here.
286N/A if (refAttr == null) {
286N/A reportSchemaError("s4s-att-must-appear", new Object[]{"attributeGroup (local)", "ref"}, elmNode);
286N/A fAttrChecker.returnAttrArray(attrValues, schemaDoc);
286N/A return null;
286N/A }
286N/A
286N/A // get global decl
286N/A attrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTEGROUP_TYPE, refAttr, elmNode);
286N/A
286N/A // no children are allowed here except annotation, which is optional.
286N/A Element child = DOMUtil.getFirstChildElement(elmNode);
286N/A if (child != null) {
286N/A String childName = DOMUtil.getLocalName(child);
286N/A if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) {
286N/A traverseAnnotationDecl(child, attrValues, false, schemaDoc);
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A } else {
286N/A String text = DOMUtil.getSyntheticAnnotation(child);
286N/A if (text != null) {
286N/A traverseSyntheticAnnotation(child, text, attrValues, false, schemaDoc);
286N/A }
286N/A }
286N/A
286N/A if (child != null) {
286N/A Object[] args = new Object [] {refAttr.rawname, "(annotation?)", DOMUtil.getLocalName(child)};
286N/A reportSchemaError("s4s-elt-must-match.1", args, child);
286N/A }
286N/A } // if
286N/A
286N/A fAttrChecker.returnAttrArray(attrValues, schemaDoc);
286N/A return attrGrp;
286N/A
286N/A } // traverseLocal
286N/A
286N/A XSAttributeGroupDecl traverseGlobal(Element elmNode,
286N/A XSDocumentInfo schemaDoc,
286N/A SchemaGrammar grammar) {
286N/A
286N/A XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl();
286N/A
286N/A // General Attribute Checking for elmNode declared globally
286N/A Object[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc);
286N/A
286N/A String nameAttr = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
286N/A
286N/A // global declaration must have a name
286N/A if (nameAttr == null) {
286N/A reportSchemaError("s4s-att-must-appear", new Object[]{"attributeGroup (global)", "name"}, elmNode);
286N/A nameAttr = NO_NAME;
286N/A }
286N/A
286N/A attrGrp.fName = nameAttr;
286N/A attrGrp.fTargetNamespace = schemaDoc.fTargetNamespace;
286N/A
286N/A // check the content
286N/A Element child = DOMUtil.getFirstChildElement(elmNode);
286N/A XSAnnotationImpl annotation = null;
286N/A
286N/A if (child!=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
286N/A annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A }
286N/A else {
286N/A String text = DOMUtil.getSyntheticAnnotation(elmNode);
286N/A if (text != null) {
286N/A annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc);
286N/A }
286N/A }
286N/A
286N/A // Traverse the attribute and attribute group elements and fill in the
286N/A // attributeGroup structure
286N/A
286N/A Element nextNode = traverseAttrsAndAttrGrps(child, attrGrp, schemaDoc, grammar, null);
286N/A if (nextNode!=null) {
286N/A // An invalid element was found...
286N/A Object[] args = new Object [] {nameAttr, "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))", DOMUtil.getLocalName(nextNode)};
286N/A reportSchemaError("s4s-elt-must-match.1", args, nextNode);
286N/A }
286N/A
286N/A if (nameAttr.equals(NO_NAME)) {
286N/A // if a global group doesn't have a name, then don't add it.
286N/A fAttrChecker.returnAttrArray(attrValues, schemaDoc);
286N/A return null;
286N/A }
286N/A
286N/A // Remove prohibited attributes from the set
286N/A attrGrp.removeProhibitedAttrs();
286N/A
286N/A // check for restricted redefine:
286N/A XSAttributeGroupDecl redefinedAttrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction(
286N/A XSDHandler.ATTRIBUTEGROUP_TYPE,
286N/A new QName(XMLSymbols.EMPTY_STRING, nameAttr, nameAttr, schemaDoc.fTargetNamespace),
286N/A schemaDoc, elmNode);
286N/A if(redefinedAttrGrp != null) {
286N/A Object[] errArgs = attrGrp.validRestrictionOf(nameAttr, redefinedAttrGrp);
286N/A if (errArgs != null) {
286N/A reportSchemaError((String)errArgs[errArgs.length-1], errArgs, child);
286N/A reportSchemaError("src-redefine.7.2.2", new Object [] {nameAttr, errArgs[errArgs.length-1]}, child);
286N/A }
286N/A }
286N/A
286N/A XSObjectList annotations;
286N/A if (annotation != null) {
286N/A annotations = new XSObjectListImpl();
286N/A ((XSObjectListImpl)annotations).addXSObject (annotation);
286N/A } else {
286N/A annotations = XSObjectListImpl.EMPTY_LIST;
286N/A }
286N/A
286N/A attrGrp.fAnnotations = annotations;
286N/A
286N/A // make an entry in global declarations.
286N/A if (grammar.getGlobalAttributeGroupDecl(attrGrp.fName) == null) {
286N/A grammar.addGlobalAttributeGroupDecl(attrGrp);
286N/A }
286N/A
286N/A // also add it to extended map
286N/A final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
286N/A final XSAttributeGroupDecl attrGrp2 = grammar.getGlobalAttributeGroupDecl(attrGrp.fName, loc);
286N/A if (attrGrp2 == null) {
286N/A grammar.addGlobalAttributeGroupDecl(attrGrp, loc);
286N/A }
286N/A
286N/A // handle duplicates
286N/A if (fSchemaHandler.fTolerateDuplicates) {
286N/A if (attrGrp2 != null) {
286N/A attrGrp = attrGrp2;
286N/A }
286N/A fSchemaHandler.addGlobalAttributeGroupDecl(attrGrp);
286N/A }
286N/A
286N/A fAttrChecker.returnAttrArray(attrValues, schemaDoc);
286N/A return attrGrp;
286N/A
286N/A } // traverseGlobal
286N/A
286N/A} // XSDAttributeGroupTraverser