KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > AbstractRuntimeClasspathEntry


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.jdt.internal.launching;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.PlatformObject;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.jdt.core.IClasspathEntry;
21 import org.eclipse.jdt.core.IJavaProject;
22 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
23 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
24 import org.eclipse.jdt.launching.IRuntimeClasspathEntry2;
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * Common function for runtime classpath entries.
30  * <p>
31  * Clients implementing runtime classpath entries must subclass this
32  * class.
33  * </p>
34  * @since 3.0
35  */

36 public abstract class AbstractRuntimeClasspathEntry extends PlatformObject implements IRuntimeClasspathEntry2 {
37     
38     private IPath sourceAttachmentPath = null;
39     private IPath rootSourcePath = null;
40     private int classpathProperty = IRuntimeClasspathEntry.USER_CLASSES;
41     /**
42      * Associated Java project, or <code>null</code>
43      */

44     private IJavaProject fJavaProject;
45     
46     /* (non-Javadoc)
47      *
48      * Default implementation returns <code>false</code>.
49      * Subclasses should override if required.
50      *
51      * @see org.eclipse.jdt.internal.launching.IRuntimeClasspathEntry2#isComposite()
52      */

53     public boolean isComposite() {
54         return false;
55     }
56     
57     /* (non-Javadoc)
58      *
59      * Default implementation returns an empty collection.
60      * Subclasses should override if required.
61      *
62      * @see org.eclipse.jdt.internal.launching.IRuntimeClasspathEntry2#getRuntimeClasspathEntries()
63      */

64     public IRuntimeClasspathEntry[] getRuntimeClasspathEntries() throws CoreException {
65         return new IRuntimeClasspathEntry[0];
66     }
67     
68     /**
69      * Throws an exception with the given message and underlying exception.
70      *
71      * @param message error message
72      * @param exception underlying exception or <code>null</code> if none
73      * @throws CoreException
74      */

75     protected void abort(String JavaDoc message, Throwable JavaDoc exception) throws CoreException {
76         IStatus status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR, message, exception);
77         throw new CoreException(status);
78     }
79
80     /* (non-Javadoc)
81      *
82      * Default implementation generates a string containing an XML
83      * document. Subclasses should override <code>buildMemento</code>
84      * to specify the contents of the required <code>memento</code>
85      * node.
86      *
87      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getMemento()
88      */

89     public String JavaDoc getMemento() throws CoreException {
90         Document JavaDoc doc= DebugPlugin.newDocument();
91         Element JavaDoc root = doc.createElement("runtimeClasspathEntry"); //$NON-NLS-1$
92
doc.appendChild(root);
93         root.setAttribute("id", getTypeId()); //$NON-NLS-1$
94
Element JavaDoc memento = doc.createElement("memento"); //$NON-NLS-1$
95
root.appendChild(memento);
96         buildMemento(doc, memento);
97         return DebugPlugin.serializeDocument(doc);
98     }
99     
100     /**
101      * Constructs a memento for this classpath entry in the given
102      * document and element. The memento element has already been
103      * appended to the document.
104      *
105      * @param document XML document
106      * @param memento element node for client specific attributes
107      * @throws CoreException if unable to create a memento
108      */

109     protected abstract void buildMemento(Document JavaDoc document, Element JavaDoc memento) throws CoreException;
110     
111     /* (non-Javadoc)
112      *
113      * Default implementation returns <code>null</code>.
114      * Subclasses should override if required.
115      *
116      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getPath()
117      */

118     public IPath getPath() {
119         return null;
120     }
121     
122     /* (non-Javadoc)
123      *
124      * Default implementation returns <code>null</code>.
125      * Subclasses should override if required.
126      *
127      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getResource()
128      */

129     public IResource getResource() {
130         return null;
131     }
132     
133     /* (non-Javadoc)
134      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getSourceAttachmentPath()
135      */

136     public IPath getSourceAttachmentPath() {
137         return sourceAttachmentPath;
138     }
139     /* (non-Javadoc)
140      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#setSourceAttachmentPath(org.eclipse.core.runtime.IPath)
141      */

142     public void setSourceAttachmentPath(IPath path) {
143         sourceAttachmentPath = path;
144     }
145     /* (non-Javadoc)
146      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getSourceAttachmentRootPath()
147      */

148     public IPath getSourceAttachmentRootPath() {
149         return rootSourcePath;
150     }
151     /* (non-Javadoc)
152      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#setSourceAttachmentRootPath(org.eclipse.core.runtime.IPath)
153      */

154     public void setSourceAttachmentRootPath(IPath path) {
155         rootSourcePath = path;
156     }
157     /* (non-Javadoc)
158      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getClasspathProperty()
159      */

160     public int getClasspathProperty() {
161         return classpathProperty;
162     }
163     /* (non-Javadoc)
164      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#setClasspathProperty(int)
165      */

166     public void setClasspathProperty(int property) {
167         classpathProperty = property;
168     }
169     /* (non-Javadoc)
170      *
171      * Default implementation returns <code>null</code>.
172      * Subclasses should override if required.
173      *
174      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getLocation()
175      */

176     public String JavaDoc getLocation() {
177         return null;
178     }
179     
180     /* (non-Javadoc)
181      *
182      * Default implementation returns <code>null</code>.
183      * Subclasses should override if required.
184      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getSourceAttachmentLocation()
185      */

186     public String JavaDoc getSourceAttachmentLocation() {
187         return null;
188     }
189     /* (non-Javadoc)
190      *
191      * Default implementation returns <code>null</code>.
192      * Subclasses should override if required.
193      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getSourceAttachmentRootLocation()
194      */

195     public String JavaDoc getSourceAttachmentRootLocation() {
196         return null;
197     }
198     /* (non-Javadoc)
199      *
200      * Default implementation returns <code>null</code>.
201      * Subclasses should override if required.
202      *
203      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getVariableName()
204      */

205     public String JavaDoc getVariableName() {
206         return null;
207     }
208     /* (non-Javadoc)
209      *
210      * Default implementation returns <code>null</code>.
211      * Subclasses should override if required.
212      *
213      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getClasspathEntry()
214      */

215     public IClasspathEntry getClasspathEntry() {
216         return null;
217     }
218     /* (non-Javadoc)
219      * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getJavaProject()
220      */

221     public IJavaProject getJavaProject() {
222         return fJavaProject;
223     }
224     
225     /**
226      * Sets the Java project associated with this entry.
227      *
228      * @param javaProject
229      */

230     protected void setJavaProject(IJavaProject javaProject) {
231         fJavaProject = javaProject;
232     }
233 }
234
Popular Tags