1 package net.sf.saxon.dom; 2 3 import net.sf.saxon.event.ContentHandlerProxy; 4 import net.sf.saxon.event.ReceiverOptions; 5 import net.sf.saxon.om.NamespaceConstant; 6 import net.sf.saxon.style.StandardNames; 7 import net.sf.saxon.trans.XPathException; 8 import net.sf.saxon.type.AnySimpleType; 9 import net.sf.saxon.type.AnyType; 10 import net.sf.saxon.type.SchemaType; 11 import org.w3c.dom.TypeInfo ; 12 13 import javax.xml.validation.TypeInfoProvider ; 14 15 21 22 public class TypedContentHandler extends ContentHandlerProxy { 23 private int pendingElementTypeCode; 24 25 29 30 public TypeInfoProvider getTypeInfoProvider() { 31 return new TypeInfoProviderImpl(); 32 } 33 34 35 38 39 public void startElement(int nameCode, int typeCode, int locationId, int properties) throws XPathException { 40 pendingElementTypeCode = typeCode; 41 super.startElement(nameCode, typeCode, locationId, properties); 42 } 43 44 45 49 public class TypeInfoProviderImpl extends TypeInfoProvider { 50 51 62 63 public TypeInfo getElementTypeInfo() { 64 if (pendingElementTypeCode == -1) { 65 return new TypeInfoImpl(getConfiguration(), AnyType.getInstance()); 66 } else { 67 return new TypeInfoImpl(getConfiguration(), 68 getConfiguration().getSchemaType(pendingElementTypeCode)); 69 } 70 } 71 72 94 public TypeInfo getAttributeTypeInfo(int index) { 95 if (index < 0 || index > pendingAttributes.getLength()) { 96 throw new IndexOutOfBoundsException (""+index); 97 } 98 int type = pendingAttributes.getTypeAnnotation(index); 99 if (type == -1) { 100 return new TypeInfoImpl(getConfiguration(), AnySimpleType.getInstance()); 101 } else { 102 return new TypeInfoImpl(getConfiguration(), 103 getConfiguration().getSchemaType(type)); 104 } 105 } 106 107 116 public boolean isIdAttribute(int index) { 117 int type = pendingAttributes.getTypeAnnotation(index); 118 return (type == StandardNames.XS_ID || 119 getAttributeTypeInfo(index).isDerivedFrom( 120 NamespaceConstant.SCHEMA, "ID", SchemaType.DERIVATION_RESTRICTION)); 121 } 122 123 133 134 public boolean isSpecified(int index) { 135 return (pendingAttributes.getProperties(index) & ReceiverOptions.DEFAULTED_ATTRIBUTE) == 0; 136 } 137 138 } 139 } 140 141 | Popular Tags |