KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > connect > ConnectorImpl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Ivan Popov - Bug 184211: JDI connectors throw NullPointerException if used separately
11  * from Eclipse
12  *******************************************************************************/

13 package org.eclipse.jdi.internal.connect;
14
15
16 import java.io.IOException JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.jdi.Bootstrap;
20 import org.eclipse.jdi.internal.VirtualMachineImpl;
21 import org.eclipse.jdi.internal.VirtualMachineManagerImpl;
22
23 import com.sun.jdi.VirtualMachine;
24 import com.sun.jdi.connect.Connector;
25 import com.sun.jdi.connect.Transport;
26 import com.sun.jdi.connect.spi.Connection;
27
28
29 /**
30  * this class implements the corresponding interfaces
31  * declared by the JDI specification. See the com.sun.jdi package
32  * for more information.
33  *
34  */

35 public abstract class ConnectorImpl implements Connector {
36     /** Virtual machine manager that created this connector. */
37     private VirtualMachineManagerImpl fVirtualMachineManager;
38
39     /** Transport that is used for communication. */
40     protected Transport fTransport;
41     /** Virtual Machine that is connected. */
42     protected VirtualMachineImpl fVirtualMachine;
43     
44     /**
45      * Creates a new Connector.
46      */

47     public ConnectorImpl(VirtualMachineManagerImpl virtualMachineManager) {
48         fVirtualMachineManager = virtualMachineManager;
49     }
50
51     /**
52      * @return Returns Virtual Machine Manager.
53      */

54     public VirtualMachineManagerImpl virtualMachineManager() {
55         return fVirtualMachineManager;
56     }
57     
58     /**
59      * @return Returns Virtual Machine Manager.
60      */

61     public VirtualMachineImpl virtualMachine() {
62         return fVirtualMachine;
63     }
64
65     /**
66      * @return Returns a human-readable description of this connector and its purpose.
67      */

68     public abstract String JavaDoc description();
69     
70     /**
71      * @return Returns a short identifier for the connector.
72      */

73     public abstract String JavaDoc name();
74     
75     /**
76      * Assigns Transport.
77      */

78     /*package*/ void setTransport(Transport transport) {
79         fTransport = transport;
80     }
81
82     /**
83      * @return Returns the transport mechanism used by this connector to establish connections with a target VM.
84      */

85     public Transport transport() {
86         return fTransport;
87     }
88     
89     /**
90      * Closes connection with Virtual Machine.
91      */

92     /*package*/ synchronized void close() {
93         virtualMachineManager().removeConnectedVM(fVirtualMachine);
94     }
95     
96     /**
97      * @return Returns a connected Virtual Machine.
98      */

99     protected VirtualMachine establishedConnection(Connection connection) throws IOException JavaDoc {
100         fVirtualMachine = (VirtualMachineImpl) Bootstrap.virtualMachineManager().createVirtualMachine(connection);
101         return fVirtualMachine;
102     }
103     
104     /**
105      * Argument class for arguments that are used to establish a connection.
106      */

107     public abstract class ArgumentImpl implements com.sun.jdi.connect.Connector.Argument {
108         private String JavaDoc fName;
109         private String JavaDoc fDescription;
110         private String JavaDoc fLabel;
111         private boolean fMustSpecify;
112
113         protected ArgumentImpl(String JavaDoc name, String JavaDoc description, String JavaDoc label, boolean mustSpecify) {
114             fName = name;
115             fLabel = label;
116             fDescription = description;
117             fMustSpecify = mustSpecify;
118         }
119
120         public String JavaDoc name() {
121             return fName;
122         }
123         
124         public String JavaDoc description() {
125             return fDescription;
126         }
127         
128         public String JavaDoc label() {
129             return fLabel;
130         }
131         
132         public boolean mustSpecify() {
133             return fMustSpecify;
134         }
135         
136         public abstract String JavaDoc value();
137         public abstract void setValue(String JavaDoc value);
138         public abstract boolean isValid(String JavaDoc value);
139         public abstract String JavaDoc toString();
140     }
141     
142     public class StringArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.StringArgument {
143         private static final long serialVersionUID = 6009335074727417445L;
144
145         private String JavaDoc fValue;
146
147         protected StringArgumentImpl(String JavaDoc name, String JavaDoc description, String JavaDoc label, boolean mustSpecify) {
148             super(name, description, label, mustSpecify);
149         }
150         
151         public String JavaDoc value() {
152             return fValue;
153         }
154         
155         public void setValue(String JavaDoc value) {
156             fValue = value;
157         }
158
159         public boolean isValid(String JavaDoc value) {
160             return true;
161         }
162
163         public String JavaDoc toString() {
164             return fValue;
165         }
166
167     }
168     
169     public class IntegerArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.IntegerArgument {
170         private static final long serialVersionUID = 6009335074727417445L;
171         private Integer JavaDoc fValue;
172         private int fMin;
173         private int fMax;
174
175         protected IntegerArgumentImpl(String JavaDoc name, String JavaDoc description, String JavaDoc label, boolean mustSpecify, int min, int max) {
176             super(name, description, label, mustSpecify);
177             fMin = min;
178             fMax = max;
179         }
180         
181         public String JavaDoc value() {
182             return (fValue == null) ? null : fValue.toString();
183         }
184         
185         public void setValue(String JavaDoc value) {
186             fValue = new Integer JavaDoc(value);
187         }
188
189         public boolean isValid(String JavaDoc value) {
190             Integer JavaDoc val;
191             try {
192                 val = new Integer JavaDoc(value);
193             } catch (NumberFormatException JavaDoc e) {
194                 return false;
195             }
196             return isValid(val.intValue());
197         }
198
199         public String JavaDoc toString() {
200             return value();
201         }
202
203         public int intValue() {
204             return fValue.intValue();
205         }
206         
207         public void setValue(int value) {
208             fValue = new Integer JavaDoc(value);
209         }
210
211         public int min() {
212             return fMin;
213         }
214         
215         public int max() {
216             return fMax;
217         }
218         
219         public boolean isValid(int value) {
220             return fMin <= value && value <= fMax;
221         }
222
223         public String JavaDoc stringValueOf(int value) {
224             return new Integer JavaDoc(value).toString();
225         }
226     }
227     
228     public class BooleanArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.BooleanArgument {
229         private static final long serialVersionUID = 6009335074727417445L;
230         private Boolean JavaDoc fValue;
231         
232         protected BooleanArgumentImpl(String JavaDoc name, String JavaDoc description, String JavaDoc label, boolean mustSpecify) {
233             super(name, description, label, mustSpecify);
234         }
235         
236         public String JavaDoc value() {
237             return (fValue == null) ? null : fValue.toString();
238         }
239         
240         public void setValue(String JavaDoc value) {
241             fValue = Boolean.valueOf(value);
242         }
243
244         public boolean isValid(String JavaDoc value) {
245             return true;
246         }
247         
248         public String JavaDoc toString() {
249             return value();
250         }
251
252         public boolean booleanValue() {
253             return fValue.booleanValue();
254         }
255
256         public void setValue(boolean value) {
257             fValue = Boolean.valueOf(value);
258         }
259         
260         public String JavaDoc stringValueOf(boolean value) {
261             return Boolean.valueOf(value).toString();
262         }
263     }
264     
265     public class SelectedArgumentImpl extends StringArgumentImpl implements com.sun.jdi.connect.Connector.SelectedArgument {
266         private static final long serialVersionUID = 6009335074727417445L;
267         private List JavaDoc fChoices;
268         
269         protected SelectedArgumentImpl(String JavaDoc name, String JavaDoc description, String JavaDoc label, boolean mustSpecify, List JavaDoc choices) {
270             super(name, description, label, mustSpecify);
271             fChoices = choices;
272         }
273         
274         public List JavaDoc choices() {
275             return fChoices;
276         }
277         
278         public boolean isValid(java.lang.String JavaDoc value) {
279             return fChoices.contains(value);
280         }
281     }
282 }
283
Popular Tags