KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > launching > VMStandin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.launching;
12
13
14
15 /**
16  * An implementation of IVMInstall that is used for manipulating VMs without necessarily
17  * committing changes.
18  * <p>
19  * Instances of this class act like wrappers. All other instances of IVMInstall represent
20  * 'real live' VMs that may be used for building or launching. Instances of this class
21  * behave like 'temporary' VMs that are not visible and not available for building or launching.
22  * </p>
23  * <p>
24  * Instances of this class may be constructed as a preliminary step to creating a 'live' VM
25  * or as a preliminary step to making changes to a 'real' VM.
26  * </p>
27  * When <code>convertToRealVM</code> is called, a corresponding 'real' VM is created
28  * if one did not previously exist, or the corresponding 'real' VM is updated.
29  * </p>
30  * <p>
31  * Clients may instantiate this class; it is not intended to be subclassed.
32  * </p>
33  *
34  * @since 2.1
35  */

36 public class VMStandin extends AbstractVMInstall {
37     
38     /**
39      * <code>java.version</code> system property, or <code>null</code>
40      * @since 3.1
41      */

42     private String JavaDoc fJavaVersion = null;
43
44     /*
45      * @see org.eclipse.jdt.launching.AbstractVMInstall#AbstractVMInstall(org.eclipse.jdt.launching.IVMInstallType, java.lang.String)
46      */

47     public VMStandin(IVMInstallType type, String JavaDoc id) {
48         super(type, id);
49         setNotify(false);
50     }
51     
52     /**
53      * Constructs a copy of the specified VM with the given identifier.
54      *
55      * @param sourceVM
56      * @param id
57      * @since 3.2
58      */

59     public VMStandin(IVMInstall sourceVM, String JavaDoc id) {
60         super(sourceVM.getVMInstallType(), id);
61         setNotify(false);
62         init(sourceVM);
63     }
64     
65     /**
66      * Construct a <code>VMStandin</code> instance based on the specified <code>IVMInstall</code>.
67      * Changes to this standin will not be reflected in the 'real' VM until <code>convertToRealVM</code>
68      * is called.
69      *
70      * @param realVM the 'real' VM from which to construct this standin VM
71      */

72     public VMStandin(IVMInstall realVM) {
73         this (realVM.getVMInstallType(), realVM.getId());
74         init(realVM);
75     }
76
77     /**
78      * Initializes the settings of this standin based on the settings in the given
79      * VM install.
80      *
81      * @param realVM VM to copy settings from
82      */

83     private void init(IVMInstall realVM) {
84         setName(realVM.getName());
85         setInstallLocation(realVM.getInstallLocation());
86         setLibraryLocations(realVM.getLibraryLocations());
87         setJavadocLocation(realVM.getJavadocLocation());
88         if (realVM instanceof IVMInstall2) {
89             IVMInstall2 vm2 = (IVMInstall2) realVM;
90             setVMArgs(vm2.getVMArgs());
91             fJavaVersion = vm2.getJavaVersion();
92         } else {
93             setVMArguments(realVM.getVMArguments());
94             fJavaVersion = null;
95         }
96     }
97     
98     /**
99      * If no corresponding 'real' VM exists, create one and populate it from this standin instance.
100      * If a corresponding VM exists, update its attributes from this standin instance.
101      *
102      * @return IVMInstall the 'real' corresponding to this standin VM
103      */

104     public IVMInstall convertToRealVM() {
105         IVMInstallType vmType= getVMInstallType();
106         IVMInstall realVM= vmType.findVMInstall(getId());
107         boolean notify = true;
108         
109         if (realVM == null) {
110             realVM= vmType.createVMInstall(getId());
111             notify = false;
112         }
113         // do not notify of property changes on new VMs
114
if (realVM instanceof AbstractVMInstall) {
115              ((AbstractVMInstall)realVM).setNotify(notify);
116         }
117         realVM.setName(getName());
118         realVM.setInstallLocation(getInstallLocation());
119         realVM.setLibraryLocations(getLibraryLocations());
120         realVM.setJavadocLocation(getJavadocLocation());
121         if (realVM instanceof IVMInstall2) {
122             IVMInstall2 vm2 = (IVMInstall2) realVM;
123             vm2.setVMArgs(getVMArgs());
124         } else {
125             realVM.setVMArguments(getVMArguments());
126         }
127         
128         if (realVM instanceof AbstractVMInstall) {
129              ((AbstractVMInstall)realVM).setNotify(true);
130         }
131         if (!notify) {
132             JavaRuntime.fireVMAdded(realVM);
133         }
134         return realVM;
135     }
136         
137     /* (non-Javadoc)
138      * @see org.eclipse.jdt.launching.IVMInstall#getJavaVersion()
139      */

140     public String JavaDoc getJavaVersion() {
141         return fJavaVersion;
142     }
143 }
144
Popular Tags