1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 59 60 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 61 62 import com.sun.org.apache.xerces.internal.util.DOMUtil; 63 import org.w3c.dom.Element ; 64 import com.sun.org.apache.xerces.internal.impl.xs.identity.*; 65 import com.sun.org.apache.xerces.internal.impl.xpath.*; 66 67 74 class XSDAbstractIDConstraintTraverser extends XSDAbstractTraverser { 75 76 public XSDAbstractIDConstraintTraverser (XSDHandler handler, 77 XSAttributeChecker gAttrCheck) { 78 super(handler, gAttrCheck); 79 } 80 81 void traverseIdentityConstraint(IdentityConstraint ic, 82 Element icElem, XSDocumentInfo schemaDoc, Object [] icElemAttrs) { 83 84 86 Element sElem = DOMUtil.getFirstChildElement(icElem); 88 if(sElem == null) { 89 reportSchemaError("s4s-elt-must-match.2", 90 new Object []{"identity constraint", "(annotation?, selector, field+)"}, 91 icElem); 92 return; 93 } 94 95 if (DOMUtil.getLocalName(sElem).equals(SchemaSymbols.ELT_ANNOTATION)) { 98 ic.addAnnotation(traverseAnnotationDecl(sElem, icElemAttrs, false, schemaDoc)); 99 sElem = DOMUtil.getNextSiblingElement(sElem); 100 } 101 if(sElem == null) { 103 reportSchemaError("s4s-elt-must-match.2", new Object []{"identity constraint", "(annotation?, selector, field+)"}, icElem); 104 return; 105 } 106 Object [] attrValues = fAttrChecker.checkAttributes(sElem, false, schemaDoc); 107 108 if(!DOMUtil.getLocalName(sElem).equals(SchemaSymbols.ELT_SELECTOR)) { 110 reportSchemaError("s4s-elt-must-match.1", new Object []{"identity constraint", "(annotation?, selector, field+)", SchemaSymbols.ELT_SELECTOR}, sElem); 111 } 112 Element selChild = DOMUtil.getFirstChildElement(sElem); 114 115 if (selChild !=null) { 116 if (DOMUtil.getLocalName(selChild).equals(SchemaSymbols.ELT_ANNOTATION)) { 118 ic.addAnnotation(traverseAnnotationDecl(selChild, attrValues, false, schemaDoc)); 119 selChild = DOMUtil.getNextSiblingElement(selChild); 120 } 121 else { 122 reportSchemaError("s4s-elt-must-match.1", new Object []{SchemaSymbols.ELT_SELECTOR, "(annotation?)", DOMUtil.getLocalName(selChild)}, selChild); 123 } 124 if (selChild != null) { 125 reportSchemaError("s4s-elt-must-match.1", new Object [] {SchemaSymbols.ELT_SELECTOR, "(annotation?)", DOMUtil.getLocalName(selChild)}, selChild); 126 } 127 } 128 129 String sText = ((String )attrValues[XSAttributeChecker.ATTIDX_XPATH]); 130 if(sText == null) { 131 reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_SELECTOR, SchemaSymbols.ATT_XPATH}, sElem); 132 return; 133 } 134 sText = sText.trim(); 135 136 Selector.XPath sXpath = null; 137 try { 138 sXpath = new Selector.XPath(sText, fSymbolTable, 139 schemaDoc.fNamespaceSupport); 140 Selector selector = new Selector(sXpath, ic); 141 ic.setSelector(selector); 142 } 143 catch (XPathException e) { 144 reportSchemaError(e.getKey(), new Object []{sText}, sElem); 145 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 147 return; 148 } 149 150 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 152 153 Element fElem = DOMUtil.getNextSiblingElement(sElem); 155 if(fElem == null) { 156 reportSchemaError("s4s-elt-must-match.2", new Object []{"identity constraint", "(annotation?, selector, field+)"}, sElem); 157 } 158 while (fElem != null) { 159 attrValues = fAttrChecker.checkAttributes(fElem, false, schemaDoc); 161 162 if(!DOMUtil.getLocalName(fElem).equals(SchemaSymbols.ELT_FIELD)) 163 reportSchemaError("s4s-elt-must-match.1", new Object []{"identity constraint", "(annotation?, selector, field+)", SchemaSymbols.ELT_FIELD}, fElem); 164 165 Element fieldChild = DOMUtil.getFirstChildElement(fElem); 167 if (fieldChild != null) { 168 if (DOMUtil.getLocalName(fieldChild).equals(SchemaSymbols.ELT_ANNOTATION)) { 170 ic.addAnnotation(traverseAnnotationDecl(fieldChild, attrValues, false, schemaDoc)); 171 fieldChild = DOMUtil.getNextSiblingElement(fieldChild); 172 } 173 } 174 if (fieldChild != null) { 175 reportSchemaError("s4s-elt-must-match.1", new Object [] {SchemaSymbols.ELT_FIELD, "(annotation?)", DOMUtil.getLocalName(fieldChild)}, fieldChild); 176 } 177 String fText = ((String )attrValues[XSAttributeChecker.ATTIDX_XPATH]); 178 if(fText == null) { 179 reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_FIELD, SchemaSymbols.ATT_XPATH}, fElem); 180 return; 181 } 182 fText = fText.trim(); 183 try { 184 Field.XPath fXpath = new Field.XPath(fText, fSymbolTable, 185 schemaDoc.fNamespaceSupport); 186 Field field = new Field(fXpath, ic); 187 ic.addField(field); 188 } 189 catch (XPathException e) { 190 reportSchemaError(e.getKey(), new Object []{fText}, fElem); 191 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 193 return; 194 } 195 fElem = DOMUtil.getNextSiblingElement(fElem); 196 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 198 } 199 200 } } 203 | Popular Tags |