KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > JarEntryResource


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.core;
12
13 import java.util.zip.ZipFile JavaDoc;
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 JavaDoc parent;
27     protected String JavaDoc simpleName;
28
29     public JarEntryResource(String JavaDoc simpleName) {
30         this.simpleName = simpleName;
31     }
32     
33     public abstract JarEntryResource clone(Object JavaDoc newParent);
34
35     public boolean equals(Object JavaDoc 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 JavaDoc getEntryName() {
43         String JavaDoc parentEntryName;
44         if (this.parent instanceof IPackageFragment) {
45             String JavaDoc elementName = ((IPackageFragment) this.parent).getElementName();
46             parentEntryName = elementName.length() == 0 ? "" : elementName .replace('.', '/') + '/'; //$NON-NLS-1$
47
} else if (this.parent instanceof IPackageFragmentRoot) {
48             parentEntryName = ""; //$NON-NLS-1$
49
} 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 JavaDoc getName() {
60         return this.simpleName;
61     }
62     
63     public Object JavaDoc 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 JavaDoc 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 JavaDoc parent) {
96         this.parent = parent;
97     }
98 }
99
Popular Tags