1 package net.sf.saxon.tree; 2 import net.sf.saxon.event.Receiver; 3 import net.sf.saxon.om.AttributeCollection; 4 import net.sf.saxon.om.NodeInfo; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.Type; 7 8 13 14 final class AttributeImpl extends NodeImpl { 15 16 private int nameCode; 17 private int typeCode; 18 private String value; 19 20 25 26 public AttributeImpl(ElementImpl element, int index) { 27 parent = element; 28 this.index = index; 29 AttributeCollection atts = element.getAttributeList(); 30 this.nameCode = atts.getNameCode(index); 31 this.value = atts.getValue(index); 32 this.typeCode = atts.getTypeAnnotation(index); 33 } 34 35 38 39 public int getNameCode() { 40 return nameCode; 41 } 42 43 46 47 public int getTypeAnnotation() { 48 return typeCode; 49 } 50 51 56 57 public boolean isSameNodeInfo(NodeInfo other) { 58 if (!(other instanceof AttributeImpl)) return false; 59 if (this==other) return true; 60 AttributeImpl otherAtt = (AttributeImpl)other; 61 return (parent.isSameNodeInfo(otherAtt.parent) && 62 ((nameCode&0xfffff)==(otherAtt.nameCode&0xfffff))); 63 } 64 65 71 72 protected long getSequenceNumber() { 73 return parent.getSequenceNumber() + 0x8000 + index; 74 } 76 77 81 82 public final int getNodeKind() { 83 return Type.ATTRIBUTE; 84 } 85 86 90 91 public String getStringValue() { 92 return value; 93 } 94 95 98 99 public NodeInfo getNextSibling() { 100 return null; 101 } 102 103 106 107 public NodeInfo getPreviousSibling() { 108 return null; 109 } 110 111 114 115 public NodeImpl getPreviousInDocument() { 116 return (NodeImpl)getParent(); 117 } 118 119 122 123 public NodeImpl getNextInDocument(NodeImpl anchor) { 124 if (anchor==this) return null; 125 return ((NodeImpl)getParent()).getNextInDocument(anchor); 126 } 127 128 131 132 public String generateId() { 133 return parent.generateId() + 'a' + index; 134 } 135 136 139 140 public void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId) throws XPathException { 141 int nameCode = getNameCode(); 142 int typeCode = (copyAnnotations ? getTypeAnnotation() : -1); 143 out.attribute(nameCode, typeCode, getStringValue(), locationId, 0); 144 } 145 146 } 147 148 | Popular Tags |