1 16 package org.apache.commons.jxpath.ri.model.dom; 17 18 import org.apache.commons.jxpath.ri.Compiler; 19 import org.apache.commons.jxpath.ri.QName; 20 import org.apache.commons.jxpath.ri.compiler.NodeTest; 21 import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; 22 import org.apache.commons.jxpath.ri.model.NodePointer; 23 24 30 public class NamespacePointer extends NodePointer { 31 private String prefix; 32 private String namespaceURI; 33 34 public NamespacePointer(NodePointer parent, String prefix) { 35 super(parent); 36 this.prefix = prefix; 37 } 38 39 public NamespacePointer( 40 NodePointer parent, 41 String prefix, 42 String namespaceURI) 43 { 44 super(parent); 45 this.prefix = prefix; 46 this.namespaceURI = namespaceURI; 47 } 48 49 public QName getName() { 50 return new QName(prefix); 51 } 52 53 public Object getBaseValue() { 54 return null; 55 } 56 57 public boolean isCollection() { 58 return false; 59 } 60 61 public int getLength() { 62 return 1; 63 } 64 65 public Object getImmediateNode() { 66 return getNamespaceURI(); 67 } 68 69 public String getNamespaceURI() { 70 if (namespaceURI == null) { 71 namespaceURI = parent.getNamespaceURI(prefix); 72 } 73 return namespaceURI; 74 } 75 76 public boolean isLeaf() { 77 return true; 78 } 79 80 83 public void setValue(Object value) { 84 throw new UnsupportedOperationException ("Cannot modify DOM trees"); 85 } 86 87 public boolean testNode(NodeTest nodeTest) { 88 return nodeTest == null 89 || ((nodeTest instanceof NodeTypeTest) 90 && ((NodeTypeTest) nodeTest).getNodeType() 91 == Compiler.NODE_TYPE_NODE); 92 } 93 94 public String asPath() { 95 StringBuffer buffer = new StringBuffer (); 96 if (parent != null) { 97 buffer.append(parent.asPath()); 98 if (buffer.length() == 0 99 || buffer.charAt(buffer.length() - 1) != '/') { 100 buffer.append('/'); 101 } 102 } 103 buffer.append("namespace::"); 104 buffer.append(prefix); 105 return buffer.toString(); 106 } 107 108 public int hashCode() { 109 return prefix.hashCode(); 110 } 111 112 public boolean equals(Object object) { 113 if (object == this) { 114 return true; 115 } 116 117 if (!(object instanceof NamespacePointer)) { 118 return false; 119 } 120 121 NamespacePointer other = (NamespacePointer) object; 122 return prefix.equals(other.prefix); 123 } 124 125 public int compareChildNodePointers( 126 NodePointer pointer1, 127 NodePointer pointer2) 128 { 129 return 0; 131 } 132 } | Popular Tags |