// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   ClasspathEntry.java

package com.symantec.itools.lang;

import com.symantec.itools.io.Directory;
import com.symantec.itools.io.FileSystem;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

// Referenced classes of package com.symantec.itools.lang:
//            Debug, Classpath

public class ClasspathEntry
{

    public ClasspathEntry(String s)
    {
        File file = new File(s);
        isFile = file.isFile();
        if(file.exists())
        {
            name = FileSystem.getCanonicalPath(file, true);
            return;
        } else
        {
            name = file.getName();
            return;
        }
    }

    public String getName()
    {
        return name;
    }

    public boolean isFile()
    {
        return isFile;
    }

    public boolean isDirectory()
    {
        return !isFile;
    }

    public boolean equals(Object obj)
    {
        if(obj instanceof ClasspathEntry)
            return ((ClasspathEntry)obj).name.equals(name);
        else
            return false;
    }

    public int hashCode()
    {
        return name.hashCode();
    }

    public String toString()
    {
        return name + " " + (isFile ? "file" : "directory");
    }

    public Hashtable load(Classpath classpath)
    {
        Hashtable hashtable = new Hashtable();
        try
        {
            if(isFile)
            {
                ZipFile zipfile = new ZipFile(name);
                for(Enumeration enumeration = zipfile.entries(); enumeration.hasMoreElements();)
                {
                    ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
                    if(!zipentry.isDirectory())
                        hashtable.put(zipentry.getName(), this);
                }

            } else
            {
                Directory directory = new Directory(name);
                String as[] = directory.listFiles(true);
                for(int i = 0; i < as.length; i++);
            }
        }
        catch(IOException _ex) { }
        return hashtable;
    }

    public boolean find(String s)
    {
        if(isFile)
            try
            {
                return getZipFile(name).getEntry(s) != null;
            }
            catch(IOException _ex)
            {
                return false;
            }
        else
            return (new File(FileSystem.getCanonicalPath(name, true) + s.replace('/', File.separatorChar))).exists();
    }

    protected ZipFile getZipFile(String s)
        throws IOException
    {
        if(zipFileHandle == null)
            zipFileHandle = new ZipFile(s);
        return zipFileHandle;
    }

    public void cleanup()
    {
        if(zipFileHandle != null)
        {
            try
            {
                zipFileHandle.close();
            }
            catch(IOException ioexception)
            {
                Debug.logException(ioexception);
            }
            zipFileHandle = null;
        }
    }

    protected void finalize()
        throws Throwable
    {
        super.finalize();
        cleanup();
    }

    protected boolean isFile;
    protected String name;
    private ZipFile zipFileHandle;
}
