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