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 import org.apache.commons.jxpath.util.TypeUtils; 21 import org.jdom.Attribute; 22 23 29 public class JDOMAttributePointer extends NodePointer { 30 private Attribute attr; 31 32 public JDOMAttributePointer(NodePointer parent, Attribute attr) { 33 super(parent); 34 this.attr = attr; 35 } 36 37 public QName getName() { 38 return new QName( 39 JDOMNodePointer.getPrefix(attr), 40 JDOMNodePointer.getLocalName(attr)); 41 } 42 43 public String getNamespaceURI() { 44 String uri = attr.getNamespaceURI(); 45 if (uri != null && uri.equals("")) { 46 uri = null; 47 } 48 return uri; 49 } 50 51 public Object getValue() { 52 return attr.getValue(); 53 } 54 55 public Object getBaseValue() { 56 return attr; 57 } 58 59 public boolean isCollection() { 60 return false; 61 } 62 63 public int getLength() { 64 return 1; 65 } 66 67 public Object getImmediateNode() { 68 return attr; 69 } 70 71 public boolean isActual() { 72 return true; 73 } 74 75 public boolean isLeaf() { 76 return true; 77 } 78 79 82 public void setValue(Object value) { 83 attr.setValue((String ) TypeUtils.convert(value, String .class)); 84 } 85 86 public void remove() { 87 attr.getParent().removeAttribute(attr); 88 } 89 90 92 public String asPath() { 93 StringBuffer buffer = new StringBuffer (); 94 if (parent != null) { 95 buffer.append(parent.asPath()); 96 if (buffer.length() == 0 97 || buffer.charAt(buffer.length() - 1) != '/') { 98 buffer.append('/'); 99 } 100 } 101 buffer.append('@'); 102 buffer.append(getName()); 103 return buffer.toString(); 104 } 105 106 public int hashCode() { 107 return System.identityHashCode(attr); 108 } 109 110 public boolean equals(Object object) { 111 if (object == this) { 112 return true; 113 } 114 115 if (!(object instanceof JDOMAttributePointer)) { 116 return false; 117 } 118 119 JDOMAttributePointer other = (JDOMAttributePointer) object; 120 return attr == other.attr; 121 } 122 123 public int compareChildNodePointers( 124 NodePointer pointer1, 125 NodePointer pointer2) 126 { 127 return 0; 129 } 130 } | Popular Tags |