1 11 package org.eclipse.jdt.internal.core; 12 13 import java.util.zip.ZipFile ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.core.runtime.PlatformObject; 19 import org.eclipse.jdt.core.IJarEntryResource; 20 import org.eclipse.jdt.core.IPackageFragment; 21 import org.eclipse.jdt.core.IPackageFragmentRoot; 22 import org.eclipse.jdt.internal.core.util.Util; 23 24 public abstract class JarEntryResource extends PlatformObject implements IJarEntryResource { 25 26 protected Object parent; 27 protected String simpleName; 28 29 public JarEntryResource(String simpleName) { 30 this.simpleName = simpleName; 31 } 32 33 public abstract JarEntryResource clone(Object newParent); 34 35 public boolean equals(Object obj) { 36 if (! (obj instanceof JarEntryResource)) 37 return false; 38 JarEntryResource other = (JarEntryResource) obj; 39 return this.parent.equals(other.parent) && this.simpleName.equals(other.simpleName); 40 } 41 42 protected String getEntryName() { 43 String parentEntryName; 44 if (this.parent instanceof IPackageFragment) { 45 String elementName = ((IPackageFragment) this.parent).getElementName(); 46 parentEntryName = elementName.length() == 0 ? "" : elementName .replace('.', '/') + '/'; } else if (this.parent instanceof IPackageFragmentRoot) { 48 parentEntryName = ""; } else { 50 parentEntryName = ((JarEntryDirectory) this.parent).getEntryName() + '/'; 51 } 52 return parentEntryName + this.simpleName; 53 } 54 55 public IPath getFullPath() { 56 return new Path(getEntryName()).makeAbsolute(); 57 } 58 59 public String getName() { 60 return this.simpleName; 61 } 62 63 public Object getParent() { 64 return this.parent; 65 } 66 67 public IPackageFragmentRoot getPackageFragmentRoot() { 68 if (this.parent instanceof IPackageFragment) { 69 return (IPackageFragmentRoot) ((IPackageFragment) this.parent).getParent(); 70 } else if (this.parent instanceof IPackageFragmentRoot) { 71 return (IPackageFragmentRoot) this.parent; 72 } else { 73 return ((JarEntryDirectory) this.parent).getPackageFragmentRoot(); 74 } 75 } 76 77 protected ZipFile getZipFile() throws CoreException { 78 if (this.parent instanceof IPackageFragment) { 79 JarPackageFragmentRoot root = (JarPackageFragmentRoot) ((IPackageFragment) this.parent).getParent(); 80 return root.getJar(); 81 } else if (this.parent instanceof JarPackageFragmentRoot) { 82 return ((JarPackageFragmentRoot) this.parent).getJar(); 83 } else 84 return ((JarEntryDirectory) this.parent).getZipFile(); 85 } 86 87 public int hashCode() { 88 return Util.combineHashCodes(this.simpleName.hashCode(), this.parent.hashCode()); 89 } 90 91 public boolean isReadOnly() { 92 return true; 93 } 94 95 public void setParent(Object parent) { 96 this.parent = parent; 97 } 98 } 99 | Popular Tags |