KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001, 2002,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.XSElementDecl;
22 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
23 import org.apache.xerces.impl.xs.identity.KeyRef;
24 import org.apache.xerces.impl.xs.identity.UniqueOrKey;
25 import org.apache.xerces.xni.QName;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * This class contains code that is used to traverse <keyref>s.
30  *
31  * @xerces.internal
32  *
33  * @author Neil Graham, IBM
34  * @version $Id: XSDKeyrefTraverser.java,v 1.8 2004/10/06 15:14:48 mrglavas Exp $
35  */

36 class XSDKeyrefTraverser extends XSDAbstractIDConstraintTraverser {
37
38     public XSDKeyrefTraverser (XSDHandler handler,
39                                   XSAttributeChecker gAttrCheck) {
40         super(handler, gAttrCheck);
41     }
42
43     void traverse(Element JavaDoc krElem, XSElementDecl element,
44             XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
45
46         // General Attribute Checking
47
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(krElem, false, schemaDoc);
48
49         // create identity constraint
50
String JavaDoc krName = (String JavaDoc)attrValues[XSAttributeChecker.ATTIDX_NAME];
51         if(krName == null){
52             reportSchemaError("s4s-att-must-appear", new Object JavaDoc [] {SchemaSymbols.ELT_KEYREF , SchemaSymbols.ATT_NAME }, krElem);
53             //return this array back to pool
54
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
55             return;
56         }
57         QName kName = (QName)attrValues[XSAttributeChecker.ATTIDX_REFER];
58         if(kName == null){
59             reportSchemaError("s4s-att-must-appear", new Object JavaDoc [] {SchemaSymbols.ELT_KEYREF , SchemaSymbols.ATT_REFER }, krElem);
60             //return this array back to pool
61
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
62             return;
63         }
64
65         UniqueOrKey key = null;
66         IdentityConstraint ret = (IdentityConstraint)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.IDENTITYCONSTRAINT_TYPE, kName, krElem);
67         // if ret == null, we've already reported an error in getGlobalDecl
68
// we report an error only when ret != null, and the return type keyref
69
if (ret != null) {
70             if (ret.getCategory() == IdentityConstraint.IC_KEY ||
71                 ret.getCategory() == IdentityConstraint.IC_UNIQUE) {
72                 key = (UniqueOrKey)ret;
73             } else {
74                 reportSchemaError("src-resolve", new Object JavaDoc[]{kName.rawname, "identity constraint key/unique"}, krElem);
75             }
76         }
77
78         if(key == null) {
79             fAttrChecker.returnAttrArray(attrValues, schemaDoc);
80             return;
81         }
82
83         KeyRef keyRef = new KeyRef(schemaDoc.fTargetNamespace, krName, element.fName, key);
84
85         // add to element decl
86
traverseIdentityConstraint(keyRef, krElem, schemaDoc, attrValues);
87
88         //Schema Component Constraint: Identity-constraint Definition Properties Correct
89
//2 If the {identity-constraint category} is keyref, the cardinality of the {fields} must equal that of the {fields} of the {referenced key}.
90
if(key.getFieldCount() != keyRef.getFieldCount()) {
91             reportSchemaError("c-props-correct.2" , new Object JavaDoc [] {krName,key.getIdentityConstraintName()}, krElem);
92         } else {
93             // add key reference to element decl
94
// and stuff this in the grammar
95
grammar.addIDConstraintDecl(element, keyRef);
96         }
97
98         // and put back attributes
99
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
100     } // traverse(Element,int,XSDocumentInfo, SchemaGrammar)
101
} // XSDKeyrefTraverser
102

103
Popular Tags