KickJava   Java API By Example, From Geeks To Geeks.

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


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.launching;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.jdt.internal.launching.LaunchingMessages;
17
18
19 /**
20  * The location of a library (for example rt.jar).
21  * <p>
22  * Clients may instantiate this class; it is not intended to be subclassed.
23  * </p>
24  */

25 public final class LibraryLocation {
26     private IPath fSystemLibrary;
27     private IPath fSystemLibrarySource;
28     private IPath fPackageRootPath;
29     private URL JavaDoc fJavadocLocation;
30     
31     /**
32      * Creates a new library location.
33      *
34      * @param libraryPath The location of the JAR containing java.lang.Object
35      * Must not be <code>null</code>.
36      * @param sourcePath The location of the zip file containing the sources for <code>library</code>
37      * Must not be <code>null</code> (Use Path.EMPTY instead)
38      * @param packageRoot The path inside the <code>source</code> zip file where packages names
39      * begin. If the source for java.lang.Object source is found at
40      * "src/java/lang/Object.java" in the zip file, the
41      * packageRoot should be "src"
42      * Must not be <code>null</code>. (Use Path.EMPTY or IPath.ROOT)
43      * @throws IllegalArgumentException If the library path is <code>null</code>.
44      */

45     public LibraryLocation(IPath libraryPath, IPath sourcePath, IPath packageRoot) {
46         this(libraryPath, sourcePath, packageRoot, null);
47     }
48
49     /**
50      * Creates a new library location.
51      *
52      * @param libraryPath The location of the JAR containing java.lang.Object
53      * Must not be <code>null</code>.
54      * @param sourcePath The location of the zip file containing the sources for <code>library</code>
55      * Must not be <code>null</code> (Use Path.EMPTY instead)
56      * @param packageRoot The path inside the <code>source</code> zip file where packages names
57      * begin. If the source for java.lang.Object source is found at
58      * "src/java/lang/Object.java" in the zip file, the
59      * packageRoot should be "src"
60      * Must not be <code>null</code>. (Use Path.EMPTY or IPath.ROOT)
61      * @param javadocLocation The location of the javadoc for <code>library</code>
62      * @throws IllegalArgumentException If the library path is <code>null</code>.
63      * @since 3.1
64      */

65     public LibraryLocation(IPath libraryPath, IPath sourcePath, IPath packageRoot, URL JavaDoc javadocLocation) {
66         if (libraryPath == null)
67             throw new IllegalArgumentException JavaDoc(LaunchingMessages.libraryLocation_assert_libraryNotNull);
68
69         fSystemLibrary= libraryPath;
70         fSystemLibrarySource= sourcePath;
71         fPackageRootPath= packageRoot;
72         fJavadocLocation= javadocLocation;
73     }
74         
75     /**
76      * Returns the JRE library jar location.
77      *
78      * @return The JRE library jar location.
79      */

80     public IPath getSystemLibraryPath() {
81         return fSystemLibrary;
82     }
83     
84     /**
85      * Returns the JRE library source zip location.
86      *
87      * @return The JRE library source zip location.
88      */

89     public IPath getSystemLibrarySourcePath() {
90         return fSystemLibrarySource;
91     }
92     
93     /**
94      * Returns the path to the default package in the sources zip file
95      *
96      * @return The path to the default package in the sources zip file.
97      */

98     public IPath getPackageRootPath() {
99         return fPackageRootPath;
100     }
101     /* (non-Javadoc)
102      * @see java.lang.Object#equals(java.lang.Object)
103      */

104     public boolean equals(Object JavaDoc obj) {
105         if (obj instanceof LibraryLocation) {
106             LibraryLocation lib = (LibraryLocation)obj;
107             return getSystemLibraryPath().equals(lib.getSystemLibraryPath())
108                 && equals(getSystemLibrarySourcePath(), lib.getSystemLibrarySourcePath())
109                 && equals(getPackageRootPath(), lib.getPackageRootPath())
110                 && equalsOrNull(getJavadocLocation(), lib.getJavadocLocation());
111         }
112         return false;
113     }
114
115     /* (non-Javadoc)
116      * @see java.lang.Object#hashCode()
117      */

118     public int hashCode() {
119         return getSystemLibraryPath().hashCode();
120     }
121     
122     /**
123      * Returns whether the given paths are equal - either may be <code>null</code>.
124      * @param path1 path to be compared
125      * @param path2 path to be compared
126      * @return whether the given paths are equal
127      */

128     protected boolean equals(IPath path1, IPath path2) {
129         return equalsOrNull(path1, path2);
130     }
131     
132     /**
133      * Returns whether the given objects are equal - either may be <code>null</code>.
134      * @param o1 object to be compared
135      * @param o2 object to be compared
136      * @return whether the given objects are equal or both null
137      * @since 3.1
138      */

139     private boolean equalsOrNull(Object JavaDoc o1, Object JavaDoc o2) {
140         if (o1 == null) {
141             return o2 == null;
142         }
143         if (o2 == null) {
144             return false;
145         }
146         return o1.equals(o2);
147     }
148
149     /**
150      * Returns the Javadoc location associated with this Library location.
151      *
152      * @return a url pointing to the Javadoc location associated with
153      * this Library location, or <code>null</code> if none
154      * @since 3.1
155      */

156     public URL JavaDoc getJavadocLocation() {
157         return fJavadocLocation;
158     }
159     
160 }
161
Popular Tags