source: trunk/gcc/libjava/javax/naming/Reference.java

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.8 KB
Line 
1/* Reference.java --
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package javax.naming;
40
41import java.io.Serializable;
42import java.util.Enumeration;
43import java.util.Vector;
44
45/**
46 * @author Tom Tromey <tromey@redhat.com>
47 * @date May 16, 2001
48 */
49public class Reference implements Cloneable, Serializable
50{
51 public Reference (String className)
52 {
53 this.className = className;
54 addrs = new Vector ();
55 }
56
57 public Reference (String className, RefAddr addr)
58 {
59 this.className = className;
60 addrs = new Vector ();
61 addrs.add (addr);
62 }
63
64 public Reference (String className, String factory, String factoryLocation)
65 {
66 this.className = className;
67 this.classFactory = factory;
68 this.classFactoryLocation = factoryLocation;
69 addrs = new Vector ();
70 }
71
72 public Reference (String className, RefAddr addr,
73 String factory, String factoryLocation)
74 {
75 this.className = className;
76 this.classFactory = factory;
77 this.classFactoryLocation = factoryLocation;
78 addrs = new Vector ();
79 addrs.add (addr);
80 }
81
82 public void add (int posn, RefAddr addr)
83 {
84 addrs.add (posn, addr);
85 }
86
87 public void add (RefAddr addr)
88 {
89 addrs.add (addr);
90 }
91
92 public void clear ()
93 {
94 addrs.clear ();
95 }
96
97 public Object clone ()
98 {
99 Reference r = new Reference (className, classFactory,
100 classFactoryLocation);
101 r.addrs = (Vector) addrs.clone ();
102 return r;
103 }
104
105 // Convenience function.
106 private boolean equals (String a, String b)
107 {
108 return (a == null) ? (b == null) : a.equals (b);
109 }
110
111 public boolean equals (Object obj)
112 {
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));
120 }
121
122 public RefAddr get (int posn)
123 {
124 return (RefAddr) addrs.get (posn);
125 }
126
127 public RefAddr get (String addrType)
128 {
129 for (int i = 0; i < addrs.size (); ++i)
130 {
131 RefAddr r = (RefAddr) addrs.get (i);
132 if (addrType.equals (r.getType ()))
133 return r;
134 }
135 return null;
136 }
137
138 public Enumeration getAll ()
139 {
140 return addrs.elements ();
141 }
142
143 public String getClassName ()
144 {
145 return className;
146 }
147
148 public String getFactoryClassLocation ()
149 {
150 return classFactoryLocation;
151 }
152
153 public String getFactoryClassName ()
154 {
155 return classFactory;
156 }
157
158 public int hashCode ()
159 {
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;
166 }
167
168 public Object remove (int posn)
169 {
170 return addrs.remove (posn);
171 }
172
173 public int size ()
174 {
175 return addrs.size ();
176 }
177
178 public String toString ()
179 {
180 String x = getClass ().toString () + "[";
181 for (int i = 0; i < addrs.size (); ++i)
182 {
183 if (i > 0)
184 x += ",";
185 x += addrs.get (i).toString ();
186 }
187 return x + "]";
188 }
189
190 protected Vector addrs;
191 protected String classFactory;
192 protected String classFactoryLocation;
193 protected String className;
194}
Note: See TracBrowser for help on using the repository browser.