1 7 8 package javax.naming; 9 10 import java.util.Vector ; 11 import java.util.Enumeration ; 12 13 57 58 64 65 66 public class Reference implements Cloneable , java.io.Serializable { 67 73 protected String className; 74 79 protected Vector <RefAddr > addrs = null; 80 81 87 protected String classFactory = null; 88 89 94 protected String classFactoryLocation = null; 95 96 104 public Reference(String className) { 105 this.className = className; 106 addrs = new Vector (); 107 } 108 109 118 public Reference(String className, RefAddr addr) { 119 this.className = className; 120 addrs = new Vector (); 121 addrs.addElement(addr); 122 } 123 124 137 public Reference(String className, String factory, String factoryLocation) { 138 this(className); 139 classFactory = factory; 140 classFactoryLocation = factoryLocation; 141 } 142 143 157 public Reference(String className, RefAddr addr, 158 String factory, String factoryLocation) { 159 this(className, addr); 160 classFactory = factory; 161 classFactoryLocation = factoryLocation; 162 } 163 164 170 public String getClassName() { 171 return className; 172 } 173 174 181 public String getFactoryClassName() { 182 return classFactory; 183 } 184 185 195 public String getFactoryClassLocation() { 196 return classFactoryLocation; 197 } 198 199 207 public RefAddr get(String addrType) { 208 int len = addrs.size(); 209 RefAddr addr; 210 for (int i = 0; i < len; i++) { 211 addr = (RefAddr ) addrs.elementAt(i); 212 if (addr.getType().compareTo(addrType) == 0) 213 return addr; 214 } 215 return null; 216 } 217 218 226 public RefAddr get(int posn) { 227 return ((RefAddr ) addrs.elementAt(posn)); 228 } 229 230 240 public Enumeration <RefAddr > getAll() { 241 return addrs.elements(); 242 } 243 244 249 public int size() { 250 return addrs.size(); 251 } 252 253 258 public void add(RefAddr addr) { 259 addrs.addElement(addr); 260 } 261 262 272 public void add(int posn, RefAddr addr) { 273 addrs.insertElementAt(addr, posn); 274 } 275 276 286 public Object remove(int posn) { 287 Object r = addrs.elementAt(posn); 288 addrs.removeElementAt(posn); 289 return r; 290 } 291 292 295 public void clear() { 296 addrs.setSize(0); 297 } 298 299 311 public boolean equals(Object obj) { 312 if ((obj != null) && (obj instanceof Reference )) { 313 Reference target = (Reference )obj; 314 if (target.className.equals(this.className) && 316 target.size() == this.size()) { 317 Enumeration mycomps = getAll(); 318 Enumeration comps = target.getAll(); 319 while (mycomps.hasMoreElements()) 320 if (!(mycomps.nextElement().equals(comps.nextElement()))) 321 return false; 322 return true; 323 } 324 } 325 return false; 326 } 327 328 334 public int hashCode() { 335 int hash = className.hashCode(); 336 for (Enumeration e = getAll(); e.hasMoreElements();) 337 hash += e.nextElement().hashCode(); 338 return hash; 339 } 340 341 349 public String toString() { 350 StringBuffer buf = new StringBuffer ("Reference Class Name: " + 351 className + "\n"); 352 int len = addrs.size(); 353 for (int i = 0; i < len; i++) 354 buf.append(get(i).toString()); 355 356 return buf.toString(); 357 } 358 359 365 public Object clone() { 366 Reference r = new Reference (className, classFactory, classFactoryLocation); 367 Enumeration <RefAddr > a = getAll(); 368 r.addrs = new Vector (); 369 370 while (a.hasMoreElements()) 371 r.addrs.addElement(a.nextElement()); 372 return r; 373 } 374 377 private static final long serialVersionUID = -1673475790065791735L; 378 }; 379 | Popular Tags |