KickJava   Java API By Example, From Geeks To Geeks.

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


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.UniqueOrKey;
24 import org.apache.xerces.util.DOMUtil;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * This class contains code that is used to traverse both <key>s and
29  * <unique>s.
30  *
31  * @xerces.internal
32  *
33  * @author Neil Graham, IBM
34  * @version $Id: XSDUniqueOrKeyTraverser.java,v 1.8 2004/10/06 15:14:48 mrglavas Exp $
35  */

36 class XSDUniqueOrKeyTraverser extends XSDAbstractIDConstraintTraverser {
37
38     public XSDUniqueOrKeyTraverser (XSDHandler handler,
39                                   XSAttributeChecker gAttrCheck) {
40         super(handler, gAttrCheck);
41     }
42
43
44     void traverse(Element JavaDoc uElem, XSElementDecl element,
45             XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
46
47         // General Attribute Checking
48
Object JavaDoc[] attrValues = fAttrChecker.checkAttributes(uElem, false, schemaDoc);
49
50         // create identity constraint
51
String JavaDoc uName = (String JavaDoc)attrValues[XSAttributeChecker.ATTIDX_NAME];
52
53         if(uName == null){
54             reportSchemaError("s4s-att-must-appear", new Object JavaDoc [] {DOMUtil.getLocalName(uElem) , SchemaSymbols.ATT_NAME }, uElem);
55             //return this array back to pool
56
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
57             return;
58         }
59
60         UniqueOrKey uniqueOrKey = null;
61         if(DOMUtil.getLocalName(uElem).equals(SchemaSymbols.ELT_UNIQUE)) {
62             uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace, uName, element.fName, IdentityConstraint.IC_UNIQUE);
63         } else {
64             uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace, uName, element.fName, IdentityConstraint.IC_KEY);
65         }
66         // it's XSDElementTraverser's job to ensure that there's no
67
// duplication (or if there is that restriction is involved
68
// and there's identity).
69

70         // get selector and fields
71
traverseIdentityConstraint(uniqueOrKey, uElem, schemaDoc, attrValues);
72
73         // and stuff this in the grammar
74
grammar.addIDConstraintDecl(element, uniqueOrKey);
75
76         // and fix up attributeChecker
77
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
78     } // traverse(Element,XSDElementDecl,XSDocumentInfo, SchemaGrammar)
79
} // XSDUniqueOrKeyTraverser
80
Popular Tags