01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.UniqueOrKey;
25: import org.apache.xerces.util.DOMUtil;
26: import org.w3c.dom.Element;
27:
28: /**
29: * This class contains code that is used to traverse both <key>s and
30: * <unique>s.
31: *
32: * @xerces.internal
33: *
34: * @author Neil Graham, IBM
35: * @version $Id: XSDUniqueOrKeyTraverser.java 446725 2006-09-15 20:40:10Z mrglavas $
36: */
37: class XSDUniqueOrKeyTraverser extends XSDAbstractIDConstraintTraverser {
38:
39: public XSDUniqueOrKeyTraverser(XSDHandler handler,
40: XSAttributeChecker gAttrCheck) {
41: super (handler, gAttrCheck);
42: }
43:
44: void traverse(Element uElem, XSElementDecl element,
45: XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
46:
47: // General Attribute Checking
48: Object[] attrValues = fAttrChecker.checkAttributes(uElem,
49: false, schemaDoc);
50:
51: // create identity constraint
52: String uName = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
53:
54: if (uName == null) {
55: reportSchemaError("s4s-att-must-appear",
56: new Object[] { DOMUtil.getLocalName(uElem),
57: SchemaSymbols.ATT_NAME }, uElem);
58: //return this array back to pool
59: fAttrChecker.returnAttrArray(attrValues, schemaDoc);
60: return;
61: }
62:
63: UniqueOrKey uniqueOrKey = null;
64: if (DOMUtil.getLocalName(uElem)
65: .equals(SchemaSymbols.ELT_UNIQUE)) {
66: uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace,
67: uName, element.fName, IdentityConstraint.IC_UNIQUE);
68: } else {
69: uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace,
70: uName, element.fName, IdentityConstraint.IC_KEY);
71: }
72: // it's XSDElementTraverser's job to ensure that there's no
73: // duplication (or if there is that restriction is involved
74: // and there's identity).
75:
76: // get selector and fields
77: traverseIdentityConstraint(uniqueOrKey, uElem, schemaDoc,
78: attrValues);
79:
80: // and stuff this in the grammar
81: grammar.addIDConstraintDecl(element, uniqueOrKey);
82:
83: // and fix up attributeChecker
84: fAttrChecker.returnAttrArray(attrValues, schemaDoc);
85: } // traverse(Element,XSDElementDecl,XSDocumentInfo, SchemaGrammar)
86: } // XSDUniqueOrKeyTraverser
|