1 16 package org.apache.commons.jxpath.ri.model.dynamic; 17 18 import java.util.Locale ; 19 20 import org.apache.commons.jxpath.DynamicPropertyHandler; 21 import org.apache.commons.jxpath.JXPathIntrospector; 22 import org.apache.commons.jxpath.ri.QName; 23 import org.apache.commons.jxpath.ri.model.NodeIterator; 24 import org.apache.commons.jxpath.ri.model.NodePointer; 25 import org.apache.commons.jxpath.ri.model.beans.PropertyIterator; 26 import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; 27 import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; 28 29 37 public class DynamicPointer extends PropertyOwnerPointer { 38 private QName name; 39 private Object bean; 40 private DynamicPropertyHandler handler; 41 private String [] names; 42 43 public DynamicPointer(QName name, Object bean, 44 DynamicPropertyHandler handler, Locale locale) 45 { 46 super(null, locale); 47 this.name = name; 48 this.bean = bean; 49 this.handler = handler; 50 } 51 52 public DynamicPointer(NodePointer parent, QName name, 53 Object bean, DynamicPropertyHandler handler) 54 { 55 super(parent); 56 this.name = name; 57 this.bean = bean; 58 this.handler = handler; 59 } 60 61 public PropertyPointer getPropertyPointer() { 62 return new DynamicPropertyPointer(this, handler); 63 } 64 65 public NodeIterator createNodeIterator( 66 String property, boolean reverse, NodePointer startWith) 67 { 68 return new PropertyIterator(this, property, reverse, startWith); 69 } 70 71 public NodeIterator attributeIterator(QName name) { 72 return new DynamicAttributeIterator(this, name); 73 } 74 75 public QName getName() { 76 return name; 77 } 78 79 public boolean isDynamicPropertyDeclarationSupported() { 80 return true; 81 } 82 83 86 public Object getBaseValue() { 87 return bean; 88 } 89 90 public boolean isLeaf() { 91 Object value = getNode(); 92 return value == null 93 || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); 94 } 95 96 public boolean isCollection() { 97 return false; 98 } 99 100 103 public int getLength() { 104 return 1; 105 } 106 107 public String asPath() { 108 if (parent != null) { 109 return super.asPath(); 110 } 111 return "/"; 112 } 113 114 public int hashCode() { 115 return System.identityHashCode(bean) + name.hashCode(); 116 } 117 118 public boolean equals(Object object) { 119 if (object == this) { 120 return true; 121 } 122 123 if (!(object instanceof DynamicPointer)) { 124 return false; 125 } 126 127 DynamicPointer other = (DynamicPointer) object; 128 return bean == other.bean && name.equals(other.name); 129 } 130 } | Popular Tags |