1 56 57 package org.jdom.filter; 58 59 import java.io.*; 60 import org.jdom.*; 61 62 69 public class ElementFilter extends AbstractFilter { 70 71 private static final String CVS_ID = 72 "@(#) $RCSfile: ElementFilter.java,v $ $Revision: 1.18 $ $Date: 2004/09/07 06:37:20 $ $Name: $"; 73 74 75 private String name; 76 77 78 private transient Namespace namespace; 79 80 83 public ElementFilter() {} 84 85 90 public ElementFilter(String name) { 91 this.name = name; 92 } 93 94 99 public ElementFilter(Namespace namespace) { 100 this.namespace = namespace; 101 } 102 103 109 public ElementFilter(String name, Namespace namespace) { 110 this.name = name; 111 this.namespace = namespace; 112 } 113 114 121 public boolean matches(Object obj) { 122 if (obj instanceof Element) { 123 Element el = (Element) obj; 124 return 125 (this.name == null || this.name.equals(el.getName())) && 126 (this.namespace == null || this.namespace.equals(el.getNamespace())); 127 } 128 return false; 129 } 130 131 138 public boolean equals(Object obj) { 139 if (this == obj) return true; 141 if (!(obj instanceof ElementFilter)) return false; 142 143 final ElementFilter filter = (ElementFilter) obj; 144 145 if (name != null ? !name.equals(filter.name) : filter.name != null) return false; 146 if (namespace != null ? !namespace.equals(filter.namespace) : filter.namespace != null) return false; 147 148 return true; 149 } 150 151 public int hashCode() { 152 int result; 154 result = (name != null ? name.hashCode() : 0); 155 result = 29 * result + (namespace != null ? namespace.hashCode() : 0); 156 return result; 157 } 158 159 private void writeObject(ObjectOutputStream out) throws IOException { 162 163 out.defaultWriteObject(); 164 165 out.writeObject(namespace.getPrefix()); 168 out.writeObject(namespace.getURI()); 169 } 170 171 private void readObject(ObjectInputStream in) 172 throws IOException, ClassNotFoundException { 173 174 in.defaultReadObject(); 175 176 namespace = Namespace.getNamespace( 177 (String ) in.readObject(), (String ) in.readObject()); 178 } 179 } 180 | Popular Tags |