001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.launching;
011:
012: /**
013: * An implementation of IVMInstall that is used for manipulating VMs without necessarily
014: * committing changes.
015: * <p>
016: * Instances of this class act like wrappers. All other instances of IVMInstall represent
017: * 'real live' VMs that may be used for building or launching. Instances of this class
018: * behave like 'temporary' VMs that are not visible and not available for building or launching.
019: * </p>
020: * <p>
021: * Instances of this class may be constructed as a preliminary step to creating a 'live' VM
022: * or as a preliminary step to making changes to a 'real' VM.
023: * </p>
024: * When <code>convertToRealVM</code> is called, a corresponding 'real' VM is created
025: * if one did not previously exist, or the corresponding 'real' VM is updated.
026: * </p>
027: * <p>
028: * Clients may instantiate this class; it is not intended to be subclassed.
029: * </p>
030: *
031: * @since 2.1
032: */
033: public class VMStandin extends AbstractVMInstall {
034:
035: /**
036: * <code>java.version</code> system property, or <code>null</code>
037: * @since 3.1
038: */
039: private String fJavaVersion = null;
040:
041: /*
042: * @see org.eclipse.jdt.launching.AbstractVMInstall#AbstractVMInstall(org.eclipse.jdt.launching.IVMInstallType, java.lang.String)
043: */
044: public VMStandin(IVMInstallType type, String id) {
045: super (type, id);
046: setNotify(false);
047: }
048:
049: /**
050: * Constructs a copy of the specified VM with the given identifier.
051: *
052: * @param sourceVM
053: * @param id
054: * @since 3.2
055: */
056: public VMStandin(IVMInstall sourceVM, String id) {
057: super (sourceVM.getVMInstallType(), id);
058: setNotify(false);
059: init(sourceVM);
060: }
061:
062: /**
063: * Construct a <code>VMStandin</code> instance based on the specified <code>IVMInstall</code>.
064: * Changes to this standin will not be reflected in the 'real' VM until <code>convertToRealVM</code>
065: * is called.
066: *
067: * @param realVM the 'real' VM from which to construct this standin VM
068: */
069: public VMStandin(IVMInstall realVM) {
070: this (realVM.getVMInstallType(), realVM.getId());
071: init(realVM);
072: }
073:
074: /**
075: * Initializes the settings of this standin based on the settings in the given
076: * VM install.
077: *
078: * @param realVM VM to copy settings from
079: */
080: private void init(IVMInstall realVM) {
081: setName(realVM.getName());
082: setInstallLocation(realVM.getInstallLocation());
083: setLibraryLocations(realVM.getLibraryLocations());
084: setJavadocLocation(realVM.getJavadocLocation());
085: if (realVM instanceof IVMInstall2) {
086: IVMInstall2 vm2 = (IVMInstall2) realVM;
087: setVMArgs(vm2.getVMArgs());
088: fJavaVersion = vm2.getJavaVersion();
089: } else {
090: setVMArguments(realVM.getVMArguments());
091: fJavaVersion = null;
092: }
093: }
094:
095: /**
096: * If no corresponding 'real' VM exists, create one and populate it from this standin instance.
097: * If a corresponding VM exists, update its attributes from this standin instance.
098: *
099: * @return IVMInstall the 'real' corresponding to this standin VM
100: */
101: public IVMInstall convertToRealVM() {
102: IVMInstallType vmType = getVMInstallType();
103: IVMInstall realVM = vmType.findVMInstall(getId());
104: boolean notify = true;
105:
106: if (realVM == null) {
107: realVM = vmType.createVMInstall(getId());
108: notify = false;
109: }
110: // do not notify of property changes on new VMs
111: if (realVM instanceof AbstractVMInstall) {
112: ((AbstractVMInstall) realVM).setNotify(notify);
113: }
114: realVM.setName(getName());
115: realVM.setInstallLocation(getInstallLocation());
116: realVM.setLibraryLocations(getLibraryLocations());
117: realVM.setJavadocLocation(getJavadocLocation());
118: if (realVM instanceof IVMInstall2) {
119: IVMInstall2 vm2 = (IVMInstall2) realVM;
120: vm2.setVMArgs(getVMArgs());
121: } else {
122: realVM.setVMArguments(getVMArguments());
123: }
124:
125: if (realVM instanceof AbstractVMInstall) {
126: ((AbstractVMInstall) realVM).setNotify(true);
127: }
128: if (!notify) {
129: JavaRuntime.fireVMAdded(realVM);
130: }
131: return realVM;
132: }
133:
134: /* (non-Javadoc)
135: * @see org.eclipse.jdt.launching.IVMInstall#getJavaVersion()
136: */
137: public String getJavaVersion() {
138: return fJavaVersion;
139: }
140: }
|