Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2011 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.core;
 
 import java.net.URL;
 import java.util.*;
 
 import  org.eclipse.core.resources.IResource;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IPath;
 import  org.eclipse.core.runtime.IStatus;
A package fragment root that corresponds to a .jar or .zip.

NOTE: The only visible entries from a .jar or .zip package fragment root are .class files.

NOTE: A jar package fragment root may or may not have an associated resource.

See also:
org.eclipse.jdt.core.IPackageFragmentRoot
org.eclipse.jdt.internal.core.JarPackageFragmentRootInfo
 
 public class JarPackageFragmentRoot extends PackageFragmentRoot {
 
 	private final static ArrayList EMPTY_LIST = new ArrayList();

The path to the jar file (a workspace relative path if the jar is internal, or an OS path if the jar is external)
 
 	protected final IPath jarPath;

Constructs a package fragment root which is the root of the Java package directory hierarchy based on a JAR file that is not contained in a IJavaProject and does not have an associated IResource.
 
 	protected JarPackageFragmentRoot(IPath externalJarPathJavaProject project) {
 		super(nullproject);
 		this. = externalJarPath;
 	}
Constructs a package fragment root which is the root of the Java package directory hierarchy based on a JAR file.
 
 	protected JarPackageFragmentRoot(IResource resourceJavaProject project) {
 		super(resourceproject);
 		this. = resource.getFullPath();
 	}

Compute the package fragment children of this package fragment root. These are all of the directory zip entries, and any directories implied by the path of class files contained in the jar of this package fragment root.
 
 	protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResourcethrows JavaModelException {
 		IJavaElement[] children;
 		ZipFile jar = null;
 		try {
 			IJavaProject project = getJavaProject();
 			String sourceLevel = project.getOption(.true);
 			String compliance = project.getOption(.true);
 			jar = getJar();
 
 			// always create the default package
 			rawPackageInfo.put(.new ArrayList[] {  });
 
 			for (Enumeration ejar.entries(); e.hasMoreElements();) {
 				ZipEntry member= (ZipEntrye.nextElement();
 				initRawPackageInfo(rawPackageInfomember.getName(), member.isDirectory(), sourceLevelcompliance);
 			}
 
 			// loop through all of referenced packages, creating package fragments if necessary
 			// and cache the entry names in the rawPackageInfo table
 			children = new IJavaElement[rawPackageInfo.size()];
 			int index = 0;
 			for (int i = 0, length = rawPackageInfo.keyTable.lengthi < lengthi++) {
 				String[] pkgName = (String[]) rawPackageInfo.keyTable[i];
 				if (pkgName == nullcontinue;
 				children[index++] = getPackageFragment(pkgName);
 			}
 		} catch (CoreException e) {
			if (e.getCause() instanceof ZipException) {
				// not a ZIP archive, leave the children empty
				Util.log(IStatus.ERROR, "Invalid ZIP archive: " + toStringWithAncestors()); //$NON-NLS-1$
				children = NO_ELEMENTS;
else if (e instanceof JavaModelException) {
else {
				throw new JavaModelException(e);
			}
finally {
			JavaModelManager.getJavaModelManager().closeZipFile(jar);
		}
		info.setChildren(children);
		((JarPackageFragmentRootInfoinfo). = rawPackageInfo;
		return true;
	}
Returns a new element info for this element.
	protected Object createElementInfo() {
	}
A Jar is always K_BINARY.
	protected int determineKind(IResource underlyingResource) {
	}
Returns true if this handle represents the same jar as the given handle. Two jars are equal if they share the same zip file.

See also:
Object.equals
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o instanceof JarPackageFragmentRoot) {
			return this..equals(other.jarPath);
		}
		return false;
	}
	public String getElementName() {
		return this..lastSegment();
	}
Returns the underlying ZipFile for this Jar package fragment root.

Throws:
CoreException if an error occurs accessing the jar
	public ZipFile getJar() throws CoreException {
		return JavaModelManager.getJavaModelManager().getZipFile(getPath());
	}

See also:
IPackageFragmentRoot
	public int getKind() {
	}
	}
Returns an array of non-java resources contained in the receiver.
		// We want to show non java resources of the default package at the root (see PR #1G58NB8)
		int length = defaultPkgResources.length;
		if (length == 0)
			return defaultPkgResources;
		Object[] nonJavaResources = new Object[length];
		for (int i = 0; i < lengthi++) {
			JarEntryResource nonJavaResource = (JarEntryResourcedefaultPkgResources[i];
			nonJavaResources[i] = nonJavaResource.clone(this);
		}
		return nonJavaResources;
	}
		return new JarPackageFragment(thispkgName);
	}
	public IPath internalPath() {
		if (isExternal()) {
			return this.;
else {
			return super.internalPath();
		}
	}
	public IResource resource(PackageFragmentRoot root) {
		if (this. == null) {
			// external jar
			return null;
		}
		return super.resource(root);
	}


See also:
IJavaElement
	public IResource getUnderlyingResource() throws JavaModelException {
		if (isExternal()) {
			if (!exists()) throw newNotPresentException();
			return null;
else {
			return super.getUnderlyingResource();
		}
	}
	public int hashCode() {
		return this..hashCode();
	}
	private void initRawPackageInfo(HashtableOfArrayToObject rawPackageInfoString entryNameboolean isDirectoryString sourceLevelString compliance) {
		int lastSeparator = isDirectory ? entryName.length()-1 : entryName.lastIndexOf('/');
		String[] pkgName = Util.splitOn('/'entryName, 0, lastSeparator);
		String[] existing = null;
		int length = pkgName.length;
		int existingLength = length;
		while (existingLength >= 0) {
			existing = (String[]) rawPackageInfo.getKey(pkgNameexistingLength);
			if (existing != nullbreak;
			existingLength--;
		}
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
		for (int i = existingLengthi < lengthi++) {
			if (Util.isValidFolderNameForPackage(pkgName[i], sourceLevelcompliance)) {
				System.arraycopy(existing, 0, existing = new String[i+1], 0, i);
				existing[i] = manager.intern(pkgName[i]);
				rawPackageInfo.put(existingnew ArrayList[] {  });
else {
				// non-Java resource folder
				if (!isDirectory) {
					ArrayList[] children = (ArrayList[]) rawPackageInfo.get(existing);
					if (children[1/*NON_JAVA*/] == children[1/*NON_JAVA*/] = new ArrayList();
					children[1/*NON_JAVA*/].add(entryName);
				}
				return;
			}
		}
		if (isDirectory)
			return;
		// add classfile info amongst children
		ArrayList[] children = (ArrayList[]) rawPackageInfo.get(pkgName);
		if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
			if (children[0/*JAVA*/] == children[0/*JAVA*/] = new ArrayList();
			String nameWithoutExtension = entryName.substring(lastSeparator + 1, entryName.length() - 6);
			children[0/*JAVA*/].add(nameWithoutExtension);
else {
			if (children[1/*NON_JAVA*/] == children[1/*NON_JAVA*/] = new ArrayList();
			children[1/*NON_JAVA*/].add(entryName);
		}
	}

See also:
IPackageFragmentRoot
	public boolean isArchive() {
		return true;
	}

See also:
IPackageFragmentRoot
	public boolean isExternal() {
		return resource() == null;
	}
Jars and jar entries are all read only
	public boolean isReadOnly() {
		return true;
	}

Returns whether the corresponding resource or associated file exists
	protected boolean resourceExists(IResource underlyingResource) {
		if (underlyingResource == null) {
			return
					getPath()/*don't make the path relative as this is an external archive*/,
					true/*check existence*/) != null;
else {
			return super.resourceExists(underlyingResource);
		}
	}
	protected void toStringAncestors(StringBuffer buffer) {
		if (isExternal())
			// don't show project as it is irrelevant for external jar files.
			// also see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146615
			return;
		super.toStringAncestors(buffer);
	}
	public URL getIndexPath() {
		try {
			if (entry != nullreturn ((ClasspathEntry)entry).getLibraryIndexLocation();	
catch (JavaModelException e) {
			// ignore exception
		}
		return null;
	}
New to GrepCode? Check out our FAQ X