2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.xerces.impl.xs.traversers;
20
import org.apache.xerces.impl.xs.SchemaGrammar;
21
import org.apache.xerces.impl.xs.SchemaSymbols;
22
import org.apache.xerces.impl.xs.XSElementDecl;
23
import org.apache.xerces.impl.xs.identity.IdentityConstraint;
24
import org.apache.xerces.impl.xs.identity.KeyRef;
25
import org.apache.xerces.impl.xs.identity.UniqueOrKey;
26
import org.apache.xerces.xni.QName;
27
import org.w3c.dom.Element;
30
* This class contains code that is used to traverse <keyref>s.
34
* @author Neil Graham, IBM
35
* @version $Id: XSDKeyrefTraverser.java,v 1.2 2009/12/10 03:18:40 matthewoliver Exp $
37
class XSDKeyrefTraverser extends XSDAbstractIDConstraintTraverser {
39
public XSDKeyrefTraverser (XSDHandler handler,
40
XSAttributeChecker gAttrCheck) {
41
super(handler, gAttrCheck);
44
void traverse(Element krElem, XSElementDecl element,
45
XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
47
// General Attribute Checking
48
Object[] attrValues = fAttrChecker.checkAttributes(krElem, false, schemaDoc);
50
// create identity constraint
51
String krName = (String)attrValues[XSAttributeChecker.ATTIDX_NAME];
53
reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_KEYREF , SchemaSymbols.ATT_NAME }, krElem);
54
//return this array back to pool
55
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
58
QName kName = (QName)attrValues[XSAttributeChecker.ATTIDX_REFER];
60
reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_KEYREF , SchemaSymbols.ATT_REFER }, krElem);
61
//return this array back to pool
62
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
66
UniqueOrKey key = null;
67
IdentityConstraint ret = (IdentityConstraint)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.IDENTITYCONSTRAINT_TYPE, kName, krElem);
68
// if ret == null, we've already reported an error in getGlobalDecl
69
// we report an error only when ret != null, and the return type keyref
71
if (ret.getCategory() == IdentityConstraint.IC_KEY ||
72
ret.getCategory() == IdentityConstraint.IC_UNIQUE) {
73
key = (UniqueOrKey)ret;
75
reportSchemaError("src-resolve", new Object[]{kName.rawname, "identity constraint key/unique"}, krElem);
80
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
84
KeyRef keyRef = new KeyRef(schemaDoc.fTargetNamespace, krName, element.fName, key);
86
// add to element decl
87
traverseIdentityConstraint(keyRef, krElem, schemaDoc, attrValues);
89
//Schema Component Constraint: Identity-constraint Definition Properties Correct
90
//2 If the {identity-constraint category} is keyref, the cardinality of the {fields} must equal that of the {fields} of the {referenced key}.
91
if(key.getFieldCount() != keyRef.getFieldCount()) {
92
reportSchemaError("c-props-correct.2" , new Object [] {krName,key.getIdentityConstraintName()}, krElem);
94
// add key reference to element decl
95
// and stuff this in the grammar
96
grammar.addIDConstraintDecl(element, keyRef);
99
// and put back attributes
100
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
101
} // traverse(Element,int,XSDocumentInfo, SchemaGrammar)
102
} // XSDKeyrefTraverser