KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > InterfaceTypeImpl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal;
12
13
14 import java.io.DataInputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.eclipse.jdi.internal.jdwp.JdwpClassObjectID;
21 import org.eclipse.jdi.internal.jdwp.JdwpID;
22 import org.eclipse.jdi.internal.jdwp.JdwpInterfaceID;
23
24 import com.sun.jdi.ClassNotPreparedException;
25 import com.sun.jdi.InterfaceType;
26 import com.sun.jdi.Value;
27
28 /**
29  * this class implements the corresponding interfaces
30  * declared by the JDI specification. See the com.sun.jdi package
31  * for more information.
32  *
33  */

34 public class InterfaceTypeImpl extends ReferenceTypeImpl implements InterfaceType {
35     /** JDWP Tag. */
36     public static final byte typeTag = JdwpID.TYPE_TAG_INTERFACE;
37
38     /**
39      * Creates new InterfaceTypeImpl.
40      */

41     public InterfaceTypeImpl(VirtualMachineImpl vmImpl, JdwpInterfaceID interfaceID) {
42         super("InterfaceType", vmImpl, interfaceID); //$NON-NLS-1$
43
}
44
45     /**
46      * Creates new InterfaceTypeImpl.
47      */

48     public InterfaceTypeImpl(VirtualMachineImpl vmImpl, JdwpInterfaceID interfaceID, String JavaDoc signature, String JavaDoc genericSignature) {
49         super("InterfaceType", vmImpl, interfaceID, signature, genericSignature); //$NON-NLS-1$
50
}
51
52     /**
53      * @return Create a null value instance of the type.
54      */

55     public Value createNullValue() {
56         return new ClassObjectReferenceImpl(virtualMachineImpl(), new JdwpClassObjectID(virtualMachineImpl()));
57     }
58
59     /**
60      * @return Returns type tag.
61      */

62     public byte typeTag() {
63         return typeTag;
64     }
65     
66     /**
67      * Flushes all stored Jdwp results.
68      */

69     public void flushStoredJdwpResults() {
70         super.flushStoredJdwpResults();
71
72         // For all reftypes that have this interface cached, this cache must be undone.
73
Iterator JavaDoc itr = virtualMachineImpl().allCachedRefTypes();
74         while (itr.hasNext()) {
75             ReferenceTypeImpl refType = (ReferenceTypeImpl)itr.next();
76             if (refType.fInterfaces != null && refType.fInterfaces.contains(this)) {
77                 refType.flushStoredJdwpResults();
78             }
79         }
80         
81     }
82     
83     /**
84      * @return Returns the currently prepared classes which directly implement this interface.
85      */

86     public List JavaDoc implementors() {
87         // Note that this information should not be cached.
88
List JavaDoc implementors = new ArrayList JavaDoc();
89         Iterator JavaDoc itr = virtualMachineImpl().allRefTypes();
90         while (itr.hasNext()) {
91             ReferenceTypeImpl refType = (ReferenceTypeImpl)itr.next();
92             if (refType instanceof ClassTypeImpl) {
93                 try {
94                     ClassTypeImpl classType = (ClassTypeImpl)refType;
95                     List JavaDoc interfaces = classType.interfaces();
96                     if (interfaces.contains(this)) {
97                         implementors .add(classType);
98                     }
99                 } catch (ClassNotPreparedException e) {
100                     continue;
101                 }
102             }
103         }
104         return implementors;
105     }
106     
107     /**
108      * @return Returns the currently prepared interfaces which directly extend this interface.
109      */

110     public List JavaDoc subinterfaces() {
111         // Note that this information should not be cached.
112
List JavaDoc implementors = new ArrayList JavaDoc();
113         Iterator JavaDoc itr = virtualMachineImpl().allRefTypes();
114         while (itr.hasNext()) {
115             try {
116                 ReferenceTypeImpl refType = (ReferenceTypeImpl)itr.next();
117                 if (refType instanceof InterfaceTypeImpl) {
118                     InterfaceTypeImpl interFaceType = (InterfaceTypeImpl)refType;
119                     List JavaDoc interfaces = interFaceType.superinterfaces();
120                     if (interfaces.contains(this)) {
121                         implementors.add(interFaceType);
122                     }
123                 }
124             } catch (ClassNotPreparedException e) {
125                 continue;
126             }
127         }
128         return implementors;
129     }
130     
131     /**
132      * @return Returns the interfaces directly extended by this interface.
133      */

134     public List JavaDoc superinterfaces() {
135         return interfaces();
136     }
137     
138     /**
139      * @return Returns true if this type has been initialized.
140      */

141     public boolean isInitialized() {
142         return isPrepared();
143     }
144
145     /**
146      * @return Reads ID and returns known ReferenceTypeImpl with that ID, or if ID is unknown a newly created ReferenceTypeImpl.
147      */

148     public static InterfaceTypeImpl read(MirrorImpl target, DataInputStream JavaDoc in) throws IOException JavaDoc {
149         VirtualMachineImpl vmImpl = target.virtualMachineImpl();
150         JdwpInterfaceID ID = new JdwpInterfaceID(vmImpl);
151         ID.read(in);
152         if (target.fVerboseWriter != null) {
153             target.fVerboseWriter.println("interfaceType", ID.value()); //$NON-NLS-1$
154
}
155
156         if (ID.isNull()) {
157             return null;
158         }
159             
160         InterfaceTypeImpl mirror = (InterfaceTypeImpl)vmImpl.getCachedMirror(ID);
161         if (mirror == null) {
162             mirror = new InterfaceTypeImpl(vmImpl, ID);
163             vmImpl.addCachedMirror(mirror);
164         }
165         return mirror;
166      }
167     
168     /**
169      * @return Reads ID and returns known ReferenceTypeImpl with that ID, or if ID is unknown a newly created ReferenceTypeImpl.
170      */

171     public static InterfaceTypeImpl readWithSignature(MirrorImpl target, boolean withGenericSignature, DataInputStream JavaDoc in) throws IOException JavaDoc {
172         VirtualMachineImpl vmImpl = target.virtualMachineImpl();
173         JdwpInterfaceID ID = new JdwpInterfaceID(vmImpl);
174         ID.read(in);
175         if (target.fVerboseWriter != null) {
176             target.fVerboseWriter.println("interfaceType", ID.value()); //$NON-NLS-1$
177
}
178
179         String JavaDoc signature = target.readString("signature", in); //$NON-NLS-1$
180
String JavaDoc genericSignature= null;
181         if (withGenericSignature) {
182             genericSignature= target.readString("generic signature", in); //$NON-NLS-1$
183
}
184         if (ID.isNull()) {
185             return null;
186         }
187             
188         InterfaceTypeImpl mirror = (InterfaceTypeImpl)vmImpl.getCachedMirror(ID);
189         if (mirror == null) {
190             mirror = new InterfaceTypeImpl(vmImpl, ID);
191             vmImpl.addCachedMirror(mirror);
192         }
193         mirror.setSignature(signature);
194         mirror.setGenericSignature(genericSignature);
195         return mirror;
196      }
197 }
198
Popular Tags