1 16 17 package org.apache.xerces.impl.xs.identity; 18 19 import org.apache.xerces.impl.xpath.XPathException; 20 import org.apache.xerces.impl.xs.util.ShortListImpl; 21 import org.apache.xerces.util.SymbolTable; 22 import org.apache.xerces.xni.NamespaceContext; 23 import org.apache.xerces.xs.ShortList; 24 import org.apache.xerces.xs.XSComplexTypeDefinition; 25 import org.apache.xerces.xs.XSConstants; 26 import org.apache.xerces.xs.XSTypeDefinition; 27 28 36 public class Field { 37 38 42 43 protected Field.XPath fXPath; 44 45 46 47 protected IdentityConstraint fIdentityConstraint; 48 49 53 54 public Field(Field.XPath xpath, 55 IdentityConstraint identityConstraint) { 56 fXPath = xpath; 57 fIdentityConstraint = identityConstraint; 58 } 60 64 65 public org.apache.xerces.impl.xpath.XPath getXPath() { 66 return fXPath; 67 } 69 70 public IdentityConstraint getIdentityConstraint() { 71 return fIdentityConstraint; 72 } 74 76 77 public XPathMatcher createMatcher(FieldActivator activator, ValueStore store) { 78 return new Field.Matcher(fXPath, activator, store); 79 } 81 85 86 public String toString() { 87 return fXPath.toString(); 88 } 90 94 99 public static class XPath 100 extends org.apache.xerces.impl.xpath.XPath { 101 102 106 107 public XPath(String xpath, 108 SymbolTable symbolTable, 109 NamespaceContext context) throws XPathException { 110 super(((xpath.trim().startsWith("/") ||xpath.trim().startsWith("."))? 117 xpath:"./"+xpath), 118 symbolTable, context); 119 120 for (int i=0;i<fLocationPaths.length;i++) { 122 for(int j=0; j<fLocationPaths[i].steps.length; j++) { 123 org.apache.xerces.impl.xpath.XPath.Axis axis = 124 fLocationPaths[i].steps[j].axis; 125 if (axis.type == XPath.Axis.ATTRIBUTE && 126 (j < fLocationPaths[i].steps.length-1)) { 127 throw new XPathException("c-fields-xpaths"); 128 } 129 } 130 } 131 } 133 } 135 140 protected class Matcher 141 extends XPathMatcher { 142 143 147 148 protected FieldActivator fFieldActivator; 149 150 151 protected ValueStore fStore; 152 153 157 158 public Matcher(Field.XPath xpath, FieldActivator activator, ValueStore store) { 159 super(xpath); 160 fFieldActivator = activator; 161 fStore = store; 162 } 164 168 172 protected void matched(Object actualValue, short valueType, ShortList itemValueType, boolean isNil) { 173 super.matched(actualValue, valueType, itemValueType, isNil); 174 if(isNil && (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY)) { 175 String code = "KeyMatchesNillable"; 176 fStore.reportError(code, new Object []{fIdentityConstraint.getElementName()}); 177 } 178 fStore.addValue(Field.this, actualValue, convertToPrimitiveKind(valueType), convertToPrimitiveKind(itemValueType)); 179 fFieldActivator.setMayMatch(Field.this, Boolean.FALSE); 183 } 185 private short convertToPrimitiveKind(short valueType) { 186 187 if (valueType <= XSConstants.NOTATION_DT) { 188 return valueType; 189 } 190 191 if (valueType <= XSConstants.ENTITY_DT) { 192 return XSConstants.STRING_DT; 193 } 194 195 if (valueType <= XSConstants.POSITIVEINTEGER_DT) { 196 return XSConstants.DECIMAL_DT; 197 } 198 199 return valueType; 200 } 201 202 private ShortList convertToPrimitiveKind(ShortList itemValueType) { 203 if (itemValueType != null) { 204 int i; 205 final int length = itemValueType.getLength(); 206 for (i = 0; i < length; ++i) { 207 short type = itemValueType.item(i); 208 if (type != convertToPrimitiveKind(type)) { 209 break; 210 } 211 } 212 if (i != length) { 213 final short [] arr = new short[length]; 214 for (int j = 0; j < i; ++j) { 215 arr[j] = itemValueType.item(j); 216 } 217 for(; i < length; ++i) { 218 arr[i] = convertToPrimitiveKind(itemValueType.item(i)); 219 } 220 return new ShortListImpl(arr, arr.length); 221 } 222 } 223 return itemValueType; 224 } 225 226 protected void handleContent(XSTypeDefinition type, boolean nillable, Object actualValue, short valueType, ShortList itemValueType) { 227 if (type == null || 228 type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE && 229 ((XSComplexTypeDefinition) type).getContentType() 230 != XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) { 231 232 fStore.reportError( "cvc-id.3", new Object [] { 234 fIdentityConstraint.getName(), 235 fIdentityConstraint.getElementName()}); 236 237 } 238 fMatchedString = actualValue; 239 matched(fMatchedString, valueType, itemValueType, nillable); 240 } 242 } 244 } | Popular Tags |