~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
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.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.xs.traversers;
 
19
 
 
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;
 
28
 
 
29
/**
 
30
 * This class contains code that is used to traverse <keyref>s.
 
31
 *
 
32
 * @xerces.internal 
 
33
 *
 
34
 * @author Neil Graham, IBM
 
35
 * @version $Id: XSDKeyrefTraverser.java,v 1.2 2009/12/10 03:18:40 matthewoliver Exp $
 
36
 */
 
37
class XSDKeyrefTraverser extends XSDAbstractIDConstraintTraverser {
 
38
 
 
39
    public XSDKeyrefTraverser (XSDHandler handler,
 
40
                                  XSAttributeChecker gAttrCheck) {
 
41
        super(handler, gAttrCheck);
 
42
    }
 
43
 
 
44
    void traverse(Element krElem, XSElementDecl element,
 
45
            XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
 
46
 
 
47
        // General Attribute Checking
 
48
        Object[] attrValues = fAttrChecker.checkAttributes(krElem, false, schemaDoc);
 
49
 
 
50
        // create identity constraint
 
51
        String krName = (String)attrValues[XSAttributeChecker.ATTIDX_NAME];
 
52
        if(krName == null){
 
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);
 
56
            return;
 
57
        }
 
58
        QName kName = (QName)attrValues[XSAttributeChecker.ATTIDX_REFER];
 
59
        if(kName == null){
 
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);
 
63
            return;
 
64
        }
 
65
 
 
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
 
70
        if (ret != null) {
 
71
            if (ret.getCategory() == IdentityConstraint.IC_KEY ||
 
72
                ret.getCategory() == IdentityConstraint.IC_UNIQUE) {
 
73
                key = (UniqueOrKey)ret;
 
74
            } else {
 
75
                reportSchemaError("src-resolve", new Object[]{kName.rawname, "identity constraint key/unique"}, krElem);
 
76
            }
 
77
        }
 
78
 
 
79
        if(key == null) {
 
80
            fAttrChecker.returnAttrArray(attrValues, schemaDoc);
 
81
            return;
 
82
        }
 
83
 
 
84
        KeyRef keyRef = new KeyRef(schemaDoc.fTargetNamespace, krName, element.fName, key);
 
85
 
 
86
        // add to element decl
 
87
        traverseIdentityConstraint(keyRef, krElem, schemaDoc, attrValues);
 
88
 
 
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);
 
93
        } else {
 
94
            // add key reference to element decl
 
95
            // and stuff this in the grammar
 
96
            grammar.addIDConstraintDecl(element, keyRef);
 
97
        }
 
98
 
 
99
        // and put back attributes
 
100
        fAttrChecker.returnAttrArray(attrValues, schemaDoc);
 
101
    } // traverse(Element,int,XSDocumentInfo, SchemaGrammar)
 
102
} // XSDKeyrefTraverser
 
103