KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > batch > ClasspathSourceJar


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.compiler.batch;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.util.zip.ZipEntry JavaDoc;
16
17 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
18 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
19 import org.eclipse.jdt.internal.compiler.util.Util;
20
21 public class ClasspathSourceJar extends ClasspathJar {
22     private String JavaDoc encoding;
23
24     public ClasspathSourceJar(File JavaDoc file, boolean closeZipFileAtEnd,
25             AccessRuleSet accessRuleSet, String JavaDoc encoding,
26             String JavaDoc destinationPath) {
27         super(file, closeZipFileAtEnd, accessRuleSet, destinationPath);
28         this.encoding = encoding;
29     }
30
31     public NameEnvironmentAnswer findClass(char[] typeName, String JavaDoc qualifiedPackageName, String JavaDoc qualifiedBinaryFileName, boolean asBinaryOnly) {
32         if (!isPackage(qualifiedPackageName))
33             return null; // most common case
34

35         ZipEntry JavaDoc sourceEntry = this.zipFile.getEntry(qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java);
36         if (sourceEntry != null) {
37             try {
38                 return new NameEnvironmentAnswer(
39                         new CompilationUnit(
40                                 Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry),
41                                         -1, this.encoding),
42                         qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java,
43                         this.encoding, this.destinationPath),
44                         fetchAccessRestriction(qualifiedBinaryFileName));
45             } catch (IOException JavaDoc e) {
46                 // treat as if source file is missing
47
}
48         }
49         return null;
50     }
51     public NameEnvironmentAnswer findClass(char[] typeName, String JavaDoc qualifiedPackageName, String JavaDoc qualifiedBinaryFileName) {
52         return findClass(typeName, qualifiedPackageName, qualifiedBinaryFileName, false);
53     }
54 }
55
Popular Tags