KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > ClasspathEntry


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
12 package org.eclipse.ant.internal.ui.preferences;
13
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16 import org.eclipse.ant.core.IAntClasspathEntry;
17 import org.eclipse.ant.internal.ui.AntUIPlugin;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.variables.VariablesPlugin;
20
21 public class ClasspathEntry extends AbstractClasspathEntry {
22
23     private URL JavaDoc fUrl= null;
24     private String JavaDoc fVariableString= null;
25     private IAntClasspathEntry fEntry= null;
26     
27     public ClasspathEntry(Object JavaDoc o, IClasspathEntry parent) {
28         fParent= parent;
29         if (o instanceof URL JavaDoc) {
30             fUrl= (URL JavaDoc)o;
31         } else if (o instanceof String JavaDoc) {
32             fVariableString= (String JavaDoc)o;
33         } else if (o instanceof IAntClasspathEntry) {
34             fEntry= (IAntClasspathEntry)o;
35         }
36     }
37     
38     /* (non-Javadoc)
39      * @see java.lang.Object#equals(java.lang.Object)
40      */

41     public boolean equals(Object JavaDoc obj) {
42         if (obj instanceof IAntClasspathEntry) {
43             IAntClasspathEntry other= (IAntClasspathEntry)obj;
44             return other.getLabel().equals(getLabel());
45         }
46         return false;
47         
48     }
49
50     /* (non-Javadoc)
51      * @see java.lang.Object#hashCode()
52      */

53     public int hashCode() {
54         return getLabel().hashCode();
55     }
56
57     /* (non-Javadoc)
58      * @see java.lang.Object#toString()
59      */

60     public String JavaDoc toString() {
61         if (fEntry != null) {
62             return fEntry.getLabel();
63         }
64         if (getURL() != null) {
65             return getURL().getFile();
66         }
67
68         return getVariableString();
69     }
70     
71     protected URL JavaDoc getURL() {
72         return fUrl;
73     }
74     
75     protected String JavaDoc getVariableString() {
76         return fVariableString;
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.ant.core.IAntClasspathEntry#getLabel()
81      */

82     public String JavaDoc getLabel() {
83         if (fEntry == null) {
84             return toString();
85         }
86         return fEntry.getLabel();
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.ant.core.IAntClasspathEntry#getEntryURL()
91      */

92     public URL JavaDoc getEntryURL() {
93         if (fEntry != null) {
94             return fEntry.getEntryURL();
95         }
96         if (fUrl != null) {
97             return fUrl;
98         }
99             
100         try {
101             String JavaDoc expanded = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fVariableString);
102             return new URL JavaDoc("file:" + expanded); //$NON-NLS-1$
103
} catch (CoreException e) {
104             AntUIPlugin.log(e);
105         } catch (MalformedURLException JavaDoc e) {
106             AntUIPlugin.log(e);
107         }
108         return null;
109     }
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.ant.core.IAntClasspathEntry#isEclipseRuntimeRequired()
113      */

114     public boolean isEclipseRuntimeRequired() {
115         if (fEntry == null) {
116             return super.isEclipseRuntimeRequired();
117         }
118         return fEntry.isEclipseRuntimeRequired();
119     }
120 }
121
Popular Tags