1 16 17 package org.apache.xerces.impl.xs.traversers; 18 19 import org.apache.xerces.impl.xpath.XPathException; 20 import org.apache.xerces.impl.xs.SchemaSymbols; 21 import org.apache.xerces.impl.xs.identity.Field; 22 import org.apache.xerces.impl.xs.identity.IdentityConstraint; 23 import org.apache.xerces.impl.xs.identity.Selector; 24 import org.apache.xerces.util.DOMUtil; 25 import org.w3c.dom.Element ; 26 27 36 class XSDAbstractIDConstraintTraverser extends XSDAbstractTraverser { 37 38 public XSDAbstractIDConstraintTraverser (XSDHandler handler, 39 XSAttributeChecker gAttrCheck) { 40 super(handler, gAttrCheck); 41 } 42 43 void traverseIdentityConstraint(IdentityConstraint ic, 44 Element icElem, XSDocumentInfo schemaDoc, Object [] icElemAttrs) { 45 46 48 Element sElem = DOMUtil.getFirstChildElement(icElem); 50 if(sElem == null) { 51 reportSchemaError("s4s-elt-must-match.2", 52 new Object []{"identity constraint", "(annotation?, selector, field+)"}, 53 icElem); 54 return; 55 } 56 57 if (DOMUtil.getLocalName(sElem).equals(SchemaSymbols.ELT_ANNOTATION)) { 60 ic.addAnnotation(traverseAnnotationDecl(sElem, icElemAttrs, false, schemaDoc)); 61 sElem = DOMUtil.getNextSiblingElement(sElem); 62 if(sElem == null) { 64 reportSchemaError("s4s-elt-must-match.2", new Object []{"identity constraint", "(annotation?, selector, field+)"}, icElem); 65 return; 66 } 67 } 68 else { 69 String text = DOMUtil.getSyntheticAnnotation(icElem); 70 if (text != null) { 71 ic.addAnnotation(traverseSyntheticAnnotation(icElem, text, icElemAttrs, false, schemaDoc)); 72 } 73 } 74 75 Object [] attrValues = fAttrChecker.checkAttributes(sElem, false, schemaDoc); 76 77 if(!DOMUtil.getLocalName(sElem).equals(SchemaSymbols.ELT_SELECTOR)) { 79 reportSchemaError("s4s-elt-must-match.1", new Object []{"identity constraint", "(annotation?, selector, field+)", SchemaSymbols.ELT_SELECTOR}, sElem); 80 } 81 Element selChild = DOMUtil.getFirstChildElement(sElem); 83 84 if (selChild !=null) { 85 if (DOMUtil.getLocalName(selChild).equals(SchemaSymbols.ELT_ANNOTATION)) { 87 ic.addAnnotation(traverseAnnotationDecl(selChild, attrValues, false, schemaDoc)); 88 selChild = DOMUtil.getNextSiblingElement(selChild); 89 } 90 else { 91 reportSchemaError("s4s-elt-must-match.1", new Object []{SchemaSymbols.ELT_SELECTOR, "(annotation?)", DOMUtil.getLocalName(selChild)}, selChild); 92 } 93 if (selChild != null) { 94 reportSchemaError("s4s-elt-must-match.1", new Object [] {SchemaSymbols.ELT_SELECTOR, "(annotation?)", DOMUtil.getLocalName(selChild)}, selChild); 95 } 96 } 97 else { 98 String text = DOMUtil.getSyntheticAnnotation(sElem); 99 if (text != null) { 100 ic.addAnnotation(traverseSyntheticAnnotation(icElem, text, attrValues, false, schemaDoc)); 101 } 102 } 103 104 String sText = ((String )attrValues[XSAttributeChecker.ATTIDX_XPATH]); 105 if(sText == null) { 106 reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_SELECTOR, SchemaSymbols.ATT_XPATH}, sElem); 107 return; 108 } 109 sText = sText.trim(); 110 111 Selector.XPath sXpath = null; 112 try { 113 sXpath = new Selector.XPath(sText, fSymbolTable, 114 schemaDoc.fNamespaceSupport); 115 Selector selector = new Selector(sXpath, ic); 116 ic.setSelector(selector); 117 } 118 catch (XPathException e) { 119 reportSchemaError(e.getKey(), new Object []{sText}, sElem); 120 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 122 return; 123 } 124 125 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 127 128 Element fElem = DOMUtil.getNextSiblingElement(sElem); 130 if(fElem == null) { 131 reportSchemaError("s4s-elt-must-match.2", new Object []{"identity constraint", "(annotation?, selector, field+)"}, sElem); 132 } 133 while (fElem != null) { 134 attrValues = fAttrChecker.checkAttributes(fElem, false, schemaDoc); 136 137 if(!DOMUtil.getLocalName(fElem).equals(SchemaSymbols.ELT_FIELD)) 138 reportSchemaError("s4s-elt-must-match.1", new Object []{"identity constraint", "(annotation?, selector, field+)", SchemaSymbols.ELT_FIELD}, fElem); 139 140 Element fieldChild = DOMUtil.getFirstChildElement(fElem); 142 if (fieldChild != null) { 143 if (DOMUtil.getLocalName(fieldChild).equals(SchemaSymbols.ELT_ANNOTATION)) { 145 ic.addAnnotation(traverseAnnotationDecl(fieldChild, attrValues, false, schemaDoc)); 146 fieldChild = DOMUtil.getNextSiblingElement(fieldChild); 147 } 148 } 149 if (fieldChild != null) { 150 reportSchemaError("s4s-elt-must-match.1", new Object [] {SchemaSymbols.ELT_FIELD, "(annotation?)", DOMUtil.getLocalName(fieldChild)}, fieldChild); 151 } 152 else { 153 String text = DOMUtil.getSyntheticAnnotation(fElem); 154 if (text != null) { 155 ic.addAnnotation(traverseSyntheticAnnotation(icElem, text, attrValues, false, schemaDoc)); 156 } 157 } 158 String fText = ((String )attrValues[XSAttributeChecker.ATTIDX_XPATH]); 159 if(fText == null) { 160 reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_FIELD, SchemaSymbols.ATT_XPATH}, fElem); 161 return; 162 } 163 fText = fText.trim(); 164 try { 165 Field.XPath fXpath = new Field.XPath(fText, fSymbolTable, 166 schemaDoc.fNamespaceSupport); 167 Field field = new Field(fXpath, ic); 168 ic.addField(field); 169 } 170 catch (XPathException e) { 171 reportSchemaError(e.getKey(), new Object []{fText}, fElem); 172 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 174 return; 175 } 176 fElem = DOMUtil.getNextSiblingElement(fElem); 177 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 179 } 180 181 } } 184 | Popular Tags |