KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > core > sourcelookup > containers > ArchiveSourceContainer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.debug.core.sourcelookup.containers;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
17 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
18
19 /**
20  * Archive source container for an archive in the workspace. Returns instances
21  * of <code>ZipEntryStorage</code> as source elements.
22  * <p>
23  * Clients may instantiate this class. This class is not intended to
24  * be subclassed.
25  * </p>
26  * @since 3.0
27  */

28 public class ArchiveSourceContainer extends AbstractSourceContainer {
29     
30     private IFile fFile;
31     private boolean fDetectRoot;
32     private ExternalArchiveSourceContainer fDelegateContainer;
33     
34     /**
35      * Unique identifier for the archive source container type
36      * (value <code>org.eclipse.debug.core.containerType.archive</code>).
37      */

38     public static final String JavaDoc TYPE_ID = DebugPlugin.getUniqueIdentifier() + ".containerType.archive"; //$NON-NLS-1$
39

40     /**
41      * Creates an archive source container on the given file.
42      *
43      * @param archive archive in the workspace
44      * @param detectRootPath whether a root path should be detected. When
45      * <code>true</code>, searching is performed relative to a root path
46      * within the archive based on fully qualified file names. The root
47      * path is automatically determined when the first successful search
48      * is performed. For example, when searching for a file named
49      * <code>a/b/c.d</code>, and an entry in the archive named
50      * <code>r/a/b/c.d</code> exists, the root path is set to <code>r</code>.
51      * From that point on, searching is performed relative to <code>r</code>.
52      * When <code>false</code>, searching is performed by
53      * matching file names as suffixes to the entries in the archive.
54      */

55     public ArchiveSourceContainer(IFile archive, boolean detectRootPath) {
56         fFile = archive;
57         fDetectRoot = detectRootPath;
58         if (archive.exists() && archive.getLocation() != null) {
59             fDelegateContainer = new ExternalArchiveSourceContainer(archive.getLocation().toOSString(), detectRootPath);
60         }
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
65      */

66     public String JavaDoc getName() {
67         return fFile.getName();
68     }
69     
70     /**
71      * Returns the associated file in the workspace.
72      *
73      * @return associated file in the workspace
74      */

75     public IFile getFile() {
76         return fFile;
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
81      */

82     public ISourceContainerType getType() {
83         return getSourceContainerType(TYPE_ID);
84     }
85     
86     /* (non-Javadoc)
87      * @see java.lang.Object#equals(java.lang.Object)
88      */

89     public boolean equals(Object JavaDoc obj) {
90         return obj instanceof ArchiveSourceContainer &&
91             ((ArchiveSourceContainer)obj).getName().equals(getName());
92     }
93     
94     /* (non-Javadoc)
95      * @see java.lang.Object#hashCode()
96      */

97     public int hashCode() {
98         return getName().hashCode();
99     }
100
101     /* (non-Javadoc)
102      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
103      */

104     public Object JavaDoc[] findSourceElements(String JavaDoc name) throws CoreException {
105         ExternalArchiveSourceContainer container = getDelegateContainer();
106         if (container != null) {
107             return container.findSourceElements(name);
108         }
109         return EMPTY;
110     }
111     
112     /**
113      * Returns the underlying external archive source container.
114      *
115      * @return underlying external archive source container
116      * @since 3.0.1.1
117      */

118     private ExternalArchiveSourceContainer getDelegateContainer() {
119         return fDelegateContainer;
120     }
121     /* (non-Javadoc)
122      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#init(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
123      */

124     public void init(ISourceLookupDirector director) {
125         super.init(director);
126         if (fDelegateContainer != null) {
127             fDelegateContainer.init(director);
128         }
129     }
130     /* (non-Javadoc)
131      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#dispose()
132      */

133     public void dispose() {
134         super.dispose();
135         if (fDelegateContainer != null) {
136             fDelegateContainer.dispose();
137         }
138     }
139     
140     /**
141      * Returns whether root paths are automatically detected in this
142      * archive source container.
143      *
144      * @return whether root paths are automatically detected in this
145      * archive source container
146      * @since 3.0.1.1
147      */

148     public boolean isDetectRoot() {
149         return fDetectRoot;
150     }
151 }
152
Popular Tags