KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.File JavaDoc;
15 import java.net.URL JavaDoc;
16 import com.ibm.icu.text.MessageFormat;
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.eclipse.core.runtime.IConfigurationElement;
21 import org.eclipse.core.runtime.IExecutableExtension;
22 import org.eclipse.jdt.internal.launching.LaunchingMessages;
23
24 /**
25  * Abstract implementation of a VM install type.
26  * Subclasses should implement
27  * <ul>
28  * <li><code>IVMInstall doCreateVMInstall(String id)</code></li>
29  * <li><code>String getName()</code></li>
30  * <li><code>IStatus validateInstallLocation(File installLocation)</code></li>
31  * </ul>
32  * <p>
33  * Clients implementing VM install types should subclass this class.
34  * </p>
35  */

36
37 public abstract class AbstractVMInstallType implements IVMInstallType, IExecutableExtension {
38     private List JavaDoc fVMs;
39     private String JavaDoc fId;
40     
41     /**
42      * Constructs a new VM install type.
43      */

44     protected AbstractVMInstallType() {
45         fVMs= new ArrayList JavaDoc(10);
46     }
47
48     /* (non-Javadoc)
49      * Subclasses should not override this method.
50      * @see IVMType#getVMs()
51      */

52     public IVMInstall[] getVMInstalls() {
53         IVMInstall[] vms= new IVMInstall[fVMs.size()];
54         return (IVMInstall[])fVMs.toArray(vms);
55     }
56
57     /* (non-Javadoc)
58      * Subclasses should not override this method.
59      * @see IVMType#disposeVM(String)
60      */

61     public void disposeVMInstall(String JavaDoc id) {
62         for (int i= 0; i < fVMs.size(); i++) {
63             IVMInstall vm= (IVMInstall)fVMs.get(i);
64             if (vm.getId().equals(id)) {
65                 fVMs.remove(i);
66                 JavaRuntime.fireVMRemoved(vm);
67                 return;
68             }
69         }
70     }
71
72     /* (non-Javadoc)
73      * Subclasses should not override this method.
74      * @see IVMType#getVM(String)
75      */

76     public IVMInstall findVMInstall(String JavaDoc id) {
77         for (int i= 0; i < fVMs.size(); i++) {
78             IVMInstall vm= (IVMInstall)fVMs.get(i);
79             if (vm.getId().equals(id)) {
80                 return vm;
81             }
82         }
83         return null;
84     }
85
86     /* (non-Javadoc)
87      * Subclasses should not override this method.
88      * @see IVMType#createVM(String)
89      */

90     public IVMInstall createVMInstall(String JavaDoc id) throws IllegalArgumentException JavaDoc {
91         if (findVMInstall(id) != null) {
92             String JavaDoc format= LaunchingMessages.vmInstallType_duplicateVM;
93             throw new IllegalArgumentException JavaDoc(MessageFormat.format(format, new String JavaDoc[] { id }));
94         }
95         IVMInstall vm= doCreateVMInstall(id);
96         fVMs.add(vm);
97         return vm;
98     }
99     
100     /**
101      * Subclasses should return a new instance of the appropriate
102      * <code>IVMInstall</code> subclass from this method.
103      * @param id The vm's id. The <code>IVMInstall</code> instance that is created must
104      * return <code>id</code> from its <code>getId()</code> method.
105      * Must not be <code>null</code>.
106      * @return the newly created IVMInstall instance. Must not return <code>null</code>.
107      */

108     protected abstract IVMInstall doCreateVMInstall(String JavaDoc id);
109
110     /* (non-Javadoc)
111      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
112      */

113     /**
114      * Initializes the id parameter from the "id" attribute
115      * in the configuration markup.
116      * Subclasses should not override this method.
117      * @param config the configuration element used to trigger this execution.
118      * It can be queried by the executable extension for specific
119      * configuration properties
120      * @param propertyName the name of an attribute of the configuration element
121      * used on the <code>createExecutableExtension(String)</code> call. This
122      * argument can be used in the cases where a single configuration element
123      * is used to define multiple executable extensions.
124      * @param data adapter data in the form of a <code>String</code>,
125      * a <code>Hashtable</code>, or <code>null</code>.
126      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
127      */

128     public void setInitializationData(IConfigurationElement config, String JavaDoc propertyName, Object JavaDoc data) {
129         fId= config.getAttribute("id"); //$NON-NLS-1$
130
}
131
132     /* (non-Javadoc)
133      * Subclasses should not override this method.
134      * @see IVMType#getId()
135      */

136     public String JavaDoc getId() {
137         return fId;
138     }
139
140     /* (non-Javadoc)
141      * @see org.eclipse.jdt.launching.IVMInstallType#findVMInstallByName(java.lang.String)
142      */

143     public IVMInstall findVMInstallByName(String JavaDoc name) {
144         for (int i= 0; i < fVMs.size(); i++) {
145             IVMInstall vm= (IVMInstall)fVMs.get(i);
146             if (vm.getName().equals(name)) {
147                 return vm;
148             }
149         }
150         return null;
151     }
152
153     /**
154      * Returns a URL for the default javadoc location of a VM installed at the
155      * given home location, or <code>null</code> if none. The default
156      * implementation returns <code>null</code>, subclasses must override as
157      * appropriate.
158      * <p>
159      * Note, this method would ideally be added to <code>IVMInstallType</code>,
160      * but it would have been a breaking API change between 2.0 and 2.1. Thus,
161      * it has been added to the abstract base class that VM install types should
162      * subclass.
163      * </p>
164      *
165      * @param installLocation home location
166      * @return default javadoc location or <code>null</code>
167      * @since 2.1
168      */

169     public URL JavaDoc getDefaultJavadocLocation(File JavaDoc installLocation) {
170         return null;
171     }
172 }
173
Popular Tags