1 11 package org.eclipse.jdt.internal.debug.ui.jres; 12 13 import java.net.URL ; 14 import java.text.MessageFormat ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; 22 import org.eclipse.jdt.launching.LibraryLocation; 23 24 25 29 public final class LibraryStandin { 30 private IPath fSystemLibrary; 31 private IPath fSystemLibrarySource; 32 private IPath fPackageRootPath; 33 private URL fJavadocLocation; 34 35 38 public LibraryStandin(LibraryLocation libraryLocation) { 39 fSystemLibrary= libraryLocation.getSystemLibraryPath(); 40 setSystemLibrarySourcePath(libraryLocation.getSystemLibrarySourcePath()); 41 setPackageRootPath(libraryLocation.getPackageRootPath()); 42 setJavadocLocation(libraryLocation.getJavadocLocation()); 43 } 44 45 50 public IPath getSystemLibraryPath() { 51 return fSystemLibrary; 52 } 53 54 59 public IPath getSystemLibrarySourcePath() { 60 return fSystemLibrarySource; 61 } 62 63 68 void setSystemLibrarySourcePath(IPath path) { 69 fSystemLibrarySource = path; 70 } 71 72 77 public IPath getPackageRootPath() { 78 return fPackageRootPath; 79 } 80 81 86 void setPackageRootPath(IPath path) { 87 fPackageRootPath = path; 88 } 89 90 93 public boolean equals(Object obj) { 94 if (obj instanceof LibraryStandin) { 95 LibraryStandin lib = (LibraryStandin)obj; 96 return getSystemLibraryPath().equals(lib.getSystemLibraryPath()) 97 && equals(getSystemLibrarySourcePath(), lib.getSystemLibrarySourcePath()) 98 && equals(getPackageRootPath(), lib.getPackageRootPath()) 99 && equalsOrNull(getJavadocLocation(), lib.getJavadocLocation()); 100 } 101 return false; 102 } 103 104 107 public int hashCode() { 108 return getSystemLibraryPath().hashCode(); 109 } 110 111 117 protected boolean equals(IPath path1, IPath path2) { 118 return equalsOrNull(path1, path2); 119 } 120 121 128 private boolean equalsOrNull(Object o1, Object o2) { 129 if (o1 == null) { 130 return o2 == null; 131 } 132 if (o2 == null) { 133 return false; 134 } 135 return o1.equals(o2); 136 } 137 138 145 public URL getJavadocLocation() { 146 return fJavadocLocation; 147 } 148 149 155 void setJavadocLocation(URL url) { 156 fJavadocLocation = url; 157 } 158 159 164 LibraryLocation toLibraryLocation() { 165 return new LibraryLocation(getSystemLibraryPath(), getSystemLibrarySourcePath(), getPackageRootPath(), getJavadocLocation()); 166 } 167 168 173 IStatus validate() { 174 if (!getSystemLibraryPath().toFile().exists()) { 175 return new Status(IStatus.ERROR, IJavaDebugUIConstants.PLUGIN_ID, IJavaDebugUIConstants.INTERNAL_ERROR, 176 MessageFormat.format(JREMessages.LibraryStandin_0, new String []{getSystemLibraryPath().toOSString()}), null); 177 } 178 IPath path = getSystemLibrarySourcePath(); 179 if (!path.isEmpty()) { 180 if (!path.toFile().exists()) { 181 IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path); 183 if (!resource.exists()) { 184 return new Status(IStatus.ERROR, IJavaDebugUIConstants.PLUGIN_ID, IJavaDebugUIConstants.INTERNAL_ERROR, 185 MessageFormat.format(JREMessages.LibraryStandin_1, new String []{path.toOSString()}), null); 186 } 187 } 188 } 189 return Status.OK_STATUS; 190 } 191 192 } 193 | Popular Tags |