1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.identity; 59 60 import com.sun.org.apache.xerces.internal.impl.xpath.XPathException; 61 import com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition; 62 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 63 import com.sun.org.apache.xerces.internal.util.SymbolTable; 64 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 65 66 72 public class Field { 73 74 78 79 protected Field.XPath fXPath; 80 81 82 83 protected IdentityConstraint fIdentityConstraint; 84 85 89 90 public Field(Field.XPath xpath, 91 IdentityConstraint identityConstraint) { 92 fXPath = xpath; 93 fIdentityConstraint = identityConstraint; 94 } 96 100 101 public com.sun.org.apache.xerces.internal.impl.xpath.XPath getXPath() { 102 return fXPath; 103 } 105 106 public IdentityConstraint getIdentityConstraint() { 107 return fIdentityConstraint; 108 } 110 112 113 public XPathMatcher createMatcher(FieldActivator activator, ValueStore store) { 114 return new Field.Matcher(fXPath, activator, store); 115 } 117 121 122 public String toString() { 123 return fXPath.toString(); 124 } 126 130 135 public static class XPath 136 extends com.sun.org.apache.xerces.internal.impl.xpath.XPath { 137 138 142 143 public XPath(String xpath, 144 SymbolTable symbolTable, 145 NamespaceContext context) throws XPathException { 146 super(((xpath.trim().startsWith("/") ||xpath.trim().startsWith("."))? 153 xpath:"./"+xpath), 154 symbolTable, context); 155 156 for (int i=0;i<fLocationPaths.length;i++) { 158 for(int j=0; j<fLocationPaths[i].steps.length; j++) { 159 com.sun.org.apache.xerces.internal.impl.xpath.XPath.Axis axis = 160 fLocationPaths[i].steps[j].axis; 161 if (axis.type == XPath.Axis.ATTRIBUTE && 162 (j < fLocationPaths[i].steps.length-1)) { 163 throw new XPathException("c-fields-xpaths"); 164 } 165 } 166 } 167 } 169 } 171 176 protected class Matcher 177 extends XPathMatcher { 178 179 183 184 protected FieldActivator fFieldActivator; 185 186 187 protected ValueStore fStore; 188 189 193 194 public Matcher(Field.XPath xpath, FieldActivator activator, ValueStore store) { 195 super(xpath); 196 fFieldActivator = activator; 197 fStore = store; 198 } 200 204 208 protected void matched(Object actualValue, boolean isNil) { 209 super.matched(actualValue, isNil); 210 if(isNil && (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY)) { 211 String code = "KeyMatchesNillable"; 212 fStore.reportError(code, new Object []{fIdentityConstraint.getElementName()}); 213 } 214 fStore.addValue(Field.this, actualValue,fCurrMatchedType); 215 fFieldActivator.setMayMatch(Field.this, Boolean.FALSE); 219 } 221 protected void handleContent(XSTypeDefinition type, boolean nillable, Object actualValue) { 222 if (type == null || 223 type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE && 224 ((XSComplexTypeDefinition) type).getContentType() 225 != XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) { 226 227 fStore.reportError( "cvc-id.3", new Object [] { 229 fIdentityConstraint.getName(), 230 fIdentityConstraint.getElementName()}); 231 232 } 233 fCurrMatchedType = type; 234 fMatchedString = actualValue; 235 matched(fMatchedString, nillable); 236 } 238 } 240 } | Popular Tags |