Merge from the pain train
[official-gcc.git] / libjava / javax / naming / Reference.java
blob4b06f4ab910827c6d282b0b648aea632ef23a924
1 /* Reference.java --
2 Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.naming;
41 import java.io.Serializable;
42 import java.util.Enumeration;
43 import java.util.Vector;
45 /**
46 * @author Tom Tromey (tromey@redhat.com)
47 * @date May 16, 2001
49 public class Reference implements Cloneable, Serializable
51 public Reference (String className)
53 this.className = className;
54 addrs = new Vector ();
57 public Reference (String className, RefAddr addr)
59 this.className = className;
60 addrs = new Vector ();
61 addrs.add (addr);
64 public Reference (String className, String factory, String factoryLocation)
66 this.className = className;
67 this.classFactory = factory;
68 this.classFactoryLocation = factoryLocation;
69 addrs = new Vector ();
72 public Reference (String className, RefAddr addr,
73 String factory, String factoryLocation)
75 this.className = className;
76 this.classFactory = factory;
77 this.classFactoryLocation = factoryLocation;
78 addrs = new Vector ();
79 addrs.add (addr);
82 public void add (int posn, RefAddr addr)
84 addrs.add (posn, addr);
87 public void add (RefAddr addr)
89 addrs.add (addr);
92 public void clear ()
94 addrs.clear ();
97 public Object clone ()
99 Reference r = new Reference (className, classFactory,
100 classFactoryLocation);
101 r.addrs = (Vector) addrs.clone ();
102 return r;
105 // Convenience function.
106 private boolean equals (String a, String b)
108 return (a == null) ? (b == null) : a.equals (b);
111 public boolean equals (Object obj)
113 if (! (obj instanceof Reference))
114 return false;
115 Reference r = (Reference) obj;
116 return (equals (classFactory, r.classFactory)
117 && equals (classFactoryLocation, r.classFactoryLocation)
118 && equals (className, r.className)
119 && addrs.equals (r.addrs));
122 public RefAddr get (int posn)
124 return (RefAddr) addrs.get (posn);
127 public RefAddr get (String addrType)
129 for (int i = 0; i < addrs.size (); ++i)
131 RefAddr r = (RefAddr) addrs.get (i);
132 if (addrType.equals (r.getType ()))
133 return r;
135 return null;
138 public Enumeration getAll ()
140 return addrs.elements ();
143 public String getClassName ()
145 return className;
148 public String getFactoryClassLocation ()
150 return classFactoryLocation;
153 public String getFactoryClassName ()
155 return classFactory;
158 public int hashCode ()
160 // The spec says the hash code is the sum of the hash codes of the
161 // addresses. It does not mention the other fields.
162 int h = 0;
163 for (int i = 0; i < addrs.size (); ++i)
164 h += addrs.get (i).hashCode ();
165 return h;
168 public Object remove (int posn)
170 return addrs.remove (posn);
173 public int size ()
175 return addrs.size ();
178 public String toString ()
180 String x = getClass ().toString () + "[";
181 for (int i = 0; i < addrs.size (); ++i)
183 if (i > 0)
184 x += ",";
185 x += addrs.get (i).toString ();
187 return x + "]";
190 protected Vector addrs;
191 protected String classFactory;
192 protected String classFactoryLocation;
193 protected String className;