| 1 | /* Copyright (C) 2000, 2001 Free Software Foundation
|
|---|
| 2 |
|
|---|
| 3 | This file is part of libgcj.
|
|---|
| 4 |
|
|---|
| 5 | This software is copyrighted work licensed under the terms of the
|
|---|
| 6 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|---|
| 7 | details. */
|
|---|
| 8 |
|
|---|
| 9 | package javax.naming;
|
|---|
| 10 |
|
|---|
| 11 | import java.io.Serializable;
|
|---|
| 12 | import java.util.Enumeration;
|
|---|
| 13 | import java.util.Vector;
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * @author Tom Tromey <[email protected]>
|
|---|
| 17 | * @date May 16, 2001
|
|---|
| 18 | */
|
|---|
| 19 | public class Reference implements Cloneable, Serializable
|
|---|
| 20 | {
|
|---|
| 21 | public Reference (String className)
|
|---|
| 22 | {
|
|---|
| 23 | this.className = className;
|
|---|
| 24 | addrs = new Vector ();
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | public Reference (String className, RefAddr addr)
|
|---|
| 28 | {
|
|---|
| 29 | this.className = className;
|
|---|
| 30 | addrs = new Vector ();
|
|---|
| 31 | addrs.add (addr);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | public Reference (String className, String factory, String factoryLocation)
|
|---|
| 35 | {
|
|---|
| 36 | this.className = className;
|
|---|
| 37 | this.classFactory = factory;
|
|---|
| 38 | this.classFactoryLocation = factoryLocation;
|
|---|
| 39 | addrs = new Vector ();
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | public Reference (String className, RefAddr addr,
|
|---|
| 43 | String factory, String factoryLocation)
|
|---|
| 44 | {
|
|---|
| 45 | this.className = className;
|
|---|
| 46 | this.classFactory = factory;
|
|---|
| 47 | this.classFactoryLocation = factoryLocation;
|
|---|
| 48 | addrs = new Vector ();
|
|---|
| 49 | addrs.add (addr);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | public void add (int posn, RefAddr addr)
|
|---|
| 53 | {
|
|---|
| 54 | addrs.add (posn, addr);
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | public void add (RefAddr addr)
|
|---|
| 58 | {
|
|---|
| 59 | addrs.add (addr);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | public void clear ()
|
|---|
| 63 | {
|
|---|
| 64 | addrs.clear ();
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | public Object clone ()
|
|---|
| 68 | {
|
|---|
| 69 | Reference r = new Reference (className, classFactory,
|
|---|
| 70 | classFactoryLocation);
|
|---|
| 71 | r.addrs = (Vector) addrs.clone ();
|
|---|
| 72 | return r;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // Convenience function.
|
|---|
| 76 | private boolean equals (String a, String b)
|
|---|
| 77 | {
|
|---|
| 78 | return (a == null) ? (b == null) : a.equals (b);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | public boolean equals (Object obj)
|
|---|
| 82 | {
|
|---|
| 83 | if (! (obj instanceof Reference))
|
|---|
| 84 | return false;
|
|---|
| 85 | Reference r = (Reference) obj;
|
|---|
| 86 | return (equals (classFactory, r.classFactory)
|
|---|
| 87 | && equals (classFactoryLocation, r.classFactoryLocation)
|
|---|
| 88 | && equals (className, r.className)
|
|---|
| 89 | && addrs.equals (r.addrs));
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | public RefAddr get (int posn)
|
|---|
| 93 | {
|
|---|
| 94 | return (RefAddr) addrs.get (posn);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | public RefAddr get (String addrType)
|
|---|
| 98 | {
|
|---|
| 99 | for (int i = 0; i < addrs.size (); ++i)
|
|---|
| 100 | {
|
|---|
| 101 | RefAddr r = (RefAddr) addrs.get (i);
|
|---|
| 102 | if (addrType.equals (r.getType ()))
|
|---|
| 103 | return r;
|
|---|
| 104 | }
|
|---|
| 105 | return null;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | public Enumeration getAll ()
|
|---|
| 109 | {
|
|---|
| 110 | return addrs.elements ();
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | public String getClassName ()
|
|---|
| 114 | {
|
|---|
| 115 | return className;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | public String getFactoryClassLocation ()
|
|---|
| 119 | {
|
|---|
| 120 | return classFactoryLocation;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | public String getFactoryClassName ()
|
|---|
| 124 | {
|
|---|
| 125 | return classFactory;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | public int hashCode ()
|
|---|
| 129 | {
|
|---|
| 130 | // The spec says the hash code is the sum of the hash codes of the
|
|---|
| 131 | // addresses. It does not mention the other fields.
|
|---|
| 132 | int h = 0;
|
|---|
| 133 | for (int i = 0; i < addrs.size (); ++i)
|
|---|
| 134 | h += addrs.get (i).hashCode ();
|
|---|
| 135 | return h;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | public Object remove (int posn)
|
|---|
| 139 | {
|
|---|
| 140 | return addrs.remove (posn);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | public int size ()
|
|---|
| 144 | {
|
|---|
| 145 | return addrs.size ();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | public String toString ()
|
|---|
| 149 | {
|
|---|
| 150 | String x = getClass ().toString () + "[";
|
|---|
| 151 | for (int i = 0; i < addrs.size (); ++i)
|
|---|
| 152 | {
|
|---|
| 153 | if (i > 0)
|
|---|
| 154 | x += ",";
|
|---|
| 155 | x += addrs.get (i).toString ();
|
|---|
| 156 | }
|
|---|
| 157 | return x + "]";
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | protected Vector addrs;
|
|---|
| 161 | protected String classFactory;
|
|---|
| 162 | protected String classFactoryLocation;
|
|---|
| 163 | protected String className;
|
|---|
| 164 | }
|
|---|