2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.jdi;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import java.util.Collection;
|
|
30 |
import java.util.Iterator;
|
|
31 |
|
|
32 |
abstract class MirrorImpl extends Object implements Mirror {
|
|
33 |
|
|
34 |
protected VirtualMachineImpl vm;
|
|
35 |
|
|
36 |
MirrorImpl(VirtualMachine aVm) {
|
|
37 |
super();
|
|
38 |
|
|
39 |
// Yes, its a bit of a hack. But by doing it this
|
|
40 |
// way, this is the only place we have to change
|
|
41 |
// typing to substitute a new impl.
|
|
42 |
vm = (VirtualMachineImpl)aVm;
|
|
43 |
}
|
|
44 |
|
|
45 |
public VirtualMachine virtualMachine() {
|
|
46 |
return vm;
|
|
47 |
}
|
|
48 |
|
|
49 |
public boolean equals(Object obj) {
|
|
50 |
if ((obj != null) && (obj instanceof Mirror)) {
|
|
51 |
Mirror other = (Mirror)obj;
|
|
52 |
return vm.equals(other.virtualMachine());
|
|
53 |
} else {
|
|
54 |
return false;
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
public int hashCode() {
|
|
59 |
return vm.hashCode();
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Throw NullPointerException on null mirror.
|
|
64 |
* Throw VMMismatchException on wrong VM.
|
|
65 |
*/
|
|
66 |
void validateMirror(Mirror mirror) {
|
|
67 |
if (!vm.equals(mirror.virtualMachine())) {
|
|
68 |
throw new VMMismatchException(mirror.toString());
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Allow null mirror.
|
|
74 |
* Throw VMMismatchException on wrong VM.
|
|
75 |
*/
|
|
76 |
void validateMirrorOrNull(Mirror mirror) {
|
|
77 |
if ((mirror != null) && !vm.equals(mirror.virtualMachine())) {
|
|
78 |
throw new VMMismatchException(mirror.toString());
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Throw NullPointerException on null mirrors.
|
|
84 |
* Throw VMMismatchException on wrong VM.
|
|
85 |
*/
|
|
86 |
void validateMirrors(Collection mirrors) {
|
|
87 |
Iterator iter = mirrors.iterator();
|
|
88 |
while (iter.hasNext()) {
|
|
89 |
MirrorImpl mirror = (MirrorImpl)iter.next();
|
|
90 |
if (!vm.equals(mirror.vm)) {
|
|
91 |
throw new VMMismatchException(mirror.toString());
|
|
92 |
}
|
|
93 |
}
|
|
94 |
}
|
|
95 |
/**
|
|
96 |
* Allow null mirrors.
|
|
97 |
* Throw VMMismatchException on wrong VM.
|
|
98 |
*/
|
|
99 |
void validateMirrorsOrNulls(Collection mirrors) {
|
|
100 |
Iterator iter = mirrors.iterator();
|
|
101 |
while (iter.hasNext()) {
|
|
102 |
MirrorImpl mirror = (MirrorImpl)iter.next();
|
|
103 |
if ((mirror != null) && !vm.equals(mirror.vm)) {
|
|
104 |
throw new VMMismatchException(mirror.toString());
|
|
105 |
}
|
|
106 |
}
|
|
107 |
}
|
|
108 |
}
|