1 57 58 package org.enhydra.apache.xerces.validators.schema.identity; 59 60 import org.enhydra.apache.xerces.utils.NamespacesScope; 61 import org.enhydra.apache.xerces.utils.StringPool; 62 import org.enhydra.apache.xerces.validators.datatype.DatatypeValidator; 63 64 70 public class Field { 71 72 76 77 protected Field.XPath fXPath; 78 79 80 84 85 protected IdentityConstraint fIdentityConstraint; 86 87 protected boolean mayMatch = true; 90 91 95 96 public Field(Field.XPath xpath, 97 IdentityConstraint identityConstraint) { 98 fXPath = xpath; 99 fIdentityConstraint = identityConstraint; 100 } 102 106 public void setMayMatch(boolean b) { 108 mayMatch = b; 109 } 111 public boolean mayMatch() { 113 return mayMatch; 114 } 116 117 public org.enhydra.apache.xerces.validators.schema.identity.XPath getXPath() { 118 return fXPath; 119 } 121 122 public IdentityConstraint getIdentityConstraint() { 123 return fIdentityConstraint; 124 } 126 128 129 public XPathMatcher createMatcher(ValueStore store) { 130 return new Field.Matcher(fXPath, store); 131 } 133 137 138 public String toString() { 139 return fXPath.toString(); 140 } 142 146 151 public static class XPath 152 extends org.enhydra.apache.xerces.validators.schema.identity.XPath { 153 154 158 159 public XPath(String xpath, StringPool stringPool, 160 NamespacesScope context) throws XPathException { 161 super(((xpath.trim().startsWith("/") ||xpath.trim().startsWith("."))? 168 xpath:"./"+xpath), stringPool, context); 169 170 } 172 } 174 179 protected class Matcher 180 extends XPathMatcher { 181 182 186 187 protected ValueStore fStore; 188 189 193 194 public Matcher(Field.XPath xpath, ValueStore store) { 195 super(xpath, true, null); 196 fStore = store; 197 } 199 203 207 protected void matched(String content, DatatypeValidator val, boolean isNil) throws Exception { 208 super.matched(content, val, isNil); 209 if(isNil) { 210 fStore.reportNilError(fIdentityConstraint); 211 } 212 fStore.addValue(Field.this, new IDValue(content, val)); 213 mayMatch = false; 217 } 219 } 221 } | Popular Tags |