<s> package org . eclipse . jdt . internal . core ; import java . util . * ; import java . util . zip . ZipEntry ; import java . util . zip . ZipException ; import java . util . zip . ZipFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . core . util . HashtableOfArrayToObject ; import org . eclipse . jdt . internal . core . util . Util ; public class JarPackageFragmentRoot extends PackageFragmentRoot { private final static ArrayList EMPTY_LIST = new ArrayList ( ) ; protected final IPath jarPath ; protected JarPackageFragmentRoot ( IPath externalJarPath , JavaProject project ) { super ( null , project ) ; this . jarPath = externalJarPath ; } protected JarPackageFragmentRoot ( IResource resource , JavaProject project ) { super ( resource , project ) ; this . jarPath = resource . getFullPath ( ) ; } protected boolean computeChildren ( OpenableElementInfo info , IResource underlyingResource ) throws JavaModelException { HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject ( ) ; IJavaElement [ ] children ; ZipFile jar = null ; try { IJavaProject project = getJavaProject ( ) ; String sourceLevel = project . getOption ( JavaCore . COMPILER_SOURCE , true ) ; String compliance = project . getOption ( JavaCore . COMPILER_COMPLIANCE , true ) ; jar = getJar ( ) ; rawPackageInfo . put ( CharOperation . NO_STRINGS , new ArrayList [ ] { EMPTY_LIST , EMPTY_LIST } ) ; for ( Enumeration e = jar . entries ( ) ; e . hasMoreElements ( ) ; ) { ZipEntry member = ( ZipEntry ) e . nextElement ( ) ; initRawPackageInfo ( rawPackageInfo , member . getName ( ) , member . isDirectory ( ) , sourceLevel , compliance ) ; } children = new IJavaElement [ rawPackageInfo . size ( ) ] ; int index = 0 ; for ( int i = 0 , length = rawPackageInfo . keyTable . length ; i < length ; i ++ ) { String [ ] pkgName = ( String [ ] ) rawPackageInfo . keyTable [ i ] ; if ( pkgName == null ) continue ; children [ index ++ ] = getPackageFragment ( pkgName ) ; } } catch ( CoreException e ) { if ( e . getCause ( ) instanceof ZipException ) { Util . log ( e , "" + toStringWithAncestors ( ) ) ; children = NO_ELEMENTS ; } else if ( e instanceof JavaModelException ) { throw ( JavaModelException ) e ; } else { throw new JavaModelException ( e ) ; } } finally { JavaModelManager . getJavaModelManager ( ) . closeZipFile ( jar ) ; } info . setChildren ( children ) ; ( ( JarPackageFragmentRootInfo ) info ) . rawPackageInfo = rawPackageInfo ; return true ; } protected Object createElementInfo ( ) { return new JarPackageFragmentRootInfo ( ) ; } protected int determineKind ( IResource underlyingResource ) { return IPackageFragmentRoot . K_BINARY ; } public boolean equals ( Object o ) { if ( this == o ) return true ; if ( o instanceof JarPackageFragmentRoot ) { JarPackageFragmentRoot other = ( JarPackageFragmentRoot ) o ; return this . jarPath . equals ( other . jarPath ) ; } return false ; } public String getElementName ( ) { return this . jarPath . lastSegment ( ) ; } public ZipFile getJar ( ) throws CoreException { return JavaModelManager . getJavaModelManager ( ) . getZipFile ( getPath ( ) ) ; } public int getKind ( ) { return IPackageFragmentRoot . K_BINARY ; } int internalKind ( ) throws JavaModelException { return IPackageFragmentRoot . K_BINARY ; } public Object [ ] getNonJavaResources ( ) throws JavaModelException { Object [ ] defaultPkgResources = ( ( JarPackageFragment ) getPackageFragment ( CharOperation . NO_STRINGS ) ) . storedNonJavaResources ( ) ; int length = defaultPkgResources . length ; if ( length == 0 ) return defaultPkgResources ; Object [ ] nonJavaResources = new Object [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { JarEntryResource nonJavaResource = ( JarEntryResource ) defaultPkgResources [ i ] ; nonJavaResources [ i ] = nonJavaResource . clone ( this ) ; } return nonJavaResources ; } public PackageFragment getPackageFragment ( String [ ] pkgName ) { return new JarPackageFragment ( this , pkgName ) ; } public IPath internalPath ( ) { if ( isExternal ( ) ) { return this . jarPath ; } else { return super . internalPath ( ) ; } } public IResource resource ( PackageFragmentRoot root ) { if ( this . resource == null ) { return null ; } return super . resource ( root ) ; } public IResource getUnderlyingResource ( ) throws JavaModelException { if ( isExternal ( ) ) { if ( ! exists ( ) ) throw newNotPresentException ( ) ; return null ; } else { return super . getUnderlyingResource ( ) ; } } public int hashCode ( ) { return this . jarPath . hashCode ( ) ; } private void initRawPackageInfo ( HashtableOfArrayToObject rawPackageInfo , String entryName , boolean isDirectory , String sourceLevel , String 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 ( pkgName , existingLength ) ; if ( existing != null ) break ; existingLength -- ; } JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; for ( int i = existingLength ; i < length ; i ++ ) { if ( Util . isValidFolderNameForPackage ( pkgName [ i ] , sourceLevel , compliance ) ) { System . arraycopy ( existing , 0 , existing = new String [ i + 1 ] , 0 , i ) ; existing [ i ] = manager . intern ( pkgName [ i ] ) ; rawPackageInfo . put ( existing , new ArrayList [ ] { EMPTY_LIST , EMPTY_LIST } ) ; } else { if ( ! isDirectory ) { ArrayList [ ] children = ( ArrayList [ ] ) rawPackageInfo . get ( existing ) ; if ( children [ 1 ] == EMPTY_LIST ) children [ 1 ] = new ArrayList ( ) ; children [ 1 ] . add ( entryName ) ; } return ; } } if ( isDirectory ) return ; ArrayList [ ] children = ( ArrayList [ ] ) rawPackageInfo . get ( pkgName ) ; if ( org . eclipse . jdt . internal . compiler . util . Util . isClassFileName ( entryName ) ) { if ( children [ 0 ] == EMPTY_LIST ) children [ 0 ] = new ArrayList ( ) ; String nameWithoutExtension = entryName . substring ( lastSeparator + 1 , entryName . length ( ) - 6 ) ; children [ 0 ] . add ( nameWithoutExtension ) ; } else { if ( children [ 1 ] == EMPTY_LIST ) children [ 1 ] = new ArrayList ( ) ; children [ 1 ] . add ( entryName ) ; } } public boolean isArchive ( ) { return true ; } public boolean isExternal ( ) { return resource ( ) == null ; } public boolean isReadOnly ( ) { return true ; } protected boolean resourceExists ( IResource underlyingResource ) { if ( underlyingResource == null ) { return JavaModel . getExternalTarget ( getPath ( ) , true ) != null ; } else { return super . resourceExists ( underlyingResource ) ; } } protected void toStringAncestors ( StringBuffer buffer ) { if ( isExternal ( ) ) return ; super . toStringAncestors ( buffer ) ; } } </s>